Skip to content

fleet gh: one passthrough that rotates personal + App tokens for every fleet gh call #8887

Closed

Description

@dezren39

Directive (Drew, 2026-11-12)

All fleet GitHub work should be done using the fleet app, which seamlessly switches between the personal token and each of the 3 GitHub App installation tokens. Build this in two steps:

  1. Now: a fleet gh subcommand on the fleet multicall binary. It selects a token (personal PAT + the 3 App installations), exports it as GH_TOKEN, and passes every argument through to the real gh binary unchanged. On a rate-limit or permission failure it retries with the next token in the rotation instead of failing the caller.
  2. Later: dedicated higher-level tools (project sync, queue sync, etc.) built on top of the same rotation, so callers stop shelling out to raw gh at all.

Why

Acceptance

  • fleet gh <args...> behaves exactly like gh <args...> (stdout/stderr/exit code passthrough) with a working token selected.
  • Rotation covers the personal token and all 3 App installations; a rate-limited or permission-denied attempt fails over to the next token and the caller sees only the final result.
  • Tokens are resolved by name from the fleet secrets broker at runtime; no token value is ever printed, logged, or written to a file.
  • project-reconcile.sh is rewired to call fleet gh instead of fetching github.project-token directly, and a full reconcile pass completes with zero "Resource not accessible" failures.
  • The follow-on (higher-level sync tools) is filed as its own issue when step 1 lands; this issue covers step 1 + the reconcile rewire.

