hermes - ✅(Solved) Fix kanban: SCHEMA_SQL crashes on existing databases when new column is added — migration code never reached [3 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#28617Fetched 2026-05-20 04:03:09
View on GitHub
Comments
1
Participants
2
Timeline
9
Reactions
0
Timeline (top)
cross-referenced ×4labeled ×3closed ×1commented ×1

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.

Fix Action

Fix / Workaround

  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

Manual Workaround (for affected users)

PR fix notes

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

Description (problem / solution / changelog)

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

Changed files

  • hermes_cli/kanban_db.py (modified, +0/-2)

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

Description (problem / solution / changelog)

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

  • Bug fix (top priority per CONTRIBUTING)
  • Tests pass
  • One logical change per PR
  • Conventional commit message
  • Closes #28617

Changed files

  • hermes_cli/kanban_db.py (modified, +7/-6)

PR #28781: fix(kanban): hoist all additive-column indexes out of SCHEMA_SQL (#28461)

Description (problem / solution / changelog)

Summary

Salvage of #28461 — fixes the Kanban DB legacy-migration crash reported in #28464 (and rediscovered in #28554, #28617, #28654, #28698) where connect() runs SCHEMA_SQL before _migrate_add_optional_columns(), so a legacy board missing any additive indexed column aborts schema init with OperationalError: no such column: <col> before the migration can add it.

The community filed six PRs for this bug (all on 2026-05-19). #28461 (itsreverence) was first and best-explained but only covered 2 of the 4 vulnerable indexes. #28754 (quocanh261997) extended coverage to 3 of the 4. This salvage combines the strengths of all the open PRs and closes the remaining gap.

What changed

Move every CREATE INDEX that depends on an additive column out of SCHEMA_SQL and create them after _migrate_add_optional_columns() adds the columns. All four additive-column indexes are now hoisted:

IndexAdditive columnIntroduced in
idx_tasks_session_idtasks.session_id#28447
idx_tasks_tenanttasks.tenant#16081
idx_tasks_idempotencytasks.idempotency_key#17805
idx_events_runtask_events.run_id#17805

Three of these were ticking landmines for any user whose board predated the column. idx_tasks_session_id was the one that bit users today because it's the most recent (#28447 merged the day before the bug reports flooded in), but the same migration trap applied to all four.

Beyond #28754's coverage:

  • idx_events_run: also hoisted out of SCHEMA_SQL and made unconditional in the migration. A legacy task_events table predating #17805 (no run_id) was still hitting the same SQLite trap that #28754 only addressed for tasks.
  • idx_tasks_idempotency: removed the redundant inner-conditional create (line ~1085) that was nested inside if "idempotency_key" not in cols:. Since the unconditional create lower in the function already runs CREATE INDEX IF NOT EXISTS, the inner one was dead code on fresh DBs once we removed the SCHEMA_SQL line.
  • Strengthened the regression test to cover all 4 indexes and to seed a pre-#17805 task_events shape that exercises the run_id migration path.
  • Added explicit rationale comments so the next contributor adding tasks.<new_col> doesn't re-introduce the trap.
  • Picked up an adjacent test fix from #28754: test_max_runtime_uses_current_run_start_after_retry now monkeypatch-es kb._pid_alive so it stops tripping tests/conftest.py's live-system guard on os.kill(<fake_pid>, 0). Pre-existing failure on origin/main, unrelated to the index ordering bug; carried in via the cherry-pick rather than split out separately.

Validation

Confirmed against origin/main:

origin/main reproduces against pre-#16081 fixture: no such column: session_id

Confirmed on this branch:

Scenario A: legacy DB missing all 4 additive columns      ✅
Scenario B: fresh DB                                       ✅
Scenario C: idempotency on already-migrated DB             ✅
Scenario D: partially-migrated DB (tenant+idempotency)     ✅

Test suite:

$ bash scripts/run_tests.sh tests/hermes_cli/test_kanban_db.py tests/hermes_cli/test_kanban_db_init.py
============================= 159 passed in 5.06s ==============================

Full tests/hermes_cli/ suite — 4888 passed, 13 pre-existing failures unrelated to kanban (gateway service / model picker / plugins) that match origin/main 1:1.

Lint diff: zero new ruff/ty issues vs origin/main (123 ty issues on changed files, identical on both base and head).

Credit

Original bug report and PR by @itsreverence (#28464 + #28461 — first to file, best write-up of the underlying ordering trap).

Cherry-picked commit on this branch authored by @quocanh261997 from #28754 (broadest open coverage — included tasks.tenant and tasks.idempotency_key).

Other PRs absorbed and to be closed as duplicates: #28741 (@stormhierta), #28562 (@kungunier), #28620 (@vanhci), #28602 (@verybigdog, DRAFT). All of them correctly diagnosed the bug; this salvage combines the broadest coverage with the most thorough comments and tests.

Closes #28464. Closes #28554. Closes #28617. Closes #28654. Closes #28698.

Changed files

  • hermes_cli/kanban_db.py (modified, +26/-18)
  • tests/hermes_cli/test_kanban_db.py (modified, +84/-1)

Code Example

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

---

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)"
    )

---

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);"
RAW_BUFFERClick to expand / collapse

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

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix kanban: SCHEMA_SQL crashes on existing databases when new column is added — migration code never reached [3 pull requests, 1 comments, 2 participants]