Repository navigation
Conversation
When the backend pod behind a stdio proxy is replaced, the transport re-attaches to the new process, but the proxy keeps answering client handshakes from the initialize it cached for the old one. The new process never sees an initialize, so servers that enforce the MCP lifecycle reject every later request. After a successful re-attach the proxy now replays the cached initialize, sends notifications/initialized and caches the new result. A JSON-RPC error means the process was already initialized, so the cache is kept; no answer clears it, so the next client handshake goes to the backend. This covers mode 2 of stacklok#6974. Mode 1, a restarted proxy facing a backend that is still initialized, stays open. Signed-off-by: somaz <genius5711@gmail.com>
somaz94
added a commit
to somaz94/somaz94
that referenced
this pull request
Nov 25, 2026
This branch has not been deployed
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
When the operator replaces the
<name>-0pod of a stdioMCPServer, the proxy re-attaches to the new process in place but keeps answering every clientinitializefrom the result it cached for the old one. The new process never receivesinitialize, so a server that enforces the MCP lifecycle (anything on the Go SDK) rejects every later request withmethod "tools/call" is invalid during session initializationuntil someone deletes the proxy pod.After a successful re-attach,
StdioTransportnow asks the streamable proxy to replay the cached handshake.HTTPProxy.ReinitializeBackendsends the storedinitializeparams to the backend inside the same singleflight as client handshakes, and on success replaces the cached result and sendsnotifications/initialized. A JSON-RPC error is read as "this process is already initialized", which is what a strict server answers when only the attach stream dropped, so the cache is kept. A replay that gets no answer clears the cache, so the next client handshake goes to the backend.docs/arch/03-transport-architecture.mddescribes the re-attach behavior.This addresses mode 2 of #6974 only. Mode 1, a restarted proxy whose first
initializereaches a backend that is still initialized, stays open, since it needs a decision between restarting the backend pod and another recovery.Type of change
Test plan
task test)task test-e2e)task lint-fix)task lint-fixreported 0 issues.task testpassed apart fromTestEnvoyBootstrap_ValidatesAgainstRealEnvoyandTestEgressSquidIPv6ConfigValidatesAgainstRealSquidinpkg/container/docker, which need a running Docker daemon that this machine did not have.TestReinitializeBackendcovers the four outcomes of the replay against a fake strict backend and fails on three of them without the change; it and the re-attachment tests inpkg/transportpassed ten runs in a row with-race. I have not reproduced the fix on a cluster.Does this introduce a user-facing change?
Yes. Before, after the backend pod of a stdio
MCPServerwas replaced, a client'sinitializesucceeded from the cache but every request after it failed on a strict server until the proxy pod was restarted. After, the proxy initializes the new process itself when it re-attaches, so requests keep working.Special notes for reviewers
Reading any JSON-RPC error as "already initialized" means a new process that rejects
initializefor some other reason goes undetected, as it does today. A request that reaches the new process between the re-attach and the end of the replay can still fail.ReinitializeBackendretries up to three times when it joins a flight another caller started, because that flight finishes without replaying.Generated with Claude Code