Repository navigation
Description
Summary
When scaleUp() throws any exception that is not a ScaleError (e.g. ThrottlingException from SSM, Unavailable from EC2, GitHub API errors), the scaleUpHandler in lambda.ts returns an empty batchItemFailures array. SQS interprets an empty array as "all messages processed successfully" and permanently deletes them. Affected GitHub Actions jobs remain queued indefinitely and eventually time out after 24 hours with no runner ever being assigned.
This issue was originally described in #5024. PR #5029 was closed without merge. PR #4990 (v7.4.1) added @octokit/plugin-retry and fixed JIT config per-instance error handling but did not fix this root cause in lambda.ts.
Root Cause
lambda.ts lines 53–64:
} catch (e) {
if (e instanceof ScaleError) {
batchItemFailures.push(...e.toBatchItemFailures(sqsMessages));
logger.warn(`${e.detailedMessage} A retry will be attempted via SQS.`, { error: e });
} else {
logger.error(`Error processing batch (size: ${sqsMessages.length}): ${(e as Error).message}, ignoring batch`, {
error: e,
});
// ← batchItemFailures is never populated here
// ← returns [] → SQS deletes ALL messages permanently
}
return { batchItemFailures };
}
The batchItemFailures array is initialized as empty on line 41 and only populated for ScaleError exceptions. For every other exception type, it remains empty and SQS permanently removes all messages.
Contributing Bug: Rate Limit Handlers in auth.ts Never Retry
onRateLimit and onSecondaryRateLimit log the rate limit event but do not return true, which is required by @octokit/plugin-throttling to trigger a retry. The handlers return undefined implicitly, causing the throttling plugin to abort immediately and throw — which then hits the lambda.ts else branch above, deleting the entire batch.
throttle: {
onRateLimit: (retryAfter: number, options: Required<EndpointDefaults>) => {
logger.warn(`GitHub rate limit: ...`);
// missing: return true
},
onSecondaryRateLimit: (retryAfter: number, options: Required<EndpointDefaults>) => {
logger.warn(`GitHub rate limit: SecondaryRateLimit ...`);
// missing: return true
},
},
Note: @octokit/plugin-retry (added in v7.4.1) handles 5xx retries from GitHub API but does not handle throttling — that is exclusively @octokit/plugin-throttling's responsibility. These two plugins serve different purposes and the throttling bug is independent.
Observed Errors (all cause message deletion)
ThrottlingException: Rate exceeded ← SSM rate limit
at putParameter
attempts: 3, totalRetryDelay: 1198ms
Unavailable: The service is unavailable. Please try again shortly. ← EC2 transient 503
at AwsEc2QueryProtocol
attempts: 3, totalRetryDelay: 191ms
POST /orgs/{org}/actions/runners/registration-token - 503 ← GitHub secondary rate limit in 860ms (not retried due to auth.ts bug)
All logged as: "Error processing batch (size: N): ..., ignoring batch" — the tell-tale sign of this bug.
Impact
- GitHub Actions jobs stuck in queue for up to 24 hours then timed out
- No DLQ routing (messages never enter SQS retry/redrive flow)
- No metrics or alarms triggered (messages appear "successfully processed")
- EC2 instances may have been partially created before the exception — wasted cost with no corresponding runner
- Silent: operators have no indication messages were lost until users report stuck jobs
Corner Cases Considered
- Empty batch: sqsMessages can be empty if all records were non-SQS event sources. [].map(...) returns [] — no-op, safe.
- Partial processing before exception: If scaleUp() processes some runner groups successfully before throwing on another group, returning all messages as failures causes already-processed messages to be re-queued. For ephemeral runners, the isJobQueued check on retry prevents duplicate EC2 launches for already-running jobs. For non-ephemeral runners, duplicate runners may be launched but the scale-down Lambda handles cleanup. Correct trade-off: a duplicate runner is recoverable; a permanently lost SQS message is not.
- ScaleError partial retry semantics preserved: ScaleError.toBatchItemFailures() only retries failedInstanceCount messages, not all. This intentional partial-retry behaviour is unchanged — the fix only affects the non-ScaleError path.
- Existing test documents the bug: lambda.test.ts line 218 explicitly asserts batchItemFailures: [] for a non-ScaleError exception — this test must be updated.
Proposed Fix
- lambdas/functions/control-plane/src/lambda.ts
} catch (e) {
if (e instanceof ScaleError) {
batchItemFailures.push(...e.toBatchItemFailures(sqsMessages));
logger.warn(`${e.detailedMessage} A retry will be attempted via SQS.`, { error: e });
} else {
logger.error(
`Error processing batch (size: ${sqsMessages.length}): ${(e as Error).message}, batch will be retried via SQS.`,
{ error: e },
);
batchItemFailures.push(...sqsMessages.map(({ messageId }) => ({ itemIdentifier: messageId })));
}
return { batchItemFailures };
}
- lambdas/functions/control-plane/src/github/auth.ts
throttle: {
onRateLimit: (retryAfter: number, options: Required<EndpointDefaults>) => {
logger.warn(
`GitHub rate limit: Request quota exhausted for request ${options.method} ${options.url}. Retrying after ${retryAfter} seconds.`,
);
return true;
},
onSecondaryRateLimit: (retryAfter: number, options: Required<EndpointDefaults>) => {
logger.warn(
`GitHub rate limit: SecondaryRateLimit detected for request ${options.method} ${options.url}. Retrying after ${retryAfter} seconds.`,
);
return true;
},
},
- lambdas/functions/control-plane/src/lambda.test.ts
// UPDATE — was asserting broken behavior:
it('Non scale error should return message as batch failure for retry.', async () => {
const error = new Error('Non scale should resolve.');
vi.mocked(scaleUp).mockRejectedValue(error);
const result = await scaleUpHandler(sqsEvent, context);
expect(result).toEqual({ batchItemFailures: [{ itemIdentifier: sqsRecord.messageId }] });
});
// UPDATE — was asserting batchItemFailures: []
it('Should return all messages as failures when scaleUp throws non-ScaleError', async () => {
const records = createMultipleRecords(2);
const multiRecordEvent: SQSEvent = { Records: records };
vi.mocked(scaleUp).mockRejectedValue(new Error('Generic error'));
const result = await scaleUpHandler(multiRecordEvent, context);
expect(result).toEqual({
batchItemFailures: [{ itemIdentifier: 'message-0' }, { itemIdentifier: 'message-1' }],
});
});
// ADD — empty batch edge case:
it('Should return empty failures when batch is empty and scaleUp throws non-ScaleError', async () => {
const emptyEvent: SQSEvent = { Records: [] };
vi.mocked(scaleUp).mockRejectedValue(new Error('Generic error'));
const result = await scaleUpHandler(emptyEvent, context);
expect(result).toEqual({ batchItemFailures: [] });
});
Affected Versions
Confirmed in v7.3.x and v7.4.x. PR #4990 (v7.4.1) does not fix this issue.
Environment
GitHub Enterprise Cloud with Data Residency, ephemeral runners, JIT config disabled, org-level runners.
Activity
github-actions commentedon Jul 14, 2026
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs. Thank you for your contributions.
edersonbrilhante commentedon Jul 22, 2026
I am working on fix in this PR #5220
t-morisawa commentedon Jul 30, 2026
Confirming this with production data. In our case the exception reaching the catch-all is
Unavailablefrom EC2 — thrown bylistEC2Runners(), i.e. therunners_maximum_countcheck, before runner creation is ever attempted.Impact
Org-level setup, 12 runner configs, ephemeral spot runners,
us-east-1. Over 7 days:Each one is a job that stays
queueduntil it times out. ~4,000 lost on a peak weekday, near zero on weekends.Where it throws
Funnel from the INFO milestones in
scaleUp(), one runner config, 7 days:Error breakdown:
Unavailable: The service is unavailable. Please try again shortly.11,640 (93%),RequestLimitExceeded518, SSMThrottlingException220. SSM failures surface wrapped asGetParameterErrorand GitHub failures asHttpError, so the bareUnavailablecan only be theDescribeInstancescall. Note this is not account-level throttling —DescribeInstancesallows 23 req/s with a bucket of 130, and our worst burst never drained it below 65.Confirmed by removing the call
We set
runners_maximum_count = -1on all configs, which makes the module skiplistEC2Runners()entirely. Nothing else changed.Comparable volume in the 07:00 hour, drop rate 24.0% → 3.6%, and zero since. Average scale-up duration also fell from ~10s to ~3.1s, consistent with the SDK no longer burning ~9s retrying
DescribeInstances.Note on #5220
#5220 adds retryable-error classification around
runnerProvider.createRunners(). Inscale-up.tsthe max-count check is a bareawaitoutside that try/catch, so it looks like this call site would still reach the catch-all. Flagging it here rather than on the PR since it seems out of that PR's scope — but it may mean #5105 isn't fully closed by it.isRetryableAwsError()there already covers$fault === 'server'andhttpStatusCode >= 500, which would classify ourUnavailablecorrectly if applied at that call site.Measurements are from a 6.5.x deployment; we checked the relevant control flow is unchanged in v7.10.0. Happy to share more detail or test a patch against our workload.
edersonbrilhante commentedon Jul 30, 2026
@t-morisawa I made a stress test with runners_maximum_count -1. I forgot checking the case using positive number in runners_maximum_count in a stressed environment. I will test and make a fix if is needed.
t-morisawa commentedon Jul 31, 2026
@edersonbrilhante
Thank you! Yes, if possible, we would really appreciate it if you could test and check that on your side.
In our environment, dozens to over a hundred workflows can launch simultaneously, and we've confirmed that this error occurs frequently on runner configurations with high usage.
edersonbrilhante commentedon Jul 31, 2026
I checked the code, and you were right. I pushed the fix and it was already merged to main.
edersonbrilhante commentedon Aug 5, 2026
@t-morisawa can we close this issue?
t-morisawa commentedon Aug 5, 2026
@edersonbrilhante
Thank you. I have updated to the latest version on my environment and confirmed that the issue is resolved. Please feel free to close this ticket/issue. Thanks again for your support.