Skip to content

kanban: SCHEMA_SQL crashes on existing databases when new column is added — migration code never reached #28617

@cannonball-me

Description

@cannonball-me

Bug Description

When the kanban schema gains a new indexed column (e.g., session_id in the tasks table), the CREATE INDEX IF NOT EXISTS statement inside SCHEMA_SQL references the new column — but on existing databases, that column doesn't exist yet. SQLite throws OperationalError: no such column: session_id during conn.executescript(SCHEMA_SQL) at connect() line 1012, before _migrate_add_optional_columns() (line 1013) gets a chance to add the column.

The migration code at line 1168-1180 is correct — it adds the column AND the index. But it's dead code because executescript(SCHEMA_SQL) already crashed.

Steps to Reproduce

  1. Run a kanban board on an older hermes-agent version (e.g., May 13 build)
  2. hermes update to a build that added session_id to the kanban schema
  3. The kanban dispatcher fails every tick with sqlite3.OperationalError: no such column: session_id

Expected Behavior

Existing databases migrate cleanly. The _migrate_add_optional_columns() function should handle the column + index addition without SCHEMA_SQL tripping over it first.

Root Cause

hermes_cli/kanban_db.py line 868 inside SCHEMA_SQL:

CREATE INDEX IF NOT EXISTS idx_tasks_session_id ON tasks(session_id);

IF NOT EXISTS only skips if the index exists — it still validates the column reference. On an existing DB without session_id, this fails before the migration code runs.

Proposed Fix

Remove the CREATE INDEX idx_tasks_session_id from SCHEMA_SQL (line 868). The migration function _migrate_add_optional_columns() at lines 1168-1180 already adds both the column and the index correctly:

if "session_id" not in cols:
    _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)"
    )

This is consistent with how run_id on task_events is handled (lines 1182-1190) — the index lives only in the migration function, not in SCHEMA_SQL.

Manual Workaround (for affected users)

sqlite3 ~/.hermes/kanban.db   "ALTER TABLE tasks ADD COLUMN session_id TEXT;    CREATE INDEX IF NOT EXISTS idx_tasks_session_id ON tasks(session_id);"

Environment

  • macOS 26.3.1
  • hermes-agent updated May 19, 2026 (306 + 82 commits)
  • SQLite via Python 3.11.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecomp/pluginsPlugin system and bundled pluginstype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions