Skip to content

fix(lambda): fail-open isJobQueued — assume queued on API errors - #5130

Merged
edersonbrilhante merged 4 commits into
github-aws-runners:mainfrom
vegardx:fix/fail-open-is-job-queued
Jul 22, 2026
Merged

edersonbrilhante merged 4 commits into
github-aws-runners:mainfrom
vegardx:fix/fail-open-is-job-queued

Conversation

@vegardx

@vegardx vegardx commented May 26, 2026

Copy link
Copy Markdown
Contributor

Problem

When enable_job_queued_check = true (default), the isJobQueued call has no error handling. If getJobForWorkflowRun throws (404, rate limit, 502), the error propagates up through scaleUp and hits the generic catch in scaleUpHandler — causing the batch to fail.

This is especially problematic in combination with the race condition described in #5026: when SQS delivers messages in multiple batches due to concurrency limits, GitHub API errors during the second batch cause jobs to be silently dropped.

Fix

Wrap the isJobQueued check in a try/catch. On any error, assume the job is still queued (fail-open) and log a warning. The worst case is creating a runner for a job that has already been handled — the runner will self-terminate when no job is available.

if (enableJobQueuedCheck) {
  let jobQueued = true;
  try {
    jobQueued = await isJobQueued(githubInstallationClient, message);
  } catch (e) {
    messageLogger.warn('isJobQueued check failed, assuming job is still queued (fail-open)', { error: e });
  }
  if (!jobQueued) {
    messageLogger.info('No runner will be created, job is not queued.');
    continue;
  }
}

Changes

  • lambdas/functions/control-plane/src/scale-runners/scale-up.ts — try/catch around isJobQueued
  • lambdas/functions/control-plane/src/scale-runners/scale-up.test.ts — test: API error → runner still created

Risk

Low — fail-open is strictly more resilient than fail-closed for job dispatch. The extra runner (if the job was already handled) self-terminates with no work.

Fixes #5026

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR makes the job-queued verification in scaleUp resilient to GitHub API failures by switching the isJobQueued check to a fail-open approach, and adds a test to validate the new behavior.

Changes:

  • Wrap isJobQueued in a try/catch and proceed with scaling when the check fails (fail-open).
  • Add a GHES unit test ensuring runners are still created when isJobQueued throws.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
lambdas/functions/control-plane/src/scale-runners/scale-up.ts Makes the isJobQueued gate fail-open on errors to avoid dropping scale events during GitHub API issues.
lambdas/functions/control-plane/src/scale-runners/scale-up.test.ts Adds coverage for the new fail-open behavior when GitHub API calls fail.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@edersonbrilhante edersonbrilhante 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.

@vegardx Please sign your commits :)

vegardx added 2 commits July 21, 2026 11:06
Wrap the isJobQueued check in a try/catch that assumes the job is still
queued when the GitHub API returns an error (404, rate limit, 502). This
prevents silent job drops when the API is transiently unavailable.

Previously, any error from getJobForWorkflowRun would propagate up and
(combined with the non-ScaleError catch behavior) cause the entire SQS
batch to be dropped.

Fixes github-aws-runners#5026
Log only message and status instead of the full error object to avoid
leaking request/response metadata from Octokit errors.
@vegardx
vegardx force-pushed the fix/fail-open-is-job-queued branch from 5f37318 to 330b56d Compare July 21, 2026 09:30
@vegardx

vegardx commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Signed and rebased onto current main. Sorry for the delay.

The fail-open catch swallowed the "Event ... is not supported" error from
isJobQueued, which meant a check_run event would silently scale up a runner.
The eventType guard earlier in scaleUp only rejects non-workflow_job events
when ephemeral runners are enabled, so this path is reachable in any
non-ephemeral deployment with the queued-check on.

Give that case its own error type and let it propagate, restoring the
pre-change behaviour. Fail-open still applies to genuine API failures, which
is what the change was for.
@vegardx

vegardx commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Copilot's review point was right, and it caught a regression I'd introduced — pushed a fix.

The Event ... is not supported path was the real problem. isJobQueued throws that for any non-workflow_job event, and my fail-open swallowed it and scaled up anyway. The eventType guard earlier in scaleUp only rejects those events when ephemeral runners are enabled, so in a non-ephemeral deployment with the queued-check on, every check_run event would have quietly created a runner. That's strictly worse than the behaviour I was trying to fix.

It now has its own error type and propagates, restoring the previous behaviour for that case. Fail-open still applies to genuine API failures, which is the point of the PR. Test included, and it fails against the previous version.

On the other two: auth/permission failures I'd argue belong in fail-open. They're usually transient (token mint races, brief 401s during rotation), and the cost of being wrong is one idle runner that scales back down, versus a silently dropped job.

404 job-not-found is the genuinely debatable one. It can mean the job was cancelled — where failing open wastes a runner — or that we're reading right after the webhook and GitHub hasn't caught up, which is the race in #5026. I've left it failing open because dropping a real job seemed worse than briefly starting a surplus runner, but that's a judgement call rather than something I derived. Happy to narrow it to 5xx/429/network if you'd rather be conservative.

Copilot AI review requested due to automatic review settings July 22, 2026 10:52

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 was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@edersonbrilhante
edersonbrilhante merged commit 8fa06ee into github-aws-runners:main Jul 22, 2026
8 checks passed
edersonbrilhante pushed a commit that referenced this pull request Jul 31, 2026
🤖 I have created a release *beep* *boop*
---


##
[7.10.1](v7.10.0...v7.10.1)
(2026-07-31)


### Bug Fixes

* **control-plane:** discard malformed SQS messages
([#5219](#5219))
([8ca5816](8ca5816))
* enable Octokit throttle retry and SSM adaptive retry under burst
([#5136](#5136))
([cbdd916](cbdd916)),
closes
[#5135](#5135)
* **lambda:** bump axios from 1.17.0 to 1.18.0 in /lambdas
([#5211](#5211))
([67bfdf8](67bfdf8))
* **lambda:** bump js-yaml from 3.14.2 to 3.15.0 in /lambdas
([#5212](#5212))
([facea4e](facea4e))
* **lambda:** bump postcss from 8.5.15 to 8.5.22 in /lambdas
([#5231](#5231))
([8ee045d](8ee045d))
* **lambda:** fail-open isJobQueued — assume queued on API errors
([#5130](#5130))
([8fa06ee](8fa06ee))
* **scale-up:** return partial runner creation results
([#5220](#5220))
([9045340](9045340))
* stop a malformed SQS body from poisoning the whole batch
([#5215](#5215))
([69e06b1](69e06b1))

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

isJobQueued check races with SQS visibility timeout and label-based runner assignment, silently dropping jobs

3 participants