Skip to content

Agents see the tabs of the window in front after the first window closes (#819) - #1119

Open
naman0r wants to merge 3 commits into
yetanotherbrowser:mainfrom
naman0r:fix/agent-live-window-tabs
Open

naman0r wants to merge 3 commits into
yetanotherbrowser:mainfrom
naman0r:fix/agent-live-window-tabs

Conversation

@naman0r

@naman0r naman0r commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What changes

With Settings › Tabs › "Today's tabs in every window" on, open a second window, close the first, and ask the side chat about the page in front of you. The chat's tabs call now lists the second window's tabs, and the tab marked "(in front)" is the one you are looking at. Before this change, the list came from the closed window: old URLs, blank titles, and that window's last front tab marked "in front".

Fixes #819

Why it happened

The bench takes the first window's browser at launch and keeps it (Sources/Fast/Bench.swift:225-228), and every agent call ran in that browser unless a test picked another window (Sources/Fast/Bench.swift:565). Closing the first window doesn't let it go. It stays out of sight with its tabs (Sources/Fast/BrowserWindows.swift:448-453). So agent-tabs (Sources/Fast/AgentBenchPage.swift:915), find(_:in:) (Sources/Fast/Bench.swift:9692) and the row's active all read the hidden window. With today's tabs in every window, that window holds its own, mostly asleep copy of every tab, which is where the stale rows came from.

The fix:

  • BrowserWindows.live(_:) (Sources/Fast/BrowserWindows.swift:365) returns the bench's window unless it was closed and not shown again. In that case it returns the window in front if that is a normal window, else the last normal window on screen. A private window is never chosen, because a tab opened there is private and the next call would refuse it. If no normal window is up, it still returns the bench's window. It reads the close times BrowserWindows already keeps for ⇧⌘T, which are cleared when the window comes back.
  • Bench.holder(of:in:) (Sources/Fast/Bench.swift:9705) keeps a task that was already working when the first window closed. Its tabs stay in that window. When a call names a tab by id that isn't in the window in front, the call runs in the window that holds the tab. Select, close, move, pin and every other verb then act on the tab's own window, never the one in front. find(_:in:) is unchanged and still looks in one window, so the callers that check find(...) === tab to see whether a tab is still open keep their meaning.
  • The bench's default browser goes through both (Sources/Fast/Bench.swift:565). The test-only window override still comes first.

Proof

  • Logic: tests that fail on main and pass here: swift test --filter AgentLiveWindowTests

AgentLiveWindowTests opens a first window with a tab on a.example, a second in front on b.example, then closes the first.

  • aClosedFirstWindowHandsTheToolsToTheOneInFront runs agent-tabs against the browser the bench now picks. Without the live(_:) change it fails with:
    AgentLiveWindowTests.swift:53:9: Expectation failed: (live → <Fast.Browser: 0x105781b90>) === (second → <Fast.Browser: 0x7764dfd400>)
    AgentLiveWindowTests.swift:59:9: Expectation failed: (front → ["https://a.example.test/"]) == ["https://b.example.test/download"]
    
    (Line numbers are from the first version of the test file, before the shared setup moved into a helper.)
  • aTabInTheClosedFirstWindowIsWorkedInItsOwnWindow names the closed window's tab by its short id, takes the window the bench routes the call to, finds the tab there and selects it as the select verb does. It expects the routed window to be the first one and the second window's front tab to be unchanged. Without holder(of:in:) it fails with:
    AgentLiveWindowTests.swift:77:13: Expectation failed: (browser → <Fast.Browser: 0x76fc69fc00>) === (first → <Fast.Browser: 0x76fc69d400>)
    AgentLiveWindowTests.swift:78:27: Expectation failed: (Bench() → Fast.Bench).find((request → ["id": "9755d911"]), in: (browser → <Fast.Browser: 0x76fc69fc00>)) → nil
    
  • aPrivateWindowInFrontLeavesTheToolsInANormalOne puts a private window in front of the second one before the first closes. Without the normal-window check in live(_:) it fails with:
    AgentLiveWindowTests.swift:83:13: Expectation failed: (BrowserWindows.shared.live(first) → <Fast.Browser: 0x78b34cd000>) === (second → <Fast.Browser: 0x78b34ca800>)
    
  • With the fix, all three pass.

Checked on

  • Checked through unit tests only, not in a built Yab Dev app. The steps in the issue were not repeated by hand.
  • Engine(s) tried: not about a page

Checklist

  • The suites this touches pass: swift test --filter 'AgentLiveWindowTests|ClosedWindowTests|TabMoveEveryWindowTests|PrivateEmptyWindowCloseTests|AgentDockStopTests|RemoteTaskReadTests|ChatAskPlaceTests', 58 tests in 7 suites
  • ./design-check --head is clean
  • Anything that changes how Yab looks was approved in the issue first (nothing on screen changes)
  • A new menu item is also a command in the field; a new Settings row is classified in NativeActions.swift (none added)
  • Words on screen and in docs are American English, with no em dashes

Not in this PR

  • Tabs dragged into the chat still resolve against Agents.shared.browser, which stays the first window (ChatColumn.swift:54-55), so a chip from the second window is still dropped. This may be Agent: with a Figma members page attached as a chip, 'give them Full Access' made the agent look at a... #850.
  • Approvals look a tab up through Agents.shared.browser too (AssistantApprovals.swift, ApprovalDetails.swift:374). An approval for a tab an agent opens in the second window, after the first is closed, may not find it.
  • Routing follows the request's id only. A verb that takes a list of ids (ids) or a second tab under another key (tab, other, target) looks those up in the window the call runs in, as on main. A tab in another window under those keys is not found, rather than acted on in the wrong window.

Not verified

  • The behavior in the running app, with a real chat, after closing the first window.
  • The full swift test run. Only the suites listed above were run.

…ses (yetanotherbrowser#819)

The bench takes the first window's browser at launch and keeps it, and
every agent call ran in it (Bench.swift:565). Closing the first window
keeps it out of sight with its tabs (BrowserWindows.swift:448), so tabs,
find and the tab marked in front came from that hidden window. With
today's tabs in every window those are stale copies of the ones on
screen. Calls now go to the window in front once the bench's window is
closed, and find still reaches a running task's tabs in the closed one.
@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest changes appear safe to merge.

Summary

Agent calls now use a normal window after the first window closes, while calls naming an existing tab use that tab's window.

  • Agent calls switch to a visible normal window after the first window closes.
  • Requests for a tab in another window run in the browser that holds it.

Reviews (3) · Last reviewed commit: "Agents keep working in a normal window w..." · Reviewed by Greptile

Comment thread Sources/Fast/Bench.swift Resolved
Comment thread Sources/Fast/BrowserWindows.swift Resolved
A tab id not found in the window in front was looked up in every
window by find, but the verb then acted on the window in front. The
bench now runs a call in the window that holds the tab it names
(Bench.holder), so select, close, move and the rest act on that tab's
own window, and find is back to looking in one window.
@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Comments Outside Diff

These findings could not be posted inline.

  • P1 Saving across windows fails Sources/Fast/Bench.swift:9698 ▶

    Removing the cross-window search breaks save_page when its tabs list spans windows. A task can keep a tab in the closed first window and open another in the second window after the handoff. holder picks one browser using only request["id"], so the save handler cannot find the other tab. Its count check rejects the whole export.

    Keep cross-window lookup for each tab in a multi-tab save while keeping window-changing actions tied to the tab's owner.

  • P1 Security Assistant skips site limits Sources/Fast/Bench.swift:9698 ▶

    Making find local skips the cloud assistant's site checks for tabs in another window. handle calls AssistantBoundary.check with the original browser before handleBound picks the tab's owner. The check finds no target and passes the request. A later snapshot finds the tab in its own window and returns its contents without checking the assistant's allowed sites again. An assistant can therefore read a known second-window tab after the user removes that site's access.

    Pick the owning browser before checking access, and use that same browser when running the call.

    How this was verified: The site check searches the original browser, while snapshot reads from the browser selected afterward and does not repeat that check.

With the first window closed and a private window in front, the bench
handed calls to the private window, so a page an agent opened there was
a private tab its next call refused. BrowserWindows.live now takes the
window in front only when it is a normal one, else the last normal
window on screen, else the first window as before.
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.

Agent chat can't find the open tab the user means and lists already closed tabs instead

1 participant