Activity

  1. developing-today commented on Nov 12, 2026

    @developing-today
    Contributor
  2. added
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 12, 2026
  3. dezren39 commented on Nov 12, 2026

    @dezren39
    MemberAuthor

    Dropped-thread catcher (2026-11-12T09:31Z run): this issue was filed from Drew's directive in the orchestration chat after the board sync failed two passes in a row on the milestone PAT error (tracked on #1408), but it carried only meta/follow-up — no queue label and no task label, so no fleet lane was ever going to pick it up. Launched in place: task/triage + queue/queued added and verified by read-back, so the repo-health-code-pilot feeder enqueues the triage/build of the fleet gh passthrough.

  4. dezren39 commented on Nov 12, 2026

    @dezren39
    MemberAuthor

    Implemented — PR #9014 (merged, febd7fa921)

    fleet gh is a domain in the fleet multicall binary (full build): it runs the real gh with every argument unchanged, exports a broker-resolved token as GH_TOKEN per attempt, and returns the final attempt's stdout/stderr/exit code byte-exact (rotation is silent by default; FLEET_GH_TRACE=1 names each attempt's source on stderr).

    Rotation (tokens resolved by name from the fleet secrets broker at runtime; never printed, logged, or written to files):

    1. personal — Drew's gh OAuth token, parsed out of the broker secret github-cli.hosts-yml;
    2. App installations of the developing.today fleet App (ID 5612056 — the App whose private key the broker carries as github-app.developing-today-fleet.private-key; a different App from the paperwork one, whose key lives only in sops) for owners developing-today, developing-today-forks, dezren39. The JWT is RS256-signed via system openssl with the key passed on an inherited fd (never on disk, never in argv); installations are resolved live from GET /app/installations, paginated (the fleet-paperwork: installations() fetches only page 1 of /app/installations — with 103 installations the developing-today org is page 2, so every App-route write fails 'no installation found' #7930 lesson). A call naming a repo/org leads the App leg with that owner's installation, since installation tokens are scope-bound.

    Retry-safety rule (as built): a write is repeated under a fresh token only when the failure proves GitHub refused it before processing — rate-limit rejections (the limiter answers before the mutation runs) and permission/scope rejections (INSUFFICIENT_SCOPES, "Resource not accessible by …", "missing required scopes"). Any other failure of a write is returned as-is, so a retry can never double-post. Reads repeat on any failure class while tokens remain. Failure classification keys on gh/GitHub's observed refusal strings.

    Reconcile rewire: project-reconcile.sh now calls fleet gh for all Project reads/writes. It no longer fetches github.project-token; the probe-gated paperwork ladder is deleted. The outbox leg survives for the all-buckets-spent case, and RECONCILE_FORCE_LIMIT still exercises it.

    Acceptance evidence (2026-11-12)

    • Tests: 7 new oracle-named unit tests in gh.rs (failure classification, retry gate, read-only whitelist, rotation order + owner hint, hosts.yml parse, base64url vectors, fake-gh end-to-end failover + write-not-repeated). Full cargo test -p fleet -p fleet-registry green (41 bin + 5 registry + integration suites).
    • Natural failover: the broker-stored hosts.yml predates today's project scope refresh, so the personal attempt on project field-list fails with a scope refusal → failover → the developing-today installation serves the real Project Bump build/buck/preludes/buck2-prelude from 3a02ea3 to 9530656 #4 field list. (Ops note: the broker's stored github-cli.hosts-yml should be re-stored from a refreshed hosts.yml so the personal leg carries project again; the rotation covers its absence meanwhile.)
    • Manufactured failover: FLEET_GH_ORDER=app:dezren39,app:developing-today on a Project Bump build/buck/preludes/buck2-prelude from 3a02ea3 to 9530656 #4 read — the user-installation attempt fails, the org installation serves the call.
    • Full reconcile pass through fleet gh (rewired script, apply mode): 113 proposals, 113 applied live, 0 queued, zero "Resource not accessible" failures — the failure class that stranded 49 updates under the old PAT (see fix(orchestrator): project-reconcile.sh times out over ~200 items — make the bounded pass the standard path #1408). Auto-adds landed for all 11 then-unboarded epics (epic: GitHub and dynamic compute — rulesets, CI capacity, and elastic compute across the orgs #8985–epic: mcpx — one canonical MCP gateway and server parity #8993, opencode#2319, openchamber#2153 — verified on the board by paginated GraphQL). One wart found and fixed in the same run: the script parses item-add JSON out of a merged 2>&1 capture, which the rotation's stderr notes polluted — fleet gh is now silent by default (note above), restoring byte-exact passthrough; the adds' Status/Kind sets, skipped that pass, are picked up by the next pass's normal sync.
    • Deployment: the release build is installed at ~/.local/bin/fleet on the laptop (previous binary kept as fleet.bak-20261112-pre-gh). Note for future installers: another lane's reinstall briefly replaced it with a main build during this run — from this merge on, main builds carry the gh domain, so the normal rebuild flow keeps it.

    Step 2 (higher-level sync tools on the rotation) is filed as #9016, per this issue's two-step shape.

    One pre-existing defect observed, deliberately not fixed here: the reconcile pass's ITEM_LIMIT=1000 now truncates the item list (the project holds 1,229 items), so its presence checks and proposals cover only the first 1,000. It predates this rewire and belongs to the #910/#1408 tracker line.

  5. dezren39 commented on Nov 12, 2026

    @dezren39
    MemberAuthor

    Follow-up from the acceptance note: the broker's stored github-cli.hosts-yml has been re-stored from the current sandbox ~/.config/gh/hosts.yml (the copy refreshed 2026-11-12 ~14:08 CST with the project scope).

    Route used: the fleet secrets client exposes get/list only; the broker is a read-through cache whose store of record is the Bitwarden vault. The write therefore used the repo's established pattern for this key (pkgs/agent-backup/bws-backup-secrets.sh): replace the vault entry for github-cli.hosts-yml in place (delete + recreate in the same project, updated note), with a round-trip SHA-256 check against the source file — the stored value differed before the rewrite and matches after. A broker POST /refresh was then triggered, and fleet secrets get github-cli.hosts-yml now hash-matches the current file.

    Verification (laptop, personal leg only, no failover — trace showed a single attempt under personal for each):

    So the personal leg now presents the refreshed token with project scope directly; rotation no longer has to cover this gap via the App.

  6. added a commit that references this issue on Nov 12, 2026
  7. developing-today-fleet commented on Nov 12, 2026

    @developing-today-fleet
    Contributor

    Done — landed and verified 2026-11-12.

    What shipped

    Verified live (sandbox, 2026-11-12 ~22:15Z)

    • fleet gh tiers: all 7 sources up — personal core 4146/5000 graphql 3083/5000; app:developing-today 5000/5000; app:developing-today-forks 5000/5000; app:dezren39 12500/12500; devtoday:developing-today 4881/5000; devtoday:dezren39 12493/12500; backup:developing-today 6850/6850.
    • The milestone-carrying write that failed all morning (code#8582 Status) now lands both directions via fleet gh, readback Done.
    • Full reconcile pass on the new route: 194s elapsed, no "Resource not accessible" failures; 11 writes queued by a GraphQL rate limit were drained and all 11 verified at their target Status on Project Bump build/buck/preludes/buck2-prelude from 3a02ea3 to 9530656 #4 by readback.
    • Tests: cargo test --release -p fleet --bin fleet — 41 passed, 0 failed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

meta/follow-upFollow-up spun out of earlier workqueue/queuedHas a queued queue taskstatus:donetask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions