Repository navigation
fix(cli): serve MCP handshake immediately on cold start - #129
Merged
Merged
Conversation
Cold `serve --mcp` previously ran a spawn->poll->proxy-attach->heal prelude before answering the MCP initialize/tools/list handshake. Under load that prelude exceeded the client init timeout, so opencode (and other MCP clients) marked the codegraph server failed and its codegraph_* tools never registered. Split the SpawnOrProxy decision into a pure `cold_start_action`: a WARM start (live daemon) attaches via the proxy as before; a COLD start now fire-and-forgets the shared daemon for the NEXT session and serves THIS session direct immediately, so the handshake is answered without blocking on daemon socket readiness. Warm proxy semantics and serve_direct are unchanged. Add a cold-start integration test asserting initialize + tools/list return within a strict bound and expose codegraph_search/codegraph_explore, plus a unit test for the cold/warm decision.
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (29.72%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage. @@ Coverage Diff @@
## main #129 +/- ##
==========================================
- Coverage 95.64% 95.63% -0.01%
==========================================
Files 115 115
Lines 55334 55348 +14
==========================================
+ Hits 52923 52934 +11
- Misses 2411 2414 +3
🚀 New features to boost your workflow:
|
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.
Summary
Cold
serve --mcppreviously ran a spawn→poll(≤400ms)→proxy-attach→heal prelude BEFORE answering the MCPinitialize/tools/listhandshake. Under load that prelude exceeded the MCP client init timeout, so opencode (and other clients) marked the codegraph MCP serverfailedand itscodegraph_*tools never registered.This splits the
SpawnOrProxydecision into a purecold_start_action(daemon_running):proxy_to_running_daemon(oldspawn_or_proxysemantics unchanged), falling back toserve_directon attach failure.spawn_shared_daemon_best_effortfor the NEXT session, thenserve_directTHIS session immediately — no poll, no blocking proxy. The daemon pid lock guarantees N concurrent cold starts converge on ≤1 daemon.Serve-path only — no extraction/resolve/store change, golden
.schemabyte-stability and the no-AI/vector/LLM guardrail untouched.Verification
make cigreen locally (fmt + clippy + test + guardrail).cold_start_serve_answers_handshake_within_bound: coldserve --mcpanswersinitialize+tools/listin <2s and exposescodegraph_search/codegraph_explore; reaps the fire-and-forget daemon in teardown; passes 3× (~0.2s each), no orphan process.cold_start_action_warm_proxies_cold_spawns_then_serves_direct.Note
In production cold start the direct session runs a transient second watcher alongside the just-spawned daemon until the session exits; safe (WAL + busy_timeout serialize writes, idempotent upserts) and bounded, but noted for reviewers.