Skip to content

chore: set bazel cpu reservation via exec_properties instead of via the cpu:n tag - #10786

Merged
basvandijk merged 5 commits into
masterfrom
basvandijk/set-cpu-reservation-via-exec_properties
Jul 16, 2026
Merged

basvandijk merged 5 commits into
masterfrom
basvandijk/set-cpu-reservation-via-exec_properties

Conversation

@basvandijk

@basvandijk basvandijk commented Jul 15, 2026 •

Copy link
Copy Markdown
Collaborator

Bazel doesn't forward the cpu:n tag, for reserving cpu cores, to the Remote Execution API. This means that on Remote Build Execution clusters (like @ Namespace) actions don't get the minimal CPUs they specified. To fix this we replace cpu:n tags with exec_properties = {"cpu": "n"} settings which are forwarded to the REAPI and work locally as well.

Note that this is supported since bazel-9.2.0. See: bazelbuild/bazel#29419.

@basvandijk basvandijk added the CI_ALL_BAZEL_TARGETS Runs all bazel targets label Jul 15, 2026
@github-actions github-actions Bot added the chore label Jul 15, 2026
@basvandijk
basvandijk marked this pull request as ready for review July 15, 2026 17:38
@basvandijk
basvandijk requested review from a team as code owners July 15, 2026 17:38
@zeropath-ai

zeropath-ai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

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

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► packages/pocket-ic/BUILD.bazel
       Add exec_properties CPU limits (cpu: 16) to multiple rust_test blocks
Enhancement ► rs/bitcoin/adapter/BUILD.bazel
       Set exec_properties CPU to 4 (cpu: "4") for rust_test
Enhancement ► rs/execution_environment/BUILD.bazel
       Set exec_properties CPU to 4 in multiple rust_ic_test blocks
Enhancement ► rs/http_endpoints/nns_delegation_manager/BUILD.bazel
       Set exec_properties CPU to 4 for rust_test
Enhancement ► rs/ledger_suite/icp/index/BUILD.bazel
       Set exec_properties CPU to 4 for rust_ic_test
Enhancement ► rs/ledger_suite/icp/ledger/BUILD.bazel
       Set exec_properties CPU to 4 for rust_ic_test
Enhancement ► rs/ledger_suite/icrc1/index-ng/BUILD.bazel
       Set exec_properties CPU to 4 for rust_test (and remove cpu:4 tag)
Enhancement ► rs/migration_canister/BUILD.bazel
       Set exec_properties CPU to 16 for rust_test
Enhancement ► rs/nervous_system/integration_tests/BUILD.bazel
       Set exec_properties CPU to 6/8/4 across several rust_test and rust_test_suite_with_extra_srcs blocks; remove cpu: tags where present
Enhancement ► rs/pocket_ic_server/BUILD.bazel
Set exec_properties CPU to 8 for rust_test
Enhancement ► rs/rosetta-api/icp/BUILD.bazel
Set exec_properties CPU to 4 for rust_test and related test configuration
Enhancement ► rs/rosetta-api/icp/tests/integration_tests/BUILD.bazel
Set exec_properties CPU to 4 for rust_test_suite; remove cpu:4 tag where present
Enhancement ► rs/rosetta-api/icrc1/BUILD.bazel
Set exec_properties CPU to 4 for rust_test_suite_with_extra_srcs; remove cpu:4 tag where present
Enhancement ► rs/sns/integration_tests/BUILD.bazel
Set exec_properties CPU to 8 for rust_ic_test_suite_with_extra_srcs and rust_ic_test; remove cpu:8 tags where present
Enhancement ► rs/tests/system_tests.bzl
Documented change to local CPUs: exec_properties used for local variant; removed reserve_cpus computation and added explicit exec_properties in local variant when cpus is provided

@zeropath-ai

zeropath-ai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

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

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► packages/pocket-ic/BUILD.bazel
    Add exec_properties CPU settings for multiple rust_test invocations
Enhancement ► rs/bitcoin/adapter/BUILD.bazel
    Replace cpu:4 tag with exec_properties CPU setting
Enhancement ► rs/execution_environment/BUILD.bazel
    Add exec_properties CPU settings to multiple rust_ic_test invocations
Enhancement ► rs/http_endpoints/nns_delegation_manager/BUILD.bazel
    Add exec_properties CPU setting and remove cpu:4 tag from rust_test
Enhancement ► rs/ledger_suite/icp/index/BUILD.bazel
    Replace cpu:4 tag with exec_properties CPU setting
Enhancement ► rs/ledger_suite/icp/ledger/BUILD.bazel
    Replace cpu:4 tag with exec_properties CPU setting
