Skip to content

fix(cua): close stale tabs on fresh-navigation reset — kill the wrong-tab drift - #956

Merged
mercurialsolo merged 1 commit into
mainfrom
fix/cua-close-stale-tabs
Jul 1, 2026
Merged

mercurialsolo merged 1 commit into
mainfrom
fix/cua-close-stale-tabs

Conversation

@mercurialsolo

Copy link
Copy Markdown
Owner

Audit finding (tab accumulation → wrong-tab landings)

Running many tasks on one warm profile piles up 40–50 tabs — the agent's
target=_blank clicks and mid-task link-opens never get cleaned up. Both
current_url and the CDP navigate/read target pick "the FIRST page tab"
from /json/list, so once stale tabs accumulate, CDP lands on a prior run's
page
: the serial-same-profile drift the auditor observed —

  • S09 showed r/MachineLearning (S04's URL), not r/webdev
  • S03 drifted to github.com; Q02 to the Reddit ToS

This also affects the warm-container profile-reuse path in prod, not just
the serial audit.

Fix

reset() now calls _close_stale_tabs() at the start of a fresh navigation
(a new task with a start_url): keep the active tab (Chrome lists it first),
close the rest via CDP /json/close/<id>. Gated to the navigation branch, so
tabs the agent opens within a run are untouched; best-effort so a CDP hiccup
never breaks reset.

Tests

test_cua_close_stale_tabs.py — closes all-but-active, no-op on single tab,
best-effort on CDP failure. 19 adjacent tests green; ruff clean.

Context

The auditor is right that fresh-profile-per-run is the cleaner test setup —
and the re-audit harness (#954) already does exactly that, where typing landed
(verified) and multi-step click navigated. This fix hardens the warm-reuse
path so the drift can't recur there either.

🤖 Generated with Claude Code

…-tab drift

Audit finding: running many tasks on one warm profile piles up 40-50 tabs (the
agent's target=_blank clicks / mid-task link-opens never get cleaned up). Both
current_url and the CDP navigate/read target pick "the FIRST page tab" from
/json/list, so once stale tabs accumulate they land on a PRIOR run's page — the
serial-same-profile drift the auditor saw (S09 showed S04's URL, S03 drifted to
github, Q02 to the Reddit ToS). This also affects the warm-container
profile-reuse path in prod, not just the serial audit.

reset() now calls _close_stale_tabs() at the START of a fresh navigation (a new
task with a start_url) — keeps the active tab (Chrome lists it first), closes
the rest via CDP /json/close/<id>. Gated to the navigation branch, so tabs the
agent opens WITHIN a run are untouched; best-effort so a CDP hiccup never breaks
reset.

Tests: test_cua_close_stale_tabs.py — closes all-but-active, no-op on single
tab, best-effort on CDP failure. 19 adjacent tests green; ruff clean.

Note: the auditor is right that fresh-profile-per-run is the cleaner test setup
(the re-audit harness #954 already does this and shows typing+multi-step work);
this fix hardens the warm-reuse path so the drift can't recur there either.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mercurialsolo
mercurialsolo merged commit 72ca8bf into main Jul 1, 2026
6 checks passed
@mercurialsolo
mercurialsolo deleted the fix/cua-close-stale-tabs branch July 1, 2026 13:19
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