Repository navigation
Conversation
Replace the hand-rolled PID-suffixed temp file + rename in save_state with tempfile::NamedTempFile::persist. Temp file names are now unique per call and the temp file is removed when a write fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
The custom code today
core/src/state.rslines 51–63 (save_state) hand-rolls an atomic write:It writes
state.jsonto a temp file named after the PID, then renames it over the target. Called fromgate.rs:135andgate.rs:159on every gate event.Gaps in the hand-rolled version:
fs::writeorfs::renamefails,state.json.tmp.<pid>stays in the session dir forever.steplock-core, or parallel tests) that save the same session race on one temp file.The proposed library
tempfile—NamedTempFile::new_in(dir)+persist(path).[dependencies];Cargo.lockdoes not change.persist.Before / after
Call sites (
gate.rs) are unchanged.Trade-offs
tempfilebecomes a runtime dep of thesteplockbinary (pullsfastrand,rustix/windows-sys,once_cell, all already in the lockfile). Small.NamedTempFilecreates files as0600, sostate.jsonwritten by the binary becomes owner-only instead of umask default (0644).ack.shandpreview.shrun as the same user, so this does not break them. It is arguably better for session state.tmp.as_file().sync_all()?if crash durability matters later.Verification
cargo test— all pass (19 + 11).cargo clippy --all-targets— clean.Checklist
tempfilefrom[dev-dependencies]to[dependencies]save_statewithNamedTempFile::new_in+persist0600mode onstate.jsonis wanted (or chmod after persist)🤖 Generated with Claude Code