Enhancement ► rs/ledger_suite/icrc1/index-ng/BUILD.bazel
    Add exec_properties CPU setting and remove cpu:4 tag
Enhancement ► rs/migration_canister/BUILD.bazel
    Add exec_properties CPU setting and remove cpu:16 tag
Enhancement ► rs/nervous_system/integration_tests/BUILD.bazel
    Add exec_properties CPU settings for multiple rust_test invocations and remove cpu tags where applicable
Enhancement ► rs/pocket_ic_server/BUILD.bazel
    Add exec_properties CPU setting for rust_test and remove cpu:8 tag from that section
Enhancement ► rs/rosetta-api/icp/BUILD.bazel
    Add exec_properties CPU setting and remove cpu:4 tag from rust_test
Enhancement ► rs/rosetta-api/icp/tests/integration_tests/BUILD.bazel
    Add exec_properties CPU setting and remove cpu:4 tag
Enhancement ► rs/rosetta-api/icrc1/BUILD.bazel
    Add exec_properties CPU setting and remove cpu:4 tag
Enhancement ► rs/sns/integration_tests/BUILD.bazel
    Add exec_properties CPU setting and remove cpu:8 tag in several tests
Enhancement ► rs/sns/integration_tests/BUILD.bazel
    Add exec_properties CPU setting to rust_ic_test_suite_with_extra_srcs and related tests
Enhancement ► rs/tests/system_tests.bzl
    Update system_test to document and implement exec_properties CPU forwarding for local variant; remove cpu tag usage in local variant wiring

@zeropath-ai

zeropath-ai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

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

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► packages/pocket-ic/BUILD.bazel
    Add exec_properties cpu:16 to multiple rust_test blocks
Enhancement ► rs/bitcoin/adapter/BUILD.bazel
    Replace cpu:4 tag with exec_properties cpu:4
Enhancement ► rs/execution_environment/BUILD.bazel
    Add exec_properties cpu:4 to rust_ic_test blocks
Enhancement ► rs/http_endpoints/nns_delegation_manager/BUILD.bazel
    Add exec_properties cpu:4; remove cpu:4 tag
Enhancement ► rs/ledger_suite/icp/index/BUILD.bazel
    Replace cpu:4 tag with exec_properties cpu:4
Enhancement ► rs/ledger_suite/icp/ledger/BUILD.bazel
    Replace cpu:4 tag with exec_properties cpu:4
Enhancement ► rs/ledger_suite/icrc1/index-ng/BUILD.bazel
    Replace cpu:4 tag with exec_properties cpu:4
Enhancement ► rs/migration_canister/BUILD.bazel
    Add exec_properties cpu:16; remove cpu:16 tag
Enhancement ► rs/nervous_system/integration_tests/BUILD.bazel
    Add exec_properties cpu:6; remove cpu:6 tag; multiple blocks now use exec_properties cpu:8/6/4 as applicable
Enhancement ► rs/pocket_ic_server/BUILD.bazel
    Add exec_properties cpu:8; remove cpu:8 tag
Enhancement ► rs/rosetta-api/icp/BUILD.bazel
    Add exec_properties cpu:4; remove cpu:4 tag
Enhancement ► rs/rosetta-api/icp/tests/integration_tests/BUILD.bazel
    Add exec_properties cpu:4; remove cpu:4 tag
Enhancement ► rs/rosetta-api/icrc1/BUILD.bazel
    Add exec_properties cpu:4; remove cpu:4 tag
Enhancement ► rs/sns/integration_tests/BUILD.bazel
    Add exec_properties cpu:8; remove cpu:8 tag in certain sections; adjust test suite blocks
Enhancement ► rs/tests/system_tests.bzl
    System test local variant now uses exec_properties cpu for CPU reservation; remove cpu:N tag forwarding

@zeropath-ai

zeropath-ai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

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

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► packages/pocket-ic/BUILD.bazel
       Add exec_properties CPU limits (cpu: 16) to multiple rust_test blocks
Enhancement ► rs/bitcoin/adapter/BUILD.bazel
       Set exec_properties CPU to 4 (cpu: "4") for rust_test
Enhancement ► rs/execution_environment/BUILD.bazel
       Set exec_properties CPU to 4 in multiple rust_ic_test blocks
Enhancement ► rs/http_endpoints/nns_delegation_manager/BUILD.bazel
       Set exec_properties CPU to 4 for rust_test
Enhancement ► rs/ledger_suite/icp/index/BUILD.bazel
       Set exec_properties CPU to 4 for rust_ic_test
Enhancement ► rs/ledger_suite/icp/ledger/BUILD.bazel
       Set exec_properties CPU to 4 for rust_ic_test
