Repository navigation
refactor(engine): write thread files through one durable atomic writer - #4417
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Thread files now go through one durable writer,
rustcode_session::atomic_file::write_atomic. It writes a temporary file whose name is unique to the process and the call,fsyncs it, renames it into place (keeping the Windows replace fallback), andfsyncs the directory on Unix.Files that now use it:
history.json,title.txt,metadata.json,workspace.json,image_cache.json,segment.json,harness.json,status.jsonand the session settings log.settings.json, workflow run records, mirror files and the project-relocate edits.Removed duplicates:
worktrees::write_atomic,workflow::store::write_atomically,acp::mirror::write_atomicandacp::project_relocate::atomic_write.harness/store.rs,acp/settings.rsandtext_generation.rs.Several of these used a fixed
<name>.tmp, so two writers of the same file could rename each other's half-written temporary.The history writer used to drop every error silently. A failed write is now reported once per file until a write of it succeeds again, in two places: standard error, and a
history.write_failedoperational event (error_kind) that the CLI and the harness register at startup.Changelog
A full disk or a crash can no longer leave a thread's history, status or settings file half-written, and a history that stops saving is now logged.
Testing
write_atomic:history.jsoncargo fmt --all -- --check,python3 scripts/check-comments.py,python3 scripts/check-rust-size.py. Compilation and tests run in CI; this machine does not compile Rust.fsyncslows a large history write. Writes stay debounced at 250 ms on a background thread, so a turn does not wait on it.Closes #4406