Repository navigation
fix(mcp): answer a second initialize with -32600 already initialized (#9895) - #9953
Conversation
…9895) A repeated well-formed initialize on an initialized stdio session now returns invalid request naming the already-initialized session; the session keeps serving. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZHDKLVQqArSZrUFKSkREo
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 9 minutes. View limit details
Comment |
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZHDKLVQqArSZrUFKSkREo
There was a problem hiding this comment.
Code Review
This pull request updates the MCP server to handle a second initialize request on an already initialized session by returning an invalid request error (-32600) with a descriptive message, allowing the session to continue serving. This is implemented using an atomic boolean flag handshake_seen in InitializeSessionService. The feedback points out a critical issue: if the first initialize request fails, the flag remains set to true, preventing any subsequent handshake retries. A code suggestion is provided to reset the flag to false if the initial request fails.
There was a problem hiding this comment.
Refuted
- Returning an error for duplicate initialize could tear down or poison the live MCP session.; refuted because: The error is returned only from this service's request handler, while independent subsequent ping and tools/list requests are asserted to receive valid responses.
- A flag-set-before-success bug is evidenced by this test suite.; refuted because: The added test covers a successful handshake followed by a duplicate, while the seeded thread already established malformed initialize does not enter this service and a typed initialize failure terminates the handshake with a fresh service on retry.
- The new guard should live in the reusable McpServer implementation rather than InitializeSessionService.; refuted because: The wrapper is the handshake/lifecycle boundary; placing state in McpServer could affect discovery sessions and other direct service uses beyond the stated production delta.
- Atomic state checking introduces portability or concurrency risk.; refuted because: The flag is an AtomicBool with a swap-based compare-and-set; the relevant invariant is per service/connection, and the change adds no unbounded allocation or blocking operation.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
Summary
initializeon an initializedripr mcp --stdiosession now returns-32600(invalid request) saying the session is already initialized, and the session keeps serving. One item of the MCP/LSP robustness sweep: remaining unhelpful errors and edge-case hangs found by driving both servers as a client #9895 MCP/LSP robustness sweep.Swarm / Source Boundary
ripr-swarmSource-of-truth Links
Proposal: n/a
Spec: n/a
ADR: 0022 (MCP adapter; no change)
Plan item: n/a
Governing issue or accepted claim: #9895
Acceptance delta (one sentence):
ripr mcp --stdiorejects a repeatedinitializewith a clear already-initialized-32600error instead of silently re-running the handshake or a bare method-not-found, and the session stays usable.Candidate Relationships
Candidate branch (GitHub PR head is authoritative after publication): claude/9895-second-initialize
Stack parent or prerequisite PR (if any): none
Proposed replacement of PR (if any; not yet accepted): none
Acceptance retained from a replaced candidate (if any): n/a
Accepted winner and losing candidate disposition (when decided): n/a (searched open and closed PRs; no equivalent found)
Scope
InitializeSessionServiceincrates/ripr/src/mcp/server.rs(the semantic owner of post-handshake request routing) rejects anyinitializeafter the handshake's own.Scope Classification
Production delta:
handshake_seenflag; the firstinitializeis the handshake, later ones returnErrorData::invalid_requestwith the already-initialized message.Evidence/support delta:
second_initialize_answers_already_initialized_and_the_session_recovers;docs/interop/mcp.mdsentence; changelog fragment.Single acceptance criterion:
initialize->-32600, message contains "already initialized", and ping/tools/list still work afterwards.Non-goals:
initialize(stays-32602, docs(orch): retire singleton wording, close compatibility cleanup, fresh-session proof (#1706 PR D) #8504); discovery sessions; other LSP/MCP sweep items.Support-tier Impact
Claim/proof notes:
Policy Impact
Ledger or exception notes:
Proof
Result, failures, or skipped proof:
cargo xtask precommitpassed static-language, no-panic-family, allow-attributes and local-context, then failed as an instrument failure (covered_by enumeration timed out after 300s while blocked on a shared cargo lock), not a source or policy failure. Remaining precommit gates and Clippy are not established locally; hosted exact-head CI should cover them.Claim Boundary
What may be claimed after this PR? What must not be claimed yet?
initializeover stdio is answered-32600already initialized. Not claimed: full precommit/CI green, or the rest of MCP/LSP robustness sweep: remaining unhelpful errors and edge-case hangs found by driving both servers as a client #9895.Rollback
Spec-Test-Code Traceability
Static Language Check
killed,survived,untested,proven, andadequate.CI Economics
n/a
Engineering Check
panic,unwrap,expect,todo, orunimplementedin production code.panic,unwrap,expect,todo, orunimplementedin tests.Gates
cargo fmt --checkcargo xtask check-static-languagecargo xtask check-no-panic-familycargo xtask check-allow-attributescargo xtask check-local-contextNot run locally (lock contention): the remaining gates above.
Generated by Claude Code