Repository navigation
fix(terminal): keep PTY and Ghostty resize ordering in lockstep - #5320
StiensWout wants to merge 7 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
ApprovabilityVerdict: Needs human review This PR fundamentally changes terminal resize synchronization between PTY and Ghostty, introducing new coordination mechanisms (flush sentinels, write barriers, acknowledgement-based grid sizing) across both server and client. While the tests are comprehensive, the significant runtime behavior changes warrant human review. You can customize Macroscope's approvability policy. Learn more. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c425f1d894604c039c0cc2372ec2346b1b8776c6. Configure here.
b8c37ed to
55f52f5
Compare

Summary
Validation
Actual T3 preview
The GIF below is captured from the real T3 Code UI and terminal drawer on this branch while resizing wide → narrow → wide. It contains no synthetic frame or added border:
This intentionally does not include terminal open/close reconciliation or Ctrl+W handling.
Note
Medium Risk
Resize RPCs now block until output drains, and synchronous resize-from-listener paths are sensitive; changes touch core terminal I/O ordering across server and web renderer.
Overview
Terminal resize is now ordered end-to-end so PTY width and Ghostty grid stay aligned during drawer resize and streaming output.
Contracts & client state:
resizereturnsTerminalResizeResultwith an attach-streamsequenceinstead ofvoid. Terminal session/buffer state trackssequencealongsideversionso the UI knows which output events have been applied.Server (
TerminalManager): Before acknowledging a resize, the manager queues a flush sentinel on the PTY output drain, publishes all prior queued output, and returns the coveredeventSequence. Flush sentinels are released on queue disposal (including exit) to avoid hangs; tests cover ordering, listener-triggered resize deadlock, and exit during a blocked drain.Web UI:
TerminalWriteBarrierwaits until React has applied output up to the resize acknowledgement’s sequence before and afterrunTerminalResize.GhosttyTerminalSurfacestarts at a 1×1 grid, buffers initial history/output until the first accepted PTY resize, uses asynconResizewith single-flight requests and retries, and prefills the opaque canvas with the theme background during async init.Reviewed by Cursor Bugbot for commit 55f52f5. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Keep PTY and Ghostty resize ordering in lockstep by sequencing resize acknowledgements
TerminalResizeResult(with asequencefield) as the return type for resize RPCs, replacingvoid, so callers know which output event the PTY had processed at acknowledgement time.TerminalManager.resizenow queues a flush sentinel and waits for all in-flight output to be published before returning, ensuring the sequence number reflects output order.GhosttyTerminalSurface) buffers writes until the first resize is acknowledged, applies grid changes only on accepted PTY resizes, and retries on unchanged-dimension rejection to avoid jitter.TerminalWriteBarrierinThreadTerminalDrawergates grid changes until the corresponding output sequence has been applied to the terminal buffer.TerminalSessionStateandTerminalBufferStatevianextTerminalSequence.resizeno longer returns immediately — it suspends until queued output drains, which could block callers if the drain stalls (guarded by deadlock detection for synchronous resize-from-listener patterns).Macroscope summarized 55f52f5.