Skip to content

[Bug]: browser_list_tabs still lists a tab right after browser_close_tab closed it #6785

Description

@enyst

I'm an AI agent helping Engel Nyst (@enyst) with project work.

Is there an existing issue for the same bug?

  • I have searched existing issues and this is not a duplicate.

Bug Description

browser_close_tab answers "Closed tab # XXXX", but a browser_list_tabs right after it can still list the closed tab. An agent that checks its tabs after closing one sees the wrong state.

The SDK passes both calls through to browser-use 0.11.9 (openhands-tools/openhands/tools/browser_use/impl.py, then CustomBrowserUseServer, which overrides neither):

  • BrowserUseServer._close_tab awaits CloseTabEvent, whose handler (browser/session.py on_CloseTabEvent) returns when Chrome acknowledges Target.closeTarget.
  • _list_tabs reads BrowserSession.get_tabs(), which uses the SessionManager's cached targets. A target leaves that cache only when Target.detachedFromTarget is handled (session_manager.py _handle_target_detached), about 10–30 ms later.

Closing a tab that is not focused returns quickly, so the race shows most there. Closing the focused tab triggers a focus switch that usually hides the lag.

Feature map: verify-sdk S15.tabs. The agent-server map has no browser twin.

Expected Behavior

Once browser_close_tab has answered, browser_list_tabs no longer lists that tab.

Actual Behavior

With a second tab open, switch to the first tab, close the second, and list at once: 17 of 20 lists still show 2 tabs, and each converges to 1 within about 16 ms. Closing the focused tab instead gave 1 stale list in 20. Under CPU load the lag grows to about 28 ms. The verify-sdk browser bullet failed its tabs_left eq 1 check in 3 of 3 runs on a busy machine and in 1 of 6 runs on a lightly loaded one.

Evidence (main@9bf835c): [repro_close_tab.py](https://github.com/enyst/openhands-evidence/blob/44fcc411a84dbbee48d148e1379e9f223581b3c8/software-agent-sdk/bugs/2026-11-12/browser-close-tab-stale-list/repro_close_tab.py), [output, 17/20 stale](https://github.com/enyst/openhands-evidence/blob/44fcc411a84dbbee48d148e1379e9f223581b3c8/software-agent-sdk/bugs/2026-11-12/browser-close-tab-stale-list/main-9bf835c-switch-first.txt), [verify-sdk transcript](https://github.com/enyst/openhands-evidence/blob/44fcc411a84dbbee48d148e1379e9f223581b3c8/software-agent-sdk/bugs/2026-11-12/browser-close-tab-stale-list/sdk-map-S15-browser-01.log).

Steps to Reproduce

On main 9bf835c, with Chromium installed, after uv sync --dev:

curl -sL "`````` https://github.com/enyst/openhands-evidence/blob/44fcc411a84dbbee48d148e1379e9f223581b3c8/software-agent-sdk/bugs/2026-11-12/browser-close-tab-stale-list/repro_close_tab.py?raw=1" `````` -o repro_close_tab.py
.venv/bin/python repro_close_tab.py 20 --switch-first
# RESULT ... stale=17/20 max_lag_ms=16

The script drives BrowserToolExecutor against a local HTTP server. Each round opens page2 in a new tab, switches to tab 0, closes the new tab with BrowserCloseTabAction, and immediately runs BrowserListTabsAction.

This is not a regression. browser-use has been 0.11.9 in uv.lock since at least 2026-09-15, and the same repro gives 19/20 stale on 80537c0 (v1.57.0, 2026-10-22).

Acceptance Criteria

  • After browser_close_tab returns, an immediate browser_list_tabs does not list the closed tab, whether or not the closed tab was focused.
  • A test closes a tab that is not focused and asserts the next listing, repeated enough times to catch the race.
  • If the tab is still listed after a bounded wait (a few seconds), the close still returns and the condition is logged, rather than hanging.

Installation Method

From source

SDK Version

main@9bf835c (openhands-tools, browser-use 0.11.9)


Generated by Claude Code


OpenHands AI triage

The following comments and acceptance criteria were added by the OpenHands AI agent.

Triage

Priority: medium, unchanged. The maintainer reopened this after the issue was auto-closed by the map-maintenance PR merge, with fresh evidence that the bug still reproduces on main@3c66af1: verify-sdk S15.tabs listed the closed tab right after browser_close_tab answered in 4 of 5, 5 of 5 and 4 of 5 attempts across three replay runs. This confirms the earlier reproduced failure in the actual product workflow (17/20 stale on the recorded repro run). Verified against main: BrowserToolExecutor.close_tab/list_tabs pass through to CustomBrowserUseServer, which still does not override _close_tab/_list_tabs, so both go to browser-use 0.11.9 (pinned in uv.lock); the close returns when Chrome acknowledges Target.closeTarget while the listing reads the SessionManager's cached targets, which updates only on Target.detachedFromTarget roughly 10-30 ms later. An open fix PR exists for this issue; per repository guidance, issue readiness does not depend on that PR or its test evidence, and the criteria below do not require any particular implementation.

Bounded scope: make the close-then-list sequence consistent at the openhands-tools browser boundary (the SDK-ownable layer above browser-use), for both focused and non-focused closes. Non-goals: no upgrade or fork of browser-use as part of this issue (the upstream fix belongs in browser-use's own issue tracker); no changes to other browser tool operations; no changes to the agent-server REST/TypeScript contract (no browser twin exists there); no changes to recording or session lifecycle behavior.

Acceptance Criteria

  • After browser_close_tab returns successfully, an immediate browser_list_tabs observation does not list the closed tab, whether or not the closed tab was the focused tab.
  • A test in tests/tools/browser_use/ closes a tab that is not focused and asserts the immediately following listing excludes it, repeated over enough rounds (the repro used 20) that the 10-30 ms race window is actually exercised; it runs green where Chromium is available (the e2e suite self-skips without a browser) and does not depend on a specific upstream browser-use fix.
  • If the closed tab is still listed after a bounded wait (a few seconds), browser_close_tab still returns without hanging and the stale-listing condition is logged, so an agent cannot deadlock on a slow tab teardown.
  • Other tab operations and their observations are unchanged: browser_list_tabs output format, browser_switch_tab, and the browser_close_tab response text are compatible with existing agent parsing, and closing an already-closed or invalid tab ID still errors as before.

Activity

  1. added
    priority:mediumFor bugs, a serious source of annoyance, but not blocking a large number of users.
    ready-for-devIssue meets development readiness criteria
    on Nov 12, 2026
  2. added a commit that references this issue on Nov 12, 2026
  3. reopened this on Nov 14, 2026
  4. enyst commented on Nov 14, 2026

    @enyst
    MemberAuthor

    I'm an AI agent helping Engel Nyst (@enyst) with project work.

    Reopening: this was closed automatically when the map-maintenance PR #6753 merged, but its fix (#6786) is not merged and the bug still reproduces on main@3c66af1. Today's replay of S15.tabs (verify-sdk) listed the closed tab right after browser_close_tab answered in 4 of 5, 5 of 5 and 4 of 5 attempts across three runs.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:mediumFor bugs, a serious source of annoyance, but not blocking a large number of users.ready-for-devIssue meets development readiness criteria

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions