Skip to content

Host: no close takes a window's last tab with it (#148) - #150

Merged
SSFSKIM merged 3 commits into
mainfrom
fix/last-tab-guard
Oct 17, 2026
Merged

SSFSKIM merged 3 commits into
mainfrom
fix/last-tab-guard

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

Closes #148.

What changes

Chrome closes a window together with its last tab, and once a profile has no window left Chrome unloads it, which stops the cua extension and its host. The next session then finds the profile host_not_live; this happened to the mini's ssfs profile four times during #116. With this change, every close the host makes or relays checks the tab's window first. If the tab is the last one in a normal window, the host opens a New Tab page there before the close goes through. The New Tab page is inactive and ungrouped, and no session owns it. Four closes are covered:

  • turn end (end_task, case end, client disconnect);
  • the create-then-ended cleanups in createTab and tabs.popup;
  • the agent's own tab.close(), which the service sends as Target.closeTarget of the tab's page target;
  • Page.close on a tab's debuggee.

Popup windows still close with their last tab. MAWS peers are left alone, because their windows belong to the app.

A turn's end closes all of a window's tabs at once, and it still opens exactly one New Tab page. Three rules make that hold, and they come from review round 1:

  • the checks run one at a time, each bounded at 2 s, after which its close goes ahead;
  • a tab counts as going while any close of it is in flight;
  • once a close of it has succeeded, it keeps counting as going until a check's own tab list no longer shows it.

A close that executeCdp has already timed out on is never sent afterwards. If a page's beforeunload refuses a Page.close, the tab stays counted as going. That costs at most one New Tab page the window didn't need, and treating the tab as staying could lose the window.

The host also keeps the previous host's log as <name>.prev.log. In the second, unexplained loss on the mini, the next host's log overwrote the record of how its predecessor ended. The launcher log there shows no reconnect attempt for 55 minutes. That fits a profile Chrome had unloaded because it had no window. It does not fit an extension that lost its port while the profile stayed loaded, since that extension would have retried every 5 s.

Why the host and not the extension (the ticket's first sketch)

  • The agent's own tab.close() reaches Chrome as debugger.sendCommand Target.closeTarget, so the extension's tabs.remove handler never sees it.
  • The host runs from the checkout and picks up new code the next time it starts. An extension loaded unpacked updates only when its user reloads it, and Store/CRX updates take hours.
  • Windows that cua creates get no special case. The host creates a window only when the profile has no normal window, and Chrome opens that window with its own New Tab page (windows.create's url "Defaults to the New Tab Page"). The check therefore never fires for such a window.

Decision Log: docs/doperpowers/specs/2026-10-07-own-chrome-extension-design.md, 2026-10-16. README updated. Plugin 0.12.1.

Tests

  • test/chrome-host.test.mjs: last tab → New Tab first, ungrouped, nobody's; a tab with siblings and a popup window's last tab close as before; Target.closeTarget and Page.close are guarded; three tabs closing together → one New Tab; MAWS peer unguarded.
  • test/extension-host.test.mjs: the real extension and the real host process in the Chrome stub; a turn ending in a window holding only its tabs leaves the window open.
  • test/chrome-host-run.test.mjs: a second host keeps the first one's log as <name>.prev.log.
  • The Chrome fakes now close a window together with its last tab, as Chrome does.

Review round 1 added four deterministic interleaving tests (removal during another check, overlapping attempts, a check that never answers, a timed-out close). Without the host changes, 10 of the new and updated tests fail; with them, the 259 tests across the 16 test files that use the host or the Chrome fakes all pass locally. CI is the gate.

Live, before the fix (mini, ssfs, 2026-10-17 04:38Z)

Starting from no window in the profile, the runner opened its own loopback page as the profile's only window. A backend client of the host (standing in for the service) created a tab, claimed the page and closed it with Target.closeTarget, then ended the turn. The unfixed host closed the agent's tab, Chrome closed the window, and the host's port closed in the same millisecond. profiles list then reported ssfs host_not_live.

Not covered here

The live check on the mini's ssfs profile (end_task in a window holding only agent tabs, then profiles list still ready) runs after merge, once the mini's resident checkout is updated and its host restarted.

Chrome closes a window with its last tab and unloads a profile left with
no window, which ends the cua extension and its host: the next session
found the profile host_not_live. Every close the host makes or relays
(turn end, the create-then-ended cleanups, the agent's Target.closeTarget
of a tab's page and Page.close) first opens a New Tab page, inactive,
ungrouped and owned by no session, in a normal window whose every other
tab is closing too. Checks run one at a time and a tab counts as closing
until Chrome reports it removed, so a turn's end closing all of a
window's tabs opens one New Tab page. MAWS peers are left alone.

The previous host's log is kept as <name>.prev.log, so the next
unexplained host_not_live leaves a record of how that host ended.

The Chrome fakes now close a window with its last tab, as Chrome does.
Plugin 0.12.1.
- A tab whose close succeeded, or that Chrome reported removed, stays going
  until a check's own tabs.query no longer lists it, so a check holding a list
  taken before the removal still opens the New Tab page.
- Close attempts are counted per tab: a failed one withdraws only itself.
- Each window check is bounded at KEEP_WAIT_MS (2 s); past it the close goes
  ahead, logged, and later closes are not held up.
- executeCdp marks itself late at its timeout; a close still behind its
  preflight is then refused, never dispatched.
- A Page.close whose beforeunload is refused keeps its tab going while it
  lives: accepted, recorded in the comment and the Decision Log entry.

The fake extension gains a primitive hold/release for the interleavings.
@SSFSKIM
SSFSKIM merged commit 76c3b84 into main Oct 17, 2026
4 checks passed
@SSFSKIM
SSFSKIM deleted the fix/last-tab-guard branch October 17, 2026 05:02
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.

Ending a session can close the user's Chrome window and kill the profile's extension host: no last-tab guard when closing agent tabs

1 participant