Skip to content

Fetch git-annex chunked annex objects in the Zarr converter - #1563

Merged
neuromechanist merged 9 commits into
devfrom
feat/zarr-chunked-annex-fetch
Sep 29, 2026
Merged

neuromechanist merged 9 commits into
devfrom
feat/zarr-chunked-annex-fetch

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

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>.vhdr exists solely as SHA256E-s982-S1073741824-C1--<hash>.vhdr, and a 100969566208-byte .eeg exists 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 eventually retry_exhausted.

Changes

  1. download_blob: a 404 is not retried (scripts/zarr/generate_zarr.py).
    stderr is now captured; (404) or NoSuchKey raises an internal S3ObjectAbsent on 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 contains 404 often enough to turn a dropped connection into a false absence.
  2. fetch_annex_object: chunk-aware fetch, called by _fetch_blob (the single place an annex key becomes an S3 location).
    • Plain key first: an unchunked dataset costs exactly one request per key, as before.
    • On 404, one s3api list-objects-v2 of <id>/objects/<fields>-S finds 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.
    • The discovered chunk size is cached per (bucket, dataset) per worker process, so later keys go straight to their chunks: at most one listing per worker for a 3000-recording dataset, not one per file. If chunk 1 is not there under the cached size (the dataset mixes chunk configurations), that key falls back to its own listing.
    • Chunks download in order and sequentially, each through 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 -s size, 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.
  3. Typed failure annex_object_missing (AnnexObjectMissing, a new _FALLBACK_REASONS entry, and a line in the failures[].code description in shared/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

  • Error typing. Only definite answers from S3 reach the typed code: a 404, or a successful listing that lacks the chunk.
    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.
  • Parallelism: sequential chunk download. Parallel chunks would multiply S3 connections per worker, against the deliberately low per-process concurrency and the JOBS-way worker parallelism. They would also need scratch for several in-flight 1 GiB chunks, which the admission model does not account for (there is no disk admission). Sequential is the safe first version. Each chunk still uses the CLI's own multipart download.
  • Streaming and ranged reads. No converter path reads annex content from S3 except through _fetch_blob. The ADR 0030 streaming path (stream_to_zarr) reads the local file that materialize_recording downloaded. 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

Location What it does Chunking impact
generate_zarr.py:4421 annex_key_size size from the plain key's -s none: the pointer holds the plain key, and -s is the whole size
:4429 _blob_key_and_size, :4453 recording_size_from_pointers, used at :7160 admission projection from pointers none (no S3 access)
:4485 download_blob the only aws s3 cp of annex content 404 now unretried and typed internally
:4617 / :4691 / :4727 new _list_annex_chunks / _download_chunks / fetch_annex_object chunk discovery and reassembly new
:5086 _fetch_blob (:5107) the only key-to-objects/<key> mapping now calls fetch_annex_object
:5140, :5155 _materialize_dir_members (CTF/MEF3/BTi, and their events) via _fetch_blob covered
:5256 materialize_recording (primary, companions, split FIF, events) via _fetch_blob covered
:5740, :5754 stage_declared_fdt key size check before download, then _fetch_blob covered
:6589 MaxShield calibration pair via _fetch_blob covered
:5408 materialize_local local working tree, no S3 none
:6206 _recording_size_bytes, :6421 stream_to_zarr local file sizes and local streaming read none
:6815 manifest size_bytes annex_key_size(primary_key) none
:4776 s3_read_json, :4814 read_index_with_etag, :4925 s3_download_file zarr/ index and events.parquet, not annex none
purge_non_raw_stores.py:545, find_collapsed_channel_stores.py, patch_power_line_frequency.py:130, hallu-zarr.sh operate on <id>/zarr/ stores only none

Outside the converter, and not changed here: backend/src/services/data-router.ts:278 and :313 build <id>/objects/<key> URLs for the data plane and manifest.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 aws executable serves a directory laid out exactly like s3://nemar/nm000276/objects/, with the CLI's own 404 line, list-objects-v2 JSON, and s3 sync into the same tree. The chunk size in keys is 1024 bytes, and the code discovers it from the listing.

  • plain key: exactly one aws call, as before
  • single-chunk small file (the .vhdr case, C1 only)
  • multi-chunk file reassembles byte-identically (sha256), chunks fetched in order, nothing left in scratch; exact-multiple and empty-key chunk arithmetic
  • missing middle chunk, wrong-size chunk, object absent in every form: AnnexObjectMissing, no partial file; another key's same-size chunks are not mistaken for it
  • 5xx whose message quotes a 404-bearing key: uncoded, no listing; failed listing: uncoded
  • chunk size discovered once across recordings; a key under a different chunk size is still found; a missing chunk under the cached size is refused
  • end to end: convert_one in remote mode on two real pyedflib EDFs whose objects are stored chunked converts, publishes zarr.json into the bucket stand-in, and issues one listing for both. A missing chunk yields annex_object_missing, which is not retryable, counts as data in count_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.
  • ruff: no new findings vs origin/dev (compared by rule and message). ty: no findings on the changed ranges.

After the next release

  • Requeue nm000276: zarr_queue.py requeue --status failed --dataset nm000276 --execute (or a hallu-zarr.sh --dataset nm000276 run).
  • Other datasets may have been uploaded with chunking. Find them with an S3 listing for chunked names, e.g. aws s3 ls s3://nemar/ --recursive | grep -E -- '-S[0-9]+-C[0-9]+--', or per dataset aws s3 ls s3://nemar/<id>/objects/ | grep -cE -- '-S[0-9]+-C[0-9]+--'. Requeue any that failed.
  • The Hallu profile needs s3:ListBucket on <id>/objects/ prefixes. It is described as having ListBucket; if that permission is prefix-conditioned to zarr/, 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_missing stays a typed, per-recording failure in the index, so a partial dataset still serves and the refusal is explicit. The dataset-level deterministic verdict now comes from dataset_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 new STORAGE_STATE_CODES (annex_object_missing). So:

    • every recording missing its object: deterministic: false, rc 1, and hallu-zarr.sh calls qpy fail without --deterministic, which takes the queue's normal bounded backoff (default 5 attempts, 1800 s base) and ends failed, not data_failed on the first run;
    • missing objects plus a genuine typed data failure (for example corrupt_or_truncated): still deterministic, as before;
    • any infra failure, or a retryable code: not deterministic, as before;
    • a partial success: rc 0 and done whatever the verdict; the missing recording is listed under failures with its code.

    The callback, both failed and ready, now carries annex_missing_count, annex_missing_first_path and annex_missing_first_key (first by path, so pool order does not choose it); AnnexObjectMissing carries its key as an attribute for this. The backend body schema is .passthrough(), so nothing there changes. The queue verdict moved into record_conversion_failure in hallu-zarr.sh. When every failed recording is annex_object_missing and the driver reported no producer error, the queue's last_error says that storage lacks the objects, names s3://<bucket>/<id>/objects/<first key>, says the dataset is retried with backoff and ends failed if the objects never arrive, and gives the remedy: fix the upload, then hallu-zarr.sh --dataset <id> --requeue failed --execute.

  • 403 case (Test and document the 403 case of annex fetch). Stand-in aws tests: a 403 on the plain key's cp is retried (two copies at _AWS_RETRIES=2), ends as an uncoded RuntimeError (never annex_object_missing), and the chunk fallback is never attempted: no listing, no chunk copy. A listing refused with AccessDenied is retried and ends uncoded as well. The hallu-zarr.sh profile comment now says the scoped profile needs s3:GetObject on <id>/objects/* and s3:ListBucket for 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_blob raises S3SizeMismatch, a RuntimeError subclass, when its last attempt was a size mismatch. The cached branch of fetch_annex_object then falls through to the listing, which types a chunk stored at the wrong size as annex_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 sequential aws s3 cp calls, 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_size anchored (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 -s5 in the name.

  • Unreachable reassembly check (Keep chunk reassembly bug uncoded). It now raises a plain RuntimeError marked as an internal error, not AnnexObjectMissing.

  • Backend data-router follow-up: the maintainer is filing it; backend/src/services/data-router.ts is untouched.

Results with biosigio 1.2.10 (uv, --refresh --no-cache):

  • The five named suites: 973 passed, 5 skipped (Linux-only RLIMIT/proc tests).
  • test_hallu_zarr_config.py: 57 passed locally, including the 6 new verdict tests; they extract convert_dataset and record_conversion_failure verbatim and run under the script's set -uo pipefail with a stand-in driver and qpy. 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.
  • ruff: no new findings vs origin/dev (compared by rule and message). ty: no new diagnostics vs origin/dev. shellcheck on hallu-zarr.sh: clean.

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1563

Version: 0.10.10-PR1563.c742654
Commit: c742654


🤖 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).
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review record

