fix(kanban): refuse corrupt db auto-init#30862
Merged
Merged
Conversation
Contributor
🔎 Lint report:
|
…indings Path.resolve() before any I/O and confine backup writes to the resolved parent directory. Adds explicit parent-equality assertions so static analyzers see the containment guarantee, and walks WAL/SHM sidecars through the same resolved-parent path so accidental .. segments are collapsed before shutil.copy2. Functionally equivalent to the original PR; preserves the corrupt bytes to <db>.corrupt.<ts>.bak in the same directory, still raises KanbanDbCorruptError from connect(). E2E with Stefan's exact hex header + malformed pages still passes. 163/163 kanban tests still pass.
| # Resolve once and pin the parent so subsequent path operations cannot | ||
| # escape it. ``Path.resolve()`` collapses any ``..`` segments and | ||
| # symlinks, and we only ever write inside ``parent``. | ||
| resolved = path.resolve() |
| if candidate.parent != parent: | ||
| return None | ||
| counter = 0 | ||
| while candidate.exists(): |
| if candidate.parent != parent: | ||
| return None | ||
| try: | ||
| shutil.copy2(resolved, candidate) |
| if candidate.parent != parent: | ||
| return None | ||
| try: | ||
| shutil.copy2(resolved, candidate) |
| return None | ||
| for suffix in ("-wal", "-shm"): | ||
| sidecar = parent / (base_name + suffix) | ||
| if sidecar.parent != parent or not sidecar.exists(): |
This was referenced May 23, 2026
teknium1
added a commit
that referenced
this pull request
May 23, 2026
Gpapas
pushed a commit
to Gpapas/hermes-agent
that referenced
this pull request
May 23, 2026
exosyphon
pushed a commit
to exosyphon/hermes-agent
that referenced
this pull request
May 24, 2026
sahilm-ti
pushed a commit
to sahilm-ti/hermes-agent
that referenced
this pull request
May 25, 2026
sahilm-ti
pushed a commit
to sahilm-ti/hermes-agent
that referenced
this pull request
May 25, 2026
mathias3
pushed a commit
to mathias3/hermes-agent
that referenced
this pull request
May 28, 2026
Bryce-huang
pushed a commit
to wbkunlun/hermes-agent
that referenced
this pull request
May 29, 2026
mosaiq-systems
pushed a commit
to mosaiq-systems/hermes-agent
that referenced
this pull request
May 29, 2026
gweeteve
pushed a commit
to gweeteve/hermes-agent
that referenced
this pull request
Jun 2, 2026
Seven74AI
pushed a commit
to Seven74AI/hermes-agent
that referenced
this pull request
Jun 13, 2026
alt-glitch
pushed a commit
that referenced
this pull request
Jun 14, 2026
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.
Salvages #30707 (@NickLarcombe) onto current main.
Summary
Adds a full
PRAGMA integrity_checkguard at kanban DB open time. If the file has a valid SQLite header but is malformed past it (Stefan's reported case: header passes but pages are damaged), the dispatcher now preserves the corrupt file askanban.db.corrupt.<ts>.bakand raisesKanbanDbCorruptErrorinstead of silently recreating the schema on top of it.Complements the existing header-byte check rather than replacing it. Both layers now run from
connect():_validate_sqlite_header(path)— cheap byte-level check (catches Interrupted OpenAI/httpx request thread survives across turns and writes TLS record bytes to unrelated file descriptors on delayed close #29507 TLS-overwrite shape)._guard_existing_db_is_healthy(path)— full integrity probe (catches malformed pages, broken internal metadata). Cached per-path in_INITIALIZED_PATHSso it runs once per process per path.Changes
hermes_cli/kanban_db.py:KanbanDbCorruptError,_backup_corrupt_db(),_guard_existing_db_is_healthy(). Called fromconnect()after the header check.tests/hermes_cli/test_kanban_db.py: 4 new regressions._write_corrupt_db()now writes a valid SQLite header followed by malformed pages — matches the actual reported corruption shape (Discord thread, May 23 2026) and forces the integrity guard (not the header check) to catch it.scripts/release.py: AUTHOR_MAP entry for @NickLarcombe.Conflict resolution
hermes_cli/kanban_db.py: PR's base wanted to replace_validate_sqlite_header(path)with the new guard. Resolved by keeping both — header check first (cheap), integrity guard second (heavier, cached).tests/hermes_cli/test_kanban_db.py: PR's base lacked the workdir/stale-event tests block that landed on main after the PR was opened. Resolved by keeping both blocks._write_corrupt_db()rewritten so tests exercise the integrity-guard path (valid header + malformed pages) instead of the header-check path. This is faithful to what the PR actually adds.Validation
tests/hermes_cli/test_kanban_db.py tests/hermes_cli/test_kanban_boards.py tests/hermes_cli/test_kanban_specify_db.py tests/gateway/test_kanban_notifier.py: 235/235 pass..bak, raisesKanbanDbCorruptErrorfromconnect(). Working as intended.Closes #30687.
Infographic