Skip to content

fix(server): dispatch request-scoped requests concurrently from the start - #1187

Merged
devcrocod merged 4 commits into
devcrocod/sep-2575-stateless-mcpfrom
fix/sep2575-concurrent-modern-dispatch
Nov 20, 2026
Merged

devcrocod merged 4 commits into
devcrocod/sep-2575-stateless-mcpfrom
fix/sep2575-concurrent-modern-dispatch

Conversation

@e5l

@e5l e5l commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Why

Follow-up to #985. That review asked for each confirmed finding to become its own fix PR with green CI. This one is the HIGH finding. On a persistent connection (stdio, WebSocket, an in-memory pair), a 2026-07-28 client's requests were served one at a time, and notifications/cancelled was ignored. The serial dispatch phase only ends on notifications/initialized, and a request-scoped client never sends that. So a slow tools/call blocked every later request until it finished, and nothing could cancel it. The spec lets clients interleave unrelated requests freely (basic/index, Statelessness) and cancel in-flight ones.

What changed

  • Protocol.dispatchRequest holds only handshake-lifecycle requests to the serial phase. A request that carries the protocol-version envelope has no initialization phase, so it goes through concurrent dispatch with in-flight tracking from the first message.
  • SingleExchangeTransport.deliver (request-scoped HTTP) now waits for the exchange's answer. It used to rely on inline dispatch returning only after the handler answered. Without this change, every handler that suspends was reported as "returned without producing a response".

Scope

Legacy pre-initialize ordering is unchanged. initialize and anything sent before notifications/initialized without an envelope still run inline in arrival order. Notifications still run inline until the handshake completes, so notifications/cancelled is handled on the delivery loop.

Tradeoffs

On request-scoped HTTP, the handler now runs on the session's handler scope rather than on the call's coroutine. A client disconnect still cancels it, through session.close() in the exchange's finally, as the disconnect test shows.

Blast Radius

Server and client Protocol dispatch for enveloped requests. Request-scoped requests are now subject to maxConcurrentHandlers and maxInFlightHandlers, like post-handshake legacy requests.

Verification

  • Failing first (b969035). EraInterleavingTest: a request-scoped request is answered while an earlier one is still running and a running request-scoped request is cancelled by notifications cancelled both failed with TimeoutCancellationException: Timed out waiting for 5000 ms. They pass after the fix.
  • Applying only the Protocol change failed ModernStreamableHttpStreamTest and ModernStreamableHttpDisconnectTest with "The request handler returned without producing a response". The deliver change fixes both.
  • Local: :kotlin-sdk-core, :kotlin-sdk-server, :kotlin-sdk-client and :integration-test jvmTest, plus ktlintCheck detekt checkKotlinAbi, all pass.
  • CI: build https://github.com/modelcontextprotocol/kotlin-sdk/actions/runs/44266889227 (success), conformance https://github.com/modelcontextprotocol/kotlin-sdk/actions/runs/44266894167 (success)

🤖 Generated with Claude Code

e5l and others added 4 commits November 18, 2026 09:23
…dently

A slow request-scoped request must not hold up the next one, and
notifications/cancelled must reach it while it runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tart

The serial phase holds inbound requests inline until the handshake
completes. A 2026-07-28 client never sends notifications/initialized, so
on a persistent connection every request-scoped request waited behind
the previous one and notifications/cancelled could not reach a running
handler. Only handshake-lifecycle requests are held to that order now.

The request-scoped HTTP exchange relied on delivery returning only once
the handler answered; it now waits for the answer itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…atch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@e5l
e5l requested a review from devcrocod November 20, 2026 09:57

@devcrocod devcrocod 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.

lgtm

@devcrocod
devcrocod merged commit 433fd6a into devcrocod/sep-2575-stateless-mcp Nov 20, 2026
2 checks passed
@devcrocod
devcrocod deleted the fix/sep2575-concurrent-modern-dispatch branch November 20, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants