fix: bot_reset purges orphaned 'you' activity rows (T69)
This commit is contained in:
+11
-2
@@ -48,6 +48,17 @@ def _apply_bot_reset(conn: Connection, e: Event) -> None:
|
||||
"SELECT id FROM chats WHERE host_bot_id = ?", (bot_id,)
|
||||
).fetchall()
|
||||
]
|
||||
# T69: purge orphaned "you" activity rows pointing at containers in this
|
||||
# bot's chats BEFORE the containers/chats themselves are deleted, otherwise
|
||||
# the subqueries find nothing and the FK constraint on activity.container_id
|
||||
# blocks the container delete.
|
||||
conn.execute(
|
||||
"DELETE FROM activity WHERE entity_id = 'you' "
|
||||
"AND container_id IN (SELECT id FROM containers WHERE chat_id IN ("
|
||||
" SELECT id FROM chats WHERE host_bot_id = ?"
|
||||
"))",
|
||||
(bot_id,),
|
||||
)
|
||||
for chat_id in chat_ids:
|
||||
conn.execute("DELETE FROM scenes WHERE chat_id = ?", (chat_id,))
|
||||
conn.execute("DELETE FROM containers WHERE chat_id = ?", (chat_id,))
|
||||
@@ -74,8 +85,6 @@ def _apply_bot_reset(conn: Connection, e: Event) -> None:
|
||||
(bot_id,),
|
||||
)
|
||||
# NOTE: bots row itself is preserved (identity, kickoff_prose intact).
|
||||
# NOTE: "you" activity (entity_id="you") may linger from a deleted chat;
|
||||
# acceptable for v1 — Phase 1.5 cleanup if needed.
|
||||
|
||||
|
||||
def get_bot(conn: Connection, bot_id: str) -> dict | None:
|
||||
|
||||
Reference in New Issue
Block a user