perf(serve): event-driven parse reuse — a no-change fetch costs nothing - #960
Merged
Conversation
The remaining warm-serve cost was the per-request discovery sweep (stat-ing thousands of session files) plus re-aggregation, even when nothing on disk had changed. Serve now watches every provider's probeRoots() via fs.watch (FSEvents-backed recursive watches on macOS) and injects a quiet-since validator into the parser: while the watched roots are quiet, a previous parse stays reusable past the burst window, and an output-level memo returns identical panel queries verbatim - so a fetch with no data changes skips the sweep AND the aggregation. Safety rails, in order: a parse is validated-reusable only if the watchers were armed before it ran; any filesystem event ends reuse instantly; a 5-minute hard cap self-heals a missed event; a root that fails to watch just goes uncovered (shorter reuse, never staleness); outside serve the validator is never installed and behavior is byte-identical. During an active AI session the session roots fire constantly, so reuse correctly stays inside the 10s burst window - the extended reuse serves the idle-browsing case it was built for. The one watched path inside the cache dir is antigravity's statusline file specifically, so serve's own cache writes never self-invalidate.
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.
Answers 'is this the best you could achieve' honestly: it was not. Warm serve still paid the discovery sweep and aggregation per request even when no session data had changed. Now fs.watch over every provider's probeRoots() (the same paths doctor reports) feeds a quiet-since validator: while roots are quiet, parses reuse past the burst window and an output memo answers identical panel queries verbatim. Full safety-rail list in the commit message; the key ones are instant invalidation on any event, a 5-minute self-healing cap for missed events, watcher failures degrading to shorter reuse rather than staleness, and byte-identical one-shot behavior (validator never installed outside serve).
Full suite 2,614 green including new validator reuse tests; builds clean.