Skip to content

daemon: keep named automation in reusable background tabs - #618

Open
MagMueller wants to merge 8 commits into
mainfrom
fix/named-daemon-cleanup
Open

daemon: keep named automation in reusable background tabs#618
MagMueller wants to merge 8 commits into
mainfrom
fix/named-daemon-cleanup

Conversation

@MagMueller

@MagMueller MagMueller commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #616.

Named local/CDP daemons now get a dedicated tab so parallel names do not navigate the same page. The lifecycle stays intentionally simple:

  • First attach: create one dedicated background tab.
  • Stale session: reattach to the current selected tab if it still exists, otherwise the dedicated tab.
  • If the user closed both: create one background replacement. Concurrent recovery shares that replacement and delayed requests retry on the recovered session.
  • Daemon shutdown or disconnect: leave every working/user tab open.

Normal helper behavior is background-first too:

  • new_tab() creates a background target.
  • switch_tab(target) attaches and moves the horse marker without changing Chrome's visible tab.
  • switch_tab(target, activate=True) or activate_tab(target) is the explicit opt-in for a visible switch.
  • Static screenshots and normal CDP input work while the tab is hidden. Activation remains available only for a user-requested visible switch or a page that demonstrably pauses visibility-dependent rendering.

This change does not automatically close normal browser tabs. Users and agents can still close a tab explicitly with close_tab().

Default daemons and named Browser Use Cloud daemons keep their existing first-page attach behavior. The existing cleanup for a harness-opened chrome://inspect permission tab also remains.

Verification:

  • uv run --with pytest pytest -q — 140 passed
  • git diff --check — passed
  • Live macOS Chrome — a document.hidden === true background tab accepted typing and a coordinate click, captured a 3456×1730 PNG, and did not change the foreground application.
  • Review race reproduction — when one request recovered the stale session first, the delayed request retried successfully on the replacement session; explicit stale-session requests still return their error.
  • Shutdown regression — the real serve stop path leaves both the dedicated and user-selected tabs open.

Summary by cubic

Keeps named local daemons on a dedicated reusable background tab and stops changing the user’s visible tab. Previously we attached to the first page and switch_tab() activated it; now switch_tab() attaches without activating, stale-session recovery is scoped and serialized with tab switches, and recovered sessions publish before domain enable so delayed requests hit the right tab.

  • Named local daemons create one background about:blank tab; default and named remote daemons still attach to the first real page.
  • Reattach prefers the current selected tab, then the dedicated tab; if both are closed, one background replacement is created and shared by concurrent recoveries; attach/setup failures leave the created tab for retry.
  • Recovery: implicit stale requests reattach and retry only on the specific recovered session; explicit session_id requests return an error; we publish the replacement before domain setup and preserve chains; tab switches wait for in-flight recovery so recovered actions are not redirected.
  • Helpers: new_tab() creates background targets; switch_tab(target) attaches and moves the horse marker; activate_tab(target) opts into a visible switch; screenshots and normal CDP input work while hidden; shutdown leaves working and user tabs open.
  • Migration: Call activate_tab(target) or switch_tab(..., activate=True) when a visible tab switch is required.

Written for commit f4c6ca2. Summary will update on new commits.

Review in cubic

@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.

All reported issues were addressed across 2 files

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

Fix all with cubic | Re-trigger cubic

Comment thread src/browser_harness/daemon.py Outdated
Comment thread src/browser_harness/daemon.py Outdated

@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.

All reported issues were addressed across 2 files (changes from recent commits).

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

Fix all with cubic | Re-trigger cubic

Comment thread src/browser_harness/daemon.py Outdated
Comment thread src/browser_harness/daemon.py Outdated
Comment thread src/browser_harness/daemon.py Outdated
@MagMueller MagMueller changed the title daemon: clean up named daemon tabs reliably daemon: give named daemons reusable dedicated tabs Aug 15, 2026

@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.

All reported issues were addressed across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread src/browser_harness/daemon.py
Comment thread tests/unit/test_daemon.py Outdated
@browser-harness-review

Copy link
Copy Markdown

✅ Skill review passed

Reviewed 3 file(s) — no findings.

@MagMueller MagMueller changed the title daemon: give named daemons reusable dedicated tabs daemon: keep named automation in reusable background tabs Aug 15, 2026

@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.

All reported issues were addressed across 7 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread src/browser_harness/daemon.py Outdated

@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.

All reported issues were addressed across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread src/browser_harness/daemon.py Outdated

@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.

All reported issues were addressed across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread src/browser_harness/daemon.py
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