Skip to content

feat(github-app): allow several github apps to be used - #5269

Merged
guicaulada merged 8 commits into
mainfrom
gc/feat/multi-github-app-support
Aug 14, 2026
Merged

guicaulada merged 8 commits into
mainfrom
gc/feat/multi-github-app-support

Conversation

@guicaulada

Copy link
Copy Markdown
Contributor

Description

Supersedes #5038 by @thomasnemer, whose branch lives in an org-owned fork that maintainers cannot push to. This PR rebases that work onto current main (porting it to the compute-provider architecture introduced in #5234/#5267) and addresses the review feedback on #5038. All of Thomas's work is preserved with co-authorship.

From the original PR:

  • New additional_github_apps variable (optional, no breaking changes) accepts extra GitHub Apps with id, key_base64, and optionally installation_id (direct values or SSM references).
  • The control-plane lambdas (scale-up, scale-down, pool, job-retry) select one app per invocation and thread the selection through the JWT → installation token → API call chain, spreading load across N × 15,000 req/hour rate-limit buckets.
  • Installation ID resolution: pre-configured installation_id wins, the primary app reuses the webhook payload's id, API lookup is the fallback.

Changes on top of #5038:

  • Ported to the compute-provider layout: the appIndex selection lives in the orchestrators (scale-up.ts, pool.ts, scale-down.ts) and flows to providers via CreateGitHubRunnerConfig.appIndex, so provider interfaces are unchanged.
  • Restored the 404 stale-installation fallback (review feedback): when installation auth fails with 404 (app uninstalled/reinstalled while messages were in flight), the flow re-resolves the installation via the API and retries once with the same app. This now also covers stale pre-configured installation ids, and has regression tests in octokit.test.ts.
  • Updated env wiring for the COMPUTE_PROVIDER_TYPE era and regenerated module docs.

Test Plan

  • vitest: control-plane 348 passed, compute-providers 270 passed, webhook 89 passed.
  • New regression tests: stale-payload 404 retry, same-id rethrow, non-404 rethrow.
  • ESLint and Prettier clean on all touched packages.
  • terraform fmt -check -recursive, terraform validate (root, runners, multi-runner, ssm), terraform test in modules/runners (1 passed).
  • READMEs regenerated with terraform-docs.

Related Issues

Closes #5037. Supersedes #5038.

Co-authored with @thomasnemer.

thomasnemer and others added 8 commits July 22, 2026 18:31
…tftest

- Restore iam_overrides conditional and aws_iam_role.runner[0].arn index
  in scale-up IAM policy (dropped during conflict resolution)
- Update pool.tftest.hcl github_app_parameters to list format
- modules/ssm/outputs.tf: use tostring(idx) when indexing for_each
  resources keyed by stringified indices; bare numeric [idx] would fail
  with an invalid-index error when additional_github_apps is non-empty
- pool.ts: pass appIdx as trailing arg to createRunners so pool-originated
  JIT-config rate-limit metrics are attributed to the correct app rather
  than always defaulting to app 0

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…termination-watcher list mismatch

The local.github_app_parameters restructure (id/key_base64 became lists,
index 0 = primary app) silently broke four consumers of the old single-object
shape, none caught by CI since validate defers value evaluation:

- outputs.tf: ssm_parameters iterated lists as objects (v.name on a list
  fails at plan/apply); replace with merge() that keeps the upstream keys
  id/key_base64/webhook_secret pointing at the primary app plus the new
  per-app github_app_id_<idx>/github_app_key_base64_<idx>/github_app_webhook_secret keys
- modules/multi-runner/outputs.tf: add the same backward-compat keys to the
  existing merge() so external consumers indexing the old keys keep working
- main.tf + modules/multi-runner/termination-watcher.tf: pass id[0]/key_base64[0]
  (primary app single object) instead of the full list to the termination-watcher
  module input typed map(string)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Merge PR #5038 onto main, porting the multi-app changes to the
compute-provider architecture and restoring the stale-installation
404 fallback.

Co-authored-by: Thomas Nemer <[email protected]>
@guicaulada
guicaulada requested review from a team as code owners August 14, 2026 11:21
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@Brend-Smits Brend-Smits left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:! Thanks for picking this up! Also thanks to @thomasnemer 🚀

@guicaulada
guicaulada merged commit 82cb0fd into main Aug 14, 2026
44 checks passed
@guicaulada
guicaulada deleted the gc/feat/multi-github-app-support branch August 14, 2026 12:21
Brend-Smits pushed a commit that referenced this pull request Aug 17, 2026
🤖 I have created a release *beep* *boop*
---


##
[7.11.0](v7.10.2...v7.11.0)
(2026-08-14)


### Features

