fix(daemon): retry WS handshake up to 3× with 5s back-off before raising#384
Open
blaineboyden wants to merge 1 commit into
Open
fix(daemon): retry WS handshake up to 3× with 5s back-off before raising#384blaineboyden wants to merge 1 commit into
blaineboyden wants to merge 1 commit into
Conversation
When the previous browser-harness daemon is cleanly shut down between batch retries, Chrome's CDP WS endpoint is transiently unresponsive for a few seconds. The single websockets.connect() call (10 s open_timeout) was enough to expose the bad window — the HTTP /json/version endpoint was still live (so get_ws_url() returned a valid URL) but the WS upgrade itself timed out. Changes: - Daemon.start() now attempts the handshake up to 3 times with a 5 s asyncio.sleep between attempts, refreshing the WS URL on each retry in case Chrome's browser UUID changed. - Error messages include the URL and final exception on all paths. - get_ws_url() error now includes the profile path to speed up diagnosis. Root cause observed: Larry's batch retry at 2026-05-22 05:04 ET — first batch connected OK; ensure_daemon() found the leftover daemon's CDP connection unhealthy, restarted the daemon, and the fresh handshake hit Chrome's 5-10 s unresponsive window after disconnect. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/browser_harness/daemon.py">
<violation number="1" location="src/browser_harness/daemon.py:210">
P2: Remote handshake error branch omits the WS URL, leaving the error-context guarantee only partially implemented. The local branch includes `({url})` but the remote branch does not, despite the PR stating WS URL should be included on all raise paths.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
| if os.environ.get("BU_CDP_WS"): | ||
| raise RuntimeError( | ||
| f"CDP WS handshake failed: {e} -- remote browser WebSocket connection failed. " | ||
| f"CDP WS handshake failed: {last_exc} -- remote browser WebSocket connection failed. " |
Contributor
There was a problem hiding this comment.
P2: Remote handshake error branch omits the WS URL, leaving the error-context guarantee only partially implemented. The local branch includes ({url}) but the remote branch does not, despite the PR stating WS URL should be included on all raise paths.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/browser_harness/daemon.py, line 210:
<comment>Remote handshake error branch omits the WS URL, leaving the error-context guarantee only partially implemented. The local branch includes `({url})` but the remote branch does not, despite the PR stating WS URL should be included on all raise paths.</comment>
<file context>
@@ -185,16 +185,33 @@ async def start(self):
if os.environ.get("BU_CDP_WS"):
raise RuntimeError(
- f"CDP WS handshake failed: {e} -- remote browser WebSocket connection failed. "
+ f"CDP WS handshake failed: {last_exc} -- remote browser WebSocket connection failed. "
"This can happen when network policy blocks the connection, the WS URL is wrong or expired, or the remote endpoint is down. "
"If you use Browser Use cloud, verify BROWSER_USE_API_KEY and get a fresh URL via start_remote_daemon()."
</file context>
Suggested change
| f"CDP WS handshake failed: {last_exc} -- remote browser WebSocket connection failed. " | |
| f"CDP WS handshake failed ({url}): {last_exc} -- remote browser WebSocket connection failed. " |
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
asyncio.sleepbetween attempts) aroundawait self.cdp.start()inDaemon.start().get_ws_url()is called again so a changed browser UUID is picked up automatically.get_ws_url()"DevTools not live yet" error now includes the profile path for faster diagnosis.Root cause
When
ensure_daemon()health-probes a live daemon and finds its CDP connection unhealthy (e.g. after a process restart), it shuts the daemon down and spawns a fresh one. Chrome's WS endpoint is then transiently unresponsive for 5–10 s while it cleans up the previous session. The singlewebsockets.connect()call (10 sopen_timeoutdefault) hit that window and timed out with no retry.Observed at
2026-05-22 05:04 ETin a daily automation run: first batch connected fine, butensure_daemon()restarted the daemon before a retry run, and the fresh handshake failed.Test plan
RuntimeErrorwith the expected message.pytest tests/unit/ -v).from browser_harness.daemon import Daemonimports cleanly.🤖 Generated with Claude Code
Summary by cubic
Retry the CDP WebSocket handshake in Daemon.start() up to 3 times with a 5s backoff to handle Chrome’s brief unresponsive window after restarts. On retries we refresh the WS URL to pick up a new browser UUID, and errors now include the WS URL (local and remote) plus the profile path in the "DevTools not live yet" message.
Written for commit e60129a. Summary will update on new commits. Review in cubic