Skip to content

Commit d3fa0e4

Browse files
committed
fix: retry SSE on transient HTTP errors after successful session
Only treat 'no-connection' as fatal on the first attempt. If we've previously connected successfully, the server may be restarting — retry with backoff instead of giving up.
1 parent f9c382d commit d3fa0e4

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/commands/local/server.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ async function consumeSSE(opts: ConsumeSSEOptions): Promise<void> {
442442
let lastEventId: string | undefined;
443443
let retries = 0;
444444
let retryDelay = SSE_INITIAL_RETRY_MS;
445+
let hasConnectedBefore = false;
445446

446447
while (!signal.aborted) {
447448
const result = await attemptSSEConnection({
@@ -456,12 +457,18 @@ async function consumeSSE(opts: ConsumeSSEOptions): Promise<void> {
456457
},
457458
});
458459

459-
if (signal.aborted || result === "no-connection") {
460+
if (signal.aborted) {
461+
return;
462+
}
463+
// Only treat "no-connection" as fatal on the first attempt.
464+
// If we've connected before, the server may be restarting — retry.
465+
if (result === "no-connection" && !hasConnectedBefore) {
460466
return;
461467
}
462468
// Reset backoff after a successful connection that later dropped,
463469
// so transient disconnects don't permanently exhaust the retry budget.
464470
if (result === "connected-then-lost") {
471+
hasConnectedBefore = true;
465472
retries = 0;
466473
retryDelay = SSE_INITIAL_RETRY_MS;
467474
}

0 commit comments

Comments
 (0)