Repository navigation
Retry transient/propagation failures in approve pipeline - #369
Merged
Merged
Conversation
Closes #340 EZID DOI minting, GitHub ref reads, and tag-protection rule application all suffer from short propagation windows during the approval pipeline. These are not real failures, but they currently abort approval and force the admin to re-run the resume flow. - backend/src/services/github.ts: add githubFetchWithRetry (3 attempts, 1s delay). Retry 5xx/429/network always; retry 404 only when the caller knows the resource exists (just-written ref, blob from a resolved tree, ruleset endpoint after a repo flip). Wire into getTreeAtRef, getBlobContent, getMainBranchSha, getFileContent (no 404 retry; 404=null is intended), applyTagProtection. - backend/src/routes/admin.ts: wrap tag_protect step with withRetry. Wrap doi_create with withRetry, gated on provider==='ezid' because EZID IDs are deterministic and createEzidConceptDoi already handles 'already exists' by fetching the existing record. Zenodo's createDeposition is not idempotent and stays unwrapped. - backend/src/routes/admin.ts: widen isRetryable regex to also match EZID-style 'EZID HTTP error (503 ...)' messages, not just GitHub-style 'HTTP 503'. Without this, EZID 5xx propagation errors silently bypassed the retry path.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR369Version: 🤖 Updated on each push. |
Reviewer findings: - Regex match on '5xx anywhere in body' could mis-retry a 4xx whose body text happens to contain a 5xx code. - applyTagProtection swallowed terminal failures by returning false, so outer withRetry never saw them and the operator-facing error lost the status + body context. - doi_create did not plumb the retry attempt count to step telemetry. - Retry helper was untestable in isolation. Changes: - backend/src/services/retry.ts: extract withRetry + isRetryable into their own module. Add HttpError class with numeric .status. isRetryable classifies HttpError / Error.status numerically first; the message regex is now a fallback for legacy errors only and never overrides a 4xx that has been explicitly tagged. - backend/src/services/github.ts: read helpers (getTreeAtRef, getBlobContent, getFileContent, getMainBranchSha) and applyTagProtection throw HttpError with the response status. applyTagProtection now returns void and throws on terminal failure with status + body snippet, surfacing operator-actionable diagnostics. - backend/src/services/ezid.ts: ezidRequest throws HttpError on non-ANVL HTTP failures. EZID 5xx is now classified by status, not by string-matching 'EZID HTTP error (503 ...)'. - backend/src/routes/admin.ts: import withRetry from the new module, drop the in-file copy. tag_protect step no longer checks a boolean return — relies on throw. doi_create plumbs attempts to updateProgress. - test/retry.test.ts: 27 unit tests covering HttpError, status-tagged Error, network message classification, GitHub/EZID legacy regex fallback, dataset-id false-positive guard, retry control flow, and custom isRetryable. No mocks; pure functions only.
Contributor
Author
Review fix-up (commit d00136a)Addressed all critical and important findings from the multi-agent review. Fixed (critical/important):
Added (test gap):
Wired through:
Knowingly skipped (out of scope for #340):
Verified:
|
This was referenced Apr 27, 2026
neuromechanist
added a commit
that referenced
this pull request
Apr 28, 2026
Move the publish orchestrator's transient-failure retry from inside one Worker invocation to across invocations driven by the CLI. PR #369's inline withRetry on s3_lock made each call issue ~120 S3 PUTs in a single invocation and reliably tripped Cloudflare's per-invocation subrequest limit; on tag_protect the 1s x 3 inline delay never outlasted GitHub's "Repository has been locked" window. Backend (admin.ts): - Drop withRetry on s3_lock and tag_protect; surface 500 immediately - Sync the in-memory dataset after doi_create so publish_doi in the same invocation sees the freshly minted ezid_identifier instead of null ("No EZID identifier found" after a re-run) CLI (api.ts, commands/admin.ts): - approvePublication wraps the request loop in 5-attempt x 10s retry across fresh Worker invocations: each retry gets a fresh subrequest budget and a real propagation window. Retries are gated on transient errors (5xx/429, network, GitHub 403 "Repository has been locked"); CI 422, validation 400, auth 401/403, 404 surface immediately. - onRetry callback surfaces "[!] step failed... retrying in 10s (attempt N/5)" through the existing spinner. Closes #382
3 of 4 tasks
neuromechanist
added a commit
that referenced
this pull request
Apr 28, 2026
* fix(approve): cross-invocation retry, drop subrequest blowout Move the publish orchestrator's transient-failure retry from inside one Worker invocation to across invocations driven by the CLI. PR #369's inline withRetry on s3_lock made each call issue ~120 S3 PUTs in a single invocation and reliably tripped Cloudflare's per-invocation subrequest limit; on tag_protect the 1s x 3 inline delay never outlasted GitHub's "Repository has been locked" window. Backend (admin.ts): - Drop withRetry on s3_lock and tag_protect; surface 500 immediately - Sync the in-memory dataset after doi_create so publish_doi in the same invocation sees the freshly minted ezid_identifier instead of null ("No EZID identifier found" after a re-run) CLI (api.ts, commands/admin.ts): - approvePublication wraps the request loop in 5-attempt x 10s retry across fresh Worker invocations: each retry gets a fresh subrequest budget and a real propagation window. Retries are gated on transient errors (5xx/429, network, GitHub 403 "Repository has been locked"); CI 422, validation 400, auth 401/403, 404 surface immediately. - onRetry callback surfaces "[!] step failed... retrying in 10s (attempt N/5)" through the existing spinner. Closes #382 * fix(approve): wire step into ApiError, dedupe results, add classifier tests Address pr-review-toolkit findings on PR #383: - ApiError now carries an optional `step` field, populated by request() from the orchestrator's top-level `step` JSON field. Previously the onRetry callback read step from `details`, which is `undefined` for every orchestrator failure (details is only populated by the s3_lock partial-fail path), so the spinner always printed the literal "step" instead of the actual step name. - Dedupe accumulated step_results by step name on both success and final failure. Without this, a step that failed-then-succeeded across a retry boundary appears twice in the post-publication summary. - On final failure (after all 5 attempts exhausted), attach the per-attempt step timeline to the thrown error so the CLI handler can show "which step failed when, and how many attempts each took" instead of just the final 500 message. - Export isRetryablePublishError as a pure predicate and add 23 unit tests covering: 5xx/429/network retried, "Repository has been locked" 403 retried, plain 4xx/auth 403 not retried, non-ApiError inputs not retried, boundary checks at 499/600. No mocks, mirrors the test/retry.test.ts pattern.
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.
Closes #340
Summary
The approval pipeline aborts on transient propagation failures from GitHub (tag protection, ref/tree/blob reads after a write) and from EZID/DataCite (5xx during DOI minting). These are recoverable: a retry seconds later succeeds. Current behavior forces an admin to babysit each approval and re-run resume.
This PR adds retry at two layers:
1.
githubFetchWithRetryinbackend/src/services/github.tsInternal helper that retries 5xx/429/network always. Optionally retries 404 (
retryOn404: true) only where the caller knows the resource exists — i.e. propagation lag is the only plausible cause. Wired into:getTreeAtRef(ref + tree fetch) — propagation 404 retriedgetBlobContent— propagation 404 retried (blob SHA came from a tree we just resolved)getMainBranchSha— propagation 404 retriedgetFileContent— no 404 retry (404 is a valid 'file missing' signal returned asnull)applyTagProtection— propagation 404 retried (rulesets endpoint can briefly 404 right after a repo visibility flip)2. Step-level retry in
backend/src/routes/admin.tstag_protectwrapped withwithRetry.applyTagProtectionalready treats 422 (rule exists) as success, so retry is naturally idempotent.doi_createwrapped withwithRetry, gated onprovider === \"ezid\". EZID DOIs are deterministic (buildConceptIdentifieris a pure function ofdatasetId), andcreateEzidConceptDoialready handles 'already exists' by fetching the existing record — so retry is safe. Zenodo'screateDepositionis not idempotent (each call mints a fresh deposition); it stays unwrapped.isRetryableregex from `/(?:http|status)\s*(5\d\d|429)\b/i` to `/(?:http|status)[\s(](?:error\s\()?\s*(5\d\d|429)\b/i` so it also matches EZID-style "EZID HTTP error (503 ...)" messages, not just GitHub-style "HTTP 503". Without this, EZID 5xx propagation errors silently bypassed retry.Out of scope
BIDS validation CI failures still surface as 4xx and are not retried — they are real dataset problems that don't resolve with time, matching the issue's distinction.
Test plan
Pre-existing test failures filed as separate issues