cmux-tui: output store review fixes (mode-change panic, resume offsets, segment gaps and overlaps)
LA
6d ago+228+228+012345678901234567890123456789-56-56-01234567890123456789
Summary
Follow-up to #22937, which merged with the review-1 fixes before reviews 2 and 3 finished. This PR fixes what those reviews found in the terminal output store (cmux-tui-core/src/output_store*.rs).
- Daemon panic: after a runtime change from
fullto another mode,pendingwas not cleared, soterminal.output_readcould slice out of range or return stale bytes. A pass that is not full mode now clears it. A memory read usespendingonly while it ends at the stream end. - Offsets used twice after a restart: a re-adopted terminal now resumes at the larger of the snapshot's stream end and the last stored segment frame. The segment end comes from frame headers only (seeks, no decompression). It is also used when the cap removed the snapshot.
- Segment reads:
- A read stops at a crash gap and sets
truncated. - Overlapping older frames are skipped, so the window has no duplicate bytes and
next_offsetnever goes back. - After a cut frame, a new file starts, so frames written after a crash stay readable.
- A read stops at a crash gap and sets
- Lock race in
read_after: the read tries again when the writer flushed between its segment read and its memory read (the retry condition was inverted). - Shutdown: the shutdown path on the journal writer thread also writes the store's last snapshots.
- Base fixes: two clippy lints (unnecessary qualification) in
mux/agent_reports.rsandserver/tests/event_shape_tests.rs. These are red on the base tip0b3a76d5.cmux-worktree-carehas more base clippy reds; I left them to their owner.
Observed / Not run
- Ran on rbx:
cargo clippy -D warningsfor ghostty-vt and cmux-tui-core: clean.terminal_host_recovery, filtersoutput_store::,output_coalescing,short_lived,output_read: 12 of 12 passed.- cmux-tui-core
journal_checkpoint::andoutput_read_serves: 13 of 13 passed.
a_respawned_terminal_resumes_its_agent_sessionfails the same way on the base (it fails before and after this change).- Gate receipt: in the landing comment.
Changelog
none
Need help on this PR? Tag @codesmith-bot with what you need.
Summary by cubic
Fixes the terminal output store review findings: a daemon panic after a mode change, resume offsets reused after restart, and segment reads missing gaps or overlapping frames.
- A read that is not full mode now clears unflushed bytes, so
output_readcannot panic on a stalepending. - A re-adopted terminal resumes at the larger of its snapshot end and its last stored segment frame (read from headers at start).
- Segment reads stop at crash gaps and mark the window truncated; overlapping older frames are skipped.
- A cut segment tail is truncated before appending; files that cannot be verified are left as is, and verified lengths avoid a header walk per flush.
- Segment file names use a stable sha256 digest, so they survive Rust upgrades.
- A memory read retries when the writer flushes between the segment read and the memory read.
- The writer-thread shutdown path writes the store's last snapshots.
- Fixes two base clippy lints (unnecessary qualification) in
agent_reports.rsandevent_shape_tests.rs.