Skip to content

Worker: retry GitHub 401 by refreshing cached App token #596

Closed

Description

@neuromechanist

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:

  1. On 401, invalidate the cached installation token for the current org (via __resetInstallationTokenCacheForTests-style helper exposed as a real API), then
  2. 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: add invalidateInstallationToken(installationId) public helper.
  • backend/src/services/github.ts: in githubFetchWithRetry, plumb an optional onAuthFailure callback (or token-refresher closure) that the caller can pass; default no-op. On 401, if onAuthFailure is 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

Activity

  1. added
    bug
    on May 23, 2026
  2. added a commit that references this issue on May 23, 2026
    9b2c5c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions