fix(state): reclaim kanban worker rows already on disk

Retag pre-tag `cli` rows whose cwd sits under the board's workspaces
root, gated once per database via state_meta.
This commit is contained in:
Brooklyn Nicholson 2026-07-31 13:49:36 -05:00
parent 1d58e7d231
commit 9fe36aecb1

View file

@ -7748,6 +7748,40 @@ class SessionDB(SessionSearchMixin, SessionSchemaMixin, SessionPortabilityMixin)
)
self._execute_write(_do)
def retag_kanban_worker_sessions(self, workspaces_root: str) -> int:
"""Retag legacy kanban worker rows from ``cli`` to ``kanban``.
Workers used to spawn without ``HERMES_SESSION_SOURCE``, so their runs
landed as untitled ``cli`` rows and the sidebar rendered one per attempt
labeled with the worker's own prompt. New workers tag themselves; this
reclaims the rows already on disk so they drop out of the session lists
too. Identified by cwd under the board's workspaces root — a path only
the dispatcher ever runs a session in.
Runs once per database (``state_meta`` gate) and returns the number of
rows retagged.
"""
if self.get_meta("kanban_worker_source_retagged") == "1":
return 0
prefix = str(workspaces_root).rstrip("/\\")
if not prefix:
return 0
def _do(conn):
cursor = conn.execute(
"UPDATE sessions SET source = 'kanban' "
"WHERE source = 'cli' AND (cwd = ? OR cwd LIKE ? ESCAPE '\\')",
(prefix, prefix.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_") + "/%"),
)
# Read rowcount before set_meta reuses this cursor for its INSERT,
# which would otherwise overwrite it with the meta write's count.
retagged = cursor.rowcount or 0
self.set_meta("kanban_worker_source_retagged", "1", cursor=cursor)
return retagged
return self._execute_write(_do)
def apply_telegram_topic_migration(self) -> None:
"""Create Telegram DM topic-mode tables on explicit /topic opt-in.