Skip to content

Commit f9c382d

Browse files
committed
fix: reset SSE retry counter on successful reconnection, remove duplicate code
- Reset retries and backoff delay after a successful connection that later drops, so transient disconnects don't exhaust the retry budget - Distinguish 'connected-then-lost' from 'error' in attemptSSEConnection - Remove duplicate unreachable code blocks in inferSemanticOp (biome format artifact)
1 parent 8eb274a commit f9c382d

2 files changed

Lines changed: 12 additions & 17 deletions

File tree

src/commands/local/server.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,12 @@ async function consumeSSE(opts: ConsumeSSEOptions): Promise<void> {
459459
if (signal.aborted || result === "no-connection") {
460460
return;
461461
}
462-
// result === "disconnected" — retry
462+
// Reset backoff after a successful connection that later dropped,
463+
// so transient disconnects don't permanently exhaust the retry budget.
464+
if (result === "connected-then-lost") {
465+
retries = 0;
466+
retryDelay = SSE_INITIAL_RETRY_MS;
467+
}
463468
retries += 1;
464469
if (retries > SSE_MAX_RECONNECTS) {
465470
logger.warn(
@@ -477,23 +482,24 @@ async function consumeSSE(opts: ConsumeSSEOptions): Promise<void> {
477482

478483
/**
479484
* Attempt a single SSE connection. Returns:
480-
* - `"no-connection"` if the server couldn't be reached
481-
* - `"disconnected"` if the connection was established then dropped
485+
* - `"no-connection"` if the server couldn't be reached or aborted
486+
* - `"connected-then-lost"` if the connection was established then dropped
487+
* - `"error"` if an error occurred (may or may not have connected)
482488
*/
483489
async function attemptSSEConnection(
484490
opts: ConsumeSSEOnceOptions
485-
): Promise<"no-connection" | "disconnected"> {
491+
): Promise<"no-connection" | "connected-then-lost" | "error"> {
486492
try {
487493
const connected = await consumeSSEOnce(opts);
488-
return connected ? "disconnected" : "no-connection";
494+
return connected ? "connected-then-lost" : "no-connection";
489495
} catch (err: unknown) {
490496
if (isAbortError(err) || opts.signal.aborted) {
491497
return "no-connection";
492498
}
493499
logger.debug(
494500
`SSE error: ${err instanceof Error ? err.message : String(err)}`
495501
);
496-
return "disconnected";
502+
return "error";
497503
}
498504
}
499505

src/lib/formatters/semantic-display.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,6 @@ export function inferSemanticOp(attrs: AttributeSource): string | undefined {
146146
if (getAttr(attrs, ["rpc.system.name", "rpc.service"])) {
147147
return "rpc";
148148
}
149-
if (
150-
getAttr(attrs, ["db.system.name", "db.query.summary", "db.operation.name"])
151-
) {
152-
return "db";
153-
}
154-
if (getAttr(attrs, ["graphql.operation.type"])) {
155-
return "graphql";
156-
}
157-
if (getAttr(attrs, ["rpc.system.name", "rpc.service"])) {
158-
return "rpc";
159-
}
160149
if (getAttr(attrs, ["messaging.system", "messaging.operation.name"])) {
161150
return "messaging";
162151
}

0 commit comments

Comments
 (0)