Skip to content

Phase 1: Server-side, resumable, sharded import transfer - #757

Merged
neuromechanist merged 2 commits into
feature/issue-749-epic-import-robustnessfrom
feature/issue-750-phase1-transfer
Jun 16, 2026
Merged

neuromechanist merged 2 commits into
feature/issue-749-epic-import-robustnessfrom
feature/issue-750-phase1-transfer

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Replaces the OpenNeuro->NEMAR data-transfer mechanics so large imports complete unattended:

  • Server-side S3 copy (aws s3 cp s3://openneuro.org/... s3://nemar/..., cross-account + cross-region) so bytes never transit the GitHub runner. Verified end-to-end (real cross-region copy, ETag match). This killed the 9 TB ds004395 import at the 6h runner cap.
  • Resume: a re-run lists the destination and skips already-copied objects.
  • Sharding: one dataset's transfer fans out across N matrix jobs to beat the 6h cap.

Changes

  • src/lib/s3-server-copy.ts (new): parseS3Url, serverSideS3Copy (+ curl fallback), batchServerSideCopy (bounded retry, no mid-stream exit), listExistingObjects, filterAlreadyCopied, parseShardArg/keyInShard, S3 manifest staging.
  • src/lib/import-openneuro.ts: split importOpenNeuro into prepareImport / copyShard / finalizeImport + a thin single-process driver (unchanged --local). State passes via S3 staging; the nemar-s3 UUID is reused on the finalize re-clone (configureS3Remote init->enable).
  • src/commands/admin.ts: --phase prepare|copy|finalize and --shard i/N.
  • .github/dataset-workflows/onboard-openneuro.yml: prepare -> copy (matrix shard, 350m, max-parallel 20) -> finalize; per-dataset isolation via if: !cancelled() + finalize re-list verification.

Test plan

  • Pure unit (test/s3-server-copy.test.ts, 18): URL parsing, shard partition, resume filter.
  • Real integration (test/import-openneuro-s3-copy.integration.test.ts): actual cross-region server-side copy into xx000001 sandbox + resume-skip + cleanup. Self-skips without AWS env creds; verified passing against live S3 locally.
  • Workflow structure (test/onboard-workflow.test.ts).
  • tsc + biome clean; import-openneuro.test.ts 38/38.

Notes

  • Integration test needs AWS creds (not TEST_API_URL), so it isn't auto-routed by the tiering grep; wiring it into integration-dev with AWS_* env is a small follow-up (self-skips safely meanwhile).
  • This workflow's source-of-truth is in-repo; confirm/sync the nemarDatasets/.github copy at rollout.

Closes #750
Part of epic #749

Replace the curl|aws-s3-cp client-stream (every byte through the
runner, blew the 6h cap on 9TB ds004395) with server-side
s3://openneuro.org -> s3://nemar copies, plus resume (skip
already-present objects) and key-sharding across matrix jobs.

- new src/lib/s3-server-copy.ts: parseS3Url, serverSideS3Copy (+curl
  fallback), batchServerSideCopy (bounded retry), listExistingObjects,
  filterAlreadyCopied (resume), keyInShard, S3 manifest staging.
- import-openneuro.ts: split importOpenNeuro into prepareImport /
  copyShard / finalizeImport (state via S3 staging across jobs; uuid
  reused on the finalize re-clone); single-process driver unchanged.
- admin.ts: --phase prepare|copy|finalize and --shard i/N.
- onboard-openneuro.yml: prepare -> copy(matrix shard, 350m,
  max-parallel) -> finalize, per-dataset isolation via !cancelled() +
  finalize re-list verification.
- tests: pure unit (parse/shard/resume) + real cross-region copy
  integration (self-skips without AWS creds) + workflow structure.

Part of #749. Closes #750.
- curlStreamCopy: set -o pipefail so a curl failure can't upload a
  0-byte object and exit 0 (false success).
- listExistingObjects: guard against a truncated page (auto-pagination
  disabled) -> throw instead of a silent partial destination view.
- finalize: assert finalize uuid == manifest.nemarUuid; make git-annex
  key-registration failures fatal (was non-fatal -> uncloneable blobs).
- getJson: descriptive error on corrupt/truncated staging JSON.
- cleanupStaging: warn on non-zero exit instead of swallowing.
- workflow: derive the copy shard list from env.SHARDS in parse-ids
  (single source of truth; removes SHARDS/matrix drift).
- tests: batchServerSideCopy real copied+failed[] paths, partial
  expectedSizes skip, workflow needs-graph wiring.

Addresses code-review + silent-failure + test-coverage findings on #757.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

/review-pr (3 Sonnet subagents: code-review, silent-failure-hunter, pr-test-analyzer)

All findings addressed in c51bfc6.

# Sev Finding Resolution
1 CRITICAL listExistingObjects could silently truncate at 1000 objects -> finalize verify passes on an incomplete dataset Verified aws s3api list-objects-v2 auto-paginates on CLI v2 (returned all 11,000 objects for on005752, IsTruncated: null). Added a loud guard: throw if IsTruncated/NextContinuationToken ever appears, so a disabled-auto-pagination env fails instead of proceeding on a partial view.
2 CRITICAL curlStreamCopy pipe without pipefail -> a curl 403 uploads a 0-byte object and exits 0 Added set -o pipefail. (Pre-existing bug carried from the old s3Copy.)
3 HIGH batchSetKeysPresent failures non-fatal -> publish a dataset with blobs unfindable by clones Now fatal in finalize (idempotent -> re-run retries).
4 HIGH finalize derives nemar-s3 uuid but never checks it matches prepare's Added nemarUuid === manifest.nemarUuid assertion before registration.
5 HIGH getJson JSON.parse with no context on corrupt/truncated staging Wrapped with a descriptive error (URI + cause).
6 MED filterAlreadyCopied expectedSizes dormant Documented; the pipefail + atomic server-side copy remove the 0-byte-partial risk it guarded.
7 MED SHARDS env vs hardcoded matrix list can drift parse-ids now emits the shard list from env.SHARDS (single source of truth).
8 MED cleanupStaging swallows all errors Warns on non-zero exit.

Tests added: batchServerSideCopy real copied + failed[] accumulation (verified live vs S3), filterAlreadyCopied partial-expectedSizes skip, workflow needs: graph wiring. tsc + biome clean; 61 unit pass.

No findings skipped.

@github-actions

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR757

Version: 0.8.53-PR757.c51bfc6
Commit: c51bfc6


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit afb8b33 into feature/issue-749-epic-import-robustness Jun 16, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-750-phase1-transfer branch June 16, 2026 00:07

This branch was previously deployed

1 inactive deployment
npm — c51bfc6e Deployed Jun 15, 2026 by neuromechanist via publish #1397
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