fix(realtime): carry SSE Retry-After into the reconnect outcome (04-02)
A 429/503 Retry-After reached only onRetryHint, so passing the read result to the reconnect coordinator retried before the server allowed. readSseForReconnect returns the hint as serverNotBeforeMs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
bcad7b0d12
commit
02d3fdf546
@@ -12,6 +12,7 @@ import {
|
||||
} from "../../../application/ports/realtime/event-authority.ts";
|
||||
import { isRealtimeResumeCursor } from "../../../contracts/realtime-events.ts";
|
||||
import { systemClock } from "../../platform/system-clock.ts";
|
||||
import type { RealtimeReconnectOutcome } from "../reconnect-coordinator.ts";
|
||||
import { parseRetryAfterDelay } from "../reconnect-policy.ts";
|
||||
import {
|
||||
isRealtimeResult,
|
||||
@@ -468,6 +469,28 @@ export function createFetchSseConnection(
|
||||
return Object.freeze({ read, close });
|
||||
}
|
||||
|
||||
/**
|
||||
* Bridges one read to the reconnect coordinator's outcome shape. A validated
|
||||
* Retry-After (429/503) or SSE `retry:` hint reaches only `onRetryHint`, not
|
||||
* the failure, so a plain `read` result lets the coordinator retry early.
|
||||
*/
|
||||
export async function readSseForReconnect(
|
||||
connection: FetchSseConnection,
|
||||
input: FetchSseReadInput,
|
||||
): Promise<RealtimeReconnectOutcome<FetchSseClosedOutcome>> {
|
||||
let serverNotBeforeMs: number | null = null;
|
||||
const result = await connection.read({
|
||||
...input,
|
||||
onRetryHint(retryMs) {
|
||||
serverNotBeforeMs = retryMs;
|
||||
input.onRetryHint?.(retryMs);
|
||||
},
|
||||
});
|
||||
return Object.freeze(
|
||||
result.ok ? { result } : { result, serverNotBeforeMs },
|
||||
);
|
||||
}
|
||||
|
||||
function fixedEndpoint(endpoint: string, applicationOrigin: string): URL {
|
||||
let parsedEndpoint: URL;
|
||||
let parsedOrigin: URL;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export {
|
||||
createFetchSseConnection,
|
||||
readSseForReconnect,
|
||||
SSE_CONTINUE,
|
||||
type FetchSseClosedOutcome,
|
||||
type FetchSseConnection,
|
||||
|
||||
Reference in New Issue
Block a user