Repository navigation
Cross-invocation retry for approve, drop subrequest blowout - #383
Conversation
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
… 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.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR383Version: 🤖 Updated on each push. |
/review-pr findings + responsesRan Addressed (cbc282d)code-reviewer #1 (important): silent-failure-hunter #2 (high): Final-failure context loss. silent-failure-hunter #3 (medium): Duplicated pr-test-analyzer #1 (criticality 9): Classifier needs unit tests. Discussed but not changedsilent-failure-hunter #6 (claimed CRITICAL): D1 UPDATE failure in code-reviewer #2 (important): repo_public budget verification. comment-analyzer: All 6 added comments verified accurate against the code ( Test results
|
Closes #382 (follow-up to #340 / #369).
Summary
PR #369 made the publish orchestrator retry transient failures inside a single Worker invocation. That fixed some GitHub propagation 5xx, but introduced three new failure modes:
s3_lockblew the CF subrequest limit. EachapplyObjectLockbatch fires ~40 S3 PUTs + listObjectKeys pagination. The 3-attempt inline retry tripled that and reliably hit "Too many subrequests by single Worker invocation" — every re-run failed identically.tag_protecthalted on "Repository has been locked". GitHub briefly locks a repo right after a visibility flip; 1s × 3 inline retries never outlasted the lock window.publish_doisaw a staleezid_identifier.doi_createupdated D1 but the in-memorydatasetsnapshot loaded at orchestrator start stayed null, sopublish_doiin the same invocation threw "No EZID identifier found".Original goal ("failures don't stop the process") was right; the implementation was wrong. Move retry across invocations, where each attempt gets a fresh subrequest budget and a real propagation window — exactly what an admin doing it by hand was already doing.
Changes
Backend (
backend/src/routes/admin.ts)withRetryons3_lockandtag_protect.s3_public_read,doi_create,create_tag,create_releasekeep their wrappers — their per-call subrequest cost is small and idempotent.dataset(concept_doi, doi_provider, ezid_identifier/ezid_status, zenodo_concept_id, is_sandbox) right afterdoi_createwrites to D1, so subsequent steps in the same invocation see fresh values.CLI (
src/lib/api.ts,src/commands/admin.ts)approvePublicationnow wraps the existing request loop in a 5-attempt × 10s retry gated on transient errors:repository has been lockeds3_lock_offsetis preserved across retries;useResumeflips totrueafter the first attempt so already-completed steps stay skipped.onRetrycallback surfaces[!] <step> failed: <err>andRetrying in 10s (attempt N/5)…through the CLI spinner.Test plan
tsc --noEmitclean (both root and backend)bun test test/publish-workflow.test.ts test/admin-restructure.test.ts test/doi-provider.test.ts— 119/119 passbun test— 789 pass, 36 skip, 3 fail. The 3 failures are the pre-existing unrelated ones from PR Retry transient/propagation failures in approve pipeline #369 (Test: broadcast email template asserts removed 'osc.earth' branding #366 broadcast-email, Test: 'dataset clone' for missing dataset prints to stderr, not stdout #367 dataset-clone-stderr, Test: 'admin revert --list' nonexistent dataset error not matched in output #368 admin-revert).nemar admin publish approve nm000131 -yagainst dev backend; verify retries fire on transient tag_protect / s3_lock and the pipeline completes without manual re-invocation.Out of scope
s3_public_read,doi_create,create_tag,create_release) keep their inlinewithRetry. CLI retry stacks on top — fine, since their cost is bounded.