* **github-app:** allow several github apps to be used
([#5269](#5269))
([82cb0fd](82cb0fd))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: runners-releaser[bot] <194412594+runners-releaser[bot]@users.noreply.github.com>
guicaulada added a commit that referenced this pull request Sep 8, 2026
## Description

Follow-up to #5269, item 2 of the [#5038
review](#5038 (review)).
Stacked on #5282 (manifest transport); review that first.

Replaces uniform random GitHub App selection with budget-aware
selection, ported from our production fork:

- The auth module tracks the last observed `x-ratelimit-remaining` per
app, fed by `metricGitHubAppRateLimit` headers and the throttling plugin
callbacks.
- Selection picks the app with the most budget remaining; apps with no
observed state are assumed full.
- Apps that hit a secondary rate limit are skipped for 60 seconds; if
every app is cooling down, the one with the most budget is used anyway.
- Iteration starts at a random offset so concurrent cold-started lambdas
do not converge on the same app.

Uniform random kept sending ~1/N of traffic to apps that were already
exhausted. Selection state is per warm container and converges within a
few invocations; a cold container starts as before.

## Test Plan

- control-plane: 353 tests passed, including six new selection tests
(budget preference, unobserved-assumed-full, cooldown skip, all-cooling
fallback, single-app short-circuit, explicit appIndex) and a
selector-feed test for the rate-limit headers.
- ESLint + Prettier clean.

## Related Issues

Follow-up to #5269 / #5038. Depends on #5282.
guicaulada added a commit that referenced this pull request Sep 8, 2026
## Description

Follow-up to #5269, as promised in the [#5038
review](#5038 (review))
(items 1, 3, 4, and 5). We run this design in production.

- **Deliver additional GitHub App credentials via an SSM manifest
parameter** instead of colon-joined parameter names in the lambda
environment. Lambda's total environment limit is 4 KB, which the
colon-joined lists hit at roughly 15–20 apps with typical parameter
paths; the manifest keeps the environment constant regardless of app
count (Intelligent-Tiering covers manifests beyond the 4 KB standard
parameter tier).
- **Removes the positional list alignment** between
id/key/installation-id parameter names, which could silently shift
installation ids across apps if the lists drifted.
- **Rate-limit metric reads app ids from already-loaded credentials**
(`getLoadedAppId`) instead of re-reading SSM per app index; out-of-range
indexes no longer throw inside the swallowed catch.
- **Documents that additional apps must be installed on the same
orgs/repos** as the primary app, in a new "Distributing load across
multiple GitHub Apps" section of the rate-limits guide.

Internal contract only: Terraform and the lambdas deploy together, so
the env transport change is invisible to module users.
`additional_github_apps` is unchanged.

## Test Plan

- control-plane: 346 tests passed, including rewritten manifest-based
credential loading tests.
- `terraform fmt`/`validate` clean on root, runners, multi-runner, ssm;
`terraform test` in `modules/runners` passes.
- ESLint + Prettier clean; READMEs regenerated with terraform-docs.

## Related Issues

Follow-up to #5269 / #5038.

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
guicaulada added a commit that referenced this pull request Sep 8, 2026
Follow-up to #5269, item 2 of the [#5038
review](#5038 (review)).
Stacked on #5282 (manifest transport); review that first.

Replaces uniform random GitHub App selection with budget-aware
selection, ported from our production fork:

- The auth module tracks the last observed `x-ratelimit-remaining` per
app, fed by `metricGitHubAppRateLimit` headers and the throttling plugin
callbacks.
- Selection picks the app with the most budget remaining; apps with no
observed state are assumed full.
- Apps that hit a secondary rate limit are skipped for 60 seconds; if
every app is cooling down, the one with the most budget is used anyway.
- Iteration starts at a random offset so concurrent cold-started lambdas
do not converge on the same app.

Uniform random kept sending ~1/N of traffic to apps that were already
exhausted. Selection state is per warm container and converges within a
few invocations; a cold container starts as before.

- control-plane: 353 tests passed, including six new selection tests
(budget preference, unobserved-assumed-full, cooldown skip, all-cooling
fallback, single-app short-circuit, explicit appIndex) and a
selector-feed test for the rate-limit headers.
- ESLint + Prettier clean.

Follow-up to #5269 / #5038. Depends on #5282.
guicaulada added a commit that referenced this pull request Sep 8, 2026
Replaces uniform random GitHub App selection with selection based on the
last observed rate-limit budget. Apps under a secondary rate-limit
cooldown are temporarily skipped, and randomized starting points spread
cold-start traffic across apps.

Uses the credential storage interface introduced on main and preserves
the selected app index throughout each operation. Includes a regression
test verifying selection from an injected credentials store without
reading SSM.

This PR targets `main` and contains only the rate-limit selection
change. The manifest prerequisite was merged separately in #5282.
Replaces #5283, which was originally merged into the parent feature
branch.

Validation: 350 control-plane tests passed; TypeScript, ESLint, and diff
whitespace checks passed. The commit is signed and verified.

Follow-up to #5269 / #5038.
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.

Support for multiple GitHub Apps to overcome API rate limits at scale

3 participants