Repository navigation
Fetch git-annex chunked annex objects in the Zarr converter - #1563
Conversation
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1563Version: 🤖 Updated on each push. |
nm000276 was uploaded with git-annex chunk=1GiB, so its bucket holds only SHA256E-s<size>-S<chunk>-C<n>--<hash> objects and every plain-key fetch 404'd (all 40 recordings failed). - download_blob: a 404 raises S3ObjectAbsent at once instead of being retried; every other failure is retried exactly as before. - fetch_annex_object: plain key first (one request, unchanged for unchunked datasets); on 404, discover the chunk size with one list-objects-v2, cache it per dataset, download C1..Cn in order through download_blob and append to a temp file, check the total, rename atomically. - A key the bucket holds in no complete form fails typed (annex_object_missing, not retryable); transient errors stay uncoded. Tested: new real-subprocess tests over a bucket stand-in laid out like nm000276, plus convert_one on chunked EDFs; converter suites pass.
The failures[].code description names every NEMAR-side code; add the new one. Description text only; bun test zarr mcp passes (root and backend).
478f610 to
c742654
Compare
Review recordOne Sonnet 5.5 review pass. No critical findings. Verified by the reviewer: chunk-name derivation is correct (
Verification: five named suites 973 passed, 5 skipped with biosigio 1.2.10 from PyPI; |
Why
nm000276 (SWEC iEEG Dataset) was uploaded with git-annex chunking (
chunk=1GiB).Its bucket holds only chunked object names: the annex key
SHA256E-s982--<hash>.vhdrexists solely asSHA256E-s982-S1073741824-C1--<hash>.vhdr, and a 100969566208-byte.eegexists as...-S1073741824-C1--...through...-C94--....The converter asked for the plain key, got a 404, and all 40 recordings failed as uncoded infra errors (
Key "nm000276/objects/SHA256E-s982--...vhdr" does not exist), retried and eventuallyretry_exhausted.Changes
download_blob: a 404 is not retried (scripts/zarr/generate_zarr.py).stderr is now captured;
(404)orNoSuchKeyraises an internalS3ObjectAbsenton the first answer.S3 is strongly consistent, so the old four retries with backoff asked the same question four times.
Every other failure (throttle, 5xx, wedge past the timeout, short copy) is retried exactly as before and still ends as an uncoded
RuntimeError.The not-found test is narrower than
s3_read_json's bare"404": a transfer failure quotes the key, and a 64-digit hex hash contains404often enough to turn a dropped connection into a false absence.fetch_annex_object: chunk-aware fetch, called by_fetch_blob(the single place an annex key becomes an S3 location).s3api list-objects-v2of<id>/objects/<fields>-Sfinds the chunked copies (exact-name match, so other keys that happen to have the same size are ignored). The chunk size is derived from the listing, never assumed to be 1 GiB. A variant counts as complete only when every chunk C1..Cn, where n = ceil(size/S), is listed at its expected size.download_blob, so each keeps the existing timeout, retry and size check. Each is appended to a temp assembly file through an 8 MiB copy buffer, the total is checked against the key's-ssize, and the file is renamed into place atomically. Memory stays bounded; scratch peaks at the file plus one chunk (1 GiB at production chunking). On any failure, nothing is left in the recording's work directory.annex_object_missing(AnnexObjectMissing, a new_FALLBACK_REASONSentry, and a line in thefailures[].codedescription inshared/zarr-index.schema.json).It is raised when the bucket definitively holds no complete copy: plain 404 and no chunked copy, a chunk absent, or a chunk whose listed size disagrees with its key.
It is not in
RETRYABLE_CODES, so the recording is refused and the rest of the dataset still serves (ADR 0005).Decisions
A 5xx, a throttle, a timeout, a listing that errors, and AccessDenied all stay uncoded and retryable (tests cover a 5xx whose message quotes a
404-bearing key, and a failed listing).Before this change a missing object burned five runs and then became an unexplained
retry_exhausted; now it says what it is on the first run.The upload path verifies content on the remote before pushing git, so "pointer committed, content not yet uploaded" is not the expected state.
If content is uploaded later, a requeue re-decides the recording.
One gap remains: with a cached chunk size, a chunk whose stored size is wrong fails
download_blob's size check and is retried as a truncation, ending uncoded. The listing path, which every dataset's first chunked key takes, catches it as typed._fetch_blob. The ADR 0030 streaming path (stream_to_zarr) reads the local file thatmaterialize_recordingdownloaded. There are no ranged reads and no presigned URLs, so no second path needed handling.Audit: every place the converter maps an annex key to S3 or to a size
generate_zarr.py:4421annex_key_size-s-sis the whole size:4429_blob_key_and_size,:4453recording_size_from_pointers, used at:7160:4485download_blobaws s3 cpof annex content:4617/:4691/:4727new_list_annex_chunks/_download_chunks/fetch_annex_object:5086_fetch_blob(:5107)objects/<key>mappingfetch_annex_object:5140,:5155_materialize_dir_members(CTF/MEF3/BTi, and their events)_fetch_blob:5256materialize_recording(primary, companions, split FIF, events)_fetch_blob:5740,:5754stage_declared_fdt_fetch_blob:6589MaxShield calibration pair_fetch_blob:5408materialize_local:6206_recording_size_bytes,:6421stream_to_zarr:6815manifestsize_bytesannex_key_size(primary_key):4776s3_read_json,:4814read_index_with_etag,:4925s3_download_filezarr/index and events.parquet, not annexpurge_non_raw_stores.py:545,find_collapsed_channel_stores.py,patch_power_line_frequency.py:130,hallu-zarr.sh<id>/zarr/stores onlyOutside the converter, and not changed here:
backend/src/services/data-router.ts:278and:313build<id>/objects/<key>URLs for the data plane andmanifest.json. For a chunked dataset those URLs 404 too, so they need a follow-up.Tests
The new tests use real subprocesses and no mocks. A stand-in
awsexecutable serves a directory laid out exactly likes3://nemar/nm000276/objects/, with the CLI's own 404 line,list-objects-v2JSON, ands3 syncinto the same tree. The chunk size in keys is 1024 bytes, and the code discovers it from the listing..vhdrcase, C1 only)AnnexObjectMissing, no partial file; another key's same-size chunks are not mistaken for it404-bearing key: uncoded, no listing; failed listing: uncodedconvert_onein remote mode on two real pyedflib EDFs whose objects are stored chunked converts, publisheszarr.jsoninto the bucket stand-in, and issues one listing for both. A missing chunk yieldsannex_object_missing, which is not retryable, counts as data incount_infra_failures, and publishes nothing.Results with biosigio 1.2.10 (uv,
--refresh --no-cache):test_generate_zarr.py test_zarr_queue.py test_purge_non_raw_stores.py test_find_collapsed_channel_stores.py test_patch_power_line_frequency.py: 959 passed, 5 skipped (Linux-only RLIMIT/proc tests); baseline was 944 passed + 15 new.test_hallu_zarr_config.py: 51 passed locally; the other 74 need bash 4+ and this macOS host has bash 3.2 (the script's own guard). The file is unchanged, and the Linux CI job runs it.bun test zarr mcp: root 879 pass, backend 679 pass.origin/dev(compared by rule and message). ty: no findings on the changed ranges.After the next release
zarr_queue.py requeue --status failed --dataset nm000276 --execute(or ahallu-zarr.sh --dataset nm000276run).aws s3 ls s3://nemar/ --recursive | grep -E -- '-S[0-9]+-C[0-9]+--', or per datasetaws s3 ls s3://nemar/<id>/objects/ | grep -cE -- '-S[0-9]+-C[0-9]+--'. Requeue any that failed.s3:ListBucketon<id>/objects/prefixes. It is described as having ListBucket; if that permission is prefix-conditioned tozarr/, the listing fails loudly as an uncoded, retryable error rather than being read as "missing".Review round 1
Commits, one per finding:
All-missing runs stay retryable at the dataset level (
Keep all-missing-object runs retryable,Name the missing object in the queue error).annex_object_missingstays a typed, per-recording failure in the index, so a partial dataset still serves and the refusal is explicit. The dataset-leveldeterministicverdict now comes fromdataset_failure_is_deterministic(failures, failure_entries): true only when something failed, nothing is infra (count_infra_failures == 0), and at least one typed failure is outside the newSTORAGE_STATE_CODES(annex_object_missing). So:deterministic: false, rc 1, andhallu-zarr.shcallsqpy failwithout--deterministic, which takes the queue's normal bounded backoff (default 5 attempts, 1800 s base) and endsfailed, notdata_failedon the first run;corrupt_or_truncated): still deterministic, as before;donewhatever the verdict; the missing recording is listed underfailureswith its code.The callback, both
failedandready, now carriesannex_missing_count,annex_missing_first_pathandannex_missing_first_key(first by path, so pool order does not choose it);AnnexObjectMissingcarries its key as an attribute for this. The backend body schema is.passthrough(), so nothing there changes. The queue verdict moved intorecord_conversion_failureinhallu-zarr.sh. When every failed recording isannex_object_missingand the driver reported no producererror, the queue'slast_errorsays that storage lacks the objects, namess3://<bucket>/<id>/objects/<first key>, says the dataset is retried with backoff and endsfailedif the objects never arrive, and gives the remedy: fix the upload, thenhallu-zarr.sh --dataset <id> --requeue failed --execute.403 case (
Test and document the 403 case of annex fetch). Stand-inawstests: a 403 on the plain key'scpis retried (two copies at_AWS_RETRIES=2), ends as an uncodedRuntimeError(neverannex_object_missing), and the chunk fallback is never attempted: no listing, no chunk copy. A listing refused withAccessDeniedis retried and ends uncoded as well. Thehallu-zarr.shprofile comment now says the scoped profile needss3:GetObjecton<id>/objects/*ands3:ListBucketfor the<id>/objects/prefixes. Without ListBucket, a missing plain key returns 403, the chunked fallback never runs, and every chunked recording fails uncoded: safe, but the feature does nothing.Wrong-size chunk under a cached chunk size (
Type a wrong-size chunk under a cached size).download_blobraisesS3SizeMismatch, aRuntimeErrorsubclass, when its last attempt was a size mismatch. The cached branch offetch_annex_objectthen falls through to the listing, which types a chunk stored at the wrong size asannex_object_missing, or fetches again when the stored chunk is right and only the transfer was short. Both paths are tested.No resume (
Document chunked fetch cost and no resume). This is documented in_download_chunks: about 94 sequentialaws s3 cpcalls, roughly 17 min at 100 MB/s, for a 100 GB file in 1 GiB chunks. The 1800 s cap applies per chunk. Scratch peaks at the file plus one chunk. Resume is not implemented.annex_key_sizeanchored (Read annex key size from the key's fields only). The size is read from the key's fields only (before the first--), as a whole-s<N>field. Tested with WORM and URL keys that contain-s5in the name.Unreachable reassembly check (
Keep chunk reassembly bug uncoded). It now raises a plainRuntimeErrormarked as an internal error, notAnnexObjectMissing.Backend data-router follow-up: the maintainer is filing it;
backend/src/services/data-router.tsis untouched.Results with biosigio 1.2.10 (uv,
--refresh --no-cache):test_hallu_zarr_config.py: 57 passed locally, including the 6 new verdict tests; they extractconvert_datasetandrecord_conversion_failureverbatim and run under the script'sset -uo pipefailwith a stand-in driver andqpy. The other 74 need bash 4+, which this macOS host (bash 3.2) does not have, so the Linux CI job covers them.bun test zarr mcp(root): 879 pass. No schema text changed this round.origin/dev(compared by rule and message). ty: no new diagnostics vsorigin/dev. shellcheck onhallu-zarr.sh: clean.