Skip to content

fix(transport): don't replay the Last-Event-ID event on resume - #1461

Open
0z5a wants to merge 1 commit into
modelcontextprotocol:mainfrom
0z5a:fix/resume-skip-last-event-id
Open

0z5a wants to merge 1 commit into
modelcontextprotocol:mainfrom
0z5a:fix/resume-skip-last-event-id

Conversation

@0z5a

@0z5a 0z5a commented Nov 16, 2026

Copy link
Copy Markdown

This picks up the replay part of #1165, which was closed as stale, and answers its open review question about the standalone priming event.

Problem

CachedTx::sync replayed the cache starting at the event named by Last-Event-ID, so that event was always delivered twice. The transports spec says the client sends the "last event ID it received" and the server replays messages "that would have been sent after the last event ID". The EventStore::replay_events_after contract in this crate already says "strictly after". Only the default in-memory path (LocalSessionManager without an event store) was off by one.

On main, with the default config and a standalone GET carrying events 0, 1, 2: resuming from 1 replays 1 and 2, and resuming from 2 replays 2. rmcp's own client and the TypeScript SDK client both resume with the id of the last event they processed, so every reconnect after a dropped connection re-delivers one message. That message can be a progress notification, a response, or a sampling/elicitation request, and it reaches the client a second time.

Change

  • sync(index) now skips through index itself, so only later events are replayed.
  • The common (standalone GET) cache now starts at index 1. A standalone GET sends a synthetic priming event with the hardcoded id 0. Before this change, the first cached notification also had id 0, so a strict "after 0" would have skipped a notification the client never saw. With the cache starting at 1, resuming from the priming id 0 still replays every cached notification, and dead_primary_replacement_replays_cached_events passes unchanged. Request-wise streams already index their priming event, so they need no change.
  • A fresh GET without Last-Event-ID still replays the whole retained common cache, as before. Without a cursor the server cannot tell what the client already has, so that stays out of scope here. The event-store path is unchanged.
  • Resuming from an id older than the retained window still replays whatever is retained (saturating_sub), as before. This PR only removes the off-by-one and leaves eviction behaviour alone.

Tests

  • tests/test_sse_concurrent_streams.rs::resume_does_not_replay_the_last_event_id: receives a notification on the standalone stream, drops it, resumes with that notification's id, and asserts the notification does not come back. It fails on main (Last-Event-ID 0 was already delivered and must not be replayed) and passes with the fix.
  • session::local::resume_tests::resume_replays_only_events_after_last_event_id: a request-wise cache holding 0/3, 1/3, 2/3 resumed from 1/3. On main it replays ["1/3", "2/3"]; with the fix it replays ["2/3"].
  • With the fix, test_sse_concurrent_streams passes 18/18 (17/18 on main). test_streamable_http_priming (5), test_streamable_http_event_store (2), test_streamable_http_stale_session (4), test_streamable_http_reconnect_classification (10), test_streamable_http_disconnect_cancel (2), test_custom_headers (39), test_streamable_http_client_concurrency (20), test_streamable_http_limit_lifecycle (10), test_sep_2260_stream_enforcement (2), test_sep_2260_stream_routing (1), test_inflight_response_drain (2) and the rmcp lib tests (440 with the streamable HTTP client and server features) pass on macOS arm64. cargo fmt --check is clean.

AI disclosure: this PR was written with Claude Code (claude-opus-5-5): the investigation, the fix, the tests and this description. The test results above are from the runs described.

CachedTx::sync replayed the cache starting at the event named by
Last-Event-ID, so the last event the client received was sent again on
every resume. Replay only the events after it, as the EventStore path
already does.

The standalone GET stream's synthetic priming event has the fixed id 0,
which the first cached common event also used. Start the common cache at
1 so that resuming from the priming event still replays every cached
notification.
@0z5a
0z5a requested a review from a team as a code owner November 16, 2026 13:24
@github-actions github-actions Bot added T-test Testing related changes T-core Core library changes T-transport Transport layer changes labels Nov 16, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T13:27:56.658734Z ee3e578 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

@michaelneale is on triage rotation this week and is the reviewer for this one.

Labels come from the PR labeler. Please review the change.

Automated triage. Labels are a first pass and the assigned maintainer has the final say.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-test Testing related changes T-transport Transport layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant