Skip to content

fix(kanban): remove duplicate idx_tasks_session_id from SCHEMA_SQL#28620

Closed
vanhci wants to merge 1 commit into
NousResearch:mainfrom
vanhci:fix/kanban-session-id-v2
Closed

fix(kanban): remove duplicate idx_tasks_session_id from SCHEMA_SQL#28620
vanhci wants to merge 1 commit into
NousResearch:mainfrom
vanhci:fix/kanban-session-id-v2

Conversation

@vanhci

@vanhci vanhci commented May 19, 2026

Copy link
Copy Markdown

Fix: Remove duplicate idx_tasks_session_id from SCHEMA_SQL

Issue: #28617

Root Cause

When the kanban schema gains a new indexed column (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) in connect(), before _migrate_add_optional_columns() gets a chance to add the column.

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

Fix

Remove the CREATE INDEX IF NOT EXISTS idx_tasks_session_id ON tasks(session_id); from SCHEMA_SQL. The migration function _migrate_add_optional_columns() already adds both the column and the index correctly for legacy databases.

This is consistent with how run_id on task_events is handled — the idx_events_run index lives only in the migration function, not in SCHEMA_SQL.

Verification

  • idx_tasks_session_id now only appears once, in _migrate_add_optional_columns() (line ~1176)
  • idx_tasks_session_id no longer appears in SCHEMA_SQL
  • Fresh installs: unaffected (migration runs, creates the index)
  • Legacy installs: migration now runs successfully without crashing

@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 labels May 19, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #28461 — both remove idx_tasks_session_id from SCHEMA_SQL and rely on _migrate_add_optional_columns() to create the index. See also #28562, #28602 (competing fixes for the same issue #28464).

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Thanks @vanhci — closing as duplicate of #28781, which combined all six community PRs that hit this bug on 2026-05-19 into one salvage (merged in 7552e0f). You correctly diagnosed the SCHEMA_SQL-before-migration ordering issue. The salvage extends coverage to all four additive-column indexes (idx_tasks_session_id, idx_tasks_tenant, idx_tasks_idempotency, idx_events_run) and ships a regression test seeding a pre-#16081 + pre-#17805 fixture.

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

3 participants