Fix off-by-one error in reconnection attempts (#1356)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
This commit is contained in:
Copilot 2026-02-23 11:38:47 -05:00 • committed by GitHub
commit 2c9bb5d368
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -228,7 +228,10 @@ internal sealed partial class StreamableHttpClientSessionTransport : TransportBa
SseStreamState state,
CancellationToken cancellationToken)
{
int attempt = 0;
// When LastEventId is null, the first attempt is the initial GET SSE connection (not a reconnection),
// so we start at -1 to avoid counting it against MaxReconnectionAttempts.
// When LastEventId is already set, all attempts are true reconnections, so we start at 0.
int attempt = state.LastEventId is null ? -1 : 0;
// Delay before first attempt if we're reconnecting (have a Last-Event-ID)
bool shouldDelay = state.LastEventId is not null;