Repository navigation
Closed
Description
Problem
When a browser enters the background, terminal output may stop with:
Terminal output stopped because this device could not keep up.
The WebSocket closes with code 4008 (output_stalled) when terminal output cannot be delivered or consumed within the configured backpressure limits.
This can affect both desktop and mobile browsers.
Root cause hypothesis
Background browsers may throttle or suspend JavaScript execution, delaying terminal output processing and acknowledgements.
The current lifecycle handles background transitions inconsistently:
- Desktop browsers may retain interactive PTY attachments while inactive.
- fix(ui): let a phone release its pane as soon as it is hidden #748 releases interactive attachments when mobile browsers become hidden.
- feat(terminal): a tab out of use watches its pane read-only instead of pausing #700 switches released panes to read-only
watch. - Read-only
watch-datacontinues streaming without parser ACK-based flow control.
Both interactive output and read-only observations can therefore encounter backpressure while the browser is inactive.
The exact failure path requires reproduction and confirmation.
Proposed solution
- Suspend hidden output. When
document.visibilityState === "hidden", stop unnecessary terminal output subscriptions, including interactive attachments and read-only watches. - Restore on foreground. Reconnect to the existing pane and restore its terminal view using existing mechanisms.
- Preserve running sessions. Backgrounding must not interrupt herdr panes, commands, or AI agents.
- Reuse existing lifecycle handling. Avoid duplicate state, additional buffering, or unnecessary abstractions. Preserve ownership, queued-input, and mirrored-pane safeguards.
- Keep bounded backpressure. Do not increase buffer limits, silently discard output, or introduce automatic reconnect loops.
A desktop window that remains visible but loses focus should retain its existing behavior.
Acceptance criteria
- Hidden desktop and mobile browsers stop receiving unnecessary terminal output.
- Backgrounding during sustained output does not trigger
4008due to hidden-client streaming. - Returning to the browser restores the same running pane.
- Repeated background/foreground transitions do not leak observers or duplicate subscriptions.
- Other active clients remain unaffected.
- Existing foreground backpressure protections remain intact.
- Regression tests cover desktop and mobile visibility transitions, sustained output, and recovery.
Related code
src/components/PaneTerminal.tsxsrc/lib/ws.tsserver/watch.tsserver/index.tsserver/machine-relay.ts
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]fix(terminal): prevent output stalls when mobile browsers enter the background[/-][+]fix(terminal): prevent output stalls when browsers enter the background[/+]fix(relay): stop a relayed pane only past 256 KiB queued, like this PC (
fix(terminal): attach again when a page put away comes back to a stop…
devswha commentedon Oct 17, 2026
Thanks for the report. The stall was fixed by #968, which merged after this issue was opened: a 4008 that reaches a page while it is hidden, or within 5 s of it being shown again, now attaches the pane again by itself once the page is back in use.
We re-tested on current main (171ad70) with a really hidden tab and a really frozen one. The tests used raw CDP, because Playwright keeps every page visible: another tab opened in front, and
Page.setWebLifecycleState frozen. They used headless Chrome on Linux, at desktop size and with phone emulation, against an isolated herdr session.Not covered: a real Android device, and a tab Chrome discards entirely. Please reopen with your browser, OS and steps if you still see the overload notice after coming back to a tab.