Skip to content

The forge authoring App's installation token is resolved once per cycle and exported for the cycle's whole life, but it expires after about an hour

Id: TD-PPagop-26082833 · Status: resolved · Filed: 2026-08-28 · Resolved: 2026-09-09 · Ref: https://github.com/Pullwright/agent-ops/pull/1313

What. lib/standdown.sh’s run_standdown_checks calls forge_auth_effective_gh_token (lib/forge-auth.sh, D25) exactly once, at stand-down, and exports the resolved credential as GH_TOKEN for the rest of the cycle’s process. When that credential is the forge authoring App’s own minted installation token, it carries GitHub’s ~1 h installation-token lifetime; nothing re-resolves it, so a cycle that outlives the token keeps presenting an expired one. lib/github-app-token.sh’s own cache assumes the opposite shape — its refresh_buffer=300 exists so that a caller re-asking near expiry gets a fresh mint — but this caller asks once and never again.

Why it matters. A cycle routinely outlives an hour by design. lib/stage-budget.sh’s shipped priors are implementer: 150 minutes and reviewer: 90, and one agent-cycle.sh process runs the Co-Ordinator, Refiner, Implementer, Reviewer and Approver in sequence. So on a node authenticating as the App, GH_TOKEN can be expired by the time the Implementer reaches its git push and gh pr create — which is precisely where a cycle’s authoring acts are concentrated, at the end of the stage, after all the work is done. The observable failure is a 401 on the push, with the stage’s output already paid for.

It is also strictly worse than the status quo on a node carrying both credentials. Today the long-lived GH_TOKEN PAT authenticates the whole cycle. After D25 the App’s short-lived token overwrites it at stand-down and lib/forge-auth.sh’s degrade path never runs again, so the PAT that would still be valid is no longer in the environment. The D25 degrade guarantee covers “the App could not mint at stand-down”; it does not cover “the App minted, and the token then aged out mid-cycle”.

Latent until an owner provisions the App — the values ship unset — but it fires on the first node that does.

Where.

  • lib/standdown.sh, step 1.9 (the IFS=$'\t' read … < <(forge_auth_effective_gh_token) block and the export GH_TOKEN= immediately after it).
  • lib/forge-auth.sh’s forge_auth_effective_gh_token, which is written as a once-per-cycle resolution and documented as such.
  • docs/IMPLEMENTATION-PIPELINE-SPEC.md component 14h and requirement 2’s unnumbered pre-check, both of which describe the once-per-cycle resolution as the design.

Suggested fix. Three shapes worth weighing, none of them safe to pick from inside a review pass:

  1. Re-resolve before each stage — cheap (a cache hit costs nothing) and bounded by the longest single stage rather than the whole cycle, but a 150-minute Implementer stage still straddles an expiry.
  2. Stop exporting a long-lived GH_TOKEN at all and scope the credential to each invocation as a leading GH_TOKEN="$(…)" gh …, the shape approver_post_review already uses for the Approver’s own token. Correct, but it has to reach every gh/git call site in a cycle, including the agent stages’ own shells, which is the hard part.
  3. Install a git credential helper that mints on demand, so git and gh both ask for a fresh token at the moment they need one. This is the shape that also closes TD-PPagop-26082834, and the one that scales to the cron entry points, but it is the largest change.

Whichever is chosen, a test should pin it: a cycle whose clock has advanced past the minted token’s expires_at must present a valid credential to its next authoring call, not the stale one.

Noticed while reviewing PR #863 (issue #607, D25 — the forge authoring App).

Migrated to https://github.com/Poetic-Poems/agent-ops/issues/1021.