mux: non-blocking browser CDP I/O + real headful Chrome default
Two browser-pane improvements on top of the CDP base already on main.
Anti-lag: browser CDP I/O can no longer freeze the terminal
Before: the server processed each connection's commands serially and browser-* handlers did their CDP call inline (up to the call timeout), so one wedged/slow Chrome dammed the socket that also carries terminal input for attach clients. Omnibar/nav actions blocked the TUI event loop the same way.
Now, three invariants:
- The TUI event loop performs no blocking CDP I/O: nav/back/forward/reload/activate go through the off-loop dispatcher.
- The server connection loop performs no CDP I/O: each browser surface owns a per-surface worker thread with a bounded queue; browser-* handlers and the resize CDP reconfigure enqueue and ack immediately (accepted, not completed; failures surface via browser-state/status events).
- Failures localize: two consecutive CDP timeouts mark only that surface
Failed("browser is not responding"), once per stall episode, re-armed when a fresh frame clears it. Other panes stay live.
Worker machinery: per-kind latest-wins slots (resize vs nav, no cross-kind clobber), no mutex held across a blocking call, worker reaped on kill and on the pane-missing adoption path, wedged-pane close is fire-and-forget (close_target_detached). Regression test drives a Chrome wedged after bootstrap and asserts a second navigate + a resize + list-workspaces all ack under 500ms on the same socket, plus a non-blocking close.
Real headful Chrome by default
browser.mode defaults to headful, launching the user's real Google Chrome in a visible window with a persistent profile, so signed-in sites treat the pane as a human. --disable-blink-features=AutomationControlled plus a launched-only best-effort UA de-headless (Browser.getVersion cached once, HeadlessChrome→Chrome, setUserAgentOverride before Page.enable, never fails a surface, external browsers untouched) clear the two loudest bot signals. browser.mode: "headless" opts back into a hidden window. Docs cover the Chrome 136 / SingletonLock real-profile caveats and agent-browser ws:// attach (no wss overclaim).
Verification
Built and tested on the AWS M4 Pro builder (macOS 15.7.4) because this dev Mac's macOS 26 SDK can't link ghostty-vt-sys: cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace all green; cargo test -p mux-core --test-threads=64 clean ×3 (does not reintroduce the PTY-exhaustion CI failure just fixed on main). smoke-tui.py passes; smoke-attach.py hits the known themed-prompt false positive that also fails on plain main (CI is its gate).
16 files, all under mux/. No new dependencies.
🤖 Generated with Claude Code
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.
[!NOTE]
Medium Risk
Large concurrency and lifecycle changes across browser, mux socket, and attach paths; behavior is heavily regression-tested but wedged-Chrome and queue semantics affect all browser users.
Overview
Browser panes no longer run blocking CDP on the TUI event loop or the mux control socket. Each surface gets a worker thread with a bounded queue: pointer/key input may drop under load, URL nav and resize use latest-wins slots, and back/forward/reload/activate stay FIFO with explicit ok:false when the queue is full. Handlers ack immediately (ok:true means accepted); failures show up via status events and per-surface “browser is not responding” after two CDP timeouts, with recovery when frames return (including attach client title/state broadcast).
Headful Chrome is the default (browser.mode: "headful"): visible window, session-scoped persistent profile, --disable-blink-features=AutomationControlled, and a one-time launched-runtime UA tweak (HeadlessChrome → Chrome). headless opts back in. CDP gains Browser.getVersion, set_user_agent, and fire-and-forget close_target_detached.
The TUI routes omnibar and browser shortcuts through the off-loop browser input dispatcher, surfacing “browser is busy” when the outer queue is full. Docs/config/protocol are updated for mode, queue semantics, browser.discover default false, profile/Chrome 136 caveats, and browser attach streaming over protocol v6.
Reviewed by Cursor Bugbot for commit 20c4fbabf8cdb1461a6b92b6b02ea2332b82610b. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Moves all blocking browser CDP work off the UI/socket path and makes headful Chrome with a persistent profile the default, improving responsiveness and realism. Attach now streams browser panes, and protocol/browser commands return immediate acks with clearer backpressure and recovery.
-
New Features
- Each browser surface runs CDP on a worker thread with a bounded queue; server and TUI enqueue and ack immediately (
ok:true= accepted, not completed). Discrete controls (back/forward/reload/activate) use FIFO and returnok:falsewhen the queue is full; high‑rate pointer/key input may drop to keep the UI non‑blocking. - URL navigation uses a latest‑wins slot; resize uses its own latest‑wins slot; wedged‑pane close is fire‑and‑forget via
close_target_detached. - Headful Chrome is now the default via
browser.mode: "headful"with a visible window and persistent profile; launched runtimes add--disable-blink-features=AutomationControlledand a one‑time UA de‑headless (Browser.getVersion,HeadlessChrome→Chrome; external browsers untouched).browser.mode: "headless"opts back in. - Protocol adds
browser-*input and control commands that enqueue work and return immediate acks;attach-surfacestreams both PTY and browser panes. Docs cover session‑scoped profiles, Chrome 136 profile lock caveats,browser.discoverdefaulting tofalse, andws:///http://CDP endpoints (nowss://).
- Each browser surface runs CDP on a worker thread with a bounded queue; server and TUI enqueue and ack immediately (
-
Bug Fixes
- Localized stall handling: two consecutive CDP timeouts mark only that surface failed with “browser is not responding”; a fresh frame clears it, and recovery state/title is broadcast to attached clients.
- Backpressure is explicit: the TUI surfaces outer‑queue drops (“browser is busy; command dropped”) and worker‑level failures via status events.
Summary by CodeRabbit
- New Features
- Added configurable browser panes
browser.mode(headful/headless) with session-scoped profiles and improved Chrome/CDP attachment guidance. - Browser navigation/control (navigate/back/forward/reload/activate) now routes through an off-loop queued dispatcher with explicit backpressure handling.
- Added configurable browser panes
- Bug Fixes
- Improved reliability under stalled/blocked CDP calls: non-responsive reporting is throttled and recovers cleanly; shutdown and failed attachments now terminate promptly.
- Documentation
- Updated browser pane, configuration, and protocol docs with the new mode, queue semantics, and browser-state/frame streaming details.