Skip to content

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

Closed
kungunier wants to merge 1 commit into
NousResearch:mainfrom
kungunier:fix/kanban-schema-index-before-migration
Closed

fix(kanban): move session_id index creation from SCHEMA_SQL to migration#28562
kungunier wants to merge 1 commit into
NousResearch:mainfrom
kungunier:fix/kanban-schema-index-before-migration

Conversation

@kungunier

Copy link
Copy Markdown

Problem

When upgrading from an older Hermes version to v0.14.0, existing kanban.db files lack the session_id column. SCHEMA_SQL includes:

CREATE TABLE IF NOT EXISTS tasks (...);
CREATE INDEX IF NOT EXISTS idx_tasks_session_id ON tasks(session_id);  -- 💥

CREATE TABLE IF NOT EXISTS is a no-op on existing tables (old schema, no session_id). But the CREATE INDEX on the next line references session_id before _migrate_add_optional_columns() gets a chance to add it via ALTER TABLE. Crash.

Fix

Remove the premature CREATE INDEX from SCHEMA_SQL. The index creation is already handled correctly inside _migrate_add_optional_columns() (line 1166–1178), where ALTER TABLE ADD COLUMN runs first.

One line deleted, no logic changed — the index still gets created, just at the right time.

Verification

  • Fresh install: SCHEMA_SQL creates table + all columns → migration is a no-op → index created during migration ✓
  • Upgrade from old DB: SCHEMA_SQL no-ops on existing table → migration adds session_id column → migration creates index ✓

Fixes #28554

The CREATE INDEX IF NOT EXISTS on tasks(session_id) in SCHEMA_SQL
runs before _migrate_add_optional_columns(), causing a
'sqlite3.OperationalError: no such column: session_id' crash on
existing kanban.db files created by older Hermes versions.

The index creation is already handled correctly inside
_migrate_add_optional_columns() (line 1166-1178) where the
ALTER TABLE ADD COLUMN runs first. Remove the premature copy.

Fixes #28554
@kungunier kungunier force-pushed the fix/kanban-schema-index-before-migration branch from 16f14b3 to 60165a7 Compare May 19, 2026 06:45
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins duplicate This issue or pull request already exists labels May 19, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #28461 — both PRs move the session_id index creation from SCHEMA_SQL to after migration to fix the legacy kanban.db upgrade crash. Fixes #28464.

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Thanks @kungunier — 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/plugins Plugin system and bundled plugins 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.

fix(kanban): SCHEMA_SQL CREATE INDEX on session_id fails when upgrading from older kanban.db

3 participants