Skip to content

fix: close replayed request SSE streams when no request remains in flight - #2779

Open
ashwinmridul wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
ashwinmridul:fix/2558-close-replayed-request-stream
Open

fix: close replayed request SSE streams when no request remains in flight#2779
ashwinmridul wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
ashwinmridul:fix/2558-close-replayed-request-stream

Conversation

@ashwinmridul

Copy link
Copy Markdown

Fixes #2558 (v1.x backport of the original close-after-replay slice).

Summary

On main, a Last-Event-ID resume of a per-request SSE stream already closes and unregisters that stream when no in-flight request still maps to it. v1.x still armed keep-alive on that successor, so resume polling could hang open and a later reconnect with getStreamIdForEventId could be refused with 409.

This PR ports that behavior:

  • After replay, if the stream is not the standalone GET stream and _requestToStreamMapping has no remaining request for it, close the controller and drop the mapping.
  • Keep-alive is armed only when the resumed stream stays registered.
  • Standalone _GET_stream is unchanged.

I am not taking the widened Exchange state-machine scope from the later issue comment; that belongs on main first. This is the original close-when-idle replay fix for the v1 line.

Tests

  • New regression: reconnect after closeSSEStream + retired request replays the stored result, then a second reconnect is 200 (not 409).
  • Existing keep-alive supersede coverage now uses _GET_stream, which is the stream that should stay open.
  • npx vitest run test/server/streamableHttp.test.ts: 188 passed.

Note on #2677

I am not opening a third PR for the draft-07 $schema bug. #2085 and #2653 already fix it on v1.x.

…ight

After Last-Event-ID replay, keep-alive was holding the successor stream open even when the correlated request had already retired, so a later reconnect could be refused with 409. Close and unregister per-request streams in that case; leave the standalone GET stream open.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ashwinmridul
ashwinmridul requested a review from a team as a code owner September 10, 2026 12:46
@changeset-bot

changeset-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3b11713

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Sep 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@modelcontextprotocol/sdk@2779

commit: 3b11713

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