Python: fix: unique temporary filenames for concurrent FileCheckpointStorage saves (#8182) - #8220
Closed
Atik (ptimizeroracle) wants to merge 2 commits into
Closed
Conversation
…saves (microsoft#8182) Signed-off-by: ptimizeroracle <contact@binblok.com>
Atik (ptimizeroracle)
temporarily deployed
to
github-app-auth
September 10, 2026 09:01 — with
GitHub Actions
Inactive
Atik (ptimizeroracle)
temporarily deployed
to
github-app-auth
September 10, 2026 09:01 — with
GitHub Actions
Inactive
Atik (ptimizeroracle)
temporarily deployed
to
github-app-auth
September 10, 2026 09:02 — with
GitHub Actions
Inactive
Atik (ptimizeroracle)
temporarily deployed
to
github-app-auth
September 10, 2026 09:03 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Failed writes can leave an unbounded number of uniquely named temporary files.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Prevents concurrent checkpoint saves from racing on a shared temporary file.
Changes:
- Generates a unique temporary filename per save.
- Adds a concurrent same-ID save regression test.
File summaries
| File | Description |
|---|---|
_checkpoint.py |
Uses PID/UUID-based temporary filenames. |
test_checkpoint.py |
Tests concurrent saves and final-state loading. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
335
to
338
| tmp_path = file_path.with_suffix(f".json.{os.getpid()}.{uuid.uuid4().hex}.tmp") | ||
| with open(tmp_path, "w") as f: | ||
| json.dump(encoded_checkpoint, f, indent=2, ensure_ascii=False) | ||
| os.replace(tmp_path, file_path) |
Author
|
@microsoft-github-policy-service agree |
Signed-off-by: ptimizeroracle <contact@binblok.com>
Atik (ptimizeroracle)
temporarily deployed
to
github-app-auth
September 10, 2026 09:29 — with
GitHub Actions
Inactive
Author
|
addressed in 6b7311d: failed writes now unlink their own temp file before re-raising, so failures don't accumulate. added a test that simulates a replace failure and asserts no .tmp leftovers. 48/48 local. |
Author
Atik (ptimizeroracle)
deployed
to
github-app-auth
September 12, 2026 20:27 — with
GitHub Actions
Active
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.
description
fixes #8182
every writer used the same temp name,
{id}.json.tmp. so when two saves of one checkpoint id run at the same time, oneos.replaceeats the temp file the other writer is about to replace, and that save dies with a rawFileNotFoundErrornow each writer gets its own temp name,
{id}.json.{pid}.{uuid}.tmp. still ends in.tmpso the*.jsonglobs inlist_checkpointsandlist_checkpoint_idsnever pick these upvalidation
before: 20 concurrent saves of one id, several of them crash in
os.replaceafter: same probe, 0 errors
added
test_file_checkpoint_storage_concurrent_saves_same_id(10 concurrent saves, no exceptions, final state loads)test_checkpoint.py47/47 local, ruff cleani only changed the temp name. no exception type changes, that question stays in the issue thread
ai assistance: i led this contribution and used a coding agent to help write the change and its test. validation was run locally. happy to use a different suffix format if you have one