Skip to content

perf(sessions): skip codex rescans for unchanged rollouts - #2786

Merged
ScriptedAlchemy merged 1 commit into
masterfrom
fleet/store-depth-bound
Oct 1, 2026
Merged

ScriptedAlchemy merged 1 commit into
masterfrom
fleet/store-depth-bound

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

Refs #2658, #2521.

Cause

Every history pass, each unchanged resumed Codex rollout:

  • rebuilt its prior context by re-reading the rollout up to its cursor (CodexContextState::scan_prior), even when the scan had no frame. The prior-context cache holds 512 rollouts, so past that every pass re-read every rollout;
  • built a ProjectRootMatcher (a git spawn) for its scope, even when no frame consulted it.

Change

  • Rebuild prior context only when the scan has a frame.
  • Resolve the scope matcher lazily, once, on the first frame that consults it.

Evidence

  • Test an_unchanged_resumed_rollout_does_not_rebuild_its_prior_context (sessions lib):

    • after the prior-context cache is evicted, an unchanged pass does 0 rescans and persists 0 frames;
    • an appended record leads to 1 rescan and 1 persisted frame;
    • it fails without the guard (1 rescan instead of 0).
  • Isolated hotpath daemon on the 8× store (about 60.6k messages; 120 streamed messages per window, 183 ingested):

    Before After
    Raw bytes per message 32.4 MB / 19.3 MB 5.05 MB / 3.11 MB
    matcher_new 17,693 calls (186 s) 0
    scan_prior 17,600 calls 0
  • For comparison, the base store (about 7.6k messages) reads 2.48 MB / 2.05 MB per message.

  • Suites:

    Suite Passed
    sessions lib 527
    application lib 483
    application_suite 66
    session_suite 433
    mcp_suite 614
  • clippy -D warnings and fmt are clean.

An unchanged resumed rollout rebuilt its prior context by re-reading the
file up to its cursor, and resolved its scope matcher (a git spawn) on
every pass, even though it admitted no frame. Past 512 rollouts the
prior-context cache thrashed, so every pass re-read every rollout.

Rebuild prior context only when the scan has a frame, and resolve the
scope matcher lazily on the first frame that consults it.
@changeset-bot

changeset-bot Bot commented Oct 1, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: de1412c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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