direct: write deployment state atomically - #6329
Merged
Merged
Conversation
unlockedSave truncated the state file in place. A crash mid-write left a state file the CLI cannot parse next to an intact WAL that Open never reads, because Open parses the state file first and returns on error. The deployment state was then unrecoverable. Write to a temp file in the same directory and rename it over the state file instead; replayWAL already removes the WAL only after the save succeeds. Co-authored-by: Isaac
Collaborator
Integration test reportCommit: f485b01
Top 6 slowest tests (at least 2 minutes):
|
The test pinned how the state file is written (replaced, not truncated in place) rather than what callers observe. What matters is that the save lands; the mechanism is an implementation detail explained in a comment. Co-authored-by: Isaac
shreyas-goenka
approved these changes
Aug 20, 2026
| // only then removes the WAL, and Open parses the state file before it looks at | ||
| // the WAL. A torn write would therefore leave a state file that Open rejects | ||
| // next to an intact WAL it never reads. | ||
| func (db *DeploymentState) unlockedSave() error { |
Contributor
There was a problem hiding this comment.
a unit test for the failure paths would be good to assert this actually works
| @@ -0,0 +1 @@ | |||
| Write the deployment state atomically so an interrupted save cannot leave a state file that the CLI refuses to read. | |||
Collaborator
Integration test reportCommit: c718024
17 interesting tests: 12 FAIL, 2 KNOWN, 2 SKIP, 1 RECOVERED
Top 50 slowest tests (at least 2 minutes):
|
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.
unlockedSave truncated the state file in place, so a crash mid-write left a state file the CLI cannot parse next to an intact WAL. Open parses the state file before it stats the WAL and returns on error, so recovery never ran and the deployment state was unrecoverable.
Write to a temp file in the same directory and rename it over the state file instead. replayWAL already removes the WAL only after the save succeeds.