Repository navigation
Epic: Robust unattended OpenNeuro → NEMAR import (#749) - #765
Merged
Merged
Conversation
* feat: server-side sharded import transfer 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. * fix: address Phase 1 review findings - 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.
* version-doi: async 202+poll publish that can't time out (#751) Restructure /webhooks/publish-version-doi (EZID) into a fast 202 + async residual (waitUntil) + poll-for-completion, gated on MANIFEST_VIA_CENTRAL_WORKFLOW so prod keeps the legacy synchronous path until the flip. Kills the deterministic 60s curl timeout for high-file-count datasets (file-count-bound, not bytes). - Cheapen metadata read to O(1) Contents API (readRepoMetadata useContentsApi), replacing the recursive getTreeAtRef whole-tree fetch. - Reuse manifest_jobs as the publish state machine: accepted -> dispatched -> ready|failed; manifest-ready stays the single owner of the dataset_versions insert. Migration 0042 adds request_source + widens the status enum. - New GET /webhooks/version-doi-status for the CI poller. - Converge the admin orchestrator version_doi step onto the same mint+dispatch (no inline generateManifest / dataset_versions insert under central flow). - Move Zenodo backup off the request path; skip for OpenNeuro (on-prefix). - Tests (no mocks): migration + lifecycle SQL, status SELECT, idempotency + poll-decision pure functions. * version-doi: address PR review (state-machine + observability) From the 4-agent /review-pr pass: - Promote UPDATE now checks meta.changes; throw on 0 rows so a vanished/already- promoted accepted row is recorded as failed instead of dispatching a workflow whose callback can never complete (CRITICAL). - waitUntil last-resort .catch() now attempts a terminal failed-mark (status != 'ready' guard) so a residual whose own failed-UPDATE threw can't leave the row stuck non-terminal (the poller would wait to its CI timeout). - GET /version-doi-status wraps the D1 read; logs + returns 503 so a DB outage is distinguishable from 'no row yet'; unknown response now carries outcome:'wait'. - dispatchCentralManifestJob args -> discriminated union (promoteNonce XOR requestSource); ManifestJobStatus literal union for the pure decision fns. - Tests: version v-prefix normalization + admin request_source='admin' dispatched insert.
…752) (#760) * archive: >100GB skip policy + skipped state (#752) Datasets over 100 GiB (or 200k files) skip the zip build that can't finish in run-generate-archive.yml's 60-min cap, and steer to the range-resumable per-file direct download. - Migration 0043: additive archive_skip_reason TEXT (no CHECK; avoids recreating the FTS-backed datasets table just to add a 'skipped' enum value). skipped = archive_skip_reason IS NOT NULL; archive_status stays NULL. - services/archive-policy.ts: ARCHIVE_MAX_BYTES/FILES + pure shouldSkipArchive. - /webhooks/archive-ready: accept status='skipped' + reason -> record reason, no auto-retry. - Landing payload (data-router/data.ts) exposes archive {status,size,skip_reason} so the website can render zip vs wget/curl recipe. - Admin archive-sweep: oversized + no-archive candidates marked skipped (from the cheap datasets.file_size/total_files) instead of 'absent'. - Tests (no mocks): shouldSkipArchive boundaries; migration 0043 + skipped-state SQL. * archive: address PR review (state cleanup + observability) From the 3-agent /review-pr pass: - archive-ready 'ready' (+ admin sweep ready) now clears archive_skip_reason so a size-reduced re-publish that builds a zip drops the stale direct-download recipe. - page-bundle.ts threads archive {status,size,skip_reason} into its landing payload (was always-null for the bundle endpoint). - archive-sweep D1 error now names the branch (ready vs skip/absent) so a dropped skip_reason write isn't masked as a 'ready' failure. - archive-ready 404 log includes status. - Tests: buildLandingPayload archive output (3 cases) + ready-clears-skip_reason.
) * prescreen: make S3 data check authoritative both ways (#753) The publication pre-screen falsely blocked annexed datasets as empty (on007523: 'binary data files not found'). decidePrescreenOutcome only let the Worker's authoritative S3 check ADD a block; it could never CLEAR a false data-shortage verdict when the blobs are actually in S3. Make it symmetric: when S3 confirms real objects, strip data-shortage reasons and, if that was the only reason to block, downgrade to pass; non-data reasons (README, Name, Authors) still block. Empty-prefix path unchanged. New no-mock decision tests. * prescreen: tighten review findings (#753) /review-pr (3 agents): (1) word-bound the data-shortage regex so a non-data block reason containing 'annex'/'storage'/'files' isn't silently stripped; drop bare 'storage' (only the synthetic s3Missing reason carries it, and that branch never strips). (2) Downgrade block->pass only when real data-shortage reasons were stripped -- never silently clear a reasonless or non-data block. (3) Log the S3 override (verdict + stripped reasons) so a downgrade is auditable. +3 tests.
* import: state machine + rollback/quarantine + admin view (#754) Per-dataset import_jobs state machine (migration 0044) as the single source of truth so an OpenNeuro import can never leave a silent orphan (cf on004395). Seeded server-side at /admin/datasets/import; onboard-openneuro.yml POSTs transitions to a new bearer-authed /webhooks/import-state (monotonic sticky upsert; preparing resets for re-import). On terminal failure runImportRecovery quarantines the orphan + emails admins by default, or auto-rolls-back via deleteDatasetCascade behind IMPORT_AUTO_ROLLBACK (off). A report job + a 6h scheduled sweep are the cancellation/loss backstops. Admin surface: GET /admin/imports + nemar admin import status/rollback/retry. Pure decision fn + upsert SQL covered by no-mock tests (279 pass). * import: address /review-pr (#754) 3-agent review: (1) by_status now a fleet-wide GROUP BY (was scoped to the ?status= filter -> misleading CLI summary); (2) rollback marks rolled_back only when deleteDatasetCascade fully succeeded (result.deleted) -- a partial cascade now quarantines so the orphan stays surfaced, both in runImportRecovery and the admin endpoint + CLI; (3) markImportStatus never throws out of recovery; (4) importReachedComplete is now a REAL guard from a published publication_request (was dead/always-false), blocking auto-delete of a published import independent of the sticky guard; (5) workflow_run_url on mid-flight callbacks + accurate sweep/cancel comments. +validateImportStateBody tests + rolled_back stickiness.
* enrichment: retry stale-SHA conflict on metadata commit (#755) Two concurrent enrichments (push-webhook run-enrichment.yml + in-process admin-reindex/import enrichDataset) both PUT .nemar/metadata.json to the same ref; the loser failed. The workflow client-push already rebase-retries, but the server-side createOrUpdateFile (Contents API) threw on the 409 stale-SHA with no retry. Wrap its GET-sha->PUT in a 3-attempt refetch loop, gated by a new pure isContentsApiShaConflict(status, body) (409, or 422 with a sha/does-not-match/ fast-forward message; mirrors isFastForwardConflict422). Last-writer-wins, no non-fast-forward failure; also closes the D1-ahead-of-repo divergence. No-mock detector test. * enrichment: tighten /review-pr findings (#755) (1) Narrow the 422 conflict regex: drop the bare 'sha' alternation (it over-matched unrelated 422s like 'Invalid sha for author' -> spurious retries); the 409 arm already covers the stale-blob conflict, and the real 422 phrases are 'does not match'/'not a fast forward'. (2) Add the unreachable-guard throw after the retry loop, matching commitFilesAsTree, so a future refactor can't silently return void. +tests for the no-over-match cases.
* prescreen: advisory, not a publication block (#756) The pre-screen flipped the request to status='blocked'+block_reason= prescreen_failed (a soft block admins overrode anyway) + emailed 'blocked' + opened a 'Block:' repo issue -- masking real blockers (BIDS also uses 'blocked'). Make it a non-blocking advisory: /webhooks/prescreen-result now records prescreen_status='concern' + prescreen_reasons (migration 0045), leaving status untouched; no block email. decidePrescreenOutcome's field renamed blocked->flagged (advisory, logic unchanged). Surfaced as a yellow 'Pre-screen advisory' in nemar dataset publish status + admin publish list. Re-request clears prescreen_reasons. +no-mock tests (status stays 'requested', one-shot, reset). 297 tests. * prescreen: address /review-pr (#756) (1) issue_url '' -> NULL (|| not ??) so the column isn't dirtied now the workflow sends empty. (2) warn on the one-shot no-op (duplicate callback). (3) de-stale the legacy prescreen_failed BLOCK_MESSAGE (no repo issue anymore). (4) log malformed prescreen_reasons; clear prescreen_reasons on the dispatch pending-set too; type the admin query's prescreen fields. +passed-branch (status-untouched + one-shot) and reasons-parse-guard tests.
Cross-phase finalization review: Phase 7 renamed decidePrescreenOutcome's return field blocked->flagged and updated backend/test/, but the older top-level test/prescreen-decision.test.ts (from #666, also covers validatePrescreenCallbackBody) still asserted .blocked. Rename to .flagged so the full epic->dev suite is green. (Values unchanged; flagged === old blocked.)
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR765Version: 🤖 Updated on each push. |
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes the OpenNeuro → NEMAR import pipeline robust and self-healing end-to-end, after the 2026-06-14 batch where 0/5 imports completed cleanly (each a distinct deterministic-timeout failure leaving orphaned state). Closes #749.
Phases completed (all squash-merged into this branch)
import_jobs) + quarantine/rollback on terminal failure + admin import-status view — no silent orphan.Migrations
0042 (manifest_jobs.request_source), 0043 (datasets.archive_skip_reason), 0044 (import_jobs), 0045 (publication_requests.prescreen_reasons) — all additive.
Cross-repo (held for the deployment pass)
nemarDatasets/.github: #50/#51/#52 merged; #53 (Phase 5 + deferred Phase-1 sharded-import sync), #54 (Phase 6), #55 (Phase 7) open/held.
Test plan