Repository navigation
Plain-HTTP download fallback for nemar dataset download - #1402
Conversation
The HTTP download path has no git-annex to hand --include/--exclude to, so the same selection is now also returned as glob groups with a matchesBidsFilter predicate. One declaration, two consumers: a second matcher would drift, and the symptom would be --subjects returning different files depending on whether git-annex happened to be installed. The args are unchanged; the git-annex path is untouched.
Reads the data plane's manifest (one request: every path, size, checksum and byte URL) and fetches a selection with a bounded worker pool. No git, no git-annex, no GitHub account. Resume is inherent: a file present at its declared size is skipped, so re-running picks up where an interrupted transfer stopped and widening a filter only fetches what is new. A failure is collected rather than thrown, so one 403 does not lose a long transfer. Addressed through the configured API origin's /data mount rather than data.nemar.org, because that mount exists in every environment, keeping environment selection in one place.
A missing git-annex was a hard exit. It now falls back to the HTTP path, announced rather than silent, and --http asks for it outright. --update and --prune are refused there rather than silently doing nothing: they reconcile a clone against its remote and there is no clone.
The unit suite cannot cover the field names of the data plane's manifest.json, and a rename on either side turns into "downloaded 0 files" with no error. These run the real command against the staging exemplar fleet and check what landed on disk.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1402Version: 🤖 Updated on each push. |
A dataset that has ever been public cannot be made anonymous: the DataCite record is harvested and permanent, the git history is in every clone, and the catalog has already served the real authors. Hiding the fields afterwards changes what NEMAR displays and nothing about what is known, while telling the depositor they are anonymous. Also records the blocker the download work surfaced: 88 percent of a dataset's files are served from raw.githubusercontent.com, so a private repository 404s all the metadata while the recordings download fine (#1403), and notes that the HTTP download path (#1402) now exists.
Review: two independent passes (code quality, silent failures)Both found the same three things independently, which is the strongest signal in here. Fixes are Critical1. A short or wrong body is reported as a complete file. 2. Resume-by-size silently mixes dataset versions. 3. Important
Suggestions
Held up under scrutinyThe worker pool is correct — |
Critical: Bun.write returns the true byte count and does not throw on a short body, so returning the manifest's declared size reported a truncated response or a captive portal's login page as a complete file. Every write is now compared against the declared size, and a mismatch is removed rather than left looking healthy. --http no longer requires the GitHub CLI. checkPrerequisitesForCommand demands `gh` and ran before the branch, so the path whose point is "no git, no git-annex, no GitHub account" died on exactly the containers and login nodes it was built for. Resume no longer mixes versions: the output directory carries a stamp, and a git repository, a different dataset, or a different version is refused. dataset_description.json is byte-identical in length across a patch bump, so it was being skipped and the tree misreported its own version. Transport, auth and disk faults now exit non-zero without --require-complete; a clean 404 stays a reported state per ADR 0005. Throttled and transient responses retry with backoff. Every error names its file and the full list is written to the output directory. The manifest is validated against a shared contract schema rather than cast, and a manifest with no git-tracked entries is refused instead of silently dropping every sidecar. Non-JSON and malformed documents surface as typed errors; a missing manifest no longer reports a public dataset as private. Globs are compiled once per filter, -j is validated, and the two comments that overclaimed now say what is actually true.
Two ADR citations named the wrong decision: 0010 is import-time S3 copy, not the Worker (that is 0002); 0017 is server-side visibility filtering, not the publish flip (that is 0001). The manifest canary is not a blocker either -- production runs the central workflow, passes skipCanary unconditionally, and that workflow has an escape hatch labelled for private repos and clones with an App token. A4 stays first, for a different reason. Also: .nemar/metadata.json is committed by the backend, not the depositor, so no depositor-side scrub can suppress it; the website has two URL-fabrication sites, so nulling the field hides neither; #1402 is proposed, not merged; owner_github is "nemarAdmin" rather than null, and the imported git history names real people; ids gap-fill rather than run sequentially. Adds what the document missed: two more visibility proxies (fleet drift, MCP events), the governance gap an unprotected main leaves open for the whole review window, the website's browser-side GitHub fetches, enrichment_json and readme on the withhold list, and the ordering constraint on de-anonymization.
The plain-HTTP dataset path and the OpenNeuro S3 fallback each carried their own worker pool. Extract lib/file-download.ts and have both call it, so the pool, resume, retries, path-traversal guard and the transport-versus-404 split are stated once. OpenNeuro gains what only the newer copy had: writes verified against the declared size (Bun.write returns a short count without throwing, so a truncated body landed as a healthy file), retries with backoff, and errors that name the file. Its result shape is unchanged; a skipped file still counts as downloaded there.
Records what this path decided: a missing git-annex degrades to a snapshot rather than exiting, the snapshot is deliberately not a repository, resume is size-only with the version stamp closing the hazard checksums would, bytes come from the durable bytes_url, and a transport fault fails the run while a clean 404 does not. Also resolves conflict markers that were committed into AGENTS.md on dev; the ADR list entry is 0060, not 0058.
* docs: analyze pseudonymous deposit for double-blind review Works out the five requirements, the twelve-item leak inventory verified against production, and what each candidate design requires. No decision taken; the ADR has to answer the collisions with ADR 0002, 0026 and 0041 first. Refs #1399. * docs: choose public data with a private repository Direction taken: serve the dataset on data.nemar.org and the website as any public dataset, keep the GitHub repository private, and flag the page as temporarily anonymous. That removes the tokenized review link entirely, since with no per-reviewer access mechanism there is nothing to conceal in the other direction. Also corrects the staleness claim: since #662 the cron warns the owner and hands off to admins, it does not delete. The hazard is five deletion warnings mid-review, not data loss. Records the three predicates the new shape creates: the website's fabricated clone URL, the CLI download path that clones a private repo, and the two candidate queries that use D1 visibility as a proxy for repository visibility. Refs nemarOrg/website#333, #1399. * docs: anonymity is only available before first publication A dataset that has ever been public cannot be made anonymous: the DataCite record is harvested and permanent, the git history is in every clone, and the catalog has already served the real authors. Hiding the fields afterwards changes what NEMAR displays and nothing about what is known, while telling the depositor they are anonymous. Also records the blocker the download work surfaced: 88 percent of a dataset's files are served from raw.githubusercontent.com, so a private repository 404s all the metadata while the recordings download fine (#1403), and notes that the HTTP download path (#1402) now exists. * docs: nm000103-107 are public, not private * docs: the data plane should keep its own URL * docs: correct the errors the fact-check found Two ADR citations named the wrong decision: 0010 is import-time S3 copy, not the Worker (that is 0002); 0017 is server-side visibility filtering, not the publish flip (that is 0001). The manifest canary is not a blocker either -- production runs the central workflow, passes skipCanary unconditionally, and that workflow has an escape hatch labelled for private repos and clones with an App token. A4 stays first, for a different reason. Also: .nemar/metadata.json is committed by the backend, not the depositor, so no depositor-side scrub can suppress it; the website has two URL-fabrication sites, so nulling the field hides neither; #1402 is proposed, not merged; owner_github is "nemarAdmin" rather than null, and the imported git history names real people; ids gap-fill rather than run sequentially. Adds what the document missed: two more visibility proxies (fleet drift, MCP events), the governance gap an unprotected main leaves open for the whole review window, the website's browser-side GitHub fetches, enrichment_json and readme on the withhold list, and the ordering constraint on de-anonymization.
|
Second round of review follow-ups, closing the two findings that were flagged and deferred. One downloader, not two. The worker pool duplicated The copy had already drifted, which is the argument for extracting it. The OpenNeuro path was discarding ADR 0062 records what this path decided: a missing git-annex degrades to a snapshot rather than exiting, the snapshot is deliberately not a repository, resume is size-only with the version stamp closing the hazard checksums would otherwise cover, bytes come from the durable Also in this push: |
The pool reports only what it transferred, which made a resumed OpenNeuro download print '1200 files (0 B)'. It now also reports the declared size of the files it skipped, so that caller can keep stating what is on disk.
The shared pool clamps concurrency to MAX_CONCURRENCY. The NEMAR HTTP path already says so when --jobs exceeds it; the OpenNeuro path did not, so -j 32 silently became 16.
…fallback # Conflicts: # src/commands/dataset.ts
Closes #1401.
nemar dataset downloadexited hard when git-annex was missing. It now falls back to a plainHTTP download, and
--httpasks for it outright.How it works
One request to
<api>/data/<id>/<version>/manifest.jsonreturns every file's path, size,checksum and byte URL; a bounded worker pool (
-j, default 4) fetches the selection. No git, nogit-annex, no GitHub account.
The data plane is addressed as the configured API origin plus
/data, notdata.nemar.org,because that mount exists in every environment while the pretty hostname does not. Environment
selection stays in one place: whichever API the CLI is already pointed at.
The decisions worth reviewing
One filter declaration, two consumers.
buildBidsFilterArgsnow also returns the selectionas glob groups, with a
matchesBidsFilterpredicate. Writing a second matcher for the HTTP pathwould have been easier and wrong: the two would drift, and the symptom is
--subjects sub-01returning different files depending on whether git-annex happened to be installed, which is
close to undebuggable from a bug report. The emitted
argsare unchanged and the git-annex pathis untouched; a table test pins every glob shape the builder emits against the matcher.
Metadata is never filtered out. A subject-scoped download that dropped
dataset_description.jsonand the sidecars would not be a readable BIDS dataset. The git-annexpath gets this for free because those files ride along in the clone; here it is explicit. The
manifest's
checksum_algorithm: "git"is what identifies them, which is a reading of the annexpolicy (ADR 0015) rather than a guess from the file extension — the extension is not reliable in
either direction (ADR 0031:
_motion.tsvis data). The same field is what makes--no-datahonest.
Resume needs no flag. A file present at its declared size is skipped. That makes an
interrupted transfer resumable by re-running the command, and makes widening a filter cheap. A
file present at the wrong size is refetched, which is the half-written file an interruption
leaves behind; skipping it would quietly hand back a truncated dataset.
Failures are collected, not thrown. A dataset with thousands of files should not lose a
two-hour transfer to one 403.
--require-completestill exits non-zero.--updateand--pruneare refused, not ignored. They reconcile a clone against its remoteand there is no clone; silently doing nothing would look like success and leave stale files.
No external tool. rclone and
aws s3 syncwere both considered and declined: the URLs hereare plain HTTPS rather than the S3 API, so
aws s3 synccannot use them at all, and rclonewould add a runtime dependency most users do not have to replace 60 lines of worker pool
(ADR 0037).
Tests
test/http-download.unit.test.ts, 20 cases, offline — the pool runs against a localBun.serveorigin rather than a stubbed
fetch, so the real request, the real stream-to-disk and the realresume decision are what is under test. Covers selection, the filter correspondence table,
resume, truncated-file refetch, partial failure, path traversal, and that concurrency is
actually bounded.
test/http-download-live.test.ts, 4 cases, live tier — walks the staging exemplar fleet(
xx099900, 16 MB, persistent by construction) end to end. This exists because the unit suitecannot cover the field names in the data plane's
manifest.json: that document is produced bythe backend and read here by name, and a rename on either side turns into "downloaded 0 files"
with no error. The file-count assertion is what catches that.
Also verified by hand against production
on008701(3,201 files): metadata-only lands 2,802files and a valid BIDS root;
--subjects sub-01then adds 20 data files and skips the 2,802already present.
Note for the anonymous-deposit work
This is the download half of what
nemarOrg/website#333needs, but it is not sufficient on itsown: 2,802 of
on008701's 3,201 manifest entries point atraw.githubusercontent.com, so witha private repository the metadata would 404 while the recordings downloaded fine. That is filed
separately.
Recorded as ADR 0062
The decisions above that outlive this PR are written down: a missing git-annex degrades to a
snapshot rather than exiting, the snapshot is deliberately not a repository, resume is size-only
(the version stamp closes the hazard a checksum would), bytes come from the durable
bytes_url,and a transport fault fails the run while a clean 404 does not.
The transfer itself is shared, not copied:
src/lib/file-download.tsholds the bounded pool,resume, retries, the path-traversal guard and the transport-versus-404 split, and both this path
and the OpenNeuro S3 fallback call it. That extraction fixed a live bug in the older copy, which
had been discarding
Bun.write's return value and so landing truncated files as healthy ones.