Skip to content

Browser service: a starved tab costs one timeout, and setup's dispose never attaches a tab (#384) - #404

Merged
SSFSKIM merged 6 commits into
mainfrom
fix/384-dispose-cascade
Nov 18, 2026
Merged

SSFSKIM merged 6 commits into
mainfrom
fix/384-dispose-cascade

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Refs #384. Fixes the cua-only cascade after a hidden tab's renderer stalls. The stall itself is not fixed here: under load Chrome starves a hidden agent tab's renderer on both hosts, so #384 stays open for that.

Mechanism

The investigation (task 94, branch diag/384-cdp-latency, never merged) found that both parity lanes run cua's browser service, host and extension, and stall the same way. After a stall, though, cua's REPL-host lane timed out two more Emulation.setFocusEmulationEnabled commands at about 1.5 s, the second while the browser service's setup ran. Tracing it here gave this sequence:

  1. A command in a case times out on a starved tab. At the turn's end the page clipboard bridge's removal sends Runtime.evaluate to that tab. The command times out at 3 s and the host detaches the tab. Both lanes show this one row.
  2. The removal's other two steps each had a fresh 3 s budget, and each attached the detached tab again. Each attach waited 1.5 s on the page guard (GUARD_WAIT_MS), then setFocusEmulationEnabled timed out on the 1.5 s that was left. That is ~9 s in all, past the turn-ended hook's 4 s deadline, so the work ran on into the next case.
  3. The next case's js_reset and fixture-setup cell start a new kernel, and its bootstrap calls setup. That setup disposes the previous runtime, and the dispose joined the removal still running. This is the rpc setup row in the timeline.

Why setup runs again, and why only cua's host pays. Every new kernel calls setup, on both hosts: each parity case starts with js_reset, and a cell timeout also starts a new kernel. In the timeline every slow rpc setup row lies outside every scenario cell, at the next case's start. The re-run is correct behaviour. The difference is the trusted worker's lifetime. The vendor's node_repl starts a fresh worker at each js_reset and each cell timeout, so its setup has no previous runtime to dispose, and the old worker's leftover turn-end work dies with it. cua's worker survives resets by design (own-REPL-host spec, Decision Log 2026-10-14), so its setup disposes. Proof: docs/evidence/2026-11-17-384-worker-lifetime/ holds a probe that drives both hosts with a fixture service reporting its worker's pid. On the vendor host the pid changes after every reset and timeout. On cua's host one pid lasts the whole run.

Fix

So, as 791 item 2 asks, only the removal and the dispose change (src/browser-service/clipboard-bridge.mjs, cdp.mjs):

  • One budget for the removal. The removal's three steps now share one action budget. On a starved tab that costs one timed-out command. The host detaches the tab at that timeout, and the spent budget sends nothing more, so nothing attaches the tab again. A tab detached earlier whose page answers again is still attached once and cleaned, as before.

  • A dispose that never attaches. Dispose removes the bridge only from tabs still attached, through a new CDP call option, attach: false. A detached tab fails at once with tab_detached, and "Debugger unattached" is not retried. All of this runs within DISPOSE_CLEANUP_MS (1 s), and a removal already under way is waited for only within that budget. The backend connection, which closes right after, ends the debugger sessions, and with them the binding and the script.

  • The page is restored later when a removal can't do it now. Disposal never attaches a tab, but the page side of the bridge is JavaScript, and ending the debugger session doesn't undo it. The page can't tell either: in Chrome 156 the binding function stays, and calling it throws nothing. So a removal that didn't remove the page side leaves the installation in its backend's StrandedPageClipboards. That covers a removal that skipped a detached tab, ran out of its budget, or got no answer from the page. The service keeps this record across setups, keyed by socket path. The next controller to attach that tab, in this runtime or a later one, removes the page side in the background. It uses its own budget and keeps the debugger on a timeout, so the attach and the command behind it neither wait nor lose the tab. (Review finding P2: real headless Chrome showed readText() pending forever after detach, dispose and reconnect.)

A removal now also counts a page script that threw as a failure (fix wave 2, review finding P2). Runtime.evaluate answers such a script with a successful reply carrying exceptionDetails, so both the removal and the recovery check for it, and the record is kept or created. An evaluation that finds no matching bridge is still a successful no-op.

Limits that remain:

  • A stranded page side is removed only when cua attaches that tab again. A user's tab that cua never touches again keeps the broken override until it reloads or navigates. The vendor does no removal at all when its worker is replaced.
  • Only a tab's own document is recorded. A bridge installed in a frame's own session or target is not.
  • The 1 s budget caps the bridge's part of the dispose, not the whole setup. The review measured 3004 ms when a re-attach was already in progress, because cdp.detachAllTabs joins an attachment under way. That join is older than this PR. I left it: skipping it could let an attach finish after the connection closes, which would leave Chrome's debugger on a tab the host had already released.

