Skip to content

Save files atomically and allow larger trusted replay recordings - #157

Merged
lance0 merged 4 commits into
masterfrom
fix/atomic-session-saves
Oct 16, 2026
Merged

lance0 merged 4 commits into
masterfrom
fix/atomic-session-saves

Conversation

@lance0

@lance0 lance0 commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Preferences and TUI JSON exports truncate the previous destination before writing, so a failed write can destroy a valid save. Long recordings also exceed replay's fixed 10 MiB cap with no way to open them.

Write buffered content to a private temporary file beside the destination, sync it, then atomically replace the old file using tempfile's cross-platform persist operation. Errors and unwinding remove the temporary file and leave the previous contents intact. Preference files retain Unix 0600 permissions; successful saves keep the existing filenames and JSON schema.

Keep the default 10 MiB replay/diff limit, add --replay-size-limit <MiB> (1–1024) for larger trusted recordings, and enforce the bound while reading as well as checking metadata. Errors explain how to raise the limit. Exports retain the complete event history.

Validation: full build/tests/clippy/fmt/doc checks and Rust 1.88 all-target check pass. Tests cover partial-write failure, failed replacement, interrupted serialization, temporary-file cleanup, preference permissions and repeated JSON replacement. An end-to-end test exports 100,000 genuine probe events above 10 MiB, confirms default rejection, then replays every event and diffs the recording successfully with an explicit limit. Reader tests cover exact boundaries, extra bytes and malformed JSON. Tests use isolated directories and never touch user preferences.

Dependency: tempfile 3.27 was already present in Cargo.lock through the test dependencies; this adds it as a production dependency without changing any locked versions. The atomic publish syncs the file first; filesystem-wide power-loss guarantees are outside this change.

Integration validation: all fourteen draft branches (#144–#157) merge cleanly together. The combined build, tests (including the large-recording CLI test), clippy, formatting, documentation and Rust 1.88 all-target check pass locally.

lance0 and others added 4 commits October 15, 2026 23:38
Atomic replacement gave TUI exports tempfile's 0600 mode, so a session
exported under sudo was unreadable by the invoking user, and replacing a
symlinked preferences file swapped the link for a regular file. Exports
now get the usual 0666 & umask; preferences stay 0600. An existing
symlink is resolved so the link's target is replaced instead.
@lance0
lance0 marked this pull request as ready for review October 16, 2026 15:40
@lance0
lance0 merged commit 295e713 into master Oct 16, 2026
6 checks passed
@lance0
lance0 deleted the fix/atomic-session-saves branch October 16, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant