fix(dashboard): preserve maintenance writes on read polling (salvage #67903) - #76895
Merged
kshitijk4poor merged 3 commits intoAug 2, 2026
Merged
Conversation
Signed-off-by: joelbrilliant <joelbrilliant1@gmail.com>
Signed-off-by: joelbrilliant <joelbrilliant1@gmail.com>
The RO branch's new FTS capability probe raises sqlite3.DatabaseError on a malformed store (the probe itself only catches OperationalError). The outer __init__ handler re-raises without closing self._conn, leaking a tracked connection for the process lifetime — which makes _backup_db_file refuse its raw-copy, so the writable heal that follows (web_server's stale-schema/malformed reopen) repairs the store WITHOUT the forensic backup repair_state_db_schema promises. Close-then-reraise on any probe failure, mirroring _open_probed's cleanup discipline. Regression test: corrupt sqlite_master (duplicate messages_fts row), assert the failed RO open leaves no live tracked connection and the subsequent writable heal creates its malformed-backup file. Mutation- checked: no-oping the cleanup handler makes the test fail.
kshitijk4poor
enabled auto-merge (rebase)
August 2, 2026 15:57
This was referenced Aug 2, 2026
Merged
This was referenced Aug 8, 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 #67903 by @joelbrilliant — both commits cherry-picked to preserve authorship, plus one fix commit for a connection-leak finding from review.
Context — what this fixes, for whom
Every Desktop user's dashboard polls
/api/sessionsevery 10s. On current main each poll opens a writable SessionDB, andclose()unconditionally runsPRAGMA wal_checkpoint(TRUNCATE)— so read-only polling repeatedly checkpoints and truncates the WAL out from under the real writer (the running gateway/agent). Measured side-by-side: a writer's 6,451,952-byte pending WAL is truncated to 0 bytes by a single dashboard-style GET on main; preserved byte-identical on this branch. A second latent bug fixed here:SessionDB(read_only=True)on main never sets FTS capability flags, so read-onlysearch_messagessilently returns 0 hits (ASCII and CJK) — this branch probes existing FTS tables on RO opens and both search paths work.What the fix does (from #67903, kept verbatim)
_open_session_db_for_profilenow requires an explicitread_onlykeyword; every read endpoint (list, search, stats, detail, messages, export, analytics, cron runs, resume resolution) opens read-only; writes (delete, rename, prune, import) stay writable. An AST test enforces the keyword on every call site.close()never requests a WAL checkpoint (writable close keeps TRUNCATE)._reconcile_columns) then read-only reopen, FTS/trigram capability probing.Review fix added in this salvage (commit 3)
The RO branch's new FTS probe raises
sqlite3.DatabaseErroron a malformed store, and__init__'s outer handler re-raised without closing the connection — leaking a tracked connection that makes_backup_db_filerefuse its raw-copy for the process lifetime, so the writable heal that follows would repair the store WITHOUT its forensic backup (live-repro'd:backup files created: []+ refusal log before; backup file present after). Fixed with close-then-reraise mirroring_open_probed's own cleanup, plus a mutation-checked regression test.Verification
tests/test_hermes_state.py: 146 passed (incl. the new leak-regression test); event-loop + session-search suites: 4 passed; web_server endpoint tests: 34 passed, 1 pre-existing skipCloses #67903 (superseded by this salvage — original author credited via cherry-pick authorship).