Enhancement ► rs/ledger_suite/icrc1/index-ng/BUILD.bazel
       Set exec_properties CPU to 4 for rust_test (and remove cpu:4 tag)
Enhancement ► rs/migration_canister/BUILD.bazel
       Set exec_properties CPU to 16 for rust_test
Enhancement ► rs/nervous_system/integration_tests/BUILD.bazel
       Set exec_properties CPU to 6/8/4 across several rust_test and rust_test_suite_with_extra_srcs blocks; remove cpu: tags where present
Enhancement ► rs/pocket_ic_server/BUILD.bazel
Set exec_properties CPU to 8 for rust_test
Enhancement ► rs/rosetta-api/icp/BUILD.bazel
Set exec_properties CPU to 4 for rust_test and related test configuration
Enhancement ► rs/rosetta-api/icp/tests/integration_tests/BUILD.bazel
Set exec_properties CPU to 4 for rust_test_suite; remove cpu:4 tag where present
Enhancement ► rs/rosetta-api/icrc1/BUILD.bazel
Set exec_properties CPU to 4 for rust_test_suite_with_extra_srcs; remove cpu:4 tag where present
Enhancement ► rs/sns/integration_tests/BUILD.bazel
Set exec_properties CPU to 8 for rust_ic_test_suite_with_extra_srcs and rust_ic_test; remove cpu:8 tags where present
Enhancement ► rs/tests/system_tests.bzl
Documented change to local CPUs: exec_properties used for local variant; removed reserve_cpus computation and added explicit exec_properties in local variant when cpus is provided

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

Thanks @basvandijk!

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

LGTM. For reference: bazelbuild/bazel#29426

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

This PR migrates CPU core reservation for Bazel tests from the cpu:n tag to exec_properties = {"cpu": "n"}, so the reservation is forwarded to Remote Execution (REAPI) and remains effective for local execution.

Changes:

  • Replaced tags = ["cpu:n"] with exec_properties = {"cpu": "n"} across multiple Rust test targets.
  • Updated the system_test macro to set CPU reservation via exec_properties for the _local variant and adjusted its documentation accordingly.

Reviewed changes

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

Show a summary per file
File Description
rs/tests/system_tests.bzl Switches local system-test CPU reservation from cpu:n tag to exec_properties.
rs/sns/integration_tests/BUILD.bazel Updates SNS integration tests to reserve CPUs via exec_properties.
rs/rosetta-api/icrc1/BUILD.bazel Updates ICRC1 rosetta test suite to reserve CPUs via exec_properties.
rs/rosetta-api/icp/tests/integration_tests/BUILD.bazel Updates ICP rosetta integration tests to reserve CPUs via exec_properties.
rs/rosetta-api/icp/BUILD.bazel Updates ICP rosetta long test to reserve CPUs via exec_properties.
rs/pocket_ic_server/BUILD.bazel Updates PocketIC server tests to reserve CPUs via exec_properties.
rs/nervous_system/integration_tests/BUILD.bazel Updates nervous system integration tests to reserve CPUs via exec_properties.
rs/migration_canister/BUILD.bazel Updates migration canister test to reserve CPUs via exec_properties.
rs/ledger_suite/icrc1/index-ng/BUILD.bazel Updates index-ng test to reserve CPUs via exec_properties.
rs/ledger_suite/icp/ledger/BUILD.bazel Updates ICP ledger test to reserve CPUs via exec_properties.
rs/ledger_suite/icp/index/BUILD.bazel Updates ICP index test to reserve CPUs via exec_properties.
rs/http_endpoints/nns_delegation_manager/BUILD.bazel Updates delegation manager test to reserve CPUs via exec_properties.
rs/execution_environment/BUILD.bazel Updates execution environment slow tests to reserve CPUs via exec_properties.
rs/bitcoin/adapter/BUILD.bazel Updates bitcoin adapter integration test to reserve CPUs via exec_properties.
packages/pocket-ic/BUILD.bazel Updates pocket-ic package tests to reserve CPUs via exec_properties.

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

Comment thread rs/tests/system_tests.bzl Outdated
Comment thread rs/tests/system_tests.bzl Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@basvandijk
basvandijk enabled auto-merge July 16, 2026 12:25
@basvandijk
basvandijk added this pull request to the merge queue Jul 16, 2026
Merged via the queue into master with commit 8349230 Jul 16, 2026
39 checks passed
@basvandijk
basvandijk deleted the basvandijk/set-cpu-reservation-via-exec_properties branch July 16, 2026 13:52
basvandijk added a commit that referenced this pull request Sep 14, 2026
## 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 #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](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

6 participants