Skip to content

fix: return 404 for unknown session id so clients recover after restart (2.2.2) - #50

Merged
ttpears merged 1 commit into
mainfrom
fix/session-recovery-404
Jul 10, 2026
Merged

fix: return 404 for unknown session id so clients recover after restart (2.2.2)#50
ttpears merged 1 commit into
mainfrom
fix/session-recovery-404

Conversation

@ttpears

@ttpears ttpears commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Closes #49.

Problem

HTTP sessions are in-memory; a redeploy wipes them. A client still holding an Mcp-Session-Id got a generic 400 (GET/DELETE) or had its stale-id POST grafted onto a fresh transport, and never re-initialized — presenting as a total connector outage for that one user while the server served everyone else at ~92% success. Seen in production right after the 2.2.1 redeploy.

Fix

Spec-correct session routing via a pure, unit-tested classifySessionRequest():

  • known session id → reuse transport
  • unknown/stale session id → HTTP 404 (code -32001) so a compliant client re-initializes (the recovery path; applies to POST/GET/DELETE)
  • no session id + POST isInitializeRequest(body) → create session
  • otherwise → 400

Stops creating orphan sessions for stale-id POSTs. New src/session-routing.test.ts covers every branch incl. the regression (stale-id POST → expired, never create). Full suite 43/43, tsc clean. Patch 2.2.2.

…rt (2.2.2)

HTTP sessions are in-memory, so a redeploy wipes them. A client still holding an
Mcp-Session-Id got a generic 400 (GET/DELETE) or had its stale-id POST grafted
onto a fresh transport, and never re-initialized — an apparent connector outage
for that user while the server served everyone else fine.

Route requests spec-correctly: an unknown session id returns HTTP 404
(code -32001) so a compliant client starts a new session, and a session is
created only for a POST carrying an initialize request (SDK isInitializeRequest).
Decision logic extracted into a pure, unit-tested classifySessionRequest().

Closes #49.
@ttpears
ttpears merged commit 79efe19 into main Jul 10, 2026
3 checks passed
@ttpears
ttpears deleted the fix/session-recovery-404 branch July 10, 2026 14:11
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.

HTTP sessions are in-memory: clients wedge after a restart instead of re-initializing (return 404 for unknown session id)

1 participant