Skip to content

fix(scale-down): reselect GitHub Apps and attribute cleanup quota - #5466

Open
guicaulada wants to merge 1 commit into
mainfrom
gc/fix/scale-down-multi-app-cleanup
Open

guicaulada wants to merge 1 commit into
mainfrom
gc/fix/scale-down-multi-app-cleanup

Conversation

@guicaulada

@guicaulada guicaulada commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Scale-down caches an installation client by owner, so an invocation can keep using the first selected GitHub App even when additional Apps have available quota. Its runner-state response metrics also omit the selected App index and attribute quota to the primary App.

Re-evaluate App selection before cache lookup and key installation clients by App, runner type, and owner. Attach success and error response hooks to both the pre-installation and installation clients, reporting quota and metrics for the App making each request, including installation lookup, paginated runner lookups, and deletion. Error hooks preserve the original error. Subsequent cleanup operations can select another configured App while retaining client reuse within the correct scope.

Validation: 354 control-plane tests pass, including selection changes for the same owner, client reuse, and correct App attribution. Runtime TypeScript, ESLint, Prettier, Lambda bundle build, and diff checks pass. No live GitHub/AWS changes were performed.

This PR targets main and contains only client-selection and quota-attribution changes.

@guicaulada
guicaulada requested a review from a team as a code owner September 23, 2026 14:26
@guicaulada
guicaulada added this pull request to stack #5468 September 23, 2026 14:28
@guicaulada
guicaulada force-pushed the gc/fix/scale-down-multi-app-cleanup branch from c404f77 to 576ac85 Compare September 23, 2026 14:36
@guicaulada
guicaulada removed this pull request from stack #5468 September 23, 2026 14:39
@guicaulada
guicaulada changed the base branch from gc/fix/orphan-cleanup to main September 23, 2026 14:39
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

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

Scanned Files

None

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Quota attribution is missing for pre-installation lookups and failed GitHub requests.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
What changed in this PR

Updates scale-down GitHub App selection, client caching, and quota attribution for multi-App cleanup workflows.

Changes:

  • Re-selects Apps before cache lookup and scopes clients by App, runner type, and owner.
  • Adds App-specific quota instrumentation.
  • Adds tests for App reselection, client reuse, and attribution.
File Summary
lambdas/​functions/​control-plane/​src/​scale-runners/​scale-down.ts Updates client selection, caching, and quota hooks.
lambdas/​functions/​control-plane/​src/​scale-runners/​scale-down.test.ts Tests multi-App selection and quota attribution.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +57 to +59
octokit.hook.after('request', async (response) => {
await metricGitHubAppRateLimit(response.headers, appIdx);
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 35ea122. A shared helper now attaches quota attribution hooks to the pre-installation client before installation lookup and to the installation client before runner operations. Added a regression checking the hooks are attached before getOrgInstallation and that both clients attribute responses to the selected App. All 354 control-plane tests pass.

Comment on lines +57 to +59
octokit.hook.after('request', async (response) => {
await metricGitHubAppRateLimit(response.headers, appIdx);
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 35ea122. The shared helper also installs a request error hook on both clients. It reports RequestError response headers for the selected App and rethrows the original error, preserving existing handling. Regression coverage checks failed-request attribution, error identity, and network errors without response headers. All 354 control-plane tests pass.

@guicaulada
guicaulada force-pushed the gc/fix/scale-down-multi-app-cleanup branch from 576ac85 to 35ea122 Compare September 23, 2026 19:35
@guicaulada
guicaulada force-pushed the gc/fix/scale-down-multi-app-cleanup branch from 35ea122 to 8c1013a Compare September 24, 2026 13:54

This branch has not been deployed

No deployments
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