Fail gracefully instead of resuming a session across a protocol change (#374) - #375
Merged
Merged
Conversation
Reconnecting a session replays the stored MCP-Session-Id, and the SDK skips
version negotiation whenever the transport carries one. The client therefore
never learns the protocol era and emits no per-request `_meta` envelope, while
the transport still stamps the MCP-Protocol-Version header restored from
sessions.json — a combination every 2026-07-28 server rejects. Each reconnect
replayed the same id, so the session could never recover.
- New bridge-side resumption planner: it rebuilds the persisted `server/discover`
result and hands it to the SDK's `connect({ prior })`, so a resumed modern
connection knows its era; it refuses to resume when the stored state cannot
support one (an id left behind by a server that has since gone stateless, no
persisted discover result, or no overlapping protocol version)
- sessions.json now drops a stored session id when a connection ends up without
one, instead of keeping it forever
- A resumed connection rejected for a protocol mismatch is retried once from
scratch with a fresh negotiation, rather than failing every reconnect
- A resumed modern connection opens its own `subscriptions/listen` stream, which
the SDK only opens on a probed connect, so list-change notifications keep
arriving
- Added unit tests and an e2e regression guard (sessions/stale-session-id, modern
matrix column) that reproduces the exact server rejection without the fix
Fixes #374
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013JRn5VpCR4jVsXqupVNhzD
…ol change
Session resumption is a 2025-era mechanism, so don't carry it across protocol
versions: a stored session id recorded with a modern (2026-07-28) protocol
version is ignored and dropped, and a resumed legacy session whose server no
longer speaks that version is marked expired with a hint to run `restart`.
This removes the resumption planner, the SDK connect({ prior }) plumbing, and
the client-side listen-stream reopening from the previous commit.
Refs #374
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013JRn5VpCR4jVsXqupVNhzD
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.
A session could get stuck reconnecting forever after its server upgraded to MCP 2026-07-28: each reconnect replayed the stored
MCP-Session-Id, which makes the SDK skip protocol negotiation, so every request went out without the required_metaenvelope and was rejected — same id, same rejection, forever.Session resumption is a 2025-era mechanism, so the fix is to not carry it across protocol versions:
sessions.json— the reconnect negotiates afresh and self-healsexpiredwith a hint to runrestart(which reconnects without the id), instead of retry-loopingisProtocolMismatchError()classifier for the wire signatures of an era mismatchsessions/stale-session-id, modern matrix column) covering both scenarios, plus unit tests for the classifierFixes #374
https://claude.ai/code/session_013JRn5VpCR4jVsXqupVNhzD