Repository navigation
Conversation
convert now runs the HDF5 guard on the source and on --raw before any sniffer opens them to tell their format (F166), and passes every input, --raw included, to the output check, under any alias (F167). The check that refuses an output inside a Zarr input is factored out of check_output (check_not_input) and covers a --to 10x-mtx folder too (F173). The free-space check now covers folder sources (Space Ranger outs/, Xenium bundles, MTX folders, Parse runs), estimated from the files the converter's plan reads rather than skipped (F168). Part of #135. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Planning used to unpack the archive's tables beside the output before convert checked anything, into a folder only a finalizer removed; a refused or failed run, which ends in os._exit, left .adata-xenium-* behind. Planning now lists the archive's members only; the tables are unpacked inside staging, read and checked there, and removed in a finally. The free-space check counts them (F169). Part of #135. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…them The HDF5 guard now covers the cases it missed, and its reads are bounded (F170, F171). copy_path copies a Zarr store with links read through only where zarr reads a file (a node's metadata, an array's chunk), as anndata would; any other link is kept as a link, a link to a folder is refused rather than followed out of the store, and a link to nothing where zarr reads is refused. The codec check no longer walks into linked folders (F172). Part of #135. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The output check and every input of convert, folder sources' free space, Xenium's archive, references in HDF5 files, links in Zarr stores, and the new refusals in troubleshooting. Part of #135. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…imates - An output whose folders reach into a Zarr input through a link is refused too: the output's folders are judged as the filesystem resolves them, not only by name (F173). - import's copy reads a link through only for a file zarr reads: a chunk under the key its array's chunk key encoding gives a chunk of its grid, a v2 node's .zattrs, a v2 group's .zmetadata, and the metadata naming a node. Any other link stays a link, whatever its name; a link among the chunks of an array whose key encoding cannot be read is refused. The copy goes back to copytree's own copy2, so a file that is no link costs no more than before (F172). - The HDF5 guard bounds what it reads by what it follows, judged from a dataset's layout and index before reading it (F171). - convert's estimate counts the files a plan reads beside a matrix file named on its own (Visium, Xenium), and measures a Zarr store kept as links by what they point at (F168, F169). - A convert source, or a file of a folder source where an HDF5 file is read, that is no regular file is refused before a sniffer can wait on it for ever (F166). Part of #135. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ributes - import's copy reads a link through only among the files of a node zarr reaches, going down the store's groups from its root in the store's own Zarr version: metadata planted inside an array, below a folder that is no group, or of the other version no longer makes a link beside it a file zarr reads (F172). - The HDF5 guard refuses an attribute of more references than it follows, from its shape, before reading it (F171). - convert's estimate walks no list of names (the text importer's rows). - An output's folders are judged as the filesystem resolves them only, so `-o in.zarr/../out.h5ad`, beside the store, is no longer refused as inside it (F173). Part of #135. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A folder is a node of the copied store only if its metadata is a JSON object of the store's Zarr version saying what node it is, so a link named `.zgroup` to some other JSON file makes no node of its folder. v2's consolidated index is read through only at the root, where zarr opens a store and reads it (F172). Part of #135. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Test Results (py3.13)3 950 tests 3 937 ✅ 6m 41s ⏱️ Results for commit 64db8f4. |
Test Results (py3.12)3 950 tests 3 937 ✅ 9m 59s ⏱️ Results for commit 64db8f4. |
Part of #149 (wave 1, released as 0.17.11 with B2 to B6).
Closes #135.
What a store or a folder of outputs holds outside itself no longer reaches an output, and
convertchecks every input, and its disk, before it writes.What changes
convertruns the HDF5 guard on the source and on--rawbefore any sniffer opens them to tell their format. A source, or a file of a folder source where an HDF5 file is read, that is no regular file (a pipe) is refused there too, rather than waited on.commands/convert.py,storage/__init__.pyconvert,--rawincluded, goes to the output check, under any alias (hard link, symlink, case).commands/convert.pyouts/, Xenium bundle, MTX folder, Parse run), or a Visium or Xenium matrix named on its own, is checked for free space, estimated from the files its converter's plan reads (matrix and tables, not images and BAMs), plus what Xenium unpacks beside the output. A Zarr store kept as links is measured by what they point at.commands/convert.pyanalysis.tar.gz; the tables are unpacked inside staging, read and checked there, and removed in afinally, so a refusal unpacks nothing and a failure leaves nothing,os._exitor not.conversion/xenium.pystorage/__init__.pycopy_path(import's copy of a Zarr store) reads a link through only where zarr reads a file, judged from each array's metadata; any other link is copied as a link; a link to a folder is refused, never followed; the codec check no longer walks into linked folders.storage/__init__.pycheck_output(check_not_input), covers a--to 10x-mtxfolder, and judges the output's folders as the filesystem resolves them, so a link into the store is caught too.util/path.py,commands/convert.pyOther finalizer-based cleanups were audited with F169: Xenium's
TemporaryDirectorywas the only disk cleanup left to a finalizer. Every scratch file (scratch_group, concat's buckets,RowScatter) is removed in afinallyor a context manager, which run before_leave. The otherweakref.finalizeonly frees memory (the shard index cache).Zarr links: the decision and its trade-off
Agreed on 2026-12-04: links are read through as anndata reads them, because datalad, git-annex and DVC keep every file of a store as a link into an object store outside it. So:
convert,subset,export, ...) still follows links, wherever they point, as zarr'sLocalStoredoes for anndata. A chunk linked to a file outside the store is read through, by design: the output holds what anndata reads.test_convert_reads_a_chunk_through_its_link_as_anndata_doeschecks that against anndata.import's copy (copy_path) copies a link as the file it points at only where zarr reads a file: among the files of the nodes zarr reaches going down the store's groups from its root, in the store's own Zarr version, with metadata zarr could read. Those are each node's metadata (zarr.json; in v2.zarrayor.zgroup,.zattrs, and the root's.zmetadata) and each array's chunks, under the key its chunk key encoding gives a chunk of its grid (v20.0or0/0; v3c/0/0,c.0.0, or v2-style keys; 0-d keys too). Any other link is copied as the link it is, whatever it is named and whatever metadata sits beside it:in.zarr/stolen,uns/notes.txt,X/README, a key past the grid or of another rank or encoding,.zattrsin a folder that is no node, or metadata planted inside an array, below a folder that is no group, or of the other version. So a file outside the store never becomes part of the output. A link among the chunks of an array whose metadata names a chunk grid or key encoding zarr does not have is refused rather than guessed at./copied the disk). datalad, git-annex and DVC link files, not folders, so their stores copy as before (test_a_store_kept_as_links_is_copied_as_the_store_they_link_to, v2 and v3, read back by anndata).shutil.copytreeand its owncopy2, so a file that is no link costs what it did (3.1statcalls per file on main and here, counted on a 204-file store); the checks add one more listing of each folder and look through links only. Each array's metadata is read only if a link sits among its chunks. B0's codec checks stay as they were, before and after the copy (tests/test_zarr_safety.pyis untouched and green);check_zarr_storeno longer follows linked folders, since the copy refuses them.What remains: a crafted store whose chunk or metadata link points at a private file still has that file read through, by
convertas by anndata, and copied byimport. That is the agreed read-through, and leaks only if the output is sent back.Changelog entry (for the 0.17.11 release PR)
Fixed
convertchecks every input before it reads one, and refuses an output that is any of them (#135). It used to open a file to tell its format before checking it for data held in another file, so an external link to a FIFO hung the run; a pipe given as the source, or where a folder source keeps its matrix, is now refused too. It also checked the output against the source alone, so-onaming CellBender's--rawfile replaced the raw matrix it was reading, exit 0. A--to 10x-mtxfolder inside a Zarr input was written among its chunks, and any output reaching into a Zarr input through a link among its folders was written there, one replacing an array of the input with a whole store; both are refused, as every other output inside an input is.outs/, a Xenium bundle, an MTX folder or a Parse run converted to.h5adwas written however full the disk was, and a full disk can stop an HDF5 write inside the library, where nothing cleans up. The estimate is the files the conversion reads, its matrix and tables, not the images and BAMs beside them, for a Visium or Xenium matrix named on its own too. A Zarr store kept as links (datalad, git-annex, DVC) was measured by the links' own few bytes; it is measured by the files they point at.analysis.tar.gzis unpacked only while writing, and always removed (#135). It was unpacked while planning, before the output was checked, and a refused or failed run left.adata-xenium-*beside the output.lsandviewtoo.importcopies a Zarr store's links as zarr reads them (#135). It copied with every link followed, so a link to a file outside the store, part of no element, came out in the output as a copy of that file, and a link to/copied the disk. A link zarr reads through, such as a chunk of a datalad, git-annex or DVC store, is still copied as the file it points at; any other link stays a link, whatever it is named; a link to a folder is refused.Tests
Each finding has a regression test whose docstring starts with its ref, checked against anndata, scipy, zarr or h5py where there is an output. The tests of the first commits were run against unmodified
main: 44 fail there. The 8 that pass there test behaviour the links decision keeps: a link store copied and read back by anndata (v2, v3), chunk links read through in all five key encodings, andconvertreading a chunk through its link. The 14 tests added for the second review fail on the commit before them.test_convert.py::test_an_external_link_is_refused_before_a_sniffer_follows_it,::test_a_pipe_where_an_hdf5_file_is_read_is_refused(FIFOs, run as the command, killed if it hangs)test_cellbender.py::test_an_output_naming_the_raw_input_is_refused(itself, hard link, symlink; the raw counts checked with scipy)test_convert.py::test_a_folder_source_is_checked_for_free_space(Visium, Xenium, MTX, Parse; a BAM beside them is not counted; X read back by anndata against each fixture's counts),::test_a_store_kept_as_links_is_measured_by_what_they_point_at,::test_the_estimate_walks_no_list_of_names;test_xenium.py::test_a_bundle_named_by_its_matrix_is_measured_as_a_wholetest_xenium.py::test_a_refused_conversion_unpacks_nothing,::test_a_conversion_failing_after_the_unpack_leaves_nothing(both run as the command, so throughos._exit),::test_the_free_space_check_counts_the_tables_an_archive_unpacks(sizes fromtarfile; read back by anndata)test_storage.py, the two tests whose docstrings start with F170test_storage.py, the tests whose docstrings start with F171 (one aperfmemory guard, run as the audit measured it)test_storage.py::test_a_link_that_is_no_file_of_an_element_stays_a_link_in_a_copy,::test_a_link_named_like_a_file_zarr_reads_elsewhere_stays_a_link(8 names),::test_metadata_planted_where_zarr_reaches_no_node_reads_no_link_through(11 cases),::test_a_link_to_a_folder_is_refused_before_the_copy_walks_it,::test_a_chunk_linked_to_nothing_is_refused_by_a_copy,::test_a_link_among_an_array_s_chunks_is_refused_when_its_keys_cannot_be_told; what stays:::test_a_store_kept_as_links_is_copied_as_the_store_they_link_to,::test_chunks_linked_out_are_read_through_in_every_key_encoding(5 encodings, against zarr),::test_convert_reads_a_chunk_through_its_link_as_anndata_doestest_mtx.py::test_a_folder_output_inside_the_zarr_input_is_refused(Zarr v2 and v3),::test_an_output_through_a_link_into_the_zarr_input_is_refused(an MTX folder, an h5ad, and over one of the input's own arrays),::test_an_output_beside_the_zarr_input_named_through_it_is_written(-o in.zarr/../out.h5ad, refused before by name); the store read back by anndataOne existing test changed:
test_xenium.py::test_an_archive_that_cannot_be_unpacked_beside_the_output_is_refused_by_name(F112). The unpack now happens inside staging, so it patchestempfile.mkdtemp, and the output's folder, made by staging, is left empty rather than not made.Review
An independent subagent reviewed the diff twice, from the code alone, and reran its own triggers against each round of fixes. What it found, and what came of it:
statcalls per copied file; the Xenium docs.Follow-ups (not in this PR)
storage.check_hdf5_inputswalks a folder source through linked folders (deliberate since F041: the converters' globs go there), so a link to/inside a Space Rangerouts/walks the disk, and an unrelated HDF5 file with an external link behind a linked folder refuses the conversion.commands/import_data.py's precheck (_source_root,_precheck) opens the source with h5py before any guard runs, soimport array/import sparseon an h5ad whose external link names a FIFO hangs.util/staging.disk_sizemeasures a link's own size, soimportof a Zarr store kept as links under-estimates its copy (convert now measures through links on its own).storage.open_storestamps the AnnData root attributes on any store opened to write, an.h5muon import included (from B6's notes).analysis.tar.gzonce to list its members, and writing again to unpack them.Local results (macOS, on the PR's last commit)
uv run pytest -m "not integration": 4,151 passed, 9 skipped.uv run pytest -m perf: 210 passed, one more thanmain(the F171 memory guard).tests/test_zarr_safety.py(B0's codec guard) is unchanged and green.OKexcept F172's: its import half is fixed, and itsconverthalf still printsDEFECT. That half assertsconvertmust not read a chunk linked out of the store, which the links decision keeps, as anndata reads it. A copy of the script checked against anndata instead confirms three things:convert's output equalsanndata.read_zarrof the same store, the stray link stays a link inimport's output, and a link to/is refused without being walked.test_performance.py::test_split_memory_stops_growing_with_the_group_countfailed in two full local runs on macOS. Its 128-group peak RSS read 76 to 81 MB against about 119 MB for 320 groups, and the limit on the difference is 32 MB. Measured interleaved withmain,maingave the same kind of low reading (86 against 119 MB). The test passes alone, in theperfrerun above and in the final unit run. It looks like a noisy reading on macOS, not this change; CI runs on Linux.🤖 Generated with Claude Code