Skip to content

fix: scope the bazel cpu reservation to the test action - #11567

Merged
basvandijk merged 1 commit into
masterfrom
bas/scope-rbe-cpu-reservation-to-test-action
Sep 14, 2026
Merged

basvandijk merged 1 commit into
masterfrom
bas/scope-rbe-cpu-reservation-to-test-action

Conversation

@basvandijk

Copy link
Copy Markdown
Collaborator

Problem

The Bazel Build with RBE step of the CI RBE Evaluation workflow times out on
essentially every push to master:

[36,930 / 36,936] [Sched] Compiling Rust bin icp_features (2 files); 5239s ... (3 actions, 0 running)
Error: The action 'Bazel Build with RBE' has timed out after 90 minutes.

The action is not compiling slowly — it never starts. [Sched] is Bazel's marker
for queued on the remote executor, the number next to it is queue time, and
0 running confirms nothing is executing. The build reaches 36,926 of 36,936
actions in 46 minutes and then spends the remaining 44 waiting. When one of these
actions did eventually get a slot it finished in about a second:

11:58:23  [36,926 / 36,936] [Sched] Compiling Rust bin unix (2 files); 4439s ... (5 actions, 0 running)
11:58:46  [36,926 / 36,936] Compiling Rust bin tests (2 files); 0s remote, remote-cache ... (5 actions, 1 running)
11:58:57  [36,928 / 36,936] Compiling Rust bin unix (2 files); 1s remote, remote-cache ...

Cause

Two things combine:

  1. A target-level exec_properties applies to every action the target owns,
    not just the test run. So on a rust_test, exec_properties = {"cpu": "16"}
    also lands on the Rustc action that compiles the test binary. The cpu:n
    tag that chore: set bazel cpu reservation via exec_properties instead of via the cpu:n tag #10786 replaced only ever affected the test action, so that PR
    widened the reservation without meaning to.
  2. Namespace RBE workers run 16 actions concurrently (hence --jobs=240 for
    15 workers). An action asking for cpu: 16 therefore only fits on a
    completely drained worker, which under cluster load essentially never happens.

The cpu: 8 targets in the same build are unaffected and compiled in 16–27s
throughout, which confirms the threshold is the worker size rather than target
complexity:

target cpu outcome
pocket-ic-server-head-nns 8 compiled in 25s
neuron_test 8 compiled in 16s
upgrade_canister_test 8 compiled in 0–11s
icp_features, icp_features-head-nns 16 starved 87 min → timeout

This has been failing on every master push since rustc: 1.97.1 -> 1.98.1
(#11534) landed, which invalidated the Rust compile cache and forced these test
binaries to be rebuilt. Because the compiles never finish they never populate the
CAS, so each run retries from scratch. Earlier failures hit the Bazel Test with RBE step with the same signature (Testing //packages/pocket-ic:slow queued for
7154s).

The non-RBE Bazel Test All job is unaffected: it runs locally on one large
runner, where cpu: 16 is just a local core reservation.

Fix

Prefix the property with test. so it is scoped to the test exec group, i.e.
to the test action only, restoring the semantics of the original cpu:n tag.

This is applied to every cpu execution property, not only the ones that
currently starve — a compile action never needed the reservation, and reserving
cores for it only wastes RBE capacity.

Verification

  • bazel build //... --nobuild analyzes all 3348 targets successfully, which
    also confirms test is a valid exec group for every rule touched here
    (rust_test, rust_ic_test, the rust_test_suite variants and sh_test);
    an unknown exec group fails analysis with "Tried to set exec_properties for
    non-existent exec groups"
    .

  • bazel aquery //packages/pocket-ic:icp_features shows the reservation has
    moved off the compile action:

    Rustc              cpu-related execution_info: []
    TestRunner         cpu-related execution_info: [{'key': 'cpu', 'value': '16'}]
    
  • bazel run //:buildifier reports no formatting changes.

Follow-up

This does not by itself fix the Bazel Test with RBE step, where the test action
still asks for a whole worker and can starve the same way. Lowering those
reservations below the worker size is left to a follow-up. It may also be worth
raising the whole-worker starvation with Namespace — a scheduler with reservation
or backfill shouldn't starve a 16-CPU request indefinitely.

🤖 Generated with Claude Code

PR #10786 replaced the `cpu:n` tag with `exec_properties = {"cpu": "n"}`
so that the CPU reservation is forwarded to the Remote Execution API.
That worked, but it also widened the reservation: a target-level
`exec_properties` applies to *every* action the target owns, so on a
`rust_test` the reservation also lands on the `Rustc` action that
compiles the test binary. The `cpu:n` tag it replaced only ever affected
the test action.

On the Namespace RBE cluster this starves the build. Workers run 16
actions concurrently (hence `--jobs=240` for 15 workers), so an action
asking for `cpu: 16` only fits on a completely drained worker. With the
cluster under load that essentially never happens, and the compile
action sits in the scheduler queue instead of running:

    [36,930 / 36,936] [Sched] Compiling Rust bin icp_features-head-nns (2 files); 5221s ... (3 actions, 0 running)
    Error: The action 'Bazel Build with RBE' has timed out after 90 minutes.

Note the `[Sched]` and `0 running`: the action never started. The build
reaches 36,926 of 36,936 actions in 46 minutes and then spends the
remaining 44 waiting. When such an action did eventually get a slot it
finished in about a second, so this is queueing, not slow compilation.
The `cpu: 8` targets in the same build compiled in 16-27s throughout.

Prefixing the property with `test.` scopes it to the `test` exec group,
i.e. to the test action only, restoring the semantics of the original
`cpu:n` tag. Verified with `bazel aquery` on
`//packages/pocket-ic:icp_features`: the `Rustc` action now carries no
cpu property while the `TestRunner` action keeps `cpu: 16`.

This is applied to every `cpu` execution property, not just the ones
that currently starve: a compile action never needed the reservation,
and reserving cores for it only wastes RBE capacity.

Note that this does not by itself fix the `Bazel Test with RBE` step,
where the test action still asks for a whole worker. Lowering those
reservations below the worker size is left to a follow-up.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@basvandijk
basvandijk requested a balanced review from Copilot September 14, 2026 12:52
@github-actions github-actions Bot added the fix label Sep 14, 2026
@basvandijk basvandijk added the CI_ALL_BAZEL_TARGETS Runs all bazel targets label Sep 14, 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.

🟢 Approval recommended

The changes consistently scope all CPU execution properties to validated test exec groups without altering requested resources.

Pull request overview

Scopes CPU reservations to test actions, preventing compilation actions from unnecessarily reserving scarce RBE capacity.

Changes:

  • Prefixes CPU execution properties with test. across Rust and shell tests.
  • Documents test-action scoping in the system-test macro.
File summaries
File Description
rs/tests/system_tests.bzl Scopes computed CPU reservations to local test actions.
rs/sns/integration_tests/BUILD.bazel Scopes SNS integration-test CPU reservations.
rs/rosetta-api/icrc1/BUILD.bazel Scopes ICRC Rosetta test CPU reservations.
rs/rosetta-api/icp/tests/integration_tests/BUILD.bazel Scopes ICP Rosetta integration-test reservations.
rs/rosetta-api/icp/BUILD.bazel Scopes ICP Rosetta test reservations.
rs/pocket_ic_server/BUILD.bazel Scopes PocketIC server test reservations.
rs/nervous_system/integration_tests/BUILD.bazel Scopes nervous-system test reservations.
rs/migration_canister/BUILD.bazel Scopes migration-canister test reservations.
rs/ledger_suite/icrc1/index-ng/BUILD.bazel Scopes ICRC index test reservations.
rs/ledger_suite/icp/ledger/BUILD.bazel Scopes ICP ledger test reservations.
rs/ledger_suite/icp/index/BUILD.bazel Scopes ICP index test reservations.
rs/http_endpoints/nns_delegation_manager/BUILD.bazel Scopes delegation-manager test reservations.
rs/execution_environment/BUILD.bazel Scopes execution-environment test reservations.
rs/bitcoin/adapter/BUILD.bazel Scopes Bitcoin adapter test reservations.
packages/pocket-ic/BUILD.bazel Scopes PocketIC package test reservations.
Review details
  • Files reviewed: 15/15 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@basvandijk
basvandijk marked this pull request as ready for review September 14, 2026 12:57
@basvandijk
basvandijk requested review from a team as code owners September 14, 2026 12:57
@zeropath-ai

zeropath-ai Bot commented Sep 14, 2026

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to 5ece952.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► packages/pocket-ic/BUILD.bazel
      Change CPU exec_properties key from "cpu" to "test.cpu" for multiple rust_test invocations
► rs/bitcoin/adapter/BUILD.bazel
      Change CPU exec_properties key from "cpu" to "test.cpu"
Enhancement ► rs/execution_environment/BUILD.bazel
      Change CPU exec_properties key from "cpu" to "test.cpu" for multiple rust_ic_test invocations
Enhancement ► rs/http_endpoints/nns_delegation_manager/BUILD.bazel
      Change CPU exec_properties key from "cpu" to "test.cpu"
Enhancement ► rs/ledger_suite/icp/index/BUILD.bazel
      Change CPU exec_properties key from "cpu" to "test.cpu"
Enhancement ► rs/ledger_suite/icp/ledger/BUILD.bazel
      Change CPU exec_properties key from "cpu" to "test.cpu"
Enhancement ► rs/ledger_suite/icrc1/index-ng/BUILD.bazel
      Change CPU exec_properties key from "cpu" to "test.cpu"
Enhancement ► rs/migration_canister/BUILD.bazel
      Change CPU exec_properties key from "cpu" to "test.cpu"
Enhancement ► rs/nervous_system/integration_tests/BUILD.bazel
      Change CPU exec_properties key from "cpu" to "test.cpu" (for both rust_test_suite_with_extra_srcs and rust_test invocations)
Enhancement ► rs/pocket_ic_server/BUILD.bazel
      Change CPU exec_properties key from "cpu" to "test.cpu"
Enhancement ► rs/rosetta-api/icp/BUILD.bazel
      Change CPU exec_properties key from "cpu" to "test.cpu"
Enhancement ► rs/rosetta-api/icp/tests/integration_tests/BUILD.bazel
      Change CPU exec_properties key from "cpu" to "test.cpu"
Enhancement ► rs/rosetta-api/icrc1/BUILD.bazel
      Change CPU exec_properties key from "cpu" to "test.cpu"
Enhancement ► rs/sns/integration_tests/BUILD.bazel
      Change CPU exec_properties key from "cpu" to "test.cpu"
Enhancement ► rs/tests/system_tests.bzl
      In system_test, set exec_properties to {"test.cpu": str(reserved_cpus)} instead of {"cpu": ...}

@zeropath-ai

zeropath-ai Bot commented Sep 14, 2026

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to 5ece952.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► packages/pocket-ic/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu" for multiple rust_test targets
► rs/bitcoin/adapter/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu" for rust_test
► rs/execution_environment/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu" for rust_ic_test (multiple instances)
Enhancement ► rs/http_endpoints/nns_delegation_manager/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/ledger_suite/icp/index/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/ledger_suite/icp/ledger/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/ledger_suite/icrc1/index-ng/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/migration_canister/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/nervous_system/integration_tests/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/pocket_ic_server/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/rosetta-api/icp/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/rosetta-api/icp/tests/integration_tests/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/rosetta-api/icrc1/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/sns/integration_tests/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu" for multiple tests
Enhancement ► rs/tests/system_tests.bzl
    Update system_test to use exec_properties with "test.cpu" instead of "cpu"

@zeropath-ai

zeropath-ai Bot commented Sep 14, 2026

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to 5ece952.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/pocket_ic_server/BUILD.bazel
    exec_properties: "cpu" → "test.cpu" for 8-core test configuration
► rs/bitcoin/adapter/BUILD.bazel
    exec_properties: "cpu" → "test.cpu"
Enhancement ► rs/execution_environment/BUILD.bazel
    exec_properties: "cpu" → "test.cpu" (multiple targets)
Enhancement ► rs/http_endpoints/nns_delegation_manager/BUILD.bazel
    exec_properties: "cpu" → "test.cpu"
Enhancement ► rs/ledger_suite/icp/index/BUILD.bazel
    exec_properties: "cpu" → "test.cpu"
Enhancement ► rs/ledger_suite/icp/ledger/BUILD.bazel
    exec_properties: "cpu" → "test.cpu"
Enhancement ► rs/ledger_suite/icrc1/index-ng/BUILD.bazel
    exec_properties: "cpu" → "test.cpu"
Enhancement ► rs/migration_canister/BUILD.bazel
    exec_properties: "cpu" → "test.cpu"
Enhancement ► rs/nervous_system/integration_tests/BUILD.bazel
    exec_properties: "cpu" → "test.cpu" (multiple occurrences)
Enhancement ► rs/pocket_ic_server/BUILD.bazel
    exec_properties: "cpu" → "test.cpu"
Enhancement ► rs/rosetta-api/icp/BUILD.bazel
    exec_properties: "cpu" → "test.cpu"
Enhancement ► rs/rosetta-api/icp/tests/integration_tests/BUILD.bazel
    exec_properties: "cpu" → "test.cpu"
Enhancement ► rs/rosetta-api/icrc1/BUILD.bazel
    exec_properties: "cpu" → "test.cpu"
Enhancement ► rs/sns/integration_tests/BUILD.bazel
    exec_properties: "cpu" → "test.cpu" (multiple occurrences)
Enhancement ► rs/tests/system_tests.bzl
    exec_properties: "cpu" tag usage changed to "test.cpu" for reservation scope

@zeropath-ai

zeropath-ai Bot commented Sep 14, 2026

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to 5ece952.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► packages/pocket-ic/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu" in multiple rust_test entries
► rs/bitcoin/adapter/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/execution_environment/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu" (multiple occurrences)
Enhancement ► rs/http_endpoints/nns_delegation_manager/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/ledger_suite/icp/index/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/ledger_suite/icp/ledger/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/ledger_suite/icrc1/index-ng/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/migration_canister/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/nervous_system/integration_tests/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu" (multiple occurrences)
Enhancement ► rs/pocket_ic_server/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/rosetta-api/icp/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/rosetta-api/icp/tests/integration_tests/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/rosetta-api/icrc1/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu"
Enhancement ► rs/sns/integration_tests/BUILD.bazel
    Change exec_properties from "cpu" to "test.cpu" (in multiple blocks)
Enhancement ► rs/tests/system_tests.bzl
    Update system_test exec_properties to use "test.cpu" instead of "cpu"

@basvandijk

Copy link
Copy Markdown
Collaborator Author

Force merging this since it fixes a bug that's effecting all RBE builds and tests.

@basvandijk
basvandijk merged commit 2d299a6 into master Sep 14, 2026
82 of 86 checks passed
@basvandijk
basvandijk deleted the bas/scope-rbe-cpu-reservation-to-test-action branch September 14, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants