The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(kanban): heal base tasks columns a foreign harness omitted before the run backfill
teknium141f9489cf62e
diff --git a/hermes_cli/kanban_db_connect.py b/hermes_cli/kanban_db_connect.pyindex 1bf4f183bfc..8654bb02800 100644--- a/hermes_cli/kanban_db_connect.py+++ b/hermes_cli/kanban_db_connect.py@@ -767,6 +767,23 @@ def init_db(db_path: Optional[Path] = None, *, board: Optional[str] = None) -> Preturn path+# Nullable/defaulted columns of the v1 ``tasks`` CREATE TABLE that external+# harnesses seeding a board with a reduced schema have omitted. Hermes's own+# DBs always carry them, so this is a no-op there; without it a board that+# also has ``task_runs`` fails every ``connect()`` inside+# ``_backfill_legacy_inflight_runs`` ("no such column: claim_lock") — before+# ``_INITIALIZED_PATHS`` caches, so the dispatcher re-raises each tick (#112953).+# DDL must match SCHEMA_SQL exactly.+_BASE_TASK_COLUMNS = (+ ("body", "body TEXT"),+ ("assignee", "assignee TEXT"),+ ("started_at", "started_at INTEGER"),+ ("workspace_kind", "workspace_kind TEXT NOT NULL DEFAULT 'scratch'"),+ ("workspace_path", "workspace_path TEXT"),+ ("claim_lock", "claim_lock TEXT"),+ ("claim_expires", "claim_expires INTEGER"),+)+# Additive ``tasks`` columns in the order legacy DBs receive them (= physical# column order for ``SELECT *`` on migrated boards)._EARLY_TASK_COLUMNS = (@@ -851,7 +868,7 @@ def _table_exists(conn: sqlite3.Connection, table: str) -> bool:def _migrate_add_optional_columns(conn: sqlite3.Connection) -> None:"""Add columns introduced after v1 to legacy DBs (called via ``init_db``)."""cols = _column_names(conn, "tasks")- for name, ddl in _EARLY_TASK_COLUMNS:+ for name, ddl in _BASE_TASK_COLUMNS + _EARLY_TASK_COLUMNS:if name not in cols:_add_column_if_missing(conn, "tasks", name, ddl)diff --git a/tests/hermes_cli/test_kanban_db.py b/tests/hermes_cli/test_kanban_db.pyindex f0a4bb94557..be31d8c0edc 100644--- a/tests/hermes_cli/test_kanban_db.py+++ b/tests/hermes_cli/test_kanban_db.py@@ -1352,6 +1352,42 @@ def test_migrate_add_optional_columns_tolerates_concurrent_migration(kanban_homeconn.close()+def test_connect_heals_reduced_tasks_schema_seeded_by_external_harness(kanban_home):+ """A board whose ``tasks`` table was created by an external harness without+ the base v1 columns (body, workspace_kind, workspace_path, claim_lock,+ claim_expires) but which already has ``task_runs`` must connect: the+ connect-time in-flight backfill SELECTs ``claim_lock`` from ``tasks`` and+ used to raise ``no such column`` on every call (#112953), before+ ``_INITIALIZED_PATHS`` cached anything, so the dispatcher failed every tick.+ """+ db_path = kanban_home / "foreign.db"+ seed = sqlite3.connect(db_path)+ seed.execute(+ "CREATE TABLE tasks (id TEXT PRIMARY KEY, title TEXT NOT NULL, assignee TEXT,"+ " status TEXT NOT NULL, priority INTEGER DEFAULT 0, created_by TEXT,"+ " created_at INTEGER NOT NULL, started_at INTEGER, completed_at INTEGER)"+ )+ seed.execute(kbc._REBUILD_SPECS["task_runs"][0])+ seed.commit()+ seed.close()++ healed = {"body", "workspace_kind", "workspace_path", "claim_lock", "claim_expires"}+ conn = kbc.connect(db_path)+ try:+ cols = {r["name"] for r in conn.execute("PRAGMA table_info(tasks)")}+ assert healed <= cols+ # Healed DDL matches the fresh schema (NOT NULL DEFAULT 'scratch' etc.).+ fresh = sqlite3.connect(":memory:")+ fresh.executescript(kb.SCHEMA_SQL)+ fresh_info = {r[1]: r[2:] for r in fresh.execute("PRAGMA table_info(tasks)")}+ healed_info = {r["name"]: tuple(r)[2:] for r in conn.execute("PRAGMA table_info(tasks)")}+ assert {c: healed_info[c] for c in healed} == {c: fresh_info[c] for c in healed}+ finally:+ conn.close()+ # Second connect (the next dispatcher tick) is a no-op, not a re-raise.+ kbc.connect(db_path).close()++# ---------------------------------------------------------------------------# Dispatcher spawn invocation — _resolve_hermes_argv()#