Skip to content

connection.md: recovery for hung attached session - #541

Open
zachary-ai wants to merge 2 commits into
browser-use:mainfrom
zachary-ai:hung-attached-session-gotcha
Open

connection.md: recovery for hung attached session#541
zachary-ai wants to merge 2 commits into
browser-use:mainfrom
zachary-ai:hung-attached-session-gotcha

Conversation

@zachary-ai

@zachary-ai zachary-ai commented Jul 19, 2026

Copy link
Copy Markdown

Adds a field-tested gotcha to interaction-skills/connection.md: when the daemon's attached tab has a hung renderer, every helper call (page_info(), js()) blocks forever with no error while the daemon log looks healthy. Documents how to diagnose via browser-level CDP over the raw socket and re-point the default session at a fresh tab, plus the trap that restart_daemon() only stops the daemon.

Hit in production on 20 Jul 2026 when a long-idle Mighty Networks feed tab stopped answering Runtime.evaluate and hung a scheduled scan for 10+ minutes.

🤖 Generated with Claude Code


Summary by cubic

Documents recovery for a hung attached CDP session and adds a close_tab() helper so agents can clean up tabs and avoid indefinite blocking. This prevents stuck page_info()/js() calls and provides a safe path to reattach to a fresh tab.

  • New Features
    • Added close_tab(target_id=None) to close a page target and run ensure_real_tab().
    • Updated interaction-skills/connection.md with steps to diagnose a hung session via raw CDP, create/attach a fresh target, set the default session, and caveats about switch_tab() blocking and restart_daemon() only stopping the daemon.

Written for commit 75e1458. Summary will update on new commits.

Review in cubic

zachary king and others added 2 commits June 11, 2026 12:26
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ring evaluate)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@browser-harness-review

Copy link
Copy Markdown

✅ Skill review passed

Reviewed 1 file(s) — no findings.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

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="helpers.py">

<violation number="1" location="helpers.py:152">
P2: Closing the current tab leaves `self.session` (in the daemon) pointing to a dead session. `ensure_real_tab()` may not always switch to a new tab — `current_tab()` can return the closed tab's URL (which doesn't start with INTERNAL), so the early-return path in `ensure_real_tab()` fires without calling `switch_tab()`. The daemon's stale-session auto-recovery on the next CDP call covers this, but there's a window where the next session-scoped call either fails or incurs a re-attach delay.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread helpers.py
# targetId — the attached session's id is not closable directly.
tid = target_id or current_tab()["targetId"]
cdp("Target.closeTarget", targetId=tid)
ensure_real_tab()

@cubic-dev-ai cubic-dev-ai Bot Jul 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Closing the current tab leaves self.session (in the daemon) pointing to a dead session. ensure_real_tab() may not always switch to a new tab — current_tab() can return the closed tab's URL (which doesn't start with INTERNAL), so the early-return path in ensure_real_tab() fires without calling switch_tab(). The daemon's stale-session auto-recovery on the next CDP call covers this, but there's a window where the next session-scoped call either fails or incurs a re-attach delay.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At helpers.py, line 152:

<comment>Closing the current tab leaves `self.session` (in the daemon) pointing to a dead session. `ensure_real_tab()` may not always switch to a new tab — `current_tab()` can return the closed tab's URL (which doesn't start with INTERNAL), so the early-return path in `ensure_real_tab()` fires without calling `switch_tab()`. The daemon's stale-session auto-recovery on the next CDP call covers this, but there's a window where the next session-scoped call either fails or incurs a re-attach delay.</comment>

<file context>
@@ -143,6 +143,14 @@ def new_tab(url="about:blank"):
+    # targetId — the attached session's id is not closable directly.
+    tid = target_id or current_tab()["targetId"]
+    cdp("Target.closeTarget", targetId=tid)
+    ensure_real_tab()
+
 def ensure_real_tab():
</file context>
Fix with cubic

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