From 034155bc4eb5e77c0ebec5a3efb2f3cc0818e79d Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 16 May 2026 11:00:55 +0200 Subject: [PATCH] fix(01-review): sweep #5 surface port-replaced-during-fetch diagnostic on buffer timeout --- src/background/index.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/background/index.ts b/src/background/index.ts index f35d080..9436d35 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -133,7 +133,20 @@ async function getVideoBufferFromOffscreen(): Promise { return new Promise((resolve) => { const timer = setTimeout(() => { port.onMessage.removeListener(handler); - logger.warn(`Buffer fetch timed out after ${BUFFER_FETCH_TIMEOUT_MS} ms`); + // Sweep #5 fix: surface the diagnostic when the timeout fires + // because the port was replaced by a reconnect mid-request. + // The OLD port (captured as `port`) has a dead listener; the + // offscreen will encode-and-send on the NEW port but the + // listener installed there belongs to a different + // getVideoBufferFromOffscreen call (if any). Without this + // diagnostic the operator sees a silent timeout that masquerades + // as an offscreen-side problem. With it, the SW log shows the + // reconnect timing was the proximate cause. + const portReplaced = videoPort !== port; + logger.warn( + `Buffer fetch timed out after ${BUFFER_FETCH_TIMEOUT_MS} ms`, + 'port_replaced_during_fetch:', portReplaced, + ); resolve({ segments: [] }); }, BUFFER_FETCH_TIMEOUT_MS); const handler = (msg: unknown) => {