From 9fe36aecb105f3d2a45d20dc2641193c7bae02e1 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Fri, 31 Jul 2026 13:49:36 -0500 Subject: [PATCH] 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. --- hermes_state.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/hermes_state.py b/hermes_state.py index 7753ea69f81..a35e5efd6e3 100644 --- a/hermes_state.py +++ b/hermes_state.py @@ -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.