Repository navigation
Phase 5: Import state machine + rollback/quarantine (#754) - #762
Merged
neuromechanist merged 2 commits intoJun 16, 2026
Conversation
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.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR762Version: 🤖 Updated on each push. |
neuromechanist
merged commit Jun 16, 2026
28a8097
into
feature/issue-749-epic-import-robustness
1 check passed
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
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_jobstable (migration 0044): one sticky row per dataset_id, lifecyclepreparing|copying|finalizing|complete|failed|quarantined|rolled_back. Separate table (not columns on the FTS-backeddatasets) so it outlives the datasets row and arolled_backorphan stays auditable./admin/datasets/import(guaranteed the moment the dataset exists).onboard-openneuro.ymlPOSTs transitions to a new bearer-authed/webhooks/import-state(monotonic sticky upsert; apreparingPOST resets a terminal row so re-import after rollback self-heals).runImportRecoveryquarantines the orphan + emails admins by default; auto-rollback (viadeleteDatasetCascade) is gated behindIMPORT_AUTO_ROLLBACK(default OFF), mirroring the fix(cron): warn owners before stale-nm deletion, never auto-delete (#662) #663 stale-cron remediation. The puredecideImportRecoveryguard auto-deletes only the unambiguous orphan (private + no DOI + no versions + never completed + not system-owned).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.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, thedecideImportRecoverysafety guard — every branch);tsc+biomeclean.import_jobswalks preparing→copying→finalizing→complete; force a failure / sweep → failed→quarantined + admin email;nemar admin import statusshows it;rollbackcleans it. No prod auto-deletion (flag off).