Flow control: clients ack what they've drawn, so a slow page doesn't queue a flood #52

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

Found by: #49

A client that can't draw as fast as a pane prints still takes all of it: the browser's xterm queues everything it was sent. Behind a flood, a throttled page took about 10 s to even read its resync, and drew output that was already stale by then.


  • Today: there are no ACKs. Each client's per-pane queue in the daemon is bounded, and a full queue means resync. The queue only fills when the client stops reading its socket. A browser keeps reading and hands every frame to term.write, which buffers without limit, so the backlog piles up inside the page instead.
  • Seen in #49 (web/e2e/flood.spec.ts, CPU throttled 6x, yes for 8 s): resyncs came about 10 s after the daemon sent them, and the pane kept drawing old flood output for 15–25 s after the flood ended. Since #49 each resync is cheap; the lag is all in the client.
  • Do what PLAN's Flow control already describes:
    • the client sends ack{pane, offset} from xterm's write callback, about every 64 KB;
    • the daemon stops sending a pane to a client more than 512 KB past its last ack, then sends resync, which since #49 means the screen alone;
    • the TUI (M31, #50) acks after its engine has taken the bytes.
  • Keep: a client that never acks (the CLI's attach, the tmux front end, old pages) works as today, falling back to the bounded queue.
  • Done when:
    • in flood.spec.ts, after-6 shows within 2 s of the flood ending, not 15–25 s;
    • a resync is read within 1 s of being sent;
    • spikes/s19-tui/bench.sh's numbers stay at least as good as after #49.
**Found by:** #49 *A client that can't draw as fast as a pane prints still takes all of it: the browser's xterm queues everything it was sent. Behind a flood, a throttled page took about 10 s to even read its `resync`, and drew output that was already stale by then.* -------- - **Today:** there are no ACKs. Each client's per-pane queue in the daemon is bounded, and a full queue means `resync`. The queue only fills when the client stops reading its socket. A browser keeps reading and hands every frame to `term.write`, which buffers without limit, so the backlog piles up inside the page instead. - **Seen in #49** (`web/e2e/flood.spec.ts`, CPU throttled 6x, `yes` for 8 s): resyncs came about 10 s after the daemon sent them, and the pane kept drawing old flood output for 15–25 s after the flood ended. Since #49 each resync is cheap; the lag is all in the client. - **Do** what PLAN's *Flow control* already describes: - the client sends `ack{pane, offset}` from xterm's write callback, about every 64 KB; - the daemon stops sending a pane to a client more than 512 KB past its last ack, then sends `resync`, which since #49 means the screen alone; - the TUI (M31, #50) acks after its engine has taken the bytes. - **Keep:** a client that never acks (the CLI's `attach`, the tmux front end, old pages) works as today, falling back to the bounded queue. - **Done when:** - in `flood.spec.ts`, `after-6` shows within 2 s of the flood ending, not 15–25 s; - a `resync` is read within 1 s of being sent; - `spikes/s19-tui/bench.sh`'s numbers stay at least as good as after #49.
Author
Owner

Done 2026-10-02, merged in 57fa00e.

  • Acks: attach takes acks. The web client acks from xterm's write callback about every 64 KB; the S19 TUI acks after its engines take the bytes.
  • Holding back: past 512 KB unacked, or with its queue full, a client is held back. Acked to within 256 KB, it gets what it missed from the log, with nothing lost, or resync (screen only, #49) if that's over 1 MB. A resize while held back resyncs. Clients that don't ack (CLI attach, tmux, the share viewer) are unchanged.
  • Found on the way, and the bigger part of the problem: the pane took its program's output into an unbounded queue, in front of everything else. Under a flood, every attach, ack and key waited behind it, Ctrl-C included, and memory grew without limit. A debug daemon was still working through a flood 17 s after it ended. Now the program writes into a bounded queue (64 chunks), and what clients ask is served first. A flood runs only as fast as the pane takes it in, as in any terminal.

Against done-when:

  • flood.spec.ts, browser throttled 6x: after-6 shows 0.22–0.42 s after the flood ends (release daemon, 4 runs; 0.22–0.35 s on the e2e suite's debug daemon), against 15–25 s before. Quiet-pane echo: 41–369 ms.
  • A resync is acted on within 10–20 ms of being sent, against 3–16 s.
  • bench.sh: no resyncs and 36% of a core with four floods, against 155 resyncs and 56% after #49. That also brings the TUI under #49's half-core target.

New daemon tests:

  • held back, then replayed with no gap;
  • held back past the log, so it resyncs;
  • a resize while held back resyncs;
  • Ctrl-C stops a flood at once.

The full browser suite passes except vm-dev-server, which also fails on main (it needs VMs).

Done 2026-10-02, merged in 57fa00e. - **Acks:** `attach` takes `acks`. The web client acks from xterm's write callback about every 64 KB; the S19 TUI acks after its engines take the bytes. - **Holding back:** past 512 KB unacked, or with its queue full, a client is held back. Acked to within 256 KB, it gets what it missed from the log, with nothing lost, or `resync` (screen only, #49) if that's over 1 MB. A resize while held back resyncs. Clients that don't ack (CLI `attach`, tmux, the share viewer) are unchanged. - **Found on the way, and the bigger part of the problem:** the pane took its program's output into an **unbounded** queue, in front of everything else. Under a flood, every attach, ack and key waited behind it, Ctrl-C included, and memory grew without limit. A debug daemon was still working through a flood 17 s after it ended. Now the program writes into a bounded queue (64 chunks), and what clients ask is served first. A flood runs only as fast as the pane takes it in, as in any terminal. **Against done-when:** - `flood.spec.ts`, browser throttled 6x: `after-6` shows **0.22–0.42 s** after the flood ends (release daemon, 4 runs; 0.22–0.35 s on the e2e suite's debug daemon), against 15–25 s before. Quiet-pane echo: 41–369 ms. - A `resync` is acted on within 10–20 ms of being sent, against 3–16 s. - `bench.sh`: no resyncs and 36% of a core with four floods, against 155 resyncs and 56% after #49. That also brings the TUI under #49's half-core target. New daemon tests: - held back, then replayed with no gap; - held back past the log, so it resyncs; - a resize while held back resyncs; - Ctrl-C stops a flood at once. The full browser suite passes except `vm-dev-server`, which also fails on main (it needs VMs).
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#52
No description provided.