fix: write the plan file atomically so a crash mid-save cannot destroy it - #172
Open
vitali87 wants to merge 1 commit into
Open
fix: write the plan file atomically so a crash mid-save cannot destroy it#172vitali87 wants to merge 1 commit into
vitali87 wants to merge 1 commit into
Conversation
…y it save_plan truncated and rewrote .pr-split/plan.json in place. The file is large (it embeds the full raw diff) and the most important save happens right after PRs are created; a crash or full disk mid-write left truncated JSON and wiped the previous good plan, orphaning the just-created PRs and branches with no record for clean/status/merge to act on. The plan is now written to a temp file in the same directory and os.replace()d over the target, with the temp file cleaned up on failure.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary
save_plantruncated and rewrote.pr-split/plan.jsonin place. The file embeds the full raw diff, and the most important save happens right after PRs are created — so a crash, SIGKILL, or full disk mid-write left truncated JSON and destroyed the previous good plan, orphaning the just-created PRs and branches with no record forclean/status/mergeto act on (#64 only cleans up the resulting error message; the data was still gone).The plan is now written to
plan.json.tmpin the same directory andos.replace()d onto the target — atomic on the same filesystem — with the temp file unlinked in afinallyon failure. Review confirmed the temp file is invisible to #169's clean check and that a stray.tmpafter SIGKILL is harmless and overwritten by the next save.Stacked on #169 (stack #159 = #64→#158→#169→this).
Test plan
test_failed_write_preserves_the_previous_plan: an ENOSPC mid-write leaves the previous plan byte-for-byte intact and loadable — fails on the basetest_no_temp_file_left_behindguards the new mechanism