Repository navigation
Conversation
Last-Event-ID names the last event the client received, but LocalSessionWorker::resume passed its index to CachedTx::sync, which replays from that index inclusive. A resuming client got the last event it had already read a second time. The rmcp client does not drop repeats, so it handled that event twice. resume now passes the index after Last-Event-ID. sync keeps its meaning (replay from an index), which a new standalone stream relies on to replay the whole cache. On the standalone stream the uncached priming event and the first cached event both had id 0, so Last-Event-ID: 0 was ambiguous. Events there now start at 1; 0 is the priming event alone.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
jokemanfire
left a comment
There was a problem hiding this comment.
Verified at e2d9e904 (base 37257723, matches the PR base). Everything below was run locally; the fork's CI has not started (action_required), so this is the only evidence there is.
What I ran
cargo test -p rmcp --features transport-streamable-http-server --lib resume_replay_tests→ 4 passed.cargo test -p rmcp --features "server client transport-streamable-http-server transport-streamable-http-client reqwest" --test test_sse_concurrent_streams→ 18 passed, including the newresume_does_not_replay_the_event_named_by_last_event_id.- Full suite with CI's feature set (
cargo metadata, every feature exceptlocal): 2011 passed, 0 failed, 18 ignored across 109 test binaries. - Red before green: I moved the additions onto base
37257723(the newresume_replay_testsmodule pasted into the base file, plus the new integration test):request_wise_resume_replays_only_events_after_last_event_id→left: ["1/0", "2/0"],right: ["2/0"]common_resume_replays_only_events_after_last_event_id→ sent ids were["0", "1"]request_wise_resume_rejects_an_event_id_that_was_never_sent→resumereturnedOk, as the body saysresume_does_not_replay_the_event_named_by_last_event_id→the event named by Last-Event-ID "0" must not be replayed
The red run also proves the second half of the body: on base the first cached standalone notification really is id 0, the same id as the priming event written by ServerSseMessage::priming("0", …) (tower.rs:2114, tower.rs:2355). That is not just an offset bug.
Checked by reading
EventId::next_indexkeeps the/<http_request_id>part, so request-wise resume ids stay inside their channel; only the per-channel index moves.- New standalone streams still pass
Some(0)fromestablish_common_channel, andsyncusessaturating_sub(front.index), so starting cached ids at 1 does not skip the first event of a fresh stream. - External
EventStoresessions never hit these indices:store_eventassigns the ids (the priming event included,tower.rs:1590-1600) andreplay_events_after(tower.rs:2025) does the resume, so the "unchanged" claim holds. EventId::from_stracceptsindexonly, soLast-Event-ID: 0= common-channel priming event, unchanged.
Two notes, neither blocking
- A resume id of exactly
last_sent + 1now returnsInvalidEventIdinstead of replaying nothing.tower.rs:2079turns a resume error into a 200 with an empty stream, so the client sees the same thing — but the failed resume also skips installing the replacement primary, and the dead channel keeps caching (cache_and_sendstores before it tries the sender), so those events arrive on the next GET withoutLast-Event-ID. Unreachable for a real client, so I would leave it; just worth knowing the two paths differ. syncstill replays the whole cache whenLast-Event-IDis older thancache.front()(trimmed bychannel_capacity), re-sending events the client already has. Pre-existing and out of scope, but it is the one remaining path where "only after Last-Event-ID" is not true; one line insync's doc would say so.
No request for changes from me. I cannot approve, and I would not before CI runs on a maintainer-approved workflow anyway.
connor4312
left a comment
There was a problem hiding this comment.
LGTM. Resume now replays strictly after Last-Event-ID on the same stream, as 2025-11-25 "Resumability and Redelivery" requires. Standalone stream ids start at 1, so 0 only means the priming event. Malformed or out-of-range ids fail without panicking. The in-memory path is still limited to legacy sessions, and replay is an offset skip with no extra copying. The session lib tests and test_sse_concurrent_streams pass, and clippy is clean.
Fixes #1577
When a client resumes an SSE stream,
LocalSessionManagersends the event named byLast-Event-IDagain. It now replays only the events after it.Motivation and Context
Last-Event-IDis the last event the client received, and the transport spec lets the server "replay messages that would have been sent after the last event ID".CachedTx::sync(index)skips the cached events beforeindexand sends the rest, so the event atindexgoes out a second time.With the default configuration, a request stream holds
0/0(priming),1/0and2/0. A client that read up to1/0and reconnects withLast-Event-ID: 1/0gets1/0and2/0. The rmcp client records the id of every event it processes and reconnects with it, so it handles1/0twice. If that event is a server request routed to the request's stream (elicitation, sampling), the client runs it twice.The standalone GET stream has the same fault, plus a clash of ids. The priming event that opens it has id
0and is not cached; the first cached event also got id0.Last-Event-ID: 0could mean "read the priming event only" or "read the first event", and the server could not tell which. The spec asks for ids that are unique within a session.The change:
resumepasses the index afterLast-Event-IDtosync, for request streams and for the standalone stream.syncstill means "replay from this index", which is what a new standalone stream needs (it replays the whole cache from 0).0is only ever the priming event andLast-Event-ID: 0replays everything cached.The existing bound check in
syncnow also rejects an id one past the last event sent, which was accepted before and replayed nothing. No client can hold such an id.Resume through an external
EventStoreis unchanged:replay_events_afteralready has this contract.#1165 made the same observation and went stale without review; its other half (keeping the cache of a completed request) landed in #1487. This PR is a separate, smaller patch for the replay offset.
How Has This Been Tested?
New tests, all failing on main (
3725772) except the last, which guards the behavior that must not change:resume_replay_tests::request_wise_resume_replays_only_events_after_last_event_id["1/0", "2/0"], expected["2/0"]resume_replay_tests::common_resume_replays_only_events_after_last_event_id0resume_replay_tests::request_wise_resume_rejects_an_event_id_that_was_never_senttest_sse_concurrent_streams::resume_does_not_replay_the_event_named_by_last_event_id(over HTTP)resume_replay_tests::new_standalone_stream_replays_every_cached_eventRun locally on Linux, Rust 1.96:
cargo +nightly fmt --all -- --check, the five clippy steps fromci.yml,cargo test --all-features,cargo test -p rmcp --lib --no-default-features,cargo test -p rmcp --features <all but local>, the docs build andtypos.Breaking Changes
None in the API. On the wire, event ids of the standalone stream now start at
1instead of0. Ids are opaque to clients.Types of changes
Checklist
Additional context
Not changed here: the priming event of the
initializeresponse also has id0(tower.rs), on a stream that cannot be resumed on its own. A client that reconnects with it lands on the standalone stream and gets every cached event, which is the right outcome for a client that has read none.AI disclosure: this PR was written primarily with Claude Code (an AI coding agent): it found the bug, wrote the fix, the tests and this description, and ran the checks above locally.
🤖 Generated with Claude Code