fix(realtime): reconnect retryable failures without a server hint (R-4.2)
reconnectable() in the reconnect coordinator returned false for
PROVIDER_UNAVAILABLE/RATE_LIMITED whenever serverNotBeforeMs was null, even
with retryable:true. The transports send exactly that for WS NETWORK_LOST /
RESTART (1006/1001/1012, error event) and SSE 502/504, and WS can never carry
a hint, so those streams ended instead of reconnecting. The bounded poll
coordinator had the same rule for retryAfterMs.
Both now decide on retryable + kind only; a missing hint falls back to policy
backoff. Transports that require a hint and lack one already report
retryable:false (SSE 429/503 without Retry-After, WS OVERLOADED), which stays
terminal.
Tests: the reconnect and poll tests that pinned the old behavior ("does not
reconnect/retry ... without a server hint") encoded the bug and are rewritten
to expect a policy-backoff retry. New seam tests wire the real
createWebSocketConnection / createFetchSseConnection into the reconnect
coordinator. RED before the fix: "reconnects a WebSocket NETWORK_LOST|RESTART
close that carries no server hint" (1 socket, expected 2), "reconnects SSE
HTTP 502|504 that carries no server hint" (got PROVIDER_UNAVAILABLE
retryable:true instead of the second attempt's FORBIDDEN), "retries retryable
RATE_LIMITED|PROVIDER_UNAVAILABLE without a server hint on policy backoff"
(execute called once). The WS test also closes with OVERLOADED to show
retryable:false stays terminal.
Gates: check:architecture, check:types:app, check:types:test, lint,
test:component pass. test:unit passes except removal-fixture.test.ts, which
needs generated artifacts/release evidence absent from this fresh worktree
(unrelated).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4e0745c569
commit
87a45893d6
@@ -341,11 +341,11 @@ export function createBoundedPollCoordinator<Value>(
|
||||
}
|
||||
result = parsedResult;
|
||||
if (!result.ok) {
|
||||
// A missing server hint falls back to policy backoff; an executor
|
||||
// that requires one reports `retryable: false` instead.
|
||||
if (
|
||||
!result.error.retryable ||
|
||||
!isPollRetryableFailureKind(result.error.kind) ||
|
||||
(isPollRetryAfterFailureKind(result.error.kind) &&
|
||||
result.error.retryAfterMs === undefined)
|
||||
!isPollRetryableFailureKind(result.error.kind)
|
||||
) {
|
||||
return pollFailure(result.error.kind);
|
||||
}
|
||||
|
||||
@@ -717,12 +717,7 @@ export function createRealtimeReconnectCoordinator<ClosedReceipt>(
|
||||
settleAttemptGate(opened.failure.result);
|
||||
phase.controller.abort();
|
||||
phase.dispose();
|
||||
if (
|
||||
!reconnectable(
|
||||
opened.failure,
|
||||
opened.serverNotBeforeMs,
|
||||
)
|
||||
) {
|
||||
if (!reconnectable(opened.failure)) {
|
||||
return opened.failure.result;
|
||||
}
|
||||
const failedAt = safeNow(clock);
|
||||
@@ -934,12 +929,7 @@ export function createRealtimeReconnectCoordinator<ClosedReceipt>(
|
||||
if (classified.outcome.ok) {
|
||||
return classified.outcome.result as RealtimeResult<void>;
|
||||
}
|
||||
if (
|
||||
!reconnectable(
|
||||
classified.outcome.failure,
|
||||
classified.outcome.serverNotBeforeMs,
|
||||
)
|
||||
) {
|
||||
if (!reconnectable(classified.outcome.failure)) {
|
||||
return classified.outcome.failure.result;
|
||||
}
|
||||
|
||||
@@ -1658,17 +1648,11 @@ function providerRetry(
|
||||
);
|
||||
}
|
||||
|
||||
function reconnectable(
|
||||
failureSnapshot: FailureSnapshot,
|
||||
serverNotBeforeMs: number | null,
|
||||
): boolean {
|
||||
if (
|
||||
serverNotBeforeMs === null &&
|
||||
(failureSnapshot.kind === "RATE_LIMITED" ||
|
||||
failureSnapshot.kind === "PROVIDER_UNAVAILABLE")
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* A transport that needs a server hint and did not get one already reports
|
||||
* `retryable: false`, so a missing hint alone never ends the loop.
|
||||
*/
|
||||
function reconnectable(failureSnapshot: FailureSnapshot): boolean {
|
||||
return (
|
||||
failureSnapshot.retryable &&
|
||||
RETRYABLE_KINDS.includes(
|
||||
|
||||
Reference in New Issue
Block a user