A second commit documents --disable-renderer-backgrounding as a diagnosis-only flag set in scripts/repl-parity/hosted/hosted.sh, as 791 item 3 asks. PARITY_CHROME_FLAGS=renderer-backgrounding is refused without PARITY_STRESS. Gate parity-browser-stress keeps no flags (its default is unchanged), and a diagnosis adds the set to the gate's run line on its own branch, as with anti-throttling. Plugin 0.28.10.

Tests

Fix wave 1 (f5e556f) adds test/browser-service/clipboard-stranded-chrome.test.mjs. It runs in real headless Chrome (skipped without one) with the service's own CdpController, Clipboard and bridge, over a backend that opens one DevTools WebSocket per attach. The steps: install the bridge, Chrome detaches the tab, dispose (the page's readText is now pending forever), the next runtime attaches. The test then checks that the page's own navigator.clipboard is back and readText answers. The wave also adds a real-host case to starved-tab.test.mjs: the next runtime's claim and reload remove the stranded side. Both fail with the restore disabled (7.1 s and 5.1 s waiting for the removal) and pass with it.

test/browser-service/starved-tab.test.mjs runs through the real host and the fake extension. Its stand-in tab's renderer never answers: Runtime.*, setFocusEmulationEnabled, Page.enable and the page guard are held.

RED, before the fix. It reproduces the hosted signature exactly:

✖ the turn's end spends one budget on a starved tab: the bridge's removal never attaches it again (9059ms)
    actual: [ 'Runtime.evaluate', 'Emulation.setFocusEmulationEnabled', 'Emulation.setFocusEmulationEnabled' ]
    expected: [ 'Runtime.evaluate' ]
✖ a second setup disposes the previous runtime without attaching a starved tab, within the dispose budget (9040ms)
    the dispose never attaches a tab: 2 !== 0

GREEN, after the fix:

✔ the turn's end spends one budget on a starved tab: the bridge's removal never attaches it again (3050ms)
✔ a second setup disposes the previous runtime without attaching a starved tab, within the dispose budget (1019ms)
✔ a tab detached during the turn whose page answers again is attached once to have the bridge removed at the turn's end (45ms)

The browser-service suite passes whole. After fix wave 1, with real Chrome on, that is 437 tests: 435 pass and 2 are skipped (the drift checks that need npm ci). So do the REPL-host tests (208: 192 pass, 16 skipped, platform-gated) and test/repl-parity/hosted.test.mjs.

Under load

The fix was cherry-picked onto the instrumented diag branch (diag/384-fix-stress at d13190f, never merged). The same parity-browser-stress and -swap gates as the baseline ran there at cpu:2. The cascade signature counts setFocusEmulationEnabled timed out at about 1.5 s outside every cell, and slow rows during rpc setup:

runs cua lane timeouts per run vendor lane timeouts per run cascade re-attaches rpc setup slow rows
baseline (task 94, unflagged) 14 20.6 (13–32) 14.4 (6–19) 26 in the 12 runs with cell labels 3
this fix 6 15.7 (1, 31, 14, 19, 15, 14) 14.3 (12–15) 0 0

Fix runs: 44199386809, 44199387760 and 44203056319, each covering both orders (vendor-first, then cua-first: cua 1/31, 14/19, 15/14; vendor 14/15, 15/15, 15/12).

The cascade is gone. Every stall on cua's lane now ends where the vendor lane's does, with one turn-end Runtime.evaluate at 3 s. The shared starvation stays, and it is noisy: one cua-first run had a 30 s stall episode inside a case's cells, the same position effect the investigation saw. Every stress run is RED on the #383 download and file-chooser family, on both lanes, as in the baseline.

Gates

Sminos-Session: linux171#3c5ca588 (cua on dc-linux171-1e68)

…, and a setup's dispose never attaches a tab (#384)

After a hidden tab's renderer stalls, cua's REPL-host lane timed out two more
Emulation.setFocusEmulationEnabled commands than the vendor's. The page clipboard
bridge's removal gave each of its three steps a fresh 3 s budget: the first timed
out, the host detached the tab, and each later step attached it again (1.5 s on the
page guard, then the focus emulation timed out on the rest). The turn's end ran past
its 4 s hook deadline, and the next setup's dispose of the previous runtime joined it.

Why only cua's host pays: every new kernel calls setup on both hosts, but the vendor's
node_repl starts a fresh trusted worker at each js_reset and cell timeout, so its setup
has no previous runtime to dispose and the old worker's leftover work dies with it.
cua's worker survives resets by design, so setup disposes (probe and outputs in
docs/evidence/2026-11-17-384-worker-lifetime). The setup re-run is correct; the fix
is in the removal and the dispose:

