fix(stats): probe session schemas read-only before migration - #1236
Open
rudycelekli wants to merge 1 commit into
Open
rudycelekli wants to merge 1 commit into
rudycelekli wants to merge 1 commit into
Conversation
Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
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.
What / Why / How
Related to #1213.
getRealBytesStats()opens each session database read-only for its aggregate, but first callsensureSessionEventsSchema(). That helper currently opens every database writable, even when all required columns already exist.Probe the schema using a normal read-only connection and return immediately for current schemas. Reopen writable only when columns are missing, preserving the legacy-schema recovery introduced in #685. The writable migration rechecks the schema before each ALTER through the existing helper.
This removes the unnecessary writable migration connection for current schemas. It does not claim to eliminate every filesystem operation from SQLite read-only WAL connections, or to solve the separate lifetime-scan caching proposals. No
immutableflag is used: uncheckpointed events must remain visible.Affected platforms
Test plan
next4621364, the new publicgetRealBytesStats()test sees the correct live-WAL totals but fails because a database connection is writable.next, but reading stats changes the main database file through a checkpoint.npm run typecheckpasses;git diff --checkpasses.npm test --ignore-scripts: 4,777 passed, 24 skipped, 213 test files passed on signed headd15c732075466eede3518bc9af2f76d9e09081ef. This includes the adapter suites. Lifecycle scripts were disabled to leave generated bundles to CI per the repo ops skill. Tests ran with isolated HOME and no provider credentials.Native checks ran on macOS with Node 22.19.0. Windows/Linux and Bun execution are not claimed. A live Claude Code hook/MCP/model session was not run; these tests cover the real SQLite-backed stats entry point and its migration boundary, not client prompt assembly. Generated bundles are left to upstream CI per the repository ops skill.
Checklist
nextAI assistance
Prepared with OpenAI Codex. The change was investigated against current source/history and existing PRs; no upstream merge was performed.