Skip to content

feat: cache per owner installation tokens + retry improvements#6

Open
hibare wants to merge 6 commits intomainfrom
installation-token-fix
Open

feat: cache per owner installation tokens + retry improvements#6
hibare wants to merge 6 commits intomainfrom
installation-token-fix

Conversation

@hibare
Copy link
Copy Markdown
Collaborator

@hibare hibare commented Apr 20, 2026

Problem

GATE creates a new installation token for every GetContents call to fetch trust policies. This causes:

  1. Transient 403 errors — newly minted tokens hit GitHub's edge before replication completes:
    {"msg":"authorization denied","code":"POLICY_LOAD_FAILED","details":"fetching .github/gate/trust-policy.yaml: fetching contents: GET https://api.github.com/repos/tr/a209462-oia-customviz-lib-looker/contents/.github/gate/trust-policy.yaml: 403 Resource not accessible by integration []"}
  2. Unnecessary API calls — repeated token minting for the same repo wastes GitHub App rate limit quota
  3. Thundering herd — concurrent requests for the same repo each mint independently

Changes

  • Token caching — cache contents:read installation tokens per repository with 5-minute expiry buffer, avoiding repeated minting
  • Retry on stale token — if a cached token gets 401/403, evict it and retry once with a fresh token
  • Replication delay — wait 2 seconds after minting a new token before using it (per GitHub Support guidance)
  • Singleflight deduplication — concurrent cache misses for the same repo coalesce into a single mint + delay
  • Installation ID singleflight — concurrent installation ID lookups also coalesced
  • Eviction guard fix — fixed zero-value comparison bug in installationCache.set eviction logic
  • Extract utilitiesparseRepository, constructRepository, permissionsKey helpers

@hibare hibare marked this pull request as ready for review April 20, 2026 09:25
@hibare hibare changed the title feat: cache per repository installation tokens + retry improvements feat: cache per owner installation tokens + retry improvements May 1, 2026
@arber-salihi
Copy link
Copy Markdown
Member

Decision: generate a token per GitHub App (and organization) in an opportunistic way. The rest is preserved.

@hibare hibare force-pushed the installation-token-fix branch from f5d7b6c to d0ad22b Compare May 4, 2026 04:18
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.

2 participants