Skip to content

Phase 3 (D): bounded auto-retry for failed archives - #743

Merged
neuromechanist merged 2 commits into
feature/issue-736-epic-publish-robustnessfrom
feature/issue-740-phase3-archive-retry
Jun 11, 2026
Merged

neuromechanist merged 2 commits into
feature/issue-736-epic-publish-robustnessfrom
feature/issue-740-phase3-archive-retry

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Phase 3 (D) of epic #736. Make failed archive generation self-healing. /webhooks/archive-ready recorded archive_status='failed' but nothing re-dispatched, so a failed archive sat failed until a human noticed (the nm000111 incident). Adds a bounded auto-retry via two mechanisms sharing one counter and cap:

  • Immediate (webhook): on a failed archive-ready callback, re-dispatch triggerArchiveGeneration right away while under the cap (fast self-heal during a publish).
  • Backstop (daily cron): archiveRetrySweep in the scheduled handler re-dispatches still-failed datasets whose last attempt is stale (>6h) — catching a chain that broke because a callback was lost.

archive_retry_count (migration 0040) counts retry dispatches and is incremented at the moment a retry is dispatched, so the webhook and sweep never double-count one attempt. Capped at MAX_ARCHIVE_RETRIES = 3 (kept small: a retry re-downloads every available annex blob before detecting a still-missing one, so each attempt is costly for large datasets) and reset to 0 on ready. No force flag needed — Phase 2 deletes the partial on failure.

Zarr is deliberately not auto-retried (per the Phase 3 decision): conversion is owned by the hourly Hallu cron (autodispatch is off), and many zarr failures are the mixed-rate EDF/BDF reader bug (#737) a re-dispatch wouldn't fix. The zarr-ready failed path still records zarr_status='failed' for dashboard visibility; a comment documents the intent so a future reader doesn't add a redispatch.

Closes #740
Part of epic #736

Files

  • backend/src/db/migrations/0040_dataset_archive_retry_count.sql — archive_retry_count INTEGER NOT NULL DEFAULT 0.
  • backend/src/services/archive-retry.ts (new) — decideArchiveRetry (pure), versionFromDoi (pure), ARCHIVE_RETRY_SWEEP_QUERY, archiveRetrySweep, MAX_ARCHIVE_RETRIES. Reuses triggerArchiveGeneration + getDatasetsToken.
  • backend/src/routes/webhooks.ts — archive-ready handler: reset count on ready; on failed, read count, decide, persist nextCount, and re-dispatch under the cap (best-effort, never 500s the callback). Zarr-ready comment.
  • backend/src/index.ts — ctx.waitUntil(archiveRetrySweep(env)) in the daily scheduled handler.

Test plan

bun test backend/test/archive-retry.test.ts — 12 tests, real in-memory SQLite (all migrations applied), no mocks:

  • decideArchiveRetry: ready resets; failed+no-version no-retry (count untouched); failed under cap retries+increments; failed at/above cap gives up; a full failure chain converges to exactly MAX_ARCHIVE_RETRIES dispatches then stops.
  • versionFromDoi: version DOI -> bare version; concept/malformed/empty -> null.
  • migration 0040: archive_retry_count defaults 0; ready-callback UPDATE resets to 0.
  • ARCHIVE_RETRY_SWEEP_QUERY: selects failed+versioned+under-cap+stale (and NULL-checked) rows; excludes ready, no-version, at-cap, and recently-checked rows.

Typecheck (tsc --noEmit) clean; Biome clean; migration-chain tests (archive-status, access-requests) still green with 0040 applied.

Deferred to epic finalization: the live archive-ready -> retry -> GitHub dispatch and the cron sweep exercise when the epic deploys to dev/prod (auto-deploy + d1 migrations apply). Deploying unmerged phase code to the shared dev Worker now would be disruptive; the glue over the unit-tested logic is thin.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Sonnet /review-pr addressed:

  • Issue 2 (Important): fixed — the re-dispatch now uses c.executionCtx.waitUntil (consistent with the other post-write side-effects in this file) so a slow GitHub /dispatches call can't delay or time out the workflow's archive-ready callback. The D1 state write still happens synchronously before the response.
  • Issue 3 (sub-threshold): documented — kept dispatch-then-update order (the inverse drops attempts on dispatch failure, which is worse) and added a comment noting the at-least-once, bounded semantics if the post-dispatch UPDATE throws.
  • Issue 1 (double-dispatch race): by design / accepted — the cap is a soft bound; the 6h archive_checked_at guard is the real deconflict and the realistic webhook path stamps immediately. Worst case is a few extra dispatches under a near-simultaneous webhook+cron race on the same dataset, not an unbounded loop.
  • Q4/Q6 (version regex, migration): confirmed sound. Pre-release DOIs aren't issued; versionFromDoi safely returns null (no retry) for any non X.Y.Z.

@github-actions

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR743

Version: 0.8.53-PR743.c65040b
Commit: c65040b


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit 51f8f16 into feature/issue-736-epic-publish-robustness Jun 11, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-740-phase3-archive-retry branch June 11, 2026 19:13

This branch was previously deployed

1 inactive deployment
npm — c65040b9 Deployed Jun 11, 2026 by neuromechanist via publish #1384
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