Repository navigation
fix(cua): close stale tabs on fresh-navigation reset — kill the wrong-tab drift - #956
Merged
Merged
Conversation
…-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>
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.
Audit finding (tab accumulation → wrong-tab landings)
Running many tasks on one warm profile piles up 40–50 tabs — the agent's
target=_blankclicks and mid-task link-opens never get cleaned up. Bothcurrent_urland the CDP navigate/read target pick "the FIRSTpagetab"from
/json/list, so once stale tabs accumulate, CDP lands on a prior run'spage: the serial-same-profile drift the auditor observed —
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, sotabs 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;
ruffclean.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