Repository navigation
Description
Symptom
Hit during the on*-dataset backfill (2026-05-23): the LLM enrichment workflow on nemarDatasets/on004849 POSTed to /webhooks/llm-enrich and got back:
HTTP 500
{"error":"LLM enrichment failed","details":"Failed to resolve ref 'main': HTTP 401"}
The Worker called GET /repos/nemarDatasets/on004849/commits/main and GitHub returned 401. The current githubFetchWithRetry treats 401 as terminal (retries only 5xx, 429, secondary 403). So a single hiccup — stale cached App installation token, transient GitHub auth blip — fails the entire enrichment cycle.
A retry (workflow_dispatch on the same repo, ~3 min later) succeeded with no changes.
Why this matters for the OpenNeuro mass-import
We're about to import all of OpenNeuro (hundreds of on* datasets). Each import dispatches llm-enrichment.yml which calls /webhooks/llm-enrich. At ~2 % single-call failure rate, hundreds of imports will produce dozens of stranded datasets unless the Worker self-heals.
Proposed fix
In backend/src/services/github.ts, extend githubFetchWithRetry (or wrap callers in enrich-dataset.ts and similar) to:
- On 401, invalidate the cached installation token for the current org (via
__resetInstallationTokenCacheForTests-style helper exposed as a real API), then - Retry the call once with a freshly minted token.
If the second call still 401s, raise. This handles both stale-cache and momentary-GitHub-auth blips without papering over real misconfiguration.
Scope
backend/src/services/github-auth.ts: addinvalidateInstallationToken(installationId)public helper.backend/src/services/github.ts: ingithubFetchWithRetry, plumb an optionalonAuthFailurecallback (or token-refresher closure) that the caller can pass; default no-op. On 401, ifonAuthFailureis provided, await it and retry the request once with the refreshed token.- Tests: simulate a 401 → 200 sequence and assert exactly one retry with a refreshed token.
Related
- nemar-cli memory:
github_app_migration.md - Epic Epic: migrate GITHUB_ADMIN_PAT to a GitHub App installation token #432: GitHub App migration
Activity
feat(github): retry GitHub 401 by refreshing App token