Resync sends the whole scrollback, so a client behind a flood never catches up #49

Closed
opened 2026-10-02 07:57:43 +00:00 by jhgaylor · 1 comment
Owner

Found by: #48 (S19)

A client that falls behind a busy pane is sent the pane's whole scrollback every time it catches up, so under a flood it never does. Both the web client and a TUI hit this.


  • What happens:
    1. When a client's queue for a pane is full, Pane::broadcast drops it and sends resync.
    2. The client attaches again. The web client sends offset: null (web/src/client.ts); even with its real offset the gap is past MAX_REPLAY_BYTES (1 MB) by then.
    3. So it gets a full snapshot(), up to 64k rows of history (about 5 MB a pane). Parsing that puts it further behind, and the loop starts over.
  • Measured (spikes/s19-tui/bench.sh, four panes each running ls --color in a loop, 200x50): 188–328 resyncs in 10 s; of 1.2–1.7 GB received, 84–90% was snapshots. Resuming from the client's offset made no difference. The screen stayed current, but the client spent 58–75% of a core on it. One flooding pane (16 MB/s) never resyncs.
  • Fix (PLAN, Attach and resume, already lists the first two as "do now"; neither is built):
    • Cap a snapshot's history at what the client keeps. AttachPane gains the number of scrollback rows the client keeps (xterm.js keeps 10k; the web client today downloads 64k and drops 54k of them).
    • Compress snapshot frames (permessage-deflate, or zstd frames). S10 measured 3.9 MB down to 183 KB.
    • After a resync, send the screen only (screen_snapshot, the path M13's floor uses). The client keeps its own scrollback and marks the gap with a dim ── skipped ── rule, as a restore does, rather than downloading history it already has.
  • Done when:
    • bench.sh with four panes: snapshots are under 10% of the bytes received, and the TUI uses under half of a core;
    • the same flood in the web client: typing into a fifth, quiet pane echoes within 100 ms;
    • a phone attaching to a 64k-row pane downloads no more than the client keeps (S10's case).
**Found by:** #48 (S19) *A client that falls behind a busy pane is sent the pane's whole scrollback every time it catches up, so under a flood it never does. Both the web client and a TUI hit this.* -------- - **What happens:** 1. When a client's queue for a pane is full, `Pane::broadcast` drops it and sends `resync`. 2. The client attaches again. The web client sends `offset: null` (`web/src/client.ts`); even with its real offset the gap is past `MAX_REPLAY_BYTES` (1 MB) by then. 3. So it gets a full `snapshot()`, up to 64k rows of history (about 5 MB a pane). Parsing that puts it further behind, and the loop starts over. - **Measured** (`spikes/s19-tui/bench.sh`, four panes each running `ls --color` in a loop, 200x50): 188–328 resyncs in 10 s; of 1.2–1.7 GB received, 84–90% was snapshots. Resuming from the client's offset made no difference. The screen stayed current, but the client spent 58–75% of a core on it. One flooding pane (16 MB/s) never resyncs. - **Fix** (PLAN, *Attach and resume*, already lists the first two as "do now"; neither is built): - **Cap a snapshot's history at what the client keeps.** `AttachPane` gains the number of scrollback rows the client keeps (xterm.js keeps 10k; the web client today downloads 64k and drops 54k of them). - **Compress snapshot frames** (permessage-deflate, or zstd frames). S10 measured 3.9 MB down to 183 KB. - **After a resync, send the screen only** (`screen_snapshot`, the path M13's `floor` uses). The client keeps its own scrollback and marks the gap with a dim `── skipped ──` rule, as a restore does, rather than downloading history it already has. - **Done when:** - `bench.sh` with four panes: snapshots are under 10% of the bytes received, and the TUI uses under half of a core; - the same flood in the web client: typing into a fifth, quiet pane echoes within 100 ms; - a phone attaching to a 64k-row pane downloads no more than the client keeps (S10's case).
Author
Owner

Done 2026-10-02, merged in a4d6490.

  • What landed:

    • attach takes a history cap per pane (web and the share viewer ask for 10k rows, tmux for 2000) and a zstd opt-in. Snapshots of 4 KB or more come as frame kind 4. The tungstenite under axum has no permessage-deflate; the web client decodes with fzstd.
    • After a resync, the web client attaches from its own offset with history: 0. A small gap replays; otherwise it gets the screen alone, keeps its scrollback, and a dim ── output skipped here ── line marks the gap.
    • The engine caps history with a formatter selection, so screen_snapshot no longer replays everything.
    • Also fixed a padding bug that put a short snapshot's screen one row too high.
  • S19's four-pane flood (spikes/s19-tui/bench.sh, S19_LEGACY=1 for before):

    Received Snapshots Frames TUI CPU
    Before 1.53 GB 1.44 GB 317 64%
    After 612 MB 9.8 KB 569 56%
  • Against done-when:

    • Snapshots under 10% of bytes: yes (0.002%).
    • TUI under half a core: no, 56%. It now draws 7x as much real output, about 8x cheaper per MB.
    • Quiet pane echo in a 6x-throttled browser: 59–99 ms on a quiet machine, 393 ms once while other sessions were busy (web/e2e/flood.spec.ts).
    • Snapshots capped at what the client keeps: yes (snapshots_carry_only_the_history_asked_for).
  • Follow-up: #52. A throttled page still takes about 10 s to read its resync, because xterm queues everything it's sent. That needs the ACK flow control PLAN describes.

Done 2026-10-02, merged in a4d6490. - **What landed:** - `attach` takes a `history` cap per pane (web and the share viewer ask for 10k rows, tmux for 2000) and a `zstd` opt-in. Snapshots of 4 KB or more come as frame kind 4. The tungstenite under axum has no permessage-deflate; the web client decodes with fzstd. - After a resync, the web client attaches from its own offset with `history: 0`. A small gap replays; otherwise it gets the screen alone, keeps its scrollback, and a dim `── output skipped here ──` line marks the gap. - The engine caps history with a formatter selection, so `screen_snapshot` no longer replays everything. - Also fixed a padding bug that put a short snapshot's screen one row too high. - **S19's four-pane flood** (`spikes/s19-tui/bench.sh`, `S19_LEGACY=1` for before): | | Received | Snapshots | Frames | TUI CPU | |---|---|---|---|---| | Before | 1.53 GB | 1.44 GB | 317 | 64% | | After | 612 MB | 9.8 KB | 569 | 56% | - **Against done-when:** - Snapshots under 10% of bytes: yes (0.002%). - TUI under half a core: **no, 56%.** It now draws 7x as much real output, about 8x cheaper per MB. - Quiet pane echo in a 6x-throttled browser: 59–99 ms on a quiet machine, 393 ms once while other sessions were busy (`web/e2e/flood.spec.ts`). - Snapshots capped at what the client keeps: yes (`snapshots_carry_only_the_history_asked_for`). - **Follow-up:** #52. A throttled page still takes about 10 s to read its resync, because xterm queues everything it's sent. That needs the ACK flow control PLAN describes.
jhgaylor referenced this issue from a commit 2026-10-02 09:53:35 +00:00
Commenting is not possible because the repository is archived.
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jhgaylor/illogical#49
No description provided.