You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(transport): hold inbound messages until the client transport is operational - #1207
Follow-up to #985. Goal: remove the CI flake that makes PRs on the stateless branch green only on rerun. RequestScopedLifecycleTest and ResponseCacheTest fail with "server/discover probe timed out" or "Expected 2026-07-28 but actual was null". Every failing log has Error handling request: server/discover ... McpException: Transport is not ready from AbstractClientTransport.send. The defect is on main.
AbstractClientTransport.start() runs initialize(), where transports start their readers, and only then moves to Operational. A reader can hand a request to Protocol in that window. The handler's reply hits the state check in send() and is dropped, so the peer waits out its timeout. Sometimes the error reply gets through instead, and the client reads it as a refusal and falls back to legacy. The integration tests start server.createSession and client.connect concurrently over ChannelTransport, and slow CI runners widen the window.
What changed
AbstractClientTransport overrides onMessage so that handlers wait on a deferred that start() completes right after the Operational transition. Nothing changes once the transport is running.
ABI dump: AbstractClientTransport now declares the onMessage it already inherited (a binary-compatible addition).
Removed the comment in ProtocolConcurrencyIntegrationTest that described early delivery. It no longer holds.
Scope
The fix goes in the base class because the pattern is shared. ChannelTransport and StdioClientTransport both start readers in initialize() and deliver before Operational. SseClientTransport can too, once the endpoint event has arrived. StreamableHttpClientTransport delivers only after a send, so it is unaffected. Server transports extend AbstractTransport, which has no state gate on send.
Tradeoffs
A subclass whose initialize() waits for a JSON-RPC message to be handled would now block. No transport in this repo does that. The closest case is an SSE server that breaks the spec by sending a JSON-RPC event before endpoint: start() would now hang instead of losing the reply. Fixing this per transport instead would mean overriding start(), which its KDoc forbids, and repeating the same fix in every reader.
Blast Radius
All AbstractClientTransport subclasses, including third-party ones, now get inbound messages only after start() returns. Delivery after that is unchanged.
Verification
ChannelTransportTest.answers a request the peer sent before start returned runs the event loop on its own scheduler while start() is suspended. Before the fix: Expected JSONRPCResponse(id=NumberId(value=1), ...) but actual was null, with Transport is not ready in the log. Passes after the fix (JVM, JS, Wasm).
AbstractClientTransportTest.should answer a message received during initialization once OPERATIONAL. Before the fix: expected:<[JSONRPCResponse(...)]> but was:<[]>. Passes after the fix.
Local: jvmTest for core, testing, client, server and integration-test, plus ktlintCheck detekt checkKotlinAbi, all green.
Stress loop on the stateless branch: the flake hit 10 of 131 baseline runs and 0 of 131 runs with this fix, and every baseline failure logged Transport is not ready. Details in this comment.
A client transport delivers inbound messages from readers started in
initialize(), while send() refuses until start() marks it Operational.
A request that arrives in that window gets a reply that is never sent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…perational
Readers started in initialize() could hand a request to the protocol
before start() moved the transport to Operational, so the reply failed
with "Transport is not ready" and the peer waited out its timeout.
AbstractClientTransport now delivers to onMessage handlers only after
start() completes, which covers ChannelTransport, StdioClientTransport
and the other client transports.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses the client-transport startup race behind intermittent discovery failures following #985. The change delays inbound callbacks until the transport becomes operational, allowing handlers to send replies.
Changes:
Adds a readiness gate to AbstractClientTransport.
Adds regression tests for messages received during initialization.
Updates public API dumps for the onMessage override.
…e start
Client transports now hold inbound messages until start() completes, so
the note describing early delivery no longer holds.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Completing the deferred can resume a waiting handler before start() returns; the new UnconfinedTestDispatcher test exercises exactly that ordering. This contradicts the blast-radius statement that inbound messages are delivered only after start() returns, which would let consumers assume callback state set after the call is ready. Please correct that statement to say delivery begins once the state is operational, or provide the stronger guarantee if intended.
The fix and test commits were cherry-picked onto devcrocod/sep-2575-stateless-mcp at f0e5530. Both applied cleanly, ABI dumps included. Each iteration ran ./gradlew :integration-test:jvmTest --rerun on the baseline and fixed trees at the same time, so both saw the same load. The machine had 16 cores, with 48 yes processes for load and Gradle under nice -n 15 --no-daemon, so the test JVMs got starved CPU. "Flake" means a failure in RequestScopedLifecycleTest or ResponseCacheTest.
Round
Baseline runs
Baseline flake
Baseline Transport is not ready
Fix runs
Fix flake
Fix not ready
1
30
5
5
30
0
0
2
30
1
1
30
0
0
3 (stopped early)
11
0
0
11
0
0
4
30
1
1
30
0
0
5 (worktrees swapped)
30
3
3
30
0
0
Total
131
10
10
131
0
0
The baseline failures match CI: The server/discover probe timed out, a legacy fallback that shows up as a missing server identity or wrong log delivery, and ResponseCacheTest counts off by one. Every failing baseline run logged Transport is not ready, and no passing run did. One-sided Fisher p = 0.0008.
Running only the two classes with 32 load processes and no nice gave 0/30 failures on both trees. Without the full suite saturating Dispatchers.Default, the window doesn't open on this machine.
Separate, pre-existing leak. Both trees sometimes fail 2-3 unrelated runTest tests with IllegalStateException: Not connected from SessionNotificationJob.handleSendNotificationEvent → Protocol.notification. Logging probes on both trees traced it to AbstractServerFeaturesTest sessions over InMemoryTransport. tearDown closes the client while a list-changed send is in flight. Neither end is an AbstractClientTransport, so this change is not on that path. The leak rate follows the worktree slot, not the code: about 9-10% in one slot and 1-3% in the other, whichever code it held. The same job and teardown are on main.
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
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.
Why
Follow-up to #985. Goal: remove the CI flake that makes PRs on the stateless branch green only on rerun.
RequestScopedLifecycleTestandResponseCacheTestfail with "server/discover probe timed out" or "Expected 2026-07-28 but actual was null". Every failing log hasError handling request: server/discover ... McpException: Transport is not readyfromAbstractClientTransport.send. The defect is on main.AbstractClientTransport.start()runsinitialize(), where transports start their readers, and only then moves toOperational. A reader can hand a request toProtocolin that window. The handler's reply hits the state check insend()and is dropped, so the peer waits out its timeout. Sometimes the error reply gets through instead, and the client reads it as a refusal and falls back to legacy. The integration tests startserver.createSessionandclient.connectconcurrently overChannelTransport, and slow CI runners widen the window.What changed
AbstractClientTransportoverridesonMessageso that handlers wait on a deferred thatstart()completes right after theOperationaltransition. Nothing changes once the transport is running.AbstractClientTransportnow declares theonMessageit already inherited (a binary-compatible addition).ProtocolConcurrencyIntegrationTestthat described early delivery. It no longer holds.Scope
The fix goes in the base class because the pattern is shared.
ChannelTransportandStdioClientTransportboth start readers ininitialize()and deliver beforeOperational.SseClientTransportcan too, once the endpoint event has arrived.StreamableHttpClientTransportdelivers only after a send, so it is unaffected. Server transports extendAbstractTransport, which has no state gate onsend.Tradeoffs
A subclass whose
initialize()waits for a JSON-RPC message to be handled would now block. No transport in this repo does that. The closest case is an SSE server that breaks the spec by sending a JSON-RPC event beforeendpoint:start()would now hang instead of losing the reply. Fixing this per transport instead would mean overridingstart(), which its KDoc forbids, and repeating the same fix in every reader.Blast Radius
All
AbstractClientTransportsubclasses, including third-party ones, now get inbound messages only afterstart()returns. Delivery after that is unchanged.Verification
ChannelTransportTest.answers a request the peer sent before start returnedruns the event loop on its own scheduler whilestart()is suspended. Before the fix:Expected JSONRPCResponse(id=NumberId(value=1), ...) but actual was null, withTransport is not readyin the log. Passes after the fix (JVM, JS, Wasm).AbstractClientTransportTest.should answer a message received during initialization once OPERATIONAL. Before the fix:expected:<[JSONRPCResponse(...)]> but was:<[]>. Passes after the fix.jvmTestfor core, testing, client, server and integration-test, plusktlintCheck detekt checkKotlinAbi, all green.Transport is not ready. Details in this comment.🤖 Generated with Claude Code