cmux-tui: output store review fixes (mode-change panic, resume offsets, segment gaps and overlaps)

LA
6d ago
+228-56

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 full to another mode, pending was not cleared, so terminal.output_read could slice out of range or return stale bytes. A pass that is not full mode now clears it. A memory read uses pending only 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_offset never goes back.
    • After a cut frame, a new file starts, so frames written after a crash stay readable.
  • 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.rs and server/tests/event_shape_tests.rs. These are red on the base tip 0b3a76d5. cmux-worktree-care has more base clippy reds; I left them to their owner.

Observed / Not run

  • Ran on rbx:
    • cargo clippy -D warnings for ghostty-vt and cmux-tui-core: clean.
    • terminal_host_recovery, filters output_store::, output_coalescing, short_lived, output_read: 12 of 12 passed.
    • cmux-tui-core journal_checkpoint:: and output_read_serves: 13 of 13 passed.
  • a_respawned_terminal_resumes_its_agent_session fails the same way on the base (it fails before and after this change).
  • Gate receipt: in the landing comment.

Changelog

none


View with [code]smith Autofix with [code]smith
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_read cannot panic on a stale pending.
  • 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.rs and event_shape_tests.rs.