fix(storage): preserve data across failed and concurrent file writes - #971
Open
saksim wants to merge 1 commit into
Open
fix(storage): preserve data across failed and concurrent file writes#971saksim wants to merge 1 commit into
saksim wants to merge 1 commit into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This was referenced Sep 9, 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.
JSON appends truncate the destination before serialization, so unsupported values can erase previous records. Malformed existing JSON is also silently discarded. In addition, factories create writers per record, making instance-local locks ineffective for concurrent writes to the same path.
Serialize first, write a temporary file in the same directory, flush/fsync, and atomically replace JSON. Preserve the original file on failure and propagate malformed-input errors. Share a process-local lock by normalized path for CSV/JSON/JSONL, run blocking file transactions with asyncio.to_thread, and wait for in-flight I/O on cancellation. Weak references release idle path locks.
Validation: 8 regression cases produce 7 failures / 1 pass on the original code. This isolated upstream branch passes all 104 tests (Python 3.11, Windows with PYTHONUTF8=1), covering serialization, invalid existing JSON, replace failures, concurrent writers in three formats, and cancellation.
This coordinates writers within one process; separate processes must use separate output files. JSON arrays still require a complete read/write per append. Formula handling and schema mapping are separate changes. See docs/file-transactions.md.
Fork tracking and CI: PR #20. Related report: saksim#4.