- the removal's steps share one budget, so a starved tab costs one timed-out command
  and nothing attaches it again; a tab detached earlier whose page answers is still
  attached once and cleaned;
- dispose removes the bridge only from tabs still attached (a new CDP call option,
  attach: false), within DISPOSE_CLEANUP_MS (1 s), waiting on a removal already under
  way only within that budget.

test/browser-service/starved-tab.test.mjs: a stand-in tab whose renderer never answers.
Before: the turn's end sent Runtime.evaluate then two setFocusEmulationEnabled
re-attaches (9 s), and a second setup re-attached twice (9 s). After: one command,
no attach, 3 s and 1 s. Plugin 0.28.10.

Sminos-Session: linux171#3c5ca588 (cua on dc-linux171-1e68)
…s-only flag set, for stress runs only (#384, #383)

hosted.sh takes PARITY_CHROME_FLAGS=renderer-backgrounding, which launches the
harness Chrome with --disable-renderer-backgrounding alone, and refuses it without
PARITY_STRESS. Task 94 found that flag alone takes most stressed runs to no CDP
timeout: under load Chrome starves a hidden agent tab's renderer on both hosts. A
stress run with it separates the download and file-chooser cases' own failures
(#383) from that starvation. It hides the product's behaviour, so it is never on the
product path or in gate parity-browser, and gate parity-browser-stress keeps no
flags: a diagnosis adds it to that gate's run line on its own branch, as with
anti-throttling.

Sminos-Session: linux171#3c5ca588 (cua on dc-linux171-1e68)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T00:45:32.708652Z cdfc120 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…when the tab is next attached (#384 review)

Disposal never attaches a tab, so when Chrome detached a claimed user tab during a
turn and the next setup disposed first, the page kept the bridge's override of
navigator.clipboard. Ending the debugger session drops the binding's listener and the
script, not the JavaScript already run, and the page cannot tell: in Chrome 156 the
binding function stays and calling it throws nothing. Its readText waited until a
reload. The 1 s disposal budget could strand a slow page the same way.

A removal that did not remove the page side (skipped, out of budget, or unanswered)
now leaves the installation in its backend's StrandedPageClipboards, which the service
keeps across setups by socket path. The next controller to attach the tab, this
runtime's or a later one's, removes it in the background, on its own budget with the
debugger kept on a timeout, so the attach and its command neither wait nor lose the
tab. Disposal stays bounded. Only a tab's own document is recorded, not a frame's.

Tests: clipboard-stranded-chrome.test.mjs, in real headless Chrome with the service's
CdpController, Clipboard and bridge: install, Chrome detaches, dispose (readText
pending), the next runtime attaches, and the page's own navigator.clipboard is back
and readText answers. Through the real host, starved-tab.test.mjs: the next runtime's
claim and reload remove the stranded side. Both fail with the restore disabled.

Sminos-Session: linux171#3c5ca588 (cua on dc-linux171-1e68)
…e, so the stranded record stays (#384 review)

Runtime.evaluate answers a page script that threw with a successful reply carrying
exceptionDetails. The stranded recovery dropped its record on any reply, and the
removal itself counted any reply as removed, so a transient page-side failure left the
override for good. Both now count exceptionDetails as a failure: the record is kept,
or created, and the next attach tries again. An evaluation that finds no matching
bridge still evaluates to false without an exception, a successful no-op.

Tests: two real-Chrome cases in clipboard-stranded-chrome.test.mjs, with the page's
document.querySelectorAll made to throw during the recovery, and during a disposal's
removal, then restored. Before: the override stayed (both time out waiting for its
removal). After: the next attach removes it and the page's own clipboard is back.

Sminos-Session: linux171#3c5ca588 (cua on dc-linux171-1e68)
…resh per test

Three Chrome launches beside wheel-scroll-chrome's on the loaded hosted runner left
that file's Chrome without a DevToolsActivePort in 20 s (run 44222491097). One launch
per file, with a navigation between tests to drop what the last one left in the page.

Sminos-Session: linux171#3c5ca588 (cua on dc-linux171-1e68)
… plugin 0.28.12

The only conflicts were the plugin version in plugin.json and marketplace.json (main
0.28.11, this branch 0.28.10), resolved to 0.28.12. Main's changes (the macOS engine's
set_value without focus, the secrets docs and the surface text) touch no file of this
branch.

Sminos-Session: linux171#3c5ca588 (cua on dc-linux171-1e68)
@SSFSKIM
SSFSKIM merged commit a39d26f into main Nov 18, 2026
10 checks passed
SSFSKIM added a commit that referenced this pull request Nov 18, 2026
…-field-unread (refs #405)

Sminos-Session: cursor235#b93055dd (cua on macbook)
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