Skip to content

fix(stats): probe session schemas read-only before migration - #1236

Open
rudycelekli wants to merge 1 commit into
mksglu:nextfrom
rudycelekli:fix/stats-schema-readonly-20261001
Open

rudycelekli wants to merge 1 commit into
mksglu:nextfrom
rudycelekli:fix/stats-schema-readonly-20261001

Conversation

@rudycelekli

Copy link
Copy Markdown

What / Why / How

Related to #1213.

getRealBytesStats() opens each session database read-only for its aggregate, but first calls ensureSessionEventsSchema(). 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 immutable flag is used: uncheckpointed events must remain visible.

Affected platforms

  • All platforms — shared session analytics and migration helper; no adapter-specific or path handling changes.

Test plan

  • RED: against next 4621364, the new public getRealBytesStats() test sees the correct live-WAL totals but fails because a database connection is writable.
  • RED: a separate native quiescent-WAL snapshot test sees the correct stats on unmodified next, but reading stats changes the main database file through a checkpoint.
  • GREEN: the snapshot keeps its main database bytes unchanged and repeat stats remain identical; the live-writer test reads uncheckpointed events and exact avoided/returned bytes with every connection read-only.
  • Extended the existing legacy-schema regression: the first read probes read-only, migrates writable, then aggregates read-only; the next read produces identical totals using only read-only connections.
  • 30 focused tests pass across real-bytes stats, byte-column migration and lifetime stats.
  • npm run typecheck passes; git diff --check passes.
  • npm test --ignore-scripts: 4,777 passed, 24 skipped, 213 test files passed on signed head d15c732075466eede3518bc9af2f76d9e09081ef. 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

  • Tests added/updated in an existing domain file; red → green recorded
  • Full suite
  • Typecheck
  • Documentation — helper comment corrected; no public API change
  • No path handling changes
  • Targets next

AI assistance

Prepared with OpenAI Codex. The change was investigated against current source/history and existing PRs; no upstream merge was performed.

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant