fix(state): release archived Bot Chat title

This commit is contained in:
KoNit-K
2026-09-14 21:23:43 +08:00
committed by Teknium
parent a654de291a
commit b6207cb590
2 changed files with 28 additions and 1 deletions

View File

@@ -97,7 +97,7 @@ class SessionTitlesMixin:
return 0
if title:
conflict = conn.execute(
"SELECT id FROM sessions WHERE title = ? AND id != ?", (title, session_id),
"SELECT id, archived, hidden FROM sessions WHERE title = ? AND id != ?", (title, session_id),
).fetchone()
if conflict:
conflict_id = conflict["id"]
@@ -105,6 +105,16 @@ class SessionTitlesMixin:
# user, so transfer it onto the tip (uniqueness + lineage kept).
if self._is_compression_ancestor(conn, ancestor_id=conflict_id, descendant_id=session_id):
conn.execute("UPDATE sessions SET title = NULL WHERE id = ?", (conflict_id,))
# A deliberately archived hidden Bot Chat is a retired registry
# entry, not a live identity. Retire its name in the same title
# transaction so a replacement can become the sole canonical row;
# the old session remains archived and otherwise untouched.
elif (title == self.CANONICAL_BOT_CHAT_TITLE and bool(conflict["archived"])
and bool(conflict["hidden"])):
conn.execute(
"UPDATE sessions SET title = NULL, title_source = NULL WHERE id = ?",
(conflict_id,),
)
else:
raise ValueError(f"Title '{title}' is already in use by session {conflict_id}")
# CAS on the values just read (``IS`` is NULL-safe): a concurrent write between