Skip to content

Phase 2: Version-DOI publish that can't time out (#751) - #758

Merged
neuromechanist merged 2 commits into
feature/issue-749-epic-import-robustnessfrom
feature/issue-751-phase2-version-doi
Jun 16, 2026
Merged

neuromechanist merged 2 commits into
feature/issue-749-epic-import-robustnessfrom
feature/issue-751-phase2-version-doi

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Restructures the EZID version-DOI publish so it can no longer hit the deterministic 60s curl timeout that blocked high-file-count OpenNeuro imports (on005385 3265 files, on005752 11000 files; the wall is file count, not bytes).

/webhooks/publish-version-doi now (under the central manifest flow) validates cheaply, creates an accepted manifest_jobs row, returns 202, and runs the heavy residual (cheap metadata read + idempotent EZID mint + central manifest dispatch + Zenodo) off the request path via waitUntil. The CI workflow polls GET /webhooks/version-doi-status until ready/failed instead of holding a 60s synchronous curl.

Gated on MANIFEST_VIA_CENTRAL_WORKFLOW: dev (true) exercises the new async path now; prod (false) keeps today's exact legacy synchronous path until a separate, gated flip (held per the epic's rollout plan).

Changes

  • Cheapen metadata read to O(1) Contents API (readRepoMetadata useContentsApi), replacing the recursive getTreeAtRef whole-tree fetch. Opt-in, so other callers are byte-identical.
  • Reuse manifest_jobs as the publish state machine: accepted -> dispatched -> ready|failed. /webhooks/manifest-ready stays the single owner of the dataset_versions insert (its contract is unchanged). Migration 0042 adds request_source + widens the status enum (no DDL on the plain-TEXT status column).
  • New GET /webhooks/version-doi-status for the CI poller (same token auth).
  • Converge the admin orchestrator version_doi step onto the same mint + dispatch (no inline generateManifest / dataset_versions insert under central flow) so there is one idempotent owner.
  • Move Zenodo backup off the request path; skip for OpenNeuro (on-prefix), which is O(bytes) and handled by Phase 3's archive policy.

Companion (cross-repo)

  • nemarDatasets/.github PR: run-version-doi.yml "Publish version DOI" step rewritten to enqueue (202 central / 200 legacy) then poll. Merge after the Worker is live on prod (the poll endpoint must exist first).

Not in this PR (gated)

  • Flip prod MANIFEST_VIA_CENTRAL_WORKFLOW="true" and re-drive on005385/on005752 — held for explicit go (would change publish behavior for all prod datasets; requires MANIFEST_CALLBACK_SECRET verified on prod).

Closes #751
Part of epic #749

Test plan

  • bun test (backend): 235 pass + 13 new (migration/lifecycle SQL, status SELECT, idempotency + poll-decision pure functions). No mocks.
  • tsc --noEmit clean; biome check clean on changed files.
  • Dev smoke (next): publish a small dev dataset end-to-end — POST 202, poll to ready, dataset_versions row appears, dev data plane manifest 200s.

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.
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.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

/review-pr summary (4 Sonnet agents: code-reviewer, silent-failure-hunter, pr-test-analyzer, type-design-analyzer)

Addressed in commit f433577:

CRITICAL — promote UPDATE didn't check meta.changes (code-reviewer + silent-failure-hunter, convergent). A 0-row promote (accepted row vanished/already promoted) still dispatched a manifest workflow whose manifest-ready callback could never find a dispatched row → poll-to-CI-timeout. Now throws on 0 rows → the residual's catch records failed. Also moved requestSource off the promote call (now redundant) and made the args a discriminated union (promoteNonce XOR requestSource) so the invalid combo is a compile error.

HIGH — waitUntil last-resort .catch() only logged. If the residual's own failed-mark UPDATE also threw, the row stayed non-terminal forever. The catch now attempts a final failed UPDATE (status != 'ready' guard).

HIGH — GET /version-doi-status D1 error was an unlogged 500. Now wrapped: logs + returns 503 so the CI log distinguishes "DB unavailable" from "no row yet". The unknown response also carries outcome:'wait' for shape consistency.

Tests — added version v-prefix normalization (criticality 8) and the admin request_source='admin' dispatched insert. 237 backend tests pass, tsc clean.

Types — added a ManifestJobStatus literal union for the pure decision functions.

Intentionally not changed (with rationale)

  • EzidVersionDoiDataset.ezid_identifier: string | null (type-design suggested non-null): kept nullable with the runtime throw in mintEzidVersionDoi. The throw is caught by the residual and recorded as failed — the desired observable outcome — whereas a non-null type would force narrowing casts across 3 call sites for no behavior gain.
  • Zenodo deposition-ID-loss on a D1 write failure (silent-failure-hunter, MEDIUM): pre-existing behavior, faithfully preserved by the maybeZenodoBackup extraction (legacy had the identical structure). Out of scope for this phase; non-fatal by design.
  • Pre-existing noNonNullAssertion warning at handleZenodoVersionDoi (published.doi!): present on the epic baseline, untouched by this PR.

@github-actions

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR758

Version: 0.8.53-PR758.f433577
Commit: f433577


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit d9b3072 into feature/issue-749-epic-import-robustness Jun 16, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-751-phase2-version-doi branch June 16, 2026 06:18

This branch was previously deployed

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