You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: fail over rate-limited GitHub App requests - #5523
Multi-app clients currently keep retrying with the selected GitHub App after rate limiting. Generic HTTP 429 responses can bypass secondary-limit detection, and waiting for a rate-limit reset can consume the Lambda runtime even when another app is available.
Add shared, bounded request-level failover for scale-up, pool, scale-down, and job retry:
Handle every 429 and rate-limit-specific 403, including responses with nonzero primary quota remaining.
Select the eligible app with the highest recently observed budget, track primary resources separately, expire stale observations, and respect cooldowns even when every app is unavailable.
Apply Retry-After/reset deadlines to the failed app, resolve the replacement app's own installation, and retry only the failed GitHub operation. Installation lookup and token minting use the same failover policy.
Attempt each app at most once per operation and return exhausted failures to existing caller retry handling without sleeping for rate-limit resets.
Attribute response accounting to the app that actually made the request, rather than the original batch selection.
Selection remains local to each warm Lambda environment. Secondary throttling can affect multiple apps; this does not introduce distributed quota coordination or guarantee linear throughput scaling.
Job-retry failures return per-record SQS batch responses, with ReportBatchItemFailures enabled in both Terraform implementations. Failed authentication, status checks, and publications are retried; successful records are acknowledged. Single-App rate-limit waits are replaced by prompt failure and queue redelivery (or the next scheduled run), documented in the tuning guide.
Test Plan
Control-plane suite: 386 tests passed, including real Octokit hook integration tests for generic/secondary 429s, rate-limit 403s, ordinary permission failures, bounded exhaustion, single-app cooldowns, separate primary resources, and organization/repository installation identity.
Verified that successful JIT requests are not replayed when a subsequent request fails over.
TypeScript, ESLint, Prettier, diff checks, and the control-plane ncc build passed.
Explicit coverage run remains below existing thresholds on both unchanged main and this branch. Line coverage improves from 94.87% to 96.07%; branch coverage improves from 87.10% to 88.66%. No coverage thresholds were changed.
Not deployed; validation is local and uses mocked GitHub HTTP responses.
Terraform: legacy job-retry module validates; all 5 orchestration job-retry tests pass on the rebased branch, including partial-batch response wiring.
If client initialization hits a primary core limit during a JIT request, deleting this promise lets later JIT requests repeat that initialization before reset. They select by registration quota, where the failed app can still have the highest (unknown) budget, and the factory's explicit app index bypasses core eligibility. This repeatedly sends authentication requests to an app already known to be throttled. Check initialization eligibility separately and skip unavailable uncached clients, while keeping cached clients usable for JIT. Extend the authentication-failure regression with a second JIT request.
Avoid caching core when JIT response omits rate-limit resource
A successful JIT response without x-ratelimit-resource replaces the inferred actions_runner_registration resource with core; the new tests already use responses without this header. If core quota is then exhausted on every app, subsequent JIT requests are rejected locally even when registration quota remains. Update the route cache only when the response supplies a resource header, and add a regression covering a second JIT request after core exhaustion.
Installation-authenticated core quotas are per installation, but this key shares their exhaustion across every installation of an app. With multiple organizations (covered by scale-up.test.ts:897–918), exhausting org A's quota now excludes the app for org B even though B has an independent budget. The initial auth selection can reject before B's client is created. Scope primary observations and selection to the installation or owner, including auth seeding, while retaining app-wide secondary cooldowns. Add a two-installation regression.
Addressed the three additional findings in the latest review summary in 3c8af39:
Uncached installation clients must have eligible core quota before authentication; cached clients can still use registration quota. The authentication-failure regression now makes a second JIT request and confirms the exhausted app is not initialized again.
Responses without x-ratelimit-resource no longer overwrite the inferred JIT resource. Repeated JIT requests remain possible after all core budgets are exhausted.
Primary quota observations and selection are scoped by GitHub endpoint and normalized installation owner, including scoped authentication seeds. Secondary cooldowns remain app-wide. Added owner/endpoint-isolation coverage.
Validation: all 377 control-plane tests pass, along with ESLint and TypeScript checks.
This early rethrow skips quota observations and metrics for ordinary HTTP failures. For example, a 404 reporting zero core quota leaves an earlier positive observation eligible, so subsequent operations select an exhausted app. Record available response headers before rethrowing, without switching apps for the failed permission or validation operation. The removed caller-side error accounting no longer handles this.
Addressed the additional finding from the Copilot review summary in c4fea0d: ordinary HTTP failures now record quota headers and metrics before being rethrown, without replaying permission or validation failures.
This overlap with #5407, open for the same issue #5409. Your hook approach cover more, so if maintainers prefer this one I will close #5407, both can't be merged together.
Few things I see:
jobRetryCheck rethrow fail the whole batch. Default batch size is 10 and no ReportBatchItemFailures, so records already published before are delivered again, can create duplicate runners. Better return batchItemFailures only for failed ones.
Thanks for taking a look. I compared #5407 and think we should keep this approach because it also covers JIT/registration requests and cleanup, while #5407 explicitly leaves registration requests without their own failover.
jobRetryCheck now returns failed message IDs, and both Terraform event source mappings enable ReportBatchItemFailures, so a failed record does not replay the successful records in its batch.
Documented the single-App behavior change: no in-Lambda wait for quota reset; failed queue records retry through SQS, and scheduled cleanup/pool work retries on subsequent runs.
The reason will be displayed to describe this comment to others. Learn more.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
The reason will be displayed to describe this comment to others. Learn more.
I tested this on a sandbox deployment with a single GitHub App (webhook, scale-up, scale-down and job-retry lambdas). The test workflow ran fine on a freshly scaled runner, the lambda logs had no warnings or errors, and the runner was terminated and de-registered by scale-down afterwards. The Lambda test suite also passes. I didn't test real failover between multiple apps, so that part is only covered by the mocked tests.
Two small things I'd like you to look at, see the comments below.
Scale-down caches installation clients by owner. Scope that cache by
selected GitHub App, runner type, and owner, and select the App before
checking the cache so a changed selection uses the corresponding client.
Preserve the shared request-level failover added in #5523. Installation
lookup and token creation stay inside its client factory; the shared
failover layer handles quota observation and metrics, avoiding duplicate
response hooks in scale-down.
Validation: all 403 control-plane tests, runtime TypeScript, ESLint, and
diff checks pass. The regression verifies selection changes for the same
owner and client reuse within each App. No AWS deployment or live runner
cleanup was performed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Multi-app clients currently keep retrying with the selected GitHub App after rate limiting. Generic HTTP 429 responses can bypass secondary-limit detection, and waiting for a rate-limit reset can consume the Lambda runtime even when another app is available.
Add shared, bounded request-level failover for scale-up, pool, scale-down, and job retry:
Selection remains local to each warm Lambda environment. Secondary throttling can affect multiple apps; this does not introduce distributed quota coordination or guarantee linear throughput scaling.
Job-retry failures return per-record SQS batch responses, with
ReportBatchItemFailuresenabled in both Terraform implementations. Failed authentication, status checks, and publications are retried; successful records are acknowledged. Single-App rate-limit waits are replaced by prompt failure and queue redelivery (or the next scheduled run), documented in the tuning guide.Test Plan
Control-plane suite: 386 tests passed, including real Octokit hook integration tests for generic/secondary 429s, rate-limit 403s, ordinary permission failures, bounded exhaustion, single-app cooldowns, separate primary resources, and organization/repository installation identity.
Verified that successful JIT requests are not replayed when a subsequent request fails over.
TypeScript, ESLint, Prettier, diff checks, and the control-plane ncc build passed.
Explicit coverage run remains below existing thresholds on both unchanged main and this branch. Line coverage improves from 94.87% to 96.07%; branch coverage improves from 87.10% to 88.66%. No coverage thresholds were changed.
Not deployed; validation is local and uses mocked GitHub HTTP responses.
Terraform: legacy job-retry module validates; all 5 orchestration job-retry tests pass on the rebased branch, including partial-batch response wiring.