fix(relay): wait a full reconnect alarm period for the extension - #101
Open
safzanpirani wants to merge 2 commits into
Open
safzanpirani wants to merge 2 commits into
safzanpirani wants to merge 2 commits into
Conversation
When the relay is down, Chrome stops the extension's idle MV3 worker, and only the 30-second reconnect alarm wakes it. After a relay start, ensureExtensionConnected waited about 10 seconds, so the CLI, MCP server, and SDK client often reported a disconnected extension before the alarm fired. The alarm period now lives in src/protocol.ts as extensionReconnectAlarmPeriodMs. The extension derives its alarm from it, and the default wait is one alarm period plus 5 seconds. An onWait hook runs once when the first probe finds the extension disconnected, and the CLI uses it to print the wait to stderr.
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.
Summary
After a relay start, the CLI, MCP server, and SDK client often reported "Browser Control extension is not connected" even though the extension was installed and working.
The extension retries its relay socket every second while its MV3 worker is alive. When the relay is down, Chrome stops that idle worker after about 30 seconds, and only the reconnect alarm wakes it again. The alarm period is 30 seconds, Chrome's minimum.
ensureExtensionConnectedwaited 50 probes 200 ms apart, about 10 seconds, so it usually gave up before the next alarm. The 10-second budget came in #32, and the 30-second alarm came in #37.This PR:
extensionReconnectAlarmPeriodMstosrc/protocol.ts, and derives the extension alarm period from it. The alarm period is still 0.5 minutes.ensureExtensionConnectedto one alarm period plus 5 seconds, 35 seconds in total, at the same 200 ms probe spacing. The CLI, MCP, and SDK callers all use this default.onWaitoption that runs once, when the first probe finds the extension disconnected. The CLI uses it to printWaiting up to 35s for the Browser Control extension to reconnectto stderr, so a missing extension no longer looks like a hang.A missing extension now fails after 35 seconds instead of 10. That trade gives a sleeping extension time to reconnect.
Verification
pnpm run ci, theruntime:preparestep from CI, andpnpm typecheckpass locally.pnpm testpasses 972 tests in 69 files, andpnpm audit:duplicatesfinds 0 clones.test/relay-lifecycle.test.ts. The first shows that the default budget covers 160 probes, 32 seconds at the default spacing, and runsonWaitexactly once. The second shows thatonWaitdoes not run when the extension is already connected.