Repository navigation
fix(terminal): hold a resized attach until herdr draws its current grid (#2289) - #2324
Conversation
…id (#2289) A resize since an attach started kept the hold only while the requested grid differed from the start grid, so a resize back to the start size let the first screen go out on herdr's redraw for the size in between. The hold's 100 ms deadline also sent the old-size screen when herdr's redraw for the new grid came later. The attach now counts the pty's resizes and, once resized, settles only on a whole herdr screen at the pty's current grid that began after the latest resize (one synchronized update drawing every row, the first filled to the width, as herdr 0.9.5 draws it). Past the hold it waits for that redraw for up to ATTACH_RESIZE_REDRAW_MS (1 s), then lets the bytes go as before. Closes #2289
… screen Review follow-ups for #2289: - Read a screen's width from its plain ASCII rows only: herdr and Bun.stringWidth count spacing marks differently, so a stale grid could pass and a current one wait out the fallback. - Settle on the latest whole screen since the latest resize, not the first that matches: a read can bring herdr's first screen, queued from before a resize round trip, followed by the redraw for the grid between. - Keep an update that has not ended as its reads and look for its end in each new read only: a large screen in small reads no longer rescans its growing prefix (1 MB in 1 KiB reads: 1288 ms -> 47 ms). - Stop waiting for the redraw past 256 KiB of held output: it goes out as one frame, and over a client's 1 MiB output window that ended a healthy client as stalled.
…sor at column 1 Review follow-ups for #2289: - Measure each row from its first move only: herdr places the cursor before its update ends, and at column 1 that is one more move to a row's start with no text, which made a valid redraw no screen. - Let only a screen at a grid the pty had (its start grid or one it was resized to) cancel a match: a diff repainting the top rows right after the redraw kept the attach waiting for the fallback. - Apply the held-output cap for the whole hold, counted in UTF-8 bytes, and forget an open update once the hold releases.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 7 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
CodeRabbit did not review this head: it hit its review limit. These are the reviews that stand in for it, with how each finding was resolved. Each reviewer was given an adversarial, read-only brief and ran unit tests only. Round 1:
Round 2:
Round 3:
Every fix has a test that fails on the commit before it, and each was checked with a targeted mutation. |
|
Merging f18aec3 (closes #2289). herdr draws an attach's first screen at the grid the attach started at and redraws for a new grid about 50 ms after a resize, so an attach resized before its first frame could show the old-size screen. An attach resized since it started is now held until herdr's whole screen at the pty's current grid arrives (recognised from one synchronized update's rows; only an update that began after the latest resize counts), capped at 1 s and 256 KiB, after which the bytes go out anyway, so no attach stays held. The lane's evidence: both orderings reproduced on main and fixed; three rounds of omo + Codex with every HIGH and MEDIUM fixed, omo APPROVE on the final; check fast green; terminal contract 262/0; real-server QA showed a right-sized first screen 20/20 against 16/20 on main. The merge pass read the diff. |
Change
Closes #2289, a follow-up to #2255. An attach resized while it started no longer shows a screen at the wrong size first, and no longer takes input before the program has the current size.
Before:
Now (
server/core/terminal-process.ts,server/core/terminals.ts):screenGrid): one synchronized update (ESC[?2026h…ESC[?2026l) that moves to the start of every row from 1 to the last.Bun.stringWidthand herdr count some marks (Devanagari) differently.ATTACH_RESIZE_REDRAW_MS(1 s), then lets the bytes go as before, so no attach stays held.ATTACH_HOLD_MAX_BYTES, counted in UTF-8 bytes). Held output goes out as one frame, and a frame over a client's 1 MiB output window ended the client as stalled.--takeover, herdr focus, RPC connections and drafts.What herdr sends
Captured from herdr 0.9.5 through the PTY host, against the isolated
ovis-testsession:ESC[?2026h, thenESC[2J, then every row moved to withESC[r;1Hand padded to the width.The test helpers produce those captures byte for byte.
Validation
Unit tests through the real attach lifecycle (
server/core/terminals.test.ts: the PTY mocked, a client that acknowledges its output, fake timers):On
010a44dd(main) the first two fail. Every later case fails on the commit before the fix it covers.server/core/terminal-process.test.tschecksscreenGridon the captured bytes:Mutations: each one is caught by the test named after it. They are: a later screen at any size cancels a match; screens at sizes the pty had no longer cancel one; the cap applies only during the redraw wait; widths are read with
Bun.stringWidth; and an update not yet ended is dropped.Real-surface QA: a real
createServer(port 0, a mkdtemp state dir) on the isolatedovis-testherdr, with one WebSocket client.input-readyis at the requested size.Scan cost: a 1 MB redraw at 1000x1000 in 1 KiB reads took 1,288 ms with a rescan of everything held, against 47 ms when each read is looked at once. That comes from a scratch benchmark.
Terminal contract tests: 262 pass, 0 fail (
attach-held,input-membership,keys-lifecycle,output,pending-input,reattach,submit,take-over,terminal-insert,watch).bun run check fast: green.Reviews
An omo code reviewer and Codex (gpt-6.1-sol, fast, xhigh) reviewed each round adversarially.
Round 1:
Round 2: omo raised a HIGH and Codex a MEDIUM, both the cursor at column 1. Codex also raised a MEDIUM for a top-row diff masking the redraw, and a MEDIUM for the cap starting only after the hold. All are fixed.
Codex's own reproductions on the final head: 11 of 12 pass. The one left is a single read over 1 MiB, which cannot occur: the Rust PTY host reads at most 64 KiB (
READ_CHUNK), and the Node host is bounded by its pipe.Round 3: omo checked the final delta and approved it, with no CRITICAL, HIGH or MEDIUM.
Known limits (LOW, not reproduced against herdr)
attach-resumedcomes early and a take-over click that was waiting is spent. The frame size has to win then anyway (omo round 3).attachScreenStartedscan everything held on each read until the hold ends. That path is from perf(terminal): paint an attach's screen without the 100 ms hold (#1642) #2255 and is bounded by the hold.Release
server/goes into the remote bundle, so the release that ships this raisesREMOTE_BUNDLE_VERSION.