Skip to content

perf(snapshots): audit the store once per process, not on every open - #7

Merged
MrScripty merged 2 commits into
mainfrom
perf/snapshot-audit-once-per-process
Nov 12, 2026
Merged

MrScripty merged 2 commits into
mainfrom
perf/snapshot-audit-once-per-process

Conversation

@MrScripty

Copy link
Copy Markdown
Owner

Summary

The MCP server opens the snapshot store for each tool call, and every open of an existing store ran PRAGMA integrity_check and PRAGMA foreign_key_check over the whole file. On a 282 MB store that added about 0.6 s to every route, read and related call, and it grows with the file.

The full audit now runs at most once per process for each store file, identified by device and inode.

  • It still runs on the first open in every process, throughout a version 1 migration, and for a file put in place under a different inode.
  • Application id, schema version and exact schema checks still run on every open.
  • No configuration flag, and mcp.py is untouched.

Measurement

Five consecutive opens in one process, on a copy of a 282 MB store:

Open 1 Opens 2–5
Before about 0.6 s about 0.6 s each
After about 0.6 s under 1 ms each

Known limits

  • A one-shot CLI call is a new process and still audits every time.
  • A store deleted and recreated in place can reuse its inode on ext4, and a server that is already running then does not audit it again. Renaming a complete file into place is audited. This is documented in the snapshots README.
  • There is no separate explicit maintenance audit; maintain() only purges expired roots and runs before every operation, so the audit was not added there.

Verification

The full CI sequence passed locally on this exact tree: 47 snapshot tests, 641 engine tests, the eleven other suites, and the structural verifier 73/73. Six of the snapshot tests and two of the engine tests are new; five deliberately wrong implementations each failed the snapshot suite.

Stack

Second of five. This branch contains the commit from #6; review the last commit.

🤖 Generated with Claude Code

MrScripty and others added 2 commits November 12, 2026 07:20
…iliation

Six engine tests have failed on main since 22 October, when two changes
landed without the tests that depend on them being updated:

- Interface 48 (ad56443). Four publication tests asserted the literal
  "interface 47;" in the server instructions, and two contract examples
  still carried interface_version 47. The assertion now reads the number
  from the interface the server under test serves, so it cannot go stale
  again, and the examples say 48.
- Publication checkout reconciliation (8c5a4ad). The create-and-retire
  apply test still asserted that apply leaves the working tree untouched.
  It now asserts the documented behaviour: HEAD, index and worktree present
  the published candidate and no other local difference exists.

No production code changes. The suite-input manifest is regenerated; it was
already stale on main because 5bce311 added files without refreshing it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The MCP server opens the snapshot store for each tool call, and every open
of an existing store ran PRAGMA integrity_check and foreign_key_check over
the whole file. On a 282 MB store that is about 0.6 s added to every
route, read and related call, growing with the file.

The full audit now runs at most once per process for each store file,
identified by device and inode. It still runs on the first open in every
process, throughout a version 1 migration, and for a file put in place
under a different inode. Application id, schema version and exact schema
checks still run on every open. Measured on a copy of that store, five
consecutive opens in one process go from about 0.6 s each to 0.6 s for the
first and under 1 ms for the rest.

Known limits, documented in the snapshots README: a one-shot CLI call is a
new process and still audits; a store deleted and recreated in place can
reuse its inode on ext4 and is then not audited again by a server that is
already running.

Tests cover one audit for two opens, a replaced file, a corrupt
replacement, the checks that stay on every open, a fresh process rejecting
a corrupted file, migration keeping all of its audits, and the server
auditing once across several tool calls.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 12, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5d52c96d-1d46-418b-81f0-8b3bdc6cf46d
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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