Skip to content

The agent that grows with you

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

Brooklyn Nicholson9fe36aecb105
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.