Skip to content
This repository was archived by the owner on Jul 16, 2026. It is now read-only.

fix(sandbox): refresh GitHub installation token for the sandbox lifetime - #1

Merged
cooper (czxtm) merged 1 commit into
feat/omp-harnessfrom
fix/github-token-refresh
Jul 11, 2026
Merged

fix(sandbox): refresh GitHub installation token for the sandbox lifetime#1
cooper (czxtm) merged 1 commit into
feat/omp-harnessfrom
fix/github-token-refresh

Conversation

@czxtm

Copy link
Copy Markdown
Member

Problem

GitHub App installation tokens expire after 60 minutes — fixed by GitHub, not extendable (a 4-hour token is not a thing GitHub offers). The sandbox entrypoint minted one once at boot; warm-pool sandboxes claimed >1 h after creation (and sessions outliving the hour) served dead tokens — every GitHub call 401'd. Verified across 16 auto_review jobs on 2026-07-09/10: all credential failures were sandboxes >60 min old at claim (nixmac#514 at 74 min, voy#1130 at 211 min, travel-frens#246 at 60 min); everything claimed fresh posted reviews fine.

Change

  1. Background re-mint loop (GITHUB_TOKEN_REFRESH_SECONDS, default 3000 s = 50 min — hourly cadence with margin so a live token always exists): re-mints and atomically rewrites the token file (~/.centaur/github-token, 0600) + git credential store, for the sandbox's whole life (idle-warm and claimed). Fail-soft: a failed re-mint keeps the previous token and retries in 300 s.
  2. No env export on the mint path: GITHUB_TOKEN/GH_TOKEN freeze into the exec'd harness at boot and go stale where files can be refreshed — and gh prefers env over everything. A /usr/local/bin/gh wrapper (shadows apt's /usr/bin/gh) re-reads the token file per invocation; both env vars are unset so no stale/stub value can shadow the fresh sources. git reads the refreshed credential store.
  3. Legacy path preserved: deployments passing a real GITHUB_TOKEN env with no App creds keep the old behavior (unset is scoped to the mint path; wrapper is a passthrough without the token file; tail auth block pins /usr/bin/gh).

Verification

Functional smoke (stubbed minter, real functions extracted from the entrypoint): boot mint writes 0600 token file + x-access-token credentials ✓; refresh loop re-mints on interval and swaps both files atomically ✓; poisoned minter keeps last token (fail-soft) ✓; wrapper overrides stale env from the file and passes through without it ✓. bash -n/sh -n clean.

Deploy

After merge + image build: bump sandbox.image.tag in gitops apps/centaur.yaml. Warm-pool pods pick the fix up on natural recycle (or delete the current warm pod — its token is already hours dead).

GitHub App installation tokens expire after 60 minutes (fixed by GitHub,
not extendable). The entrypoint minted one at boot only, so warm-pool
sandboxes claimed >1h after creation — and any session outliving the
hour — served dead tokens: every GitHub call 401'd (nixmac#514,
voy#1130, travel-frens#246, 2026-07-09/10).

- background loop re-mints on an interval (default 50 min: hourly
  cadence with margin so a live token always exists) and atomically
  rewrites the token file + git credential store for the sandbox's
  whole life
- no GITHUB_TOKEN/GH_TOKEN env export on the mint path: env freezes
  into the exec'd harness and cannot be refreshed; a /usr/local/bin/gh
  wrapper re-reads the token file per invocation instead, and the env
  vars are unset so no stale/stub value can shadow the fresh sources
- legacy env-token deployments (no App creds) keep the old behavior;
  the tail auth block pins /usr/bin/gh to bypass the wrapper
@czxtm
cooper (czxtm) merged commit e9e4b36 into feat/omp-harness Jul 11, 2026
8 of 16 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant