Repository navigation
fix(ci): terminate build instances when a CI run is cancelled - #25894
Closed
iAmMichaelConnor wants to merge 1 commit into
Closed
iAmMichaelConnor wants to merge 1 commit into
iAmMichaelConnor wants to merge 1 commit into
Conversation
Closed
4 tasks
iAmMichaelConnor
force-pushed
the
mike/ci-cancel-cleanup
branch
5 times, most recently
from
November 24, 2026 19:45
0993dc3 to
4d6106c
Compare
This was referenced Nov 24, 2026
A cancelled CI3 run leaves its EC2 build instance running. The runner signals only the Run step's shell, which runs .github/ci3.sh as a child, then SIGKILLs everything left a few seconds later, so bootstrap_ec2's cleanup never runs. Merging a pull request right after opening it hits this every time: the run starts after the merge, requests an instance, and is cancelled by cancel-stale-workflows.yml. - ci3.yml, ci3-external.yml: `exec ./.github/ci3.sh`, so the signal reaches ci3.sh and, through its exec, ci.sh. - .github/ci3.sh, ci.sh (in CI): exit on INT/TERM from the start, since bash otherwise drops a SIGINT while it waits on a command. - ci.sh: multi_job_run runs the parallel pipeline in the background and passes INT/TERM on to parallel, which TERMs its jobs; bootstrap_ec2's trap then terminates their instances. A foreground pipeline would defer the trap until it ended. - .github/ci3.sh: a first-attempt run for a pull request that is already closed exits before requesting anything, and Post-Actions then does nothing.
iAmMichaelConnor
force-pushed
the
mike/ci-cancel-cleanup
branch
from
November 24, 2026 22:08
4d6106c to
bdd27be
Compare
This was referenced Nov 25, 2026
charlielye
added a commit
that referenced
this pull request
Nov 25, 2026
…king, skip closed PRs (#25900) One CI update combining #25900, #25901, #25902 and #25903, with ci3 pinned to `main` (aztec-labs-eng/ci3@bfd124d). Each part is unchanged from its PR; the only conflict was the ci3 pin. ## 1. Cancelling a run terminates its instances (was #25900) Cancelled CI runs left their build instances running until the shutdown timer. GitHub cancels a step by signalling only the process it started: SIGINT, SIGTERM 7.5s later, then SIGKILL. The workflow steps ran `./.github/ci3.sh` without `exec`, and `ci.sh` ran `bootstrap_ec2` inside `multi_job_run` and pipelines, so the signal stopped at the step's shell and never reached the script that terminates instances. **Changes** - Workflow steps now `exec ./.github/ci3.sh …`. `ci3.sh` already execs `./ci.sh`. - Every `ci.sh` mode that launches instances now `exec`s into `bootstrap_ec2`, or into ci3's new `bootstrap_ec2_multi`. `bootstrap_ec2_multi` replaces `multi_job_run` with the same behaviour, including `INSTANCE_NAME_SUFFIX` and bench-upload only on the first job. - `merge-queue` keeps its dashboard section choice, which moves from `multi_job_run` into the mode itself. - ci3 is bumped to aztec-labs-eng/ci3#30: - `bootstrap_ec2` terminates its instance on SIGINT/SIGTERM, including while the instance is still being requested. - Instances launched from a build instance (the bench box) are tagged `ParentInstance` and terminated along with it. **Testing** - The ci3 PR adds `tests/cancel_test`, which simulates the runner's signal sequence and Ctrl-C. - I also ran that harness, with a stub aws, against this branch's real chain: `bash -c 'exec ./.github/ci3.sh fast'` and `merge-queue` (two instances). Each run exits on the first SIGINT, cancels the SSM commands, and terminates every instance plus the bench child. ## 2. Nightly npm releases pack again (was #25901) Every `next` nightly since the move to the shared ci3 (#25516) has failed at its first npm package with `npm error code ENEEDAUTH`. The release build is meant to only **pack** the npm packages (`bootstrap.sh release` sets `NPM_PACK_DIR`), and the `publish-npm` job publishes the tarballs from a GitHub runner with npm trusted publishing. The shared ci3's `deploy_npm` had no pack mode, so the build machine attempted a real publish without credentials. aztec-labs-eng/ci3#31 restores it, together with the `repository` stamp npm provenance requires. Checked offline, with npm unable to reach any registry or credential: `protocol/genesis/bootstrap.sh release` packs `@aztec-foundation/protocol-genesis@7.0.0-nightly.20261126` with `repository` set to this repository and `protocol/genesis`, and `DRY_RUN=1 scripts/publish_npm_release` accepts the tarball. ## 3. Stop running ci3's own tests here (was #25902) Removes the `ci3-tests` target. ci3 now runs its tests in its own CI on every pull request and push to `main` (aztec-labs-eng/ci3#33). Running them here meant a ci3 change was only tested once a pin bump picked it up, and they ran on a build machine whose build was using the same ci3 scripts at the same time, which broke `cancel_test`'s leftover-process check. ## 4. Skip CI for a pull request that is already closed (was #25903) A pull request merged straight after it was opened gets a CI run that only starts after the merge: - **`ci3.yml`:** the run requests a build instance, then `cancel-stale-workflows.yml` cancels it. - **`ci3-external.yml`:** nothing cancels the run, so CI runs in full for a pull request that no longer needs it. **Change** - `.github/ci3.sh` now checks the pull request's state before doing anything else, and skips CI when it is closed. - It does this only on a run's first attempt, so a manual re-run still runs CI. - If anything is uncertain, CI runs as normal. That covers another event type, no PR number, or an API error or 20s timeout. - When it skips, `.github/ci3_success.sh` (Post-Actions) does nothing: it records no CI success for the tree and doesn't act on labels such as `ci-squash-and-merge`. - `ci3-external.yml`'s Run step now gets `PR_NUMBER`. `ci3.yml`'s already did. This is the `pr_closed` part of #25894, by iAmMichaelConnor, taken on its own. Part 1 replaces #25894's cancellation changes, so a cancelled run terminates its instances. This part means a closed PR's run never requests one. **Testing** I tested `pr_closed` with a stub `gh`: | Case | Result | |---|---| | Closed PR (`pull_request`) | Skips | | Closed fork PR (`pull_request_target`) | Skips | | Open PR | Runs | | API failure | Runs | | Push event | Runs | | No PR number | Runs | 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DSxF9AgGYcAcCTjXEeJT4L --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Closing as superseded by work that has now merged:
Thanks for this. It conflicts with |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Two PRs
This is one of two PRs for the same problem: build instances left running after a cancelled CI run.
ci.shcall ci3The fix needs changes in both repositories, so it is two PRs. Neither depends on the other.
Merge order
Problem
When a CI3 run is cancelled, the EC2 build instance it started keeps running. Nothing on our side terminates it, and if the run was cancelled in its first minute, the instance has no shutdown timer either.
The cancel never reaches ci3:
kill(pid)in actions/runner'sProcessInvoker.cs, not the process group)../.github/ci3.shas a child, so ci3.sh, ci.sh,parallelandbootstrap_ec2receive nothing.bootstrap_ec2's cleanup trap, which terminates the instance, never runs.This bites whenever a pull request is merged or closed straight after it is opened:
cancel-stale-workflows.ymlcancels the run, which leaves the instance running until something else removes it.A push to the same branch would normally terminate it by name, but a closed PR gets no more pushes.
Changes
ci3.ymlandci3-external.yml:run: exec ./.github/ci3.sh $CI_MODE.execs ci.sh, so the runner's signals now land on ci.sh.ci3.ymlintends ("We use exec a lot to ensure signal propagation"); the Run steps were the missing link.ci3-external.yml's Run step also now getsPR_NUMBER, for the check below. bootstrap_ec2 also passes it into the build container and instance telemetry, as it already does for internal runs; nothing there changes behaviour on it..github/ci3.shandci.sh: exit on a cancel that arrives during start-up.multi_job_runsets its trap, a cancel duringbootstrap.sh init, the PR lookup orcheck_cachewould be dropped, and the run would go on to request an instance.ci.shsets them only under GitHub Actions, so a local Ctrl-C at start-up behaves as before.multi_job_runrestores them after its own trap.ci.sh:multi_job_runpasses the signal on to its jobs.parallel | add_timestamps | cache_logpipeline.waits for it;waitreturns as soon as a trapped signal arrives.parallel, whose pid comes fromjobs -p %%.parallel's existing--termseq 'TERM,10000'then TERMs each job's process group, andbootstrap_ec2's trap terminates the instance.parallelstarts.parallelignores TERM while it starts up, so once a signal has arrived, ci.sh re-sends TERM every second until the pipeline exits.pipefailthatci3/sourcesets..github/ci3.sh: skip runs for pull requests that are already closed.pull_requestandpull_request_targetevents, ci3.sh looks up the PR state, with a 20 s timeout.check_cache, so no CI success is recorded for the tree. This applies only to a run's first attempt, so a manual re-run still runs CI. It also writesCI3_PR_CLOSED=1toGITHUB_ENV, and.github/ci3_success.sh(Post-Actions) then does nothing, so aci-squash-and-mergelabel is not acted on.ci-draftstill get CI;cancel-stale-workflows.ymlalready cancels runs when a PR is converted to draft.Limits
Behaviour change for release runs. Cancelling a tag or release run (
multi_job_run 'x-release …') now terminates its instance mid-publish. Before, the instance finished its part of the publish, butpublish-npm(needs: ci) was still skipped, so a cancelled release was already only partly published.Local runs. A local Ctrl-C during
multi_job_run's jobs now waits for their clean-up, instance termination included, beforeci.shexits.One window stays open until the ci3 bump. With the ci3 pinned on
next, a cancel that lands whilecreate-fleetis in flight still leaks. The TERM kills theawscall before the instance id is recorded, so clean-up has nothing to terminate. ci3#28 closes that window, by tagging each launch and adding the boot timer. Until the pin moves past it, the closed-PR check is what prevents those leaks.Not covered: the nightly and socket-fix workflows, where
bootstrap_ec2runs directly under ci.sh rather than throughmulti_job_run, and the chonk-input-update run inside Post-Actions. A cancel there behaves as today: before the instance is claimed, ci3#28's boot timer bounds it; after, it runs to itsAWS_SHUTDOWN_TIME.Testing
No CI was run for this; it is a draft. Local checks:
ci.sh: I imitated the runner's cancellation.multi_job_runcopied verbatim and the realparallelfrom ci3. The step was started with default signal handling, and a stand-in job's TERM trap writes a file.next, SIGINT to the step's shell alone never reaches the job.parallel's start-up, and at 3 s; at one delay the job was stopped before it started..github/ci3.sh: I ran thegh api … --jq .statelookup against real merged and open PRs.Before merging, a reviewer should:
x-fast(past the instance request), cancel the run, and check in EC2 that its instance (aztec-packages_<pr>_amd64_x-fast) is terminated within a few seconds;Related
Related CI fixes:
ci-external-oncerequireswatchersmembership, likeci-external.envas this PR.