Skip to content

Phase 5: Import state machine + rollback/quarantine (#754) - #762

Merged
neuromechanist merged 2 commits into
feature/issue-749-epic-import-robustnessfrom
feature/issue-754-phase5-import-state
Jun 16, 2026
Merged

neuromechanist merged 2 commits into
feature/issue-749-epic-import-robustnessfrom
feature/issue-754-phase5-import-state

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

OpenNeuro imports were a fire-and-forget 3-job CI fan-out with no end-to-end state and no cleanup. on004395 (9TB) hit GitHub's 6h runner cap mid copy-shard and left a silent orphan: a private D1 row + empty repo + 3.86 TB of partial S3 objects. This adds a per-dataset state machine so an import can never leave a silent orphan.

  • import_jobs table (migration 0044): one sticky row per dataset_id, lifecycle preparing|copying|finalizing|complete|failed|quarantined|rolled_back. Separate table (not columns on the FTS-backed datasets) so it outlives the datasets row and a rolled_back orphan stays auditable.
  • Seeded server-side at /admin/datasets/import (guaranteed the moment the dataset exists). onboard-openneuro.yml POSTs transitions to a new bearer-authed /webhooks/import-state (monotonic sticky upsert; a preparing POST resets a terminal row so re-import after rollback self-heals).
  • Terminal failure → recovery: runImportRecovery quarantines the orphan + emails admins by default; auto-rollback (via deleteDatasetCascade) is gated behind IMPORT_AUTO_ROLLBACK (default OFF), mirroring the fix(cron): warn owners before stale-nm deletion, never auto-delete (#662) #663 stale-cron remediation. The pure decideImportRecovery guard auto-deletes only the unambiguous orphan (private + no DOI + no versions + never completed + not system-owned).
  • Detectors: an always() report job (cross-repo) catches the cancellation case the per-job success steps can't; a 6h scheduled-sweep block is the loss/whole-cancel backstop.
  • Admin surface: GET /admin/imports + nemar admin import status/rollback/retry.

Cross-repo workflow: nemarDatasets/.github# (also lands the deferred Phase-1 sharded-import sync — see that PR).

Closes #754
Part of epic #749

Test plan

  • bun test (279 pass; new no-mock tests: migration shape, the monotonic/sticky upsert + preparing-reset SQL, the decideImportRecovery safety guard — every branch); tsc + biome clean.
  • Gated live (after merge): re-dispatch a small import → import_jobs walks preparing→copying→finalizing→complete; force a failure / sweep → failed→quarantined + admin email; nemar admin import status shows it; rollback cleans it. No prod auto-deletion (flag off).

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).
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.
@github-actions

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR762

Version: 0.8.53-PR762.13323e1
Commit: 13323e1


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit 28a8097 into feature/issue-749-epic-import-robustness Jun 16, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-754-phase5-import-state branch June 16, 2026 22:46

This branch was previously deployed

1 inactive deployment
npm — 13323e16 Deployed Jun 16, 2026 by neuromechanist via publish #1409
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