Repository navigation
Conversation
## What was wrong Nothing between the PTY and xterm.js applied backpressure. The daemon read the PTY as fast as the program wrote, and the server queued output for each browser socket until it passed 32 MiB, then closed the socket with 1013 terminal-backpressure. The browser reconnected from its last sequence, found the 4 MiB daemon ring had moved on, and reset the terminal behind "Some terminal output was unavailable after reconnect". Under sustained output (yes, a large cat or log, a chatty build) this dropped and reset the terminal about once a second, wiping the screen and scrollback. Keystrokes typed during the flood were echoed behind megabytes of queued output or lost in the gaps. Input could be lost outright: a Ctrl+C sent just after a backpressure close never reached the server (6 of 39 trials) and the program kept running. Every keystroke also waited for the daemon's 4 ms output batch timer. ## What changed - The browser transport opts into output acknowledgement (outputAcks=1). The terminal view acknowledges each chunk once xterm has parsed it, and reports document visibility. - The server paces each terminal by its fastest visible acknowledging client. It enables daemon flow control while one exists and forwards that client's progress. Hidden clients, clients that stop acknowledging for 3 s while behind, and clients that never opt in (older apps, the CLI) do not pace the terminal and keep today's per-socket backpressure. - The daemon pauses node-pty once 1 MiB of output is unacknowledged and resumes at 512 KiB. A paused PTY whose process has exited is resumed so node-pty can drain its final output before its 200 ms socket destroy. Pacing is released when the server connection drops, the terminal closes, or the server disables it. - The first output after an idle period is flushed on setImmediate instead of after the 4 ms batch delay; streaming output still batches. The server/daemon wire gains terminal.flow-control and terminal.ack, so HOST_DAEMON_PROTOCOL_VERSION is 229. The browser terminal socket gains the outputAcks query flag and ack and visibility client messages. ## How you verified Headless Chrome (dev-browser, Metal WebGL, DPR 2) against a pnpm start:worktree build, an 87x66 terminal, timings taken inside the page from the keydown event to xterm's parse callback and the next animation frame. Medians, before -> after: - Idle keystroke to frame: 6.7 ms -> 1.9 ms (plain xterm.js with the same addons over a local socket: 0.8 ms). - Typing into a program that floods output and echoes keys: 18 of 45 keystrokes lost and 210-250 ms for the rest, 38-66 socket drops per run -> 0 lost, 29-31 ms, no drops. - Ctrl+C on yes until output stops: 145-2204 ms with up to 24 MB still to draw -> 25-62 ms with under 0.6 MB. - Ctrl+C lost during a flood: 6 of 39 trials -> 0 of 30. - Throughput for find, seq, a 30 MB cat, git log, a coloured build log and yes | head is unchanged within machine-load noise. A same-build A/B with pacing switched off gives the same timings. - Through a proxy adding 80 ms RTT: keystrokes during a flood 11 of 15 lost -> 0 lost at 143 ms; seq 3M 21-31 s -> 4.5-4.7 s. - A second, slower viewer of the same terminal no longer slows the first. - Through real bb Connect (a share of the dev server): a terminal flood stalled every request on the shared tunnel, including the owner's own remote session (/health 2.8 s, 14 s, then 504s). After, /health stays at its resting 0.12-0.31 s during a flood. Typing into a flooding program loses 0 of 45 keystrokes at 145-212 ms, and Ctrl+C settles in 121-260 ms. Turbo typecheck for every dependent of the changed contracts (77 tasks); tests for host-daemon-contract, server-contract, client-core, host-daemon, server and app; app lint (existing warnings only). Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/in-app-terminal-feels-slow-reproduce-and-measure-thr_buadiv2kqr
branch
October 6, 2026 21:01
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
Nothing between the PTY and xterm.js applied backpressure. The host daemon read a terminal's PTY as fast as the program wrote, and the server queued output for each browser socket until 32 MiB, then closed the socket with
1013 terminal-backpressure. The browser reconnected from its last sequence, found the daemon's 4 MiB ring had moved past it, and calledterminal.reset()behind "Some terminal output was unavailable after reconnect".Under sustained output (
yes, a largecator log, a chatty build) this happened about once a second:Over bb Connect the effect spreads beyond the terminal. A flood filled the tunnel shared by everything on the server's handle, and the owner's own remote session stalled. During one,
/healththrough the handle took 2.8 s, then 14 s, then returned 504s.Separately, every keystroke echo waited for the daemon's 4 ms output batch timer. That was most of bb's 6 ms idle overhead compared with plain xterm.js over a local socket.
Prompted by Discord reports that the in-app terminal feels slow ("not up to par", "a bit slow").
What changed
packages/client-core) opts in with anoutputAcks=1query flag.ThreadTerminalViewacknowledges each output chunk after xterm has parsed it and reports document visibility.TerminalOutputFlowControlinapps/server/src/services/terminals):TerminalManager):setImmediaterather than after the 4 ms batch delay. Streaming output still batches.terminal.flow-controlandterminal.ack, soHOST_DAEMON_PROTOCOL_VERSIONgoes 228 → 229.outputAcksquery flag and theackandvisibilityclient messages. Older browser clients are unaffected.How you verified
Measurement setup
pnpm start:worktreebuild driven by headless Chrome through dev-browser, with Metal WebGL at DPR 2 and an 87×66 terminal.Before → after (medians)
yesuntil output stopsseq 1 3000000find,seq, a 30 MBcat,git log --stat, a coloured build log andyes | headis unchanged within load noise. A same-build A/B with pacing switched off gives the same timings.Real bb Connect
/healthstayed at its resting 0.12–0.31 s, compared with the 504s on main.Tests
terminal.ack.Commands run
pnpm exec turbo run typecheck --filter='...[origin/main]': 78 tasks.bb-plugin-bb--prompt-librarypassed after apnpm installof the rebased lockfile.pnpm exec turbo run test lintfor@bb/host-daemon-contract,@bb/server-contract,@bb/client-core,@bb/host-daemon,@bb/serverand@bb/app.builtin-plugins.test.tshot-reload case timed out once under load and passed on rerun (28/28).🤖 Generated with Claude Code