Repository navigation
feat(serve): resident serve child reuses status snapshots across requests (#1135 part 2) - #1146
Merged
Merged
Conversation
…1135) The status snapshot keyed on a corpus fingerprint (#999) currently excludes the default optimize path: persisting scanAndDetect's findings alongside the base payload would pin a moment-in-time render of the mutable, non-fingerprinted inputs the corpus fingerprint cannot observe (settings.json, CLAUDE.md, defined skills/agents/commands, MCP config) under a key with no way to invalidate them. That is the exact defect commit 113ebb1 excluded the optimize path to avoid. This change picks option (b) from the #1135 plan: the snapshot now covers BOTH optimize=true and optimize=false (the queryKey already carries optimize as a boolean, so the two are naturally partitioned without a separate cache namespace). On a hit, the base payload is served from disk and only the optimize block is re-derived fresh through a new computeOptimizeBlock helper (re-running scanAndDetect over a fresh parseAllSessions of the unchanged corpus). On a save, the optimize block is stripped from the persisted record and replaced with an empty placeholder, so a mutation in the non-fingerprinted inputs between two requests at the same fingerprint is reflected in the second response even though the rest of the payload is byte-identical to the first. The save gate from #999 is preserved verbatim (payload.stale !== true, payload.hydration === undefined, isSessionHydrationComplete()), the resident codeburn serve in-memory output memo already keys on the full argv so the two optimize values land in different memo entries, and the desktop app's buildOverviewArgs has always sent the menubar-json query without --no-optimize, so the new hit rate lights up with zero app changes. (#1135)
…on load (#1135) Post-build review fix round on the optimize-path snapshot change: 1. Snapshot reuse is no longer attempted for one-shot optimize polls. One-shot codeburn status invocations behave exactly as on main: fresh compute, fresh generated timestamp. The pre-existing --no-optimize one-shot save-gate behavior is unchanged. 2. The corpus-change test now holds --provider constant across both calls, so the only delta is the appended session line and the test proves a corpus change is picked up, not a queryKey change. 3. loadStatusSnapshot now mirrors the save gate: a persisted record whose payload carries stale === true or a hydration block is treated as a miss and recomputed. Belt-and-braces only; the save gate that prevents such records is unchanged. 4. The optimize block cannot be re-derived on a snapshot hit without the parsed corpus. scanAndDetect consumes the full ProjectSummary trees plus a transcript scan plus ~/.claude state, so re-deriving it pays the full fresh parse the snapshot exists to avoid on exactly the cold processes the disk snapshot serves, and the resident serve child gains nothing because its in-memory output memo already dedupes a repeated argv. Deriving from warm caches is therefore not honestly achievable, so this takes the plain exit: optimize-carrying requests are excluded from reuse (useSnapshot = !queryScope.optimize everywhere, the main semantics) and the computeOptimizeBlock helper, the save-time optimize stripping, and the optimize-path snapshot tests are reverted. Honesty over cleverness. The CHANGELOG entry this branch added now describes the final semantics. Full suite green, tsc clean.
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.
The resident serve child now answers a repeat menubar-json request with an unchanged corpus from the #999 snapshot store instead of recomputing the period aggregation - measured on a real 21k-file corpus: 30-day ask drops from 7.6s to 0.6s on repeat, costs byte-identical. Reuse is gated to the serve child (one-shot CLI behavior byte-identical to main, fresh generated timestamp); optimize-carrying requests are excluded from reuse entirely after the honest finding that the optimize block requires a parse (revert stated in-commit); snapshots are re-validated on load against the same stale/hydration markers the save gate enforces; the fingerprint-miss test now isolates a true corpus change. Benefits every serve client - desktop app, menubar, web - with zero client changes. Suite 3716 green, tsc clean. Built by Kimi Code with a MiniMax verifier round (three of four findings confirmed and fixed, one covered belt-and-braces).