Skip to content

fix(core): retry in-flight MCP calls aborted by session-expiry reconnect - #67852

Merged
rekram1-node merged 1 commit into
devfrom
mcp-expired-close
Dec 2, 2026
Merged

rekram1-node merged 1 commit into
devfrom
mcp-expired-close

Conversation

@rekram1-node

Copy link
Copy Markdown
Member

When a legacy HTTP MCP session expires while two calls are in flight, the first call observes the 404/400 expiry, sets session.reported = true, and triggers reconnect, which closes the expired client. Any other call still in flight on that client then fails with SdkErrorCode.ConnectionClosed, which previously mapped to a plain Error instead of SessionExpiredError and skipped retry in McpConnection.recovering.

I updated failure() in packages/core/src/mcp/client.ts to map SdkErrorCode.ConnectionClosed to SessionExpiredError once session.reported is true, so in-flight calls wait on the reconnect lock and retry on the replacement client.

I also added a deterministic regression test in packages/core/test/mcp/resilience.test.ts that holds a second concurrent tool call in flight on an expired session while the first triggers reconnect and verifies both calls succeed after a single re-initialization.

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.

1 participant