One Sonnet 5.5 review pass. No critical findings. Verified by the reviewer: chunk-name derivation is correct (key.partition("--") is safe, annex_chunk_key reproduces git-annex's <backend>-s<size>[-m<mtime>]-S<chunk>-C<n>--<name>, MD5E and extension-less keys work, exact-name matching with fullmatch and re.escape never mixes a different key that shares a prefix); the arithmetic is right (n = max(1, ceil(size/S)), last-chunk size, exact multiples, zero size); the 404 detection matches the real aws text ((404) HeadObject, NoSuchKey, Not Found) and does not fire on a dropped connection that quotes a hex key containing "404", nor on a 403; the new code is registered wherever codes must be (_FALLBACK_REASONS, the schema code description, convert_one's generic handler, correctly absent from RETRYABLE_CODES); every failure path in _download_chunks cleans up; the cache is per worker process and dataset and falls back to a listing when chunk 1 is absent; the stand-in aws is a real subprocess over real files, so it complies with the no-mocks rule.

# Finding Resolution
1 (important) annex_object_missing is permanent by default: if every recording fails with it (S3 or GitHub metadata lagging during an import) the dataset ends terminal data_failed Per recording nothing changes: still a typed entry under failures, not in RETRYABLE_CODES, so partial datasets still serve. At dataset level a new dataset_failure_is_deterministic treats annex_object_missing as storage state (STORAGE_STATE_CODES): a dataset whose failures are all of that code is retried with the normal queue backoff (5 attempts, 1800 s base) and ends failed, not data_failed; missing objects plus a genuine typed data failure stay deterministic; partial success still publishes. The callbacks carry annex_missing_count, annex_missing_first_path and annex_missing_first_key (backend schema is passthrough); the queue message now says the storage lacks the annex objects, names the first key, and gives the remedy (fix the upload, then hallu-zarr.sh --dataset <id> --requeue failed --execute); the storage-specific text is gated on no producer error so a refused index write is never blamed on storage. Real tests: the pure rule, main() end to end over real EDFs (all missing, missing plus a truncated EDF, partial success), and 6 shell tests running the real convert_dataset and record_conversion_failure
2 (important) No test or documentation for the 403 case (no ListBucket) A 403 on the plain key is retried and ends uncoded, never annex_object_missing, and the chunk fallback is not attempted (tests assert zero listings); a listing refused with AccessDenied is retried and ends uncoded. The profile comment in hallu-zarr.sh now states that s3:GetObject on <id>/objects/* and s3:ListBucket for those prefixes are required, and that without ListBucket a missing plain key returns 403 so the chunked fallback silently never runs (safe, but the feature does not work)
3 A wrong-size chunk under a cached chunk size failed the size check, retried 4 times and ended uncoded download_blob raises S3SizeMismatch (a RuntimeError subclass, so other callers are unchanged); under a cached size fetch_annex_object falls through to the listing, which types a wrong-size chunk as annex_object_missing and fetches again when the stored chunk is right and only the transfer was short; both paths tested, and both tests fail with the fix removed
4 No resume for a failed multi-chunk download Documented in the docstring: about 94 sequential aws s3 cp calls, about 17 minutes at 100 MB/s, 1800 s cap per call, scratch peaks at file plus one chunk; resume left for a later change
5 annex_key_size used an unanchored re.search(r"-s(\d+)") Anchored to the fields part (key.partition("--")[0]); tested with WORM and URL keys containing -s5
6 The post-assembly got != size check is unreachable and raised a false permanent verdict Now an uncoded RuntimeError
7 backend/src/services/data-router.ts still builds plain object URLs Filed as #1565 (chunked datasets' data-plane and manifest links 404; no regression, since they were never downloadable); not touched here

Verification: five named suites 973 passed, 5 skipped with biosigio 1.2.10 from PyPI; test_hallu_zarr_config.py 57 passed locally including the 6 new tests (the other 74 need bash 4+ and run in Linux CI); bun test zarr mcp 879 at the root; ruff and ty no new findings vs origin/dev; shellcheck clean.

@neuromechanist
neuromechanist merged commit 5cbe1fe into dev Sep 29, 2026
12 checks passed
@neuromechanist
neuromechanist deleted the feat/zarr-chunked-annex-fetch branch September 29, 2026 20:12
neuromechanist added a commit that referenced this pull request Sep 29, 2026
The chunked annex fetch and the EEGLAB header count shipped in 0.10.10
but were missing from its entry; adds them under Fixed and the Hallu
ListBucket and requeue notes under Deploy coupling. Format test passes.

This branch was previously deployed

1 inactive deployment
npm — c7426541 Deployed Sep 29, 2026 by neuromechanist via publish #2994
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