Repository navigation
fix(serve-http): memoize project detection on the stateless request path - #409
Merged
Merged
Conversation
Stateless (2026-07-28) requests resolve the project root on every call, up to three times. For a server started outside a Git repository, each call falls through to a synchronous `git rev-parse` subprocess that blocks the event loop. On hosts with slow process creation (endpoint security scanners on Windows add 1-3 s per spawn) the stateless probe of Claude Code exceeded its 5 s budget and the client fell back to legacy sessions. Detection results, including "not a project", are now cached per path for 5 minutes (256 paths max). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
|
Integrated in #411 with original contributor commits retained. The bounded positive/negative cache stays limited to stateless request detection; explicit session binding retains live detection. Production-host smoke outside Git measured 350ms, 5ms, and 4ms for successive discovery requests locally. Cache TTL/eviction tests pass, and CI now exercises built-host discovery on all three desktop platforms. Included in 1.10.5. |
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.
Branch:
fix/http-modern-detection-cache→mainProblem
Stateless (2026-07-28) requests have no session, so
serve-httpresolves theproject root on every request, up to three times: in
handlePost,resolveModernDataDirand the binding lookup. When the server was startedoutside a Git repository, which is the usual case for a background control
plane, the fast
.gitwalk fails. Detection then falls through to asynchronous
execSync('git rev-parse --show-toplevel'), and that call blocksthe event loop.
On the Windows test host,
cmd /c vertook 0.7 s andgit --versiontook1.3–2.5 s. Measurements on that host showed:
server/discoverrequest withMCP-Protocol-Version: 2026-07-28took2.07 s on an empty test server started outside Git, and 1–5 s on the loaded
production control plane; on the same build started inside a repository it
took 0.01 s;
falling back to a legacy session. Those connections took 15–20 s overall.
Change
project-detection-cache.tsmemoizes detection per path, including"not a project", for 5 minutes. At 256 paths, a new entry evicts the oldest
cached entry.
roots changes and the CLI keep live detection.
Tests
tests/cli/project-detection-cache.test.tscovers positive and negativehits within the TTL, re-detection after expiry, and eviction at capacity.
1.39 s, the next ones 0.008–0.018 s (2.07 s each before the change).
discovery requests returned HTTP 200 on each build. The fork took 3,438 ms
for the first request and 9–10 ms for the next three. The official 1.10.4
package took 7,837–10,969 ms per request.
http://127.0.0.1:<port>/mcp:the stateless protocol is negotiated (
protocolEra: modern) and theconnection completes in 3.5 s, with no legacy fallback.
mainbaseline. See fix(serve-http): release legacy sessions whose client stream closed #408 for the comparison.