fix(kanban): drop redundant init_db() in gateway watchers (salvage #21874) - #22994
Merged
Conversation
Both `_kanban_notifier_watcher` and `_kanban_dispatcher_watcher`'s `_tick_once_for_board` called `_kb.connect(board=slug)` immediately followed by `_kb.init_db(board=slug)`. Since `connect()` already runs the schema + idempotent migration on first open per process, the explicit `init_db()` was redundant — and worse, `init_db()` deliberately busts the per-process `_INITIALIZED_PATHS` cache and re-runs the migration on a *second* connection that races the first. On every cold gateway start against a legacy DB this surfaced as either `sqlite3.OperationalError: duplicate column name: <col>` or intermittent `database is locked` errors logged at the first tick. The duplicate-column case is now tolerated by `_add_column_if_missing` (commit 7869838), but the wasted second migration plus the database-is-locked race remain fixable by skipping the redundant call entirely. Drops `_kb.init_db(board=slug)` at both call sites and adds a regression test in `tests/hermes_cli/test_kanban_notify.py` that pins the absence via source inspection plus a runtime spy. Co-authored-by: Teknium <127238744+teknium1@users.noreply.github.com>
This was referenced May 10, 2026
Contributor
🔎 Lint report:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removes the redundant
_kb.init_db(board=slug)call from both kanban gateway watchers so the dispatcher and notifier no longer race themselves on every cold start against a legacy DB.Root cause
Both
_kanban_notifier_watcherand_kanban_dispatcher_watcher's_tick_once_for_boardopened the kanban DB twice per tick: once via_kb.connect(board=slug)(which auto-runs the migration on first open per process) and again via an explicit_kb.init_db(board=slug)(which deliberately busts the per-process_INITIALIZED_PATHScache and re-runs the migration on a second connection). The two migrations raced inside the same process, surfacing as eithersqlite3.OperationalError: duplicate column name: <col>or intermittentdatabase is lockedtraces logged at the first tick after every gateway start.The duplicate-column case was fixed in commit 7869838 (PR #22627 by @wesleysimplicio) which made
_add_column_if_missingswallow the duplicate-column error. The wasted second migration plus thedatabase is lockedwindow remain — this PR addresses them by skipping the redundant call entirely.Changes
gateway/run.py: drop_kb.init_db(board=slug)at both sites (notifier watcher loop + dispatcher tick closure).connect()already runs migrations on first open per process.tests/hermes_cli/test_kanban_notify.py: regression tests pinning that neither watcher reintroduces the call (one runtime spy + one source-inspection guard).Validation
tests/hermes_cli/test_kanban_notify.pytests/hermes_cli/test_kanban_db.py + test_kanban_core_functionality.pyCloses #21378 via salvage. Salvage of #21874; original gateway-side fix by @li0near preserved as the committing author. Widened to the second redundant call site (notifier watcher) and added regression tests so the bug can't silently come back. AUTHOR_MAP entry added for li0near's commit email.