Skip to content

feat(workflow): retry HTTP 5xx and fail loud in llm-enrichment.yml - #599

Merged
neuromechanist merged 2 commits into
devfrom
598-workflow-template-retry-http-5xx-and-fail-loud-on-persistent-enrichment-failure
May 23, 2026
Merged

neuromechanist merged 2 commits into
devfrom
598-workflow-template-retry-http-5xx-and-fail-loud-on-persistent-enrichment-failure

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Closes #598.

Problem

The per-dataset `.github/workflows/llm-enrichment.yml` swallowed every non-2xx response from `/webhooks/llm-enrich` as `::warning::LLM enrichment failed - this is non-blocking` and exited 0. So:

  • on004849 (during 2026-05-23 backfill) got `HTTP 500 {"details":"Failed to resolve ref 'main': HTTP 401"}`; workflow showed green; D1 `enrichment_json` stayed null; we only caught it by spot-checking.
  • This is unacceptable when we fan out across hundreds of OpenNeuro imports.

Fix (workflow template in `backend/src/services/github.ts`)

Replace the single-shot fire-and-forget with a 3-attempt linear-backoff retry loop:

  • 2xx: break, continue to commit step.
  • 4xx: terminal config error (bad NEMAR_WEBHOOK_TOKEN, missing dataset row, malformed payload). Exit 1 immediately.
  • 5xx / curl-level (HTTP_CODE=0): retry up to 3 times with 5s / 10s / 15s backoff.
  • After all retries exhausted with non-2xx: exit 1, mark the run red, leave a clear log line about the desync.

Pairs with #596 (Worker-side 401 self-heal) — together a one-off stale-App-token-401 is fully transparent to the user.

Rollout

This template is the source of truth; existing repos still carry the old version. After this merges + deploys, sync by calling `POST /admin/datasets/:id/ci/sync` against each of the 123 dataset repos (the sync handler is idempotent and only writes drifted files).

Test plan

  • `bun test test/workflow-yaml.test.ts` — new assertions cover the retry loop, 4xx-terminal, and absence of the legacy "non-blocking warning" path.
  • `bun run lint` — clean.
  • `bun run typecheck` — 0 errors.
  • Post-merge: deploy Worker, sync templates to a single test repo (`nm099999`), workflow-dispatch the enrichment, confirm green on success and red on a simulated 5xx (`SET ENRICHMENT_FAULT=500` if such a knob exists).

Closes #598. The template at backend/src/services/github.ts now retries transient curl-level failures and HTTP 5xx from /webhooks/llm-enrich up to 3 times with linear backoff, treats HTTP 4xx as terminal config errors, and exits 1 on persistent failure. Previously every non-2xx exited 0 as a 'non-blocking warning' which silently desynced D1 from the repo and is unacceptable for the OpenNeuro mass-import.
@github-actions

github-actions Bot commented May 23, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR599

Version: 0.8.32-PR599.08b41a3
Commit: 08b41a3


🤖 Updated on each push.

Code-review findings: 1) 401 was treated as terminal alongside other 4xx codes, but during a NEMAR_WEBHOOK_TOKEN rotation a brief 401 race across Workers instances is realistic and would silently abort every in-flight workflow at attempt 1. Add a 401 carve-out so the retry loop covers the rotation window; persistent 401 still hits the post-loop exit 1. 2) Add an anchored regex assertion that the post-loop branch contains exit 1, so a future edit that removes the exit code while keeping the log message is caught by the test.
@neuromechanist
neuromechanist merged commit 94d2066 into dev May 23, 2026
10 checks passed
@neuromechanist
neuromechanist deleted the 598-workflow-template-retry-http-5xx-and-fail-loud-on-persistent-enrichment-failure branch May 23, 2026 13:52
neuromechanist added a commit that referenced this pull request May 23, 2026
…ub dispatch

Closes #602. Phase 1 of epic #601.

Removes the per-repo .github/workflows/llm-enrichment.yml that shipped to
123 dataset repos via deployWorkflows() and replaces it with:

- A new Worker endpoint POST /webhooks/github that receives GitHub App
  push events, HMAC-verifies the signature, filters to nemarDatasets
  dataset repos pushing README.md/dataset_description.json/.nemar/
  metadata.json on main or release/** branches, and fires
  repository_dispatch[run-enrichment] at nemarDatasets/.github.

- A new triggerEnrichmentRun() helper mirroring triggerManifestGeneration().

- A new webhook-signature service implementing HMAC-SHA256 verification
  with a constant-time compare (no crypto.timingSafeEqual on Workers).

- The central run-enrichment.yml workflow lives on nemarDatasets/.github
  (see nemarDatasets/.github#5). It mints a per-repo App token scoped to
  the target dataset_id, checks out the dataset repo at the given ref,
  and reuses the same Worker round-trip + retry contract as the legacy
  per-repo workflow (#599).

Tests added: webhook-signature.test.ts (11 cases), trigger-enrichment.test.ts
(4 cases), webhook-github-push.test.ts (19 cases) covering the dispatch
filter table. workflow-yaml.test.ts updated to assert the template is no
longer shipped.

Cutover script: scripts/strip-per-repo-llm-enrichment.ts deletes the
legacy file from every dataset repo. Idempotent. Operator runs once
after the App webhook URL is pointed at the new endpoint.

This branch was previously deployed

1 inactive deployment
npm — 08b41a33 Deployed May 23, 2026 by neuromechanist via publish #1113
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