Skip to content

fix(mcp): answer a second initialize with -32600 already initialized (#9895) - #9953

Merged
EffortlessSteven merged 2 commits into
mainfrom
claude/9895-second-initialize
Oct 23, 2026
Merged

EffortlessSteven merged 2 commits into
mainfrom
claude/9895-second-initialize

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

Swarm / Source Boundary

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge, dependency, or repo-ops development for ripr-swarm
  • repair or follow-up for a same-repo swarm PR
  • swarm-only CI, runner, routing, source-of-truth, or agent-operating surface
  • other swarm-scoped work:

Source-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 --stdio rejects a repeated initialize with a clear already-initialized -32600 error 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

  • InitializeSessionService in crates/ripr/src/mcp/server.rs (the semantic owner of post-handshake request routing) rejects any initialize after the handshake's own.

Scope Classification

  • One production behavior

Production delta:

  • A per-service handshake_seen flag; the first initialize is the handshake, later ones return ErrorData::invalid_request with the already-initialized message.

Evidence/support delta:

  • New stdio test second_initialize_answers_already_initialized_and_the_session_recovers; docs/interop/mcp.md sentence; changelog fragment.

Single acceptance criterion:

  • Second initialize -> -32600, message contains "already initialized", and ping/tools/list still work afterwards.

Non-goals:

Support-tier Impact

  • none

Claim/proof notes:

  • none

Policy Impact

  • none

Ledger or exception notes:

  • none

Proof

cargo fmt --check
cargo test -p ripr --test mcp_stdio second_initialize   # fails before fix (second initialize returned a full result), passes after
cargo test -p ripr --lib mcp::                           # 207 passed
cargo xtask check-traceability
cargo xtask check-changelog-fragments

Result, failures, or skipped proof:

  • cargo xtask precommit passed 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?

Rollback

  • Revert the squash commit; no schema or data changes.

Spec-Test-Code Traceability

  • Spec: docs/interop/mcp.md
  • Tests: crates/ripr/tests/mcp_stdio.rs
  • Code: crates/ripr/src/mcp/server.rs
  • Golden outputs: none
  • Metrics: none
  • ADR/learning: ADR 0022

Static Language Check

  • Static output avoids killed, survived, untested, proven, and adequate.
  • Unknowns include stop reasons where applicable.

CI Economics

n/a

Engineering Check

  • No new panic, unwrap, expect, todo, or unimplemented in production code.
  • No new panic, unwrap, expect, todo, or unimplemented in tests.
  • Errors are reported with actionable context.

Gates

  • cargo fmt --check
  • cargo xtask check-static-language
  • cargo xtask check-no-panic-family
  • cargo xtask check-allow-attributes
  • cargo xtask check-local-context

Not run locally (lock contention): the remaining gates above.


Generated by Claude Code

…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
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 125 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: 12262581-5c23-4e40-a1eb-5e9355ad4ee2
📥 Commits

Reviewing files that changed from the base of the PR and between d9475e8 and 759a455.

📒 Files selected for processing: 4
  • changelog.d/9895-mcp-second-initialize.md
  • crates/ripr/src/mcp/server.rs
  • crates/ripr/tests/mcp_stdio.rs
  • docs/interop/mcp.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 23, 2026 09:43
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZHDKLVQqArSZrUFKSkREo

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/ripr/src/mcp/server.rs Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants