Fix atomic local state writes - #6350
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6350 +/- ##
=======================================
Coverage 72.98% 72.98%
=======================================
Files 744 745 +1
Lines 78611 78670 +59
=======================================
+ Hits 57374 57419 +45
- Misses 17236 17244 +8
- Partials 4001 4007 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
rdimitrov
approved these changes
Aug 17, 2026
Publish LocalStore state files only after complete writes so concurrent readers cannot decode partial JSON. Fixes #6328
JAORMX
approved these changes
Aug 19, 2026
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
Local state writes (
GetWriter/CreateExclusiveonLocalStore) previously opened the targetfile directly and wrote to it in place. A failed or aborted write (e.g. process crash or error
mid-write) could leave a truncated or partially-written state file behind, and
CreateExclusive's"exists" check and file creation were not atomic with each other.
LocalStorewriters now write to a temp file in the same directory and publish it atomicallyon
Close— viaos.RenameforGetWriter, andos.Link(which fails if the target alreadyexists) for
CreateExclusive, closing the exclusivity race.Aborterinterface andstate.AbortWriterhelper so callers can explicitly discardan in-progress write instead of relying on
Close, which now publishes data and can itself fail.pkg/groups,pkg/migration,pkg/state/runconfig.go) to callAbortWriterin their deferred cleanup instead ofClose, and to check the error from thefinal
Close, since publishing can now fail (e.g.CreateExclusiveconflict).Type of change
Test plan
task test)API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.Special notes for reviewers
state.Storewriters are now required to implementAborter; bothLocalStoreand theKubernetes no-op store were updated. Any future
Storeimplementation needs to do the same.Generated with Claude Code