Skip to content

fix(browser): start an agent's browser command the turn the server announces it - #657

Merged
Hona merged 3 commits into
devfrom
browser-tools/control-express
Nov 22, 2026
Merged

Hona merged 3 commits into
devfrom
browser-tools/control-express

Conversation

@Hona

@Hona Hona commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Each agent browser command waited for the window's next frame between the server announcing it and the app fetching it. This PR starts the fetch in the turn the announcement arrives.

What was slow

The server announces each agent command as an rpc.experimental.browser.control stream event. Stream events wake the window for a poll in its next frame (launch::inbox_waker). The probe build (#638) measured the time from the stream thread hearing the event to on_control_event: 4.7 ms median, 12.3 ms p90 per command on blade, as a window.

What changes

  • EventHub::subscribe_to(ty, wake) (crates/opencode-kit/src/client/hub.rs): a subscriber that takes only one event type, woken only by batches that have one. subscribe is unchanged; every subscriber still gets every event it got before.
  • rpc::express (new, apps/desktop/src/surfaces/browser/rpc/express.rs): the window subscribes to rpc.experimental.browser.control on its server's hub, woken by the browser's quiet waker from fix(browser): read the engine's messages in the turn they arrive, not the next frame #640 (launch::browser_waker). The quiet poll hands each command frame to on_control_event at once.
  • No double run: the frame's poll still sees each command frame. The attachment ignores a request already in flight or in its recent list, as it does for the server's replays (machine.rs, ControlFrame::Command). command and cancel frames take the quick path, so a cancel keeps its place after its command (READER-12); attached and incompatible stay on the frame path, and so does a cancel's replay, which does nothing.
  • Other windows, other servers: the subscription follows the window's active server and is made again when it changes. A frame for a parked server, or for an attachment in another window, takes the frame path as before.

Proof

  • Four configurations (no extension, uBlock Origin Lite, cross-origin frame, both), three rounds each, as a real window, against dev: in a comment once the keeper's timing window runs.
  • Frame pacing of a session streaming text while an agent runs browser commands, against dev: in a comment.
  • tools\smoke.ps1: in a comment.

…nounces it

Stream events wake the window for its next frame, so each agent command waited 5 ms median (12 ms p90 on blade) between the server announcing it and the app fetching it. Command frames now also come to their own stream subscription, woken by the browser's quiet waker; the frame's poll sees each again and the attachment ignores a request it already took, as it ignores the server's replays.
…e after its command

READER-12 (#657 should-fix): with commands on the quick path and cancels on the frame path, a command could start before the cancel of an earlier one ran its cleanup, or run before its own cancel.
Hona added a commit that referenced this pull request Nov 21, 2026
…e after its command

READER-12 (#657 should-fix): with commands on the quick path and cancels on the frame path, a command could start before the cancel of an earlier one ran its cleanup, or run before its own cancel.
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

PR test build retired — merged into dev. Install or auto-update OpenCode (Rune) from https://anoma.ly/release/opencode/desktop-rune/dev/macos-arm64-dmg.

@Hona

Hona commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Merged dev in (481ad01): with #732 re-landing #640's browser waker, this applies as it was written (no conflicts, 5 files unchanged). Not proved here: per-command start latency on this build; it rides on the browser waker that #732 measured (0/160 back/forward failures on its build).

@Hona
Hona merged commit 29b7815 into dev Nov 22, 2026
6 checks passed
@Hona
Hona deleted the browser-tools/control-express branch November 22, 2026 22:10
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