From e6aff6133dee4224abca2b89affa445ff524468c Mon Sep 17 00:00:00 2001 From: "commit-mcgitface[bot]" <3310952+commit-mcgitface[bot]@users.noreply.github.com> Date: Tue, 19 May 2026 22:47:39 +1200 Subject: [PATCH] fix(kanban): move session_id index creation from SCHEMA_SQL to migration When the kanban schema introduced a new indexed column (session_id), the CREATE INDEX statement inside SCHEMA_SQL ran before the migration code that adds the column. On existing databases without the column, SQLite validated the column reference and crashed with: sqlite3.OperationalError: no such column: session_id The _migrate_add_optional_columns function already adds the column and creates the index, but it was never reached because coon_executescript(SCHEMA_SQL) failed first. Fix: remove the index creation from SCHEMA_SQL and let the migration function handle both old and new DBs. The index creation is now unconditional after the optional column add, guarded by IF NOT EXISTS for idempotency. Closes #28617 --- hermes_cli/kanban_db.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hermes_cli/kanban_db.py b/hermes_cli/kanban_db.py index edeae51707b0c..dfba55ff86c41 100644 --- a/hermes_cli/kanban_db.py +++ b/hermes_cli/kanban_db.py @@ -865,8 +865,6 @@ class Event: session_id TEXT ); -CREATE INDEX IF NOT EXISTS idx_tasks_session_id ON tasks(session_id); - CREATE TABLE IF NOT EXISTS task_links ( parent_id TEXT NOT NULL, child_id TEXT NOT NULL, @@ -1174,10 +1172,13 @@ def _migrate_add_optional_columns(conn: sqlite3.Connection) -> None: _add_column_if_missing( conn, "tasks", "session_id", "session_id TEXT" ) - conn.execute( - "CREATE INDEX IF NOT EXISTS idx_tasks_session_id " - "ON tasks(session_id)" - ) + # Create index unconditionally: on new DBs the column already exists from + # SCHEMA_SQL but the index still needs to be created; on legacy DBs this + # runs after the ALTER TABLE ADD COLUMN above. IF NOT EXISTS makes it safe. + conn.execute( + "CREATE INDEX IF NOT EXISTS idx_tasks_session_id " + "ON tasks(session_id)" + ) # task_events gained a run_id column; back-fill it as NULL for # historical events (they predate runs and can't be attributed).