Skip to content

fix(relay): wait a full reconnect alarm period for the extension - #101

Open
safzanpirani wants to merge 2 commits into
anomalyco:mainfrom
safzanpirani:fix/extension-reconnect-wait
Open

safzanpirani wants to merge 2 commits into
anomalyco:mainfrom
safzanpirani:fix/extension-reconnect-wait

Conversation

@safzanpirani

Copy link
Copy Markdown

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. ensureExtensionConnected waited 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:

  • adds extensionReconnectAlarmPeriodMs to src/protocol.ts, and derives the extension alarm period from it. The alarm period is still 0.5 minutes.
  • sets the default wait in ensureExtensionConnected to 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.
  • adds an onWait option that runs once, when the first probe finds the extension disconnected. The CLI uses it to print Waiting up to 35s for the Browser Control extension to reconnect to stderr, so a missing extension no longer looks like a hang.
  • updates the skill troubleshooting entry and PLAN.md.

A missing extension now fails after 35 seconds instead of 10. That trade gives a sleeping extension time to reconnect.

Verification

  • pnpm run ci, the runtime:prepare step from CI, and pnpm typecheck pass locally. pnpm test passes 972 tests in 69 files, and pnpm audit:duplicates finds 0 clones.
  • Two new tests in test/relay-lifecycle.test.ts. The first shows that the default budget covers 160 probes, 32 seconds at the default spacing, and runs onWait exactly once. The second shows that onWait does not run when the extension is already connected.
  • I ran the source CLI against a fresh relay on another port, with a separate HOME and no extension. It printed the wait line 5 seconds after start, at relay startup, and reported the disconnected extension 36 seconds later.
  • I did not run the browser smoke set, and I did not test a real sleeping worker waking on the alarm.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant