Skip to content

chore(ci): run bazel-test-all on Bazel Remote Execution @ Namespace - #12052

Merged
basvandijk merged 5 commits into
masterfrom
bas/ci-bazel-test-all-namespace-flip
Nov 13, 2026
Merged

basvandijk merged 5 commits into
masterfrom
bas/ci-bazel-test-all-namespace-flip

Conversation

@basvandijk

@basvandijk basvandijk commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Moves CI Main's bazel-test-all (CI Main / Bazel Test All) from the self-hosted dind-large runners to Bazel Remote Execution (RBE) @ Namespace. The new job is the one that ci-rbe-evaluation.yml has run, non-blocking, on every same-repo PR, merge-queue run and master push, rehearsed since #12032. On release builds it now does the real artifact upload and Attest instead of the dry run.

Before merging: create the Namespace runner profile rbe-driver-amd64-linux-16x32-no-cache: a copy of rbe-driver-amd64-linux-16x32 without the cache volume (see Security). Also see the sign-offs listed there.

What changes

  • bazel-test-all (ci-main.yml): the evaluation job's body, with the same id, name, needs and environment as before.
    • It runs on namespace-profile-rbe-driver-amd64-linux-16x32 in the nscr.io mirror of ic-build, the same image as the RBE workers. container-autobuild rewrites both pins.
    • Build step: uploads execlogs-bazel-build, which build-determinism compares with build-ic, now RBE against dind.
    • Release builds: Configure AWS credentials, then Upload artifacts through the Namespace bazel wrapper (credentials only in the uploader's step, --check_up_to_date), then Attest. Then the test step.
  • Fork PRs: ci-main.yml gets an untrusted-code input, which only ci-kickoff-manual.yml sets. With it, bazel-test-all runs on the -no-cache profile, see Security.
  • System-tests: CI Main runs only the _local variants, on every event (--exclude_tags=farm_system_test). PULL_REQUEST_BAZEL_TARGETS lists only _local variants, and check-pull-request-bazel-targets passes the same exclusion, so a re-added _farm* entry fails the check.
    • Of the Farm variants, only those of system_test_large tests (release-testing) and of the tests the nightly workflows select keep running.
    • The roughly 210 other _farm/_farm_colocate targets that CI Main ran until now run nowhere. This is the accepted decision to drop Farm from CI Main; .github/CI_README.md now says so.
    • Tests tagged system_test_large, which include the _head_nns variants of most system-tests, stay excluded from CI Main. Their _local variants (16 tests at 81b768b) ran only in the nightly local-system-tests.yml, which this PR deletes. Now only their Farm variants run, in release-testing.
  • Removed: ci-rbe-evaluation.yml, and from ci-kickoff.yml its job and the shadow rbe-build-determinism job. Also the nightly local-system-tests.yml, which ran all _local system-tests on one dind runner in about 5.5 hours.
  • githubstats: the tests of this job are bazel-test-all-bazel-test-<attempt>, whose logs come from the <job>-logs artifact. The evaluation's bazel-test-all-rbe-bazel-test-<n> stays recognized for older rows.
  • Docs and comments: rbe.bazelrc, .github/CI_README.md (new "Where the tests run"), the fix-flaky-tests skill, rs/tests/README_NEW.md, the githubstats help, and the arm64 job's ic-private gate.

Two additions for reliability

The job becomes required on PRs, the merge queue, master and the daily rc branches. Over the 14 days 2026-10-26..11-09 (first attempts), the evaluation job failed where dind passed:

RBE-only failures dind-only failures Job time, median (min): RBE vs dind
Master pushes 10 / 92 3 / 92 52* vs 80
Merge queue 2 / 108 0 / 108 9 vs 14
PRs 3 / ~280 0 15 vs 24

* Without the real upload: the evaluation only did a dry run of about 30 s. With the upload (about 27 min), master runs will take about as long as on dind. Build plus test alone take 48 min on RBE against 52 on dind.

The 10 master failures had these causes:

  • 6 runs on Nov 3 hit the 120-minute test timeout:
    • 3 (14:27-14:52Z) lost inputs, and bazel's whole-command retry then ran out of time. chore(ci): try action rewinding for lost inputs in the RBE evaluation job #12044's action rewinding targets this case, but it hasn't been exercised yet, because no inputs were lost since it landed.
    • 3 (15:58-16:01Z) were still in their first attempt at 120 minutes on a saturated cluster: 2 lost no inputs at all, 1 lost inputs but didn't get to retry. A master run's test step that afternoon passed after 118 minutes.
  • 4 runs (Oct 26 and 29): bazel exited with 34 after Namespace infrastructure errors ("Remote Execution Failure", "UNAVAILABLE: connection error"), which bazel doesn't retry. Three were in the test step, one in the build step.

So this PR adds:

  1. One rerun on exit code 34: the build and test commands run once more when bazel exits with 34 (.github/actions/bazel-namespace/rerun-on-remote-error.sh).
    • The rerun waits a minute first, reuses what the first attempt built and the tests that passed, and is announced by a warning annotation.
    • It is skipped when the first attempt reported a test that FAILED or hit its TIMEOUT, because exit 34 outranks test failures and a rerun could turn a real failure green.
    • It is also skipped when less than 15 minutes of the step's timeout are left.
  2. Timeouts: test step 190 min (bazel 180), job 415. The steps' timeouts sum to 405, and Namespace's enterprise plan allows 24-hour instances.
    • A test step of a master run usually takes 25-40 min. On a saturated cluster a single attempt took up to about 120, so 180 leaves room for a rerun of what such an attempt didn't complete.
    • Capacity itself is unchanged: each job claims the cluster with --jobs=480.

Security

  • Fork PRs: reviewed PRs from forks (ci-kickoff-manual.yml) now run this job on Namespace. They run as workflow_dispatch runs on master, and the rbe-driver profile's cache volume is committed by runs on master. Master and rc release builds start from that volume: the Bazel repository cache, the container image cache and the tool caches. So untrusted code in that privileged container could write that volume.
    • With untrusted-code, these runs use the -no-cache profile, which has "Cache Volumes" disabled. Until that profile exists, their Bazel Test All waits for a runner, which fails safe.
    • The profile keeps "Bazel Caching", which RBE needs. So these runs still share Namespace's Bazel cache (CAS, action cache) with internal PRs, master and release builds, and can write it, as the dind job does today with the DFINITY cache (--remote_upload_local_results). The evaluation never ran for fork PRs.
    • We're asking Namespace for separate Bazel caches for fork PRs, internal PRs and master/release builds, enforced on their side (their issue NSL-8566). Branch rules alone wouldn't separate fork-PR runs, which run on master, so a per-profile setting would suit us.
  • ic-private: hotfix code from ic-private is now built on RBE. It shares the workspace's CAS/action cache and Namespace's Build Event Service with public builds, as dfinity/ic-private#139 showed (902 of 1,315 actions were cache hits). Hotfix release builds upload from Namespace with ic-private's AWS role; Attest stays skipped there.
  • Open sign-offs from the plan:
    • the security OK for the two points above;
    • infra's confirmation that the upload role and the S3/R2 bucket policies have no source-IP or runner conditions. The first real upload from Namespace will show it.

Not exercised before the merge

  • The real upload to S3/R2 from Namespace: so far only dry runs. The first master push after the merge is the first real one, and the next morning's rc branch (cut at about 03:20Z) is the first rc. If the upload fails, merging isn't affected, but that commit's artifacts are missing until a rerun.
  • The ~27-minute upload between build and test: Bazel extends leases only during a command, so on master and rc runs the test step may see more lost inputs than the evaluation did with its 30-second dry run.
    • Rewinding recovers them if Namespace's action cache never returns results whose blobs are gone. That still has to be confirmed with Namespace. If it does return such results, the test fails with "lost input too many times" (exit 1), which the rerun doesn't cover.
    • Each bazel command that rewound gets one "Action rewinding" warning, with the count.
  • Fork-PR runs on the -no-cache profile, and hotfix builds of ic-private (upload with ic-private's AWS role).

Other effects

  • DFINITY remote cache: the dind job was the main writer of bazel-remote.idx. Developers and the remaining dind jobs (e.g. release-testing's qualification and release system tests, which build --config=stamped) will get fewer cache hits, so their builds get slower. Watch the first rc's dind job durations, and add a warmer job if needed.
  • Log attribution after a rerun: githubstats' last attributes the -logs artifact by run and job, so after a rerun the logs of a test that ran in both commands are the rerun's.

Merging and rollback

  • When: merge early in the day and tell the release owner. Then watch the first master run: Upload artifacts with '172' artifacts uploaded, Attest, Build Determinism. Then watch the next rc's Release Testing.
  • Rollback: revert this PR. chore(ci): rehearse the move of bazel-test-all to Namespace RBE in the evaluation job #12032's pieces work on dind too.
  • If only the upload or Attest failed: gh run rerun <run> --failed is safe, because the uploader's rclone refuses to change existing files.

Testing

  • This PR's CI runs (labeled CI_ALL_BAZEL_TARGETS): 42629014989 (4fd2858), 42637000380 (62b81bd) and 42644461118 (0795c3b) passed, with no reruns, rewinds or lost inputs. Numbers of the first:
    • Bazel Test All took 40 min on Namespace: 6 min build, 33 min tests. All 1,159 tests passed, 1 of them flaky.
    • Build Determinism compared 34,253 artifacts with no mismatches.
    • Check PULL_REQUEST_BAZEL_TARGETS passed with the exclusion.
    • The artifacts were bazel-test-all-bazel-test-1-bep/-logs, bazel-test-all-bazel-build-1-bep, execlogs-bazel-build and bazel-targets.
  • The third run shows a busy afternoon: its tests took 82 min (15:32-16:54Z), although only 231 of the 1,159 ran and the rest were cached.
    • System tests waited at Namespace for up to about 53 min before they started. For 10 minutes, none of the 43 actions in flight ran.
    • In dfinity/ic, 4-7 RBE test steps ran at the same time, 2-3 of them for master pushes. Two of those master runs' test steps took 85 and 101 min.
  • The run of the latest commits (43233278183 for e40d342: master merged in, the nightly deleted) passed. Bazel Test All took 42 min (6 min build, 35 min tests, 14:10-14:45Z): all 1,160 tests passed, 408 of them ran, with no reruns, rewinds or lost inputs. Build Determinism again compared 34,253 artifacts with no mismatches.
  • bazel test //ci/githubstats:query_test //ci/githubstats:query_help_test passes. The tests cover both RBE job names.
  • ci/scripts/targets.py check --exclude_tags=farm_system_test passes on the new PULL_REQUEST_BAZEL_TARGETS.
  • //pre-commit ruff, shfmt, DFINITY-capitalization and do-not-merge checks pass.
  • actionlint 1.7.7 on ci-main.yml and ci-kickoff.yml reports nothing that master doesn't.
  • rerun-on-remote-error.sh against a fake bazel, both as GitHub runs it and under bash -e:
    • exit codes 34 then 0, 3 or 34: one rerun, returning its code;
    • 34 with a FAILED or TIMEOUT test (also with a single attempt), or with 10 min left: no rerun, keeps 34;
    • 34 with only INCOMPLETE, REMOTE FAILURE, flaky or passed tests: one rerun;
    • 3, 0 and 124: no rerun.

🤖 Generated with Claude Code

CI Main's bazel-test-all now runs what the evaluation job of ci-rbe-evaluation.yml rehearsed
since #12032. It runs on a Namespace runner, builds and tests on Namespace's RBE cluster, and
uploads and attests the artifacts of release builds (a real upload instead of the dry run). It
replaces the dind-large job, so CI Main now runs the `_local` variants of system-tests on every
event instead of the Farm ones.

* ci-main.yml: the new bazel-test-all keeps the id, name, needs and environment. Its timeouts
  leave room for a rerun of the test command (test step 160/150 minutes, job 385; Namespace's
  enterprise instances run for up to 24 hours). The build and test commands run once more when
  bazel exits with 34, a remote execution error at Namespace that bazel doesn't retry itself
  (.github/actions/bazel-namespace/rerun-on-remote-error.sh). check-pull-request-bazel-targets
  passes --exclude_tags=farm_system_test.
* Removes ci-rbe-evaluation.yml, and from ci-kickoff.yml its job and the shadow
  rbe-build-determinism job: build-determinism now compares the RBE build with build-ic.
* PULL_REQUEST_BAZEL_TARGETS lists only the `_local` variants.
* ci/githubstats: recognizes the new job name bazel-test-all-bazel-test-<attempt>.
* Docs and comments: rbe.bazelrc, .github/CI_README.md, local-system-tests.yml, the
  fix-flaky-tests skill, repro-check, rs/tests/README_NEW.md and the arm64 gate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@basvandijk basvandijk added the CI_ALL_BAZEL_TARGETS Runs all bazel targets label Nov 9, 2026
@basvandijk
basvandijk requested a balanced review from Copilot November 9, 2026 13:50
@github-actions github-actions Bot added the chore label Nov 9, 2026

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.

🔵 Needs a closer look

The release-critical Namespace migration leaves real S3/R2 uploads, private hotfix-role uploads, and lost-input recovery unexercised, requiring release-owner validation and monitoring of the first master and RC runs.

No open issues 🎉

What changed in this PR

Moves CI Main’s required bazel-test-all job from dind runners to Namespace Bazel Remote Execution, promoting the rehearsed evaluation setup into the main build, test, and release-artifact pipeline.

Changes:

  • Migrates builds, tests, artifact uploads, and attestation to Namespace, with one retry for remote-error exit code 34 and increased timeouts.
  • Selects only _local system-test variants in CI Main and removes the evaluation workflow and shadow determinism job.
  • Updates log lookup, tests, and documentation for the new job while preserving historical log-name support.
File Description
rs/​tests/​README_NEW.md Documents Namespace test-log retrieval.
PULL_REQUEST_BAZEL_TARGETS Removes explicit Farm variants and documents local-only validation.
ci/​scripts/​repro-check Updates the runner explanation in a comment; behavior is unchanged.
ci/​githubstats/​query.py Recognizes current and historical Namespace test-job names.
ci/​githubstats/​query_test.py Covers both Namespace job-name formats.
.github/​workflows/​local-system-tests.yml Clarifies nightly test coverage in comments.
.github/​workflows/​ci-rbe-evaluation.yml Removes the superseded evaluation workflow.
.github/​workflows/​ci-main.yml Migrates the required job to Namespace and updates timeouts and target filtering.
.github/​workflows/​ci-kickoff.yml Removes evaluation and shadow determinism jobs.
.github/​CI_README.md Documents test backends and log locations.
.github/​actions/​bazel-namespace/​rerun-on-remote-error.sh Adds a single retry for Bazel exit code 34.
.github/​actions/​bazel-namespace/​rbe.bazelrc Updates comments to reflect the production workflow.
.claude/​skills/​fix-flaky-tests/​SKILL.md Updates debugging guidance for local and Farm system tests.

Review effort: Balanced

From an independent review of this PR:
* Reviewed PRs from forks (ci-kickoff-manual.yml) run as workflow_dispatch runs on master, and the
  rbe-driver profile's cache volume is committed by runs on master. Master and rc release builds
  start from that volume. So bazel-test-all now runs untrusted code (the new `untrusted-code`
  input of ci-main.yml, which only ci-kickoff-manual.yml sets) on a copy of the profile without
  a cache volume: namespace-profile-rbe-driver-amd64-linux-16x32-no-cache.
* rerun-on-remote-error.sh: no rerun when the first attempt reported a FAILED test (exit code 34
  outranks test failures, and the rerun could turn a real failure green), or when less than 15
  minutes of the step's timeout are left. It waits a minute before the rerun, and turns -e off.
* The test step gets 190/180 minutes and the job 415: on 2026-11-03 single attempts took up to
  120 minutes on a saturated cluster, so 150 left no room for a rerun.
* Docs: most Farm variants no longer run in CI, the job streams to Namespace's dashboard, the
  githubstats example. The comment change in repro-check is reverted, so the PR doesn't need
  another code owner.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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.

🟡 Changes recommended

The retry guard omits Bazel’s TIMEOUT summaries, allowing an infrastructure retry after exit 34 to reset exhausted test attempts and potentially turn a failing job green.

1 open issue

Review effort: Balanced

Bazel's test summary reports a test that hit its timeout in all its attempts as TIMEOUT, not FAILED.
After an exit code 34 the rerun would give such a test a fresh set of attempts and could turn the
job green, so rerun-on-remote-error.sh now also skips the rerun when the first attempt reported a
TIMEOUT. (Copilot's review)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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.

🔵 Needs a closer look

Security and infrastructure sign-offs remain open for shared fork/private caches, while production uploads, upload-policy compatibility, and no-cache fork runs remain unverified.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@basvandijk
basvandijk marked this pull request as ready for review November 10, 2026 09:52
@basvandijk
basvandijk requested a review from a team as a code owner November 10, 2026 09:52
Comment thread .github/workflows/ci-main.yml Resolved
basvandijk and others added 2 commits November 12, 2026 13:58
CI Main's Bazel Test All now runs the `_local` system-tests on Bazel Remote Execution @ Namespace, so the
nightly that ran all of them on one dind runner (about 5.5 hours) is no longer needed.

What only the nightly ran: the `_local` variants of the system-tests tagged `system_test_large`, which
include the `_head_nns` variants of most system-tests (16 tests at 81b768b). Their Farm variants keep
running in release-testing. CI_README now says so, and the githubstats example no longer mentions the
nightly's BuildBuddy logs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 14:03

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.

🔵 Needs a closer look

Security sign-off for fork/private builds sharing Namespace CAS/BES, confirmation of the no-cache runner profile, and infrastructure validation of real release uploads and attestations remain outstanding.

No open issues 🎉

Review effort: Balanced

@basvandijk
basvandijk added this pull request to the merge queue Nov 13, 2026
Merged via the queue into master with commit 3361b86 Nov 13, 2026
41 checks passed
@basvandijk
basvandijk deleted the bas/ci-bazel-test-all-namespace-flip branch November 13, 2026 15:28
q-uint pushed a commit to Swiss-Subnet/ic that referenced this pull request Nov 17, 2026
…es_test_local (dfinity#12116)

`ic-recovery` now stops the crypto vault (`ic-crypto-csp.socket` and
`ic-crypto-csp.service`) right after `ic-replica`. It starts the vault
again only after it has re-run `setup-permissions`, which hands the
replaced `ic_state` to `ic-replica`. So, as at boot, the vault is not
running while `setup-permissions` runs. The commands are two shared
constants in `ic_recovery::steps`:

```sh
# CMD_STOP_REPLICA
sudo systemctl stop ic-replica && sudo systemctl stop ic-crypto-csp.socket ic-crypto-csp.service;
# ... replace ic_state, or the CUP and the registry local store ...
# CMD_RESTART_REPLICA
sudo systemctl restart setup-permissions;
sudo systemctl start ic-crypto-csp.socket ic-crypto-csp.service;
sudo systemctl start ic-replica;
sudo systemctl status ic-replica;
```

Every step that stops the replica uses `CMD_STOP_REPLICA`:
- `UploadStateAndRestartStep`, in both `Remote` and `Local` mode;
- `UploadCUPAndTarStep`;
- `StopReplicaStep`, the first step of both NNS recoveries;
- the subnet merging tool's `StopReplicaAtHaltingCheckpointStep`.

`UploadStateAndRestartStep` and `UploadCUPAndTarStep` then restart the
node with `CMD_RESTART_REPLICA`. That covers app subnet recovery, NNS
recovery (failover nodes and same nodes) and subnet splitting. The
subnet merging tool only stops nodes and never runs
`CMD_RESTART_REPLICA`: the source subnet's node stays stopped, and the
destination subnet's node stays stopped until the merged state is
uploaded to it, which isn't a step of the tool yet.

## Root cause

The flaky test `sr_nns_failover_nodes_test` fails because the replica on
the upload node crash-loops after the recovery and never becomes
healthy. It panics every ~10 s until the 600 s test timeout:

```
Failed to init state layout: IoError { path: "/var/lib/ic/data/ic_state/page_deltas", message: "Failed to create directory", ... PermissionDenied }
```

Sequence of events, taken from the upload node's journal in the failed
run of 2026-11-14:

1. The orchestrator starts the replica on the recovery CUP (09:28:37.8).
2. `UploadStateToChildNNSHost` rsyncs the state as `admin` into
`new_ic_state`, so all its files are owned by `admin`. It then runs
`systemctl stop ic-replica` (09:28:39.634) and swaps `new_ic_state` in
as `ic_state`.
3. It runs `systemctl restart setup-permissions; systemctl start
ic-replica; systemctl status ic-replica`.
4. `setup-permissions.sh` runs with `set -e` and `find <dir> | xargs
chown/chmod` for one directory after another. While it walked
`/var/lib/ic/crypto`, the secret key store's temporary files vanished:
   ```
chown: cannot access '/var/lib/ic/crypto/sks_data.pb.tmp': No such file
or directory
chown: cannot access '/var/lib/ic/crypto/sks_data.pb.old': No such file
or directory
setup-permissions.service: Main process exited, code=exited,
status=123/n/a
   ```
The script aborted before it reached `ic_state`, so `ic_state` stayed
owned by `admin`. Since dfinity#9281, `setup-permissions` is the only thing
that hands the uploaded state to `ic-replica`, so this abort is fatal.
5. Because the commands are joined by `;`, `ic-replica` was started
anyway and the step reported success ("NNS recovery has finished"). The
replica then crash-loops on the `admin`-owned `ic_state`.

Why the files vanished: only `ic-replica` was stopped. The crypto vault
is a separate, socket-activated unit, so it kept running. When the
replica disconnects, the vault drops the replica's queued requests, but
a request that is already running on its thread pool runs to completion.
Such a request ends with a crash-safe rewrite of `sks_data.pb`: it
creates a hard link `sks_data.pb.old`, writes and fsyncs
`sks_data.pb.tmp`, renames it over `sks_data.pb`, and then removes
`.old`. `find` listed both temporary names, and they were gone by the
time `chown`/`chmod` ran.

The likely trigger is the forward-secure key update that the replica's
DKG key manager starts on its first start on the recovery CUP. This is
inferred from timing, because the vault logs that operation only at
debug level. On the failover nodes this update moves the key from about
epoch 1 to epoch 8, which is expensive and ends with a key store write.
In the failed runs, the tool stopped the replica 1.7 s and 1.9 s after
that work started, and the write landed about 0.4 s after the stop,
while `setup-permissions` was walking `/var/lib/ic/crypto`. In the
passing retries, the stop came 3.8 s and 13.8 s after, when the write
was already done. `WaitForCUP` polls every 15 s, so this gap is
effectively random, which fits a flake rate of about 1%. The fix doesn't
depend on which vault request does the write.

Evidence:
- The same chain appears in three failures:
`sr_nns_failover_nodes_test_local` on 2026-11-14 (master),
`sr_nns_failover_nodes_test_head_nns_local` on 2026-11-09 (dfinity#12052), and
`sr_nns_failover_nodes_test_head_nns_farm_colocate` on 2026-10-29
(master). Older failures no longer have logs.
- ElasticSearch has VM logs since 2026-09-10. In that time, about 15.8k
Farm testnets ran `systemctl restart setup-permissions`, and
`setup-permissions.service` failed only 4 times. All 4 were on the
upload node of `sr_nns_failover_nodes_test`, right after this restart,
with `sks_data.pb.tmp`/`.old` vanishing. Three of them hit the race only
in the final `restorecon` pass, after `ic_state` had already been
re-owned, so those tests passed.

## Why fix it in `ic-recovery`

- Recoveries run against nodes on GuestOS versions that are already
deployed, and a broken subnet can't be upgraded before it is recovered.
Fixing the tool makes `Remote` recoveries safe as soon as operators use
the new binary, without any GuestOS change. `Local` mode uses the
image's `/opt/ic/bin/ic-recovery`, so it gets the fix with new GuestOS
versions. For the same reason, making systemd stop the vault together
with `ic-replica` through unit dependencies would only help nodes that
already run a GuestOS version with the changed units.
- `ic-replica` is stopped first, and its processes are the vault's only
clients. Stopping the vault after it guarantees that nothing in
`/var/lib/ic/crypto` changes while `setup-permissions` runs. This
restores the boot-time order: `ic-crypto-csp.service` is ordered after
`generate-ic-config.service`, which is ordered after
`setup-permissions.service`. The socket is stopped as well, so that a
connection can't socket-activate the vault in the meantime.
`rs/tests/consensus/node_registration_test_common` and
`rs/tests/node/ipv4_integration_test.rs` already stop and start the
vault the same way, after `ic-replica`.
- The stop commands are joined by `&&`: the vault is only stopped once
`ic-replica` is down. A failed replica stop still fails the steps that
run `CMD_STOP_REPLICA` as a command of its own, as before. In
`UploadCUPAndTarStep`'s script the remaining commands still run after a
failed stop, also as before. The restart commands are joined by `;`: the
node always ends with the vault and the replica started again, and the
step's exit status doesn't change. Failing the step when
`setup-permissions` fails is left out on purpose, because
`--skip-prompts` retries a failing step forever.

**Note for crypto reviewers:** a vault request that is still running for
the replica that was just stopped is now killed right away, because the
vault has no SIGTERM handler. This is the same as a crash or a reboot.
Key store writes are crash-safe: a leftover `sks_data.pb.old` is cleaned
up when the store is opened, and a leftover `sks_data.pb.tmp` is
replaced at the next write.

## Verification

- `cargo check --all-targets --all-features -p ic-recovery -p
ic-subnet-merging`, `cargo fmt` and `./ci/scripts/rust-lint.sh` (in the
dev container, exit 0) pass. `//rs/recovery:recovery` and
`//rs/recovery/subnet_merging:subnet_merging` build, and the 6 tests
within 2 reverse-dependency levels of the changed files pass.
- The rendered commands were checked with a fake `sudo` in `bash` and
`sh`.
- If `stop ic-replica` fails, `CMD_STOP_REPLICA` doesn't stop the vault
and exits 1.
- If `restart setup-permissions` fails, the vault and `ic-replica` are
still started.
- **Current revision:** `bazel test --test_output=errors
--runs_per_test=3 --jobs=3
//rs/tests/consensus/subnet_recovery:sr_nns_failover_nodes_test_local`
passed 3 of 3 runs.
- In each run, the upload node's journal shows `Stopped
ic-replica.service` → `Stopped ic-crypto-csp.service` → `Closed
ic-crypto-csp.socket` → (state swap) → `Starting
setup-permissions.service` → `Restoring SELinux security contexts in
/var/lib/ic` → `Finished setup-permissions.service` → `Started
ic-crypto-csp.service` → `Started ic-replica.service`. There are no
`cannot access` errors.
- The test's first step, `StopReplica`, also ran `CMD_STOP_REPLICA` on
the broken NNS's download node, and the downloads from that node
succeeded.
- **Current revision, PR CI:** for changes to `rs/recovery/src/*.rs`,
`PULL_REQUEST_BAZEL_TARGETS` selects the recovery system tests,
`long_test` or not. This PR's `CI Main / Bazel Test All` run on
a90509a passed all 19 such targets:
- the `_local` and `_head_nns_local` variants of
`sr_nns_failover_nodes_test`;
- the same two variants of the five `sr_app_no_upgrade_*` tests,
including `Local` mode in `sr_app_no_upgrade_locally_test` and the
`recovery` user in `sr_app_no_upgrade_provision_write_access_test`;
  - the same two variants of the three `sr_app_same_nodes_*` tests;
  - `subnet_splitting_test_local`.

I also ran `sr_app_no_upgrade_locally_test_local` locally, on top of
master at 196bea3. On the node where the image's `ic-recovery` ran,
the journal shows the same order as above.
- **Current revision on top of master at 196bea3, covering what PR CI
doesn't run:**
- **Forced-race A/B, fix arm:** with the loop described below,
`sr_nns_failover_nodes_test_local` passed 2 of 2 runs. The loop was in
the vault's cgroup before the step and was killed by `CMD_STOP_REPLICA`
before the state swap. `setup-permissions` then completed with no
`cannot access` errors.
- **`nr_broken_dfinity_node_farm` passed.** It exercises the same-nodes
NNS recovery's `StopReplica`, `UploadState` and `UploadCUPAndRegistry`
(`UploadCUPAndTarStep`).
- On the DFINITY-owned node these steps ran on, the journal shows the
vault stopped and its socket closed before both `setup-permissions`
restarts, and both finished.
- The test recovers its other two nodes with
`guestos-recovery-upgrader`. They restart `setup-permissions` from
`guestos-recovery-engine`, which this PR doesn't change, and those
restarts finished too.
- **`nr_locally_farm` passed.** It runs the same steps through the
image's `/opt/ic/bin/ic-recovery` on the node itself (`Local` mode),
with the same pattern on that node.
- **`subnet_cooling_down_test_local` passed.** The subnet merging tool's
`StopReplicaAtHaltingCheckpointStep` stopped `ic-replica`, the vault and
its socket on both download nodes, and the state downloads and
validation that follow succeeded.
- **First revision of this PR, which stopped the vault right before
`setup-permissions`, on Farm (`_farm_colocate`):**
- **Plain runs:** 2 of 3 passed. The third timed out in `WaitForCUP`
before any changed code ran, because the file-server VM serving
`registry.tar` never became reachable. In about 820 earlier Farm runs of
this test, that VM never stayed unreachable like this; it came up after
at most 132 s.
- **Forced-race A/B:** right before `UploadStateToChildNNSHost`, a
test-only change (not part of this PR) starts a root loop on the upload
node. The loop joins `ic-crypto-csp.service`'s cgroup and keeps deleting
and recreating 200 files in `/var/lib/ic/crypto/churn`, so it dies
exactly when the vault is stopped.
- master + loop: 2 of 2 runs failed exactly like the flaky runs (`chown:
cannot access '/var/lib/ic/crypto/churn/...'`, `status=123`, the replica
crash-looping on `Failed to init state layout ... PermissionDenied`, the
600 s timeout).
- fix + loop: 3 of 3 runs passed, with the vault and the loop stopped
before `setup-permissions` ran.
- **Not run by PR CI:**
- `subnet_cooling_down_test`, the only system test of the subnet merging
tool, is a `long_test` that `PULL_REQUEST_BAZEL_TARGETS` doesn't select,
so it only runs with the `CI_ALL_BAZEL_TARGETS` label.
- `sr_app_failover_nodes_*`,
`sr_app_large_no_upgrade_with_chain_keys_test` and the nested `nr_*` NNS
recovery tests (except `nr_large_with_mainnet_state`, which is `manual`)
are `system_test_large` with `backend = "farm"`. They only run on Farm
in release testing.

## Possible follow-ups (not in this PR)

- Make `setup-permissions.sh` tolerate paths that vanish while it runs,
as defense in depth for new GuestOS images.
- Let `ic-recovery` report a failed `setup-permissions`. Today a failure
only shows up in the node's journal. Doing this needs a decision on how
`--skip-prompts` should handle retries.
- `guestos-recovery-engine.sh` calls `perform_recovery` as an `if`
condition. That suspends `set -e` inside the function, so a failed
`systemctl restart setup-permissions` there goes unnoticed.
- `setup_file_server` in `sr_nns_failover_nodes_test` doesn't wait until
`registry.tar` is actually served. A file-server VM that never comes up
therefore only shows up as the 600 s test timeout.

This PR was created following the steps in
`.claude/skills/fix-flaky-tests/SKILL.md`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
q-uint pushed a commit to Swiss-Subnet/ic that referenced this pull request Nov 26, 2026
…#12259)

`//rs/nns/governance:governance_integration_test` flaked in about 7% of
its executions on Namespace RBE, and never on the self-hosted runners.
All 9 failed attempts last week died the same way. The RBE worker's
kernel OOM killer SIGKILLed the test binary, which Bazel prints as
`FAIL: ... (Killed)`.

The test's 23 TLA-checked tests run in parallel, and each started up to
10 Apalache JVMs at once (`MAX_THREADS` per `perform_trace_check` call).
So all 99 JVMs ran together, and the test needed about 33-38 GiB. RBE
workers have 64 GiB, no swap and 16 action slots. When the other actions
on the worker held another 22-31 GiB, it ran out of memory. Since dfinity#12052
moved CI Main's tests to RBE, these flakes show up in CI Main.

# Changes

- `run_apalache` in `rs/tla_instrumentation` now holds a permit from a
process-wide counting semaphore while its Apalache process runs. The
semaphore is a `std` `Mutex` and `Condvar`.
- So at most `MAX_CONCURRENT_APALACHE_PROCESSES` (8) Apalache processes
run at the same time per process. Further checks wait until one exits.
- A new `tla_instrumentation_test` target runs the crate's unit tests
under Bazel:
  - new tests of the semaphore;
  - the existing `tla_state` test, which no target ran before.

# Behaviour changes

Peak memory and wall time of `governance_integration_test` for different
limits, measured locally on 32 CPUs:

| Concurrent Apalache processes | Peak memory | Wall time |
|---|---|---|
| unlimited (before) | 33.4 GiB | 120.0 s |
| 16 | 10.9 GiB | 96.5 s |
| 8 (this PR) | 8.1 GiB | 95.7 s |
| 4 | 7.6 GiB | 166.0 s |

The limit applies to every test that checks TLA traces:
- `merge_neurons_test`;
- the `rs/nns/integration_tests` tests that call `perform_trace_check`;
- the `rs/tla_instrumentation` tests.

This PR was created following the steps in
`.claude/skills/fix-flaky-tests/SKILL.md`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants