Repository navigation
fix(transport): honor retry policy and server retry interval on SSE stream errors - #1572
seedfunded wants to merge 2 commits into
Conversation
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 5586fbb0 (base 37257723). Ran locally: the fork's CI has not started (action_required), so these numbers are the only ones available.
What I ran
cargo test -p rmcp --lib --features "client,transport-streamable-http-client" transport::common::client_side_sse→ 23 passed.cargo test -p rmcp --test test_streamable_http_reconnect_classification --features "client,transport-streamable-http-client,reqwest"→ 14 passed.cargo fmt --all -- --check→ clean on stable (CI formats with nightly, which I do not have here).- Red before green: I put the four new tests on the base file (kept this PR's tests, restored the two source hunks) and ran the same lib filter → 3 failed / 20 passed:
never_retry_does_not_reconnect_after_stream_error→Matchesfails: base yieldsSome(Ok(..))from the reconnected stream, so the reconnect really happenedmax_times_zero_does_not_reconnect_after_stream_error→ sameserver_retry_interval_applies_after_stream_error→left: [0ns],right: [5s]
So claims 1 and 2 in the body are real and the fix works.
One test does not pin its change. graceful_close_with_never_retry_transitions_to_terminated passes on base as well (20 passed there includes it). The only observable difference of the added this.state.set(SseAutoReconnectStreamState::Terminated) in the None branch is that a non-fused inner stream which yields Some after None will not be read again; a second poll_next on an exhausted Connected stream already returns None without reconnecting, so the assertions in that test hold either way. Either drop it from the list of regression tests or make it use such a source; as written, a reader will think it covers the third change and it does not.
Two things I would rather see as follow-ups than in this PR
- The first wait after an error uses
server_retry_interval.unwrap_or(interval), while a failed reconnect usesserver_retry_interval.max(interval)(:538-543). With a server sendingretry: 100andExponentialBackoff, the first reconnect is at 100ms and later ones at the backoff delay. That asymmetry is pre-existing (the graceful path already usedunwrap_or), but now both error and graceful paths share it. retry_timesis reset to 0 every time a connection succeeds, so a server that accepts and immediately errors loops forever regardless ofmax_times;max_timesonly counts failed connection attempts. Also pre-existing, and also newly visible now that stream errors go through the policy.
The only thing I would change is the fourth test; the code change itself looks right to me, and with the error branch now surfacing map_fatal_stream_error for NeverRetry/max_times: 0, the body's "Breaking: None" is accurate as far as I can tell (a client that installed NeverRetry was reconnecting against its own configuration before).
|
Thanks for the thorough review and local verification, @jokemanfire—good catch on Updated in Agreed on keeping the |
connor4312
left a comment
There was a problem hiding this comment.
LGTM. Stream errors now go through the retry policy and the server's retry: interval, the same as a graceful close, using the field #1519 keeps across reconnects. NeverRetry/max_times: Some(0) now end the stream with the original error. 404/auth/scope errors are still terminal, and the wait is cancellable. The unit tests use paused time, and the streamable HTTP integration suites pass with an explicit feature set.
Minor: the description's "N + 1 attempts" only applies to N = 0; for N ≥ 1 the total number of attempts doesn't change. The two older behaviours jokemanfire raised (how the server interval combines with the policy, and the counter resetting after each successful connection) are worth separate issues.
Motivation
In
SseAutoReconnectStream::poll_next, theSome(Err(e))branch bypassedSseRetryPolicy::retry(0)andserver_retry_interval, jumping straight intoRetryingviaconnector.retry_connection(...).This caused three inconsistencies with the graceful-close (
None) path and SEP-1699 / WHATWG SSE reconnection rules:NeverRetryandmax_times: Some(0)still reconnected on stream errors: A non-oversized stream error (e.g.,ConnectionReset) triggered an unwanted reconnect attempt instead of terminating and surfacing the fatal stream error. Policies withmax_times: Some(N)also performedN + 1reconnect attempts on stream errors.retry:intervals were ignored on stream errors: Even when the server sent aretryfield, an abrupt stream error reconnected immediately with zero delay instead of waitingserver_retry_interval(or the initial policy delay).Terminated: ReturningPoll::Ready(None)while staying inConnectedrisked re-polling the exhausted inner stream if polled again.Changes
crates/rmcp/src/transport/common/client_side_sse.rs:self.retry_policy.retry(0)andself.server_retry_intervalonSome(Err(e)), matching theNonebranch: transition toWaitingNextRetrywhen retries are permitted, or transition toTerminatedand returnmap_fatal_stream_error(e)when retries are disabled.Terminatedbefore returningPoll::Ready(None)in theNonebranch whenretry_policy.retry(0)isNone.never_retry_does_not_reconnect_after_stream_errormax_times_zero_does_not_reconnect_after_stream_errorserver_retry_interval_applies_after_stream_errorgraceful_close_with_never_retry_transitions_to_terminatedVerification
cargo test -p rmcp --lib --features "client,transport-streamable-http-client" transport::common::client_side_ssecargo test -p rmcp --test test_streamable_http_reconnect_classification --features "client,transport-streamable-http-client"cargo test -p rmcp --test test_streamable_http_get_404_session_expired --features "client,transport-streamable-http-client-reqwest,reqwest"cargo clippy -p rmcp --lib --features "client,server,transport-streamable-http-client-reqwest,transport-streamable-http-server,reqwest,transport-io" -- -D warningscargo fmt --all -- --check