fix: replace H5AD only after successful write - #2570
Open
stanbot8 wants to merge 2 commits into
Open
Conversation
stanbot8
force-pushed
the
agent/issue-522-transactional-h5ad-overwrite
branch
from
July 24, 2026 08:51
c1561d0 to
12ae834
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2570 +/- ##
==========================================
- Coverage 87.83% 85.90% -1.94%
==========================================
Files 49 49
Lines 7799 7823 +24
==========================================
- Hits 6850 6720 -130
- Misses 949 1103 +154
|
flying-sheep
left a comment
Member
There was a problem hiding this comment.
Looks good, but the tests need slimming down
stanbot8
force-pushed
the
agent/issue-522-transactional-h5ad-overwrite
branch
from
July 24, 2026 13:08
12ae834 to
c66a734
Compare
Stage each destructive write next to the target. Replace the target only after the new file is complete. Preserve the target after write and replacement failures.
stanbot8
force-pushed
the
agent/issue-522-transactional-h5ad-overwrite
branch
from
July 24, 2026 13:49
c66a734 to
68c7fa5
Compare
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
HDF5 can truncate a live H5AD target before it reports a lock failure (h5py issue 1864, HDF5 issue HDFFV-11230). This change writes a complete replacement to a temporary file. It replaces the target only after the write succeeds. Closes #522.
Design
The live target is never opened with
mode="w". A failed write leaves an existing target unchanged. A successful replacement publishes a complete new file. The replacement preserves symbolic links.The implementation changes
src/anndata/_io/h5ad.py. The design follows the reported truncation reproducer, the requested overwrite behavior, and the HDF5 lock analysis.Limitations
Tests
All 11 CPU matrix jobs passed. The benchmark and patch coverage checks passed.
Commands
pytest -q tests/test_readwrite.py -k 'test_write_h5ad'