Resume Cloud terminal replays inside escape sequences
Opening or resizing a Cloud terminal while an agent streams output could print escape-sequence fragments as text (1;31mstyled, 8;;https://example.comlink) or disconnect every viewer. The daemon built each byte-mode replay from its screen but dropped the escape sequence or UTF-8 code point its parser was in the middle of, so the live bytes that completed it landed in a fresh parser as plain text. A resize at such a byte cancelled all byte attachments instead.
The VT boundary tracker in ghostty-vt now keeps the bytes fed since the last safe point (up to 1 MiB; direct Kitty uploads keep their own larger budget). VtReplay.bytes still ends at a parser boundary and the incomplete sequence travels separately as pending_sequence, because consumers write color-override OSCs right after a replay and those must not land inside the sequence. Consumers write pending last, after their colors and immediately before the live stream. A daemon resize now disconnects byte viewers only inside an oversized non-Kitty control string.
On the wire, vt-state and resized carry an optional base64 pending field only for attachments that advertise the new terminal-pending-sequence-v1 capability, matching how terminal-color-overrides-v1 avoids breaking strict SDK decoders. Other attachments get the bytes appended to the replay, which is correct for raw consumers such as chatmux-relay. The macOS pane, the iOS cmux-tui client and the cmux-tui remote client advertise it. The terminal-host protocol is unchanged: hosts still snapshot and resize only at a boundary. Spec: events.md, commands.md, transports.md.
Testing
Rust, on a Blacksmith Testbox (cargo test --locked, umask 022):
- Red at
ac210e0(tests only):ghostty-vttheme_portable_replay_resumes_inside_every_partial_sequence,..._zsh_startup_at_every_byte,replay_after_invalid_utf8_does_not_duplicate_replacement_characters,oversized_pending_sequence_is_reported_as_not_resumable, andcmux-tui-corebyte_mirror_attached_inside_any_sequence_matches_the_terminal,byte_mirror_survives_owner_resize_inside_any_sequence,byte_mirrors_joining_during_owner_churn_converge_on_the_terminalall failed, printing fragments like1;31mstyled. - Green at
ab84d73. The byte-mirror tests model the pane (replay must end at a boundary beforependingis written) and compare text, cursor and grid with the daemon at every byte split of a transcript with CSI, OSC (BEL and ST), OSC 8, DCS, APC and multi-byte UTF-8, including three viewers joining during owner resizes. Added: serializer tests for both wire shapes, and a remote-client test for replay, colors, pending ordering. - Full
cargo test --locked --no-fail-fastonab84d73vs unmodifiedmain(58a9cbc) on the same box: 4500 vs 4493 passing. The same 18 tests fail on both (hook, journal, plugin). Two more failed once on the branch under full-suite load (cmux-remoteoversized_probe_stdout_kills_and_reaps_sshwithText file busy,status_disables_repository_fsmonitor) and passed three isolated reruns; this PR does not touch that crate.cargo fmt --check,cargo clippy --locked --all-targets -D warningsandcheck-spec-inventory.pypass.
Swift, in CI's changed-suites app-host run:
- Red at
929c2ea(test only):CloudRestoreReplayGridTests/replayResumesTheSequenceTheDaemonParserIsInsidefailed forvt-stateandresizedwith the screen readingBEFORE 1mRED AFTER. It drives a real manual-I/O Ghostty surface throughCloudTuiManualMirrorSession. - Green at
ab84d73: that test and the new decoder test pass; 356 XCTest and 203 of 207 Swift Testing tests in 12 changed suites pass. - Four
CloudRestoreReplayGridTestsgeometry-claim tests (hiddenRestoreReclaimsGeometryWithoutInput,intentionallyPassiveMirrorStillWaitsForExplicitFocus,typingIntoTheGeometryOwnerSendsOnlyOneWayInput,typingIntoAPaneAnotherClientSizesReclaimsTheGridFirst) time out waiting forresize-surfacein both the red and green runs. At929c2eathe Swift app code equalsmain, so they fail independently of this change; I could not get a cleanmainrerun because no recentmainCI run kept app products.
Not verified: iOS beyond compilation (its CmuxTUI tests need the local sshd lab), and a live Cloud VM. VMs pick up the daemon side only after their guest daemon upgrades; an app build against an older daemon behaves as before.
Changelog
Fixed: Cloud terminals no longer show escape-sequence fragments or disconnect when opened or resized during streaming output
🤖 Generated with Claude Code
Summary by CodeRabbit
- Bug Fixes
- Terminal replays and resizes now preserve incomplete control sequences, allowing subsequent output to continue correctly without displaying sequence fragments as text.
- Remote and cloud terminal views retain the correct display state and colors when replay occurs mid-sequence.
- Oversized incomplete control sequences that cannot be safely resumed are handled without corrupting the terminal stream.
- Existing clients continue to receive incomplete sequence data as part of the replay.
- Documentation
- Documented how clients receive and apply pending sequence data during terminal attachment and resize.