Skip to content

fix(storage): preserve data across failed and concurrent file writes - #971

Open
saksim wants to merge 1 commit into
NanmiCoder:mainfrom
saksim:codex/upstream-file-transactions
Open

fix(storage): preserve data across failed and concurrent file writes#971
saksim wants to merge 1 commit into
NanmiCoder:mainfrom
saksim:codex/upstream-file-transactions

Conversation

@saksim

@saksim saksim commented Sep 9, 2026

Copy link
Copy Markdown

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.

@saksim
saksim requested a review from NanmiCoder as a code owner September 9, 2026 03:09
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant