fix(synthesis): keep the service worker alive during the reduce#197
Merged
Conversation
Raising MAX_REDUCE_OUTPUT_TOKENS to 32768 made the reduce generate longer,
and the reduce is the one long single fetch in the corpus flow. The map
phase's many short messages naturally reset the MV3 idle timer, but the
reduce runs "cold" afterward — no messages for minutes — so Chrome tears
the background SW down mid-fetch and chrome.runtime.sendMessage's callback
fires with undefined (lastError: "message port closed"), surfaced as the
opaque "Synthesis failed: no response".
Mirror the reader's proven startSwKeepalive() (runQuickAudit uses it for
its single-shot audit): a 20s ping to the zero-cost xray:llm:corpus-config
handler spanning the whole run (declared before the try, stopped in the
finally on every exit path) keeps the SW alive during the cold reduce.
Also: sendMessage() now reads chrome.runtime.lastError and returns
{ok:false, error, swLost:true} instead of a bare undefined, so a lost SW
surfaces a real reason + a "try again, cached extracts make the retry
cheap" hint; and CORPUS_REDUCE_TIMEOUT_MS 420000 -> 480000 (with the SW
kept alive, the AbortController is the sole limiter).
Verified with a 5-dimension adversarial review (keepalive lifecycle,
sendMessage blast radius, MV3 semantics, render-guard interaction,
timeout) — 0 confirmed findings.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Immediately after #196 (raising the reduce output cap to 32768), corpus synthesis started failing with "Synthesis failed: no response".
Root cause is a service-worker lifetime interaction the previous fix exposed:
xray:llm:corpus-mapmessages naturally reset the MV3 idle timer.chrome.runtime.sendMessage's callback then fires withundefined(lastError= "message port closed"), whichsynthesis-block.jsflattened to the opaque "no response."Fix (mirrors the reader's proven pattern)
The reader already solves "long single LLM call in the SW" with
startSwKeepalive()(src/reader/index.js~2599, used byrunQuickAudit). The corpus synthesis had no keepalive. This adds it:startSwKeepalive()insynthesis-block.js— a 20ssetIntervalping to the zero-costxray:llm:corpus-confighandler, spanning the whole run (declared before thetry,stop()in thefinallyso it's cleaned up on every exit path). EachonMessagedelivery resets the idle timer, keeping the SW alive through the cold reduce.sendMessage()now readschrome.runtime.lastErrorand resolves{ok:false, error, swLost:true}instead of a bareundefined— a lost SW surfaces a real reason plus an actionable "try again — the cached extracts make the retry cheap" hint, instead of "no response."CORPUS_REDUCE_TIMEOUT_MS420000 → 480000 — with the SW now kept alive, the AbortController is the sole limiter, so give the largest breadth briefs headroom.Verification
npm run buildclean ·npm test1976 pass / 0 fail ·npm run lint0 errors.🤖 Generated with Claude Code