Skip to content

fix(kanban): move session_id index creation from SCHEMA_SQL to migration - #28693

Closed
ticketclosed-wontfix wants to merge 1 commit into
NousResearch:mainfrom
ticketclosed-wontfix:fix/kanban-session-id-index-migration
Closed

fix(kanban): move session_id index creation from SCHEMA_SQL to migration#28693
ticketclosed-wontfix wants to merge 1 commit into
NousResearch:mainfrom
ticketclosed-wontfix:fix/kanban-session-id-index-migration

Conversation

@ticketclosed-wontfix

Copy link
Copy Markdown
Contributor

What

Remove the CREATE INDEX IF NOT EXISTS idx_tasks_session_id ON tasks(session_id) statement from SCHEMA_SQL in hermes_cli/kanban_db.py, and move the index creation into the existing _migrate_add_optional_columns() migration function.

Why

When the kanban schema introduced the session_id column on the tasks table, the CREATE INDEX statement was placed inside SCHEMA_SQL (line 868). On existing databases that predate this column, conn.executescript(SCHEMA_SQL) fails before the column migration code runs:

sqlite3.OperationalError: no such column: session_id

The _migrate_add_optional_columns function already contains the correct logic — it adds the column with ALTER TABLE and then creates the index. However, it is unreachable because conn.executescript(SCHEMA_SQL) crashes first (line 1012 vs line 1013).

Fixes #28617.

How & Tested

  1. pytest tests/hermes_cli/test_kanban_db.py -v — 157 passed, 0 failed.
  2. Verified the test_session_id_index_exists test asserts the index is present on a fresh DB (since the index is now created unconditionally by the migration function).
  3. Verified the test_session_id_filters_listings and test_session_id_compose_with_tenant_filter tests continue to pass (column + index round-tripped through list queries).

Platforms

Tested on Fedora 44 (x86_64), SQLite 3.49.2. The change is SQLite-only, no platform-specific code.

Checklist

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
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #28461. This is the same fix (move idx_tasks_session_id from SCHEMA_SQL to migration) already addressed by #28461, #28562, #28597, and #28620.

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard duplicate This issue or pull request already exists labels May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants