Skip to content

Make local scheduling respect exec_properties resources - #29284

Closed
keith wants to merge 2 commits into
bazelbuild:masterfrom
keith:ks/make-local-scheduling-respect-exec_properties-resources
Closed

keith wants to merge 2 commits into
bazelbuild:masterfrom
keith:ks/make-local-scheduling-respect-exec_properties-resources

Conversation

@keith

@keith keith commented Apr 13, 2026 •

Copy link
Copy Markdown
Member

Previously only tests supported a target level way to hint the resources
required by the target. This is done with tags = ["resources:cpu:10"].
Now this syntax is supported for normal actions as well, and both normal
actions and test actions support this same format in exec_properties
with exec_properties = {"resources:cpu": "10"}, or exec_group specific
versions like: exec_properties = {"cpp_link.resources:cpu": "10"}.

Work towards #19679 (doesn't
handle a default flag currently)
Work towards #17368
Work towards #25770

Fixes #6477
Fixes #19805
Fixes #25195
Fixes #25792
Fixes #25793

RELNOTES[inc]: exec_properties now respects resources:cpu and resources:memory for local resource estimation.

@katre katre left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice fix.

@github-actions github-actions Bot added the community-reviewed Reviewed by a trusted community contributor label Apr 16, 2026
@meisterT

Copy link
Copy Markdown
Member

I think this deserves a RELNOTES[INC] in the commit description so that we mention this as backwards incompatible change in future releases.


What happens if one mentions "invalid" resources in exec_properties?

@keith

keith commented Apr 23, 2026

Copy link
Copy Markdown
Member Author

I think this deserves a RELNOTES[INC] in the commit description so that we mention this as backwards incompatible change in future releases.

done

keith added 2 commits April 23, 2026 08:48
Previously only tests supported a target level way to hint the resources
required by the target. This is done with `tags = ["resources:cpu:10"]`.
Now this syntax is supported for normal actions as well, and both normal
actions and test actions support this same format in `exec_properties`
with `exec_properties = {"resources:cpu": "10"}`, or exec_group specific
versions like: `exec_properties = {"cpp_link.resources:cpu": "10"}`.

Work towards bazelbuild#19679 (doesn't
handle a default flag currently)

Fixes bazelbuild#19805
Fixes bazelbuild#25195
Fixes bazelbuild#25792
Fixes bazelbuild#25793
@keith
keith force-pushed the ks/make-local-scheduling-respect-exec_properties-resources branch from 0ea3ea9 to b0e5e53 Compare April 23, 2026 15:48
@keith

keith commented Apr 23, 2026 •

Copy link
Copy Markdown
Member Author

What happens if one mentions "invalid" resources in exec_properties?

In the case you have an invalid value like -1, or a string instead of a number, it fails with:

ERROR: /tmp/demo/BUILD.bazel:14:8: Compiling main.c failed: 'resources:cpu:abc' has a 'resources:<str>:<float>' entry, but its value 'cpu:abc' didn't pass validation: can't be parsed as a float

(just updated because of this comment to not throw a nasty exception but instead fail nicely like it does with tests today)

If you have an empty cpu value like resources:cpu: today for tests it silently ignores it, I changed it in this change to make it fail since that seems undesirable. Now it fails the same way as above.

If you have a custom resource like:

exec_properties = {"resources:gpu": "3"},

which isn't known, you get this error:

ERROR: /tmp/demo/BUILD.bazel:20:8: Compiling main.c failed: Resource foo is not being tracked by the resource manager. Available resources are: cpu, memory

This goes away if you actually use it with --local_resources=gpu=N. (note you only get this error when the local runner actually tries to run the thing, for anyone trying to test this behavior)

Do these examples cover the cases you were thinking about?

How is this surfaced to the user?

improved to be like it is today @ HEAD with tests vs an exception

@github-actions github-actions Bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Apr 28, 2026
@keith
keith deleted the ks/make-local-scheduling-respect-exec_properties-resources branch April 28, 2026 15:29
@keith

keith commented Apr 28, 2026

Copy link
Copy Markdown
Member Author

@bazel-io flag

@bazel-io bazel-io added the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Apr 28, 2026
@iancha1992

Copy link
Copy Markdown
Contributor

@bazel-io fork 9.2.0

@bazel-io bazel-io removed the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Apr 28, 2026
@keith

keith commented Apr 28, 2026

Copy link
Copy Markdown
Member Author

thanks! (definitely just 9.x for this one)

bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Apr 30, 2026
…lbuild#29426)

Previously only tests supported a target level way to hint the resources
required by the target. This is done with `tags = ["resources:cpu:10"]`.
Now this syntax is supported for normal actions as well, and both normal
actions and test actions support this same format in `exec_properties`
with `exec_properties = {"resources:cpu": "10"}`, or exec_group specific
versions like: `exec_properties = {"cpp_link.resources:cpu": "10"}`.

Work towards bazelbuild#19679 (doesn't
handle a default flag currently)
Work towards bazelbuild#17368
Work towards bazelbuild#25770

Fixes bazelbuild#6477
Fixes bazelbuild#19805
Fixes bazelbuild#25195
Fixes bazelbuild#25792
Fixes bazelbuild#25793

RELNOTES[inc]: `exec_properties` now respects `resources:cpu` and
`resources:memory` for local resource estimation.

Closes bazelbuild#29284.

Closes bazelbuild#29419

PiperOrigin-RevId: 906919034
Change-Id: Ia9effd70a71f4e1f42021d945cdc7b1d9d52bbf6
(cherry picked from commit d35da0e)
alexeagle added a commit to bazel-contrib/bazel-lib that referenced this pull request Jul 10, 2026
## Summary
- Document bazelbuild/bazel#29284 as the proper
fix for local resource scheduling on Bazel 9.2.0+
- Note that `exec_properties` with `resources:cpu` and
`resources:memory` is preferred over the `resource_set` workaround when
available

## Test plan
- [x] Docs-only change; no code behavior changes
Silic0nS0ldier added a commit to Silic0nS0ldier/bazel that referenced this pull request Sep 2, 2026
copybara-service Bot pushed a commit that referenced this pull request Sep 14, 2026
### Description
Fixes a regression introduced by #29284 where local resource specifications (`resources:*:*`, `cpu:*` and `memory:*`) affected builtin actions such as;
- `test.xml` generator action
- C spawn include scanner

Also moves resource overriding into `ResourceSetOrBuilder` to reduce the risk of drift between `BaseSpawn` and `SimpleSpawn`.

### Motivation
Deriving local resource sets in these builtin spawns causes otherwise lightweight tasks to backup (and temporarily block) other larger spawns due to them taking an unreasonably high number of resource permits. In the case of `test.xml` generation, when resources are exhausted it can cause tests to visibly appear as if they are running for much longer than they really are (exacerbation of an existing issue where `test.xml` generation scheduling is not differentiated from spawn running in UI and potentially elsewhere).

### Build API Changes
No

### Checklist
- [x] I have added tests for the new use cases (if any).
- [x] I have updated the documentation (if applicable).

### Release Notes
RELNOTES: Fix for regression in #29284 that caused select builtin actions to incorrectly inherit resource set overrides.

Closes #30747.

PiperOrigin-RevId: 981231820
Change-Id: If2dd7b33fefca8ebe2ba4866cc87bc7316230fd1
bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Sep 15, 2026
…build#29284 (https… (bazelbuild#31136)

…://github.com/bazelbuild/pull/30747)

Fixes a regression introduced by bazelbuild#29284 where local resource
specifications (`resources:*:*`, `cpu:*` and `memory:*`) affected
builtin actions such as;
- `test.xml` generator action
- C spawn include scanner

Also moves resource overriding into `ResourceSetOrBuilder` to reduce the
risk of drift between `BaseSpawn` and `SimpleSpawn`.

Deriving local resource sets in these builtin spawns causes otherwise
lightweight tasks to backup (and temporarily block) other larger spawns
due to them taking an unreasonably high number of resource permits. In
the case of `test.xml` generation, when resources are exhausted it can
cause tests to visibly appear as if they are running for much longer
than they really are (exacerbation of an existing issue where `test.xml`
generation scheduling is not differentiated from spawn running in UI and
potentially elsewhere).

No

- [x] I have added tests for the new use cases (if any).
- [x] I have updated the documentation (if applicable).

RELNOTES: Fix for regression in bazelbuild#29284 that caused select builtin
actions to incorrectly inherit resource set overrides.

Closes bazelbuild#30747.

PiperOrigin-RevId: 981231820
Change-Id: If2dd7b33fefca8ebe2ba4866cc87bc7316230fd1

<!--
Thank you for contributing to Bazel!
Please read the contribution guidelines: https://bazel.build/contribute
-->

### Description
<!--
Please provide a brief summary of the changes in this PR.
-->

### Motivation
<!--
Why is this change important? Does it fix a specific bug or add a new
feature?
If this PR fixes an existing issue, please link it here (e.g. "Fixes
bazelbuild#1234").
-->

### Build API Changes
<!--
Does this PR affect the Build API? (e.g. Starlark API, providers,
command-line flags, native rules)
If yes, please answer the following:
1. Has this been discussed in a design doc or issue? (Please link it)
2. Is the change backward compatible?
3. If it's a breaking change, what is the migration plan?
-->

No

### Checklist

- [ ] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

<!--
If this is a new feature, please add 'RELNOTES[NEW]: <description>'
here.
If this is a breaking change, please add 'RELNOTES[INC]: <reason>' here.
If this change should be mentioned in release notes, please add
'RELNOTES: <reason>' here.
-->

RELNOTES: None

Commit
bazelbuild@af88dde

Co-authored-by: Jordan Mele <[email protected]>
copybara-service Bot pushed a commit that referenced this pull request Oct 2, 2026
Baseline: 6332cd9

Cherry picks:

   + 1f39b46:
     Avoid storing missing mandatory attribute state as a field on
     Rule.

New features:

  - `DefaultInfo.executable` exposes the executable of configured
    targets and directly constructed providers, including providers
    returned by `ctx.super()`.

Important changes:

  - Skip implicit output generation when mandatory rule attributes
    are missing to prevent secondary error messages.
  - Fix crash when evaluating target patterns or paths containing
    invalid characters or wildcards on Windows.
  - Facts of reproducible module extensions are now restored to the
    expected state after external modifications by every Bazel
    command that updates the lockfile.
  - Fix for regression in #29284 that caused select builtin actions
    to incorrectly inherit resource set overrides.
  - `bazel fetch --force` no longer causes the fetched repos to be
    fetched again by the next build with a spurious warning about
    external modifications.

This release contains contributions from many people at Google, as well as Benjamin Peterson, Daniel Burrell, David Zbarsky, Fabian Meumertzheim, Fabian Meumertzheim, Henner Zeller, jdymitarai, Jordan Mele, Keith Smiley, Raiyyan Ur Rahman Mohammed, Son Luong Ngoc.
rdesgroppes added a commit to DataDog/datadog-agent that referenced this pull request Oct 8, 2026
### What does this PR do?
Book 6144 MiB for the `GoLink` action of the 9 non-`manual`
`dd_agent_go_test` unit test targets whose packages import the e2e
framework, through the `go_link` exec group's `resources:memory`.

6144 is the multiple of 1024 closest to their peak link RSS, measured
between 5826 MiB (lower bound) and 6241 MiB (upper bound) on Linux.

Document the pattern in `bazel/AGENTS.md`.

### Motivation
`bazel:test:windows-amd64:go` failed in the merge queue
(https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/2121988398) with
5 unit test binaries failing to link and `client_test` timing out after
304s instead of passing in seconds:
```
runtime: VirtualAlloc of 1540096 bytes failed with errno=1455
fatal error: out of memory
```

Since #57555, `rules_go` is patched for `GoLink` to declare a flat 2048
MiB `resource_set`, which stopped the `go_e2e_test_binaries` OOM kills
on `main` but can't account for outliers.

Linking these unit tests peaks at about 30 times the on-disk footprint
of their binaries, which embed the e2e framework and weigh 195MiB to
227MiB.

On 32GiB `c5.4xlarge` runners, Bazel thus runs enough of these links at
once to exhaust the commit limit.

### Describe how you validated your changes
`bazel aquery` shows `resources:memory=6144` on the `GoLink` actions of
the 9 targets only, not on their compile or test actions.

With `--local_resources=memory=13000`, a Bazel profile of their 9 links
shows at most 2 running concurrently instead of 6.

### Additional Notes
Bazel honors `resources:*` exec properties in local scheduling since
9.2.0 (bazelbuild/bazel#29284), overriding the action's `resource_set`.
gh-worker-dd-mergequeue-cf854d Bot pushed a commit to DataDog/datadog-agent that referenced this pull request Oct 9, 2026
…57863)

### What does this PR do?
Tell Bazel to account for 6144 MiB (RSS) for the `GoLink` action of the 9 `dd_agent_go_test` unit test targets whose packages import the e2e framework, through a `go_link:enormous` tag that the macro translates into the `go_link` exec group's `resources:memory`.

6144 is the multiple of 1024 closest to their peak link RSS, measured between 5826 MiB (lower bound) and 6241 MiB (upper bound) on Linux.

Document the pattern in `bazel/AGENTS.md`.

### Motivation
`bazel:test:windows-amd64:go` [failed in the merge queue](https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/2121988398) with 5 unit test binaries failing to link and `client_test` timing out after 304s instead of passing in seconds:
```
runtime: VirtualAlloc of 1540096 bytes failed with errno=1455
fatal error: out of memory
```
... and this was [not an isolated case](https://app.datadoghq.com/logs?query=service%3Agitlab-ci%20%40ci.pipeline.name%3A%22DataDog%2Fdatadog-agent%22%20%22VirtualAlloc%22&agg_m=count&agg_m_source=base&agg_t=count&clustering_pattern_field_path=message&cols=host%2Cservice%2Cci.node.name&index=ci-app-pipeline-logs-gitlab-datadog-agent&messageDisplay=inline&refresh_mode=sliding&storage=hot&stream_sort=time%2Cdesc&viz=stream&from_ts=1790877978397&to_ts=1791482778397).

Since #57555, `rules_go` is patched for `GoLink` to declare a flat 2048 MiB `resource_set` (in lieu of only 250), which stopped the `go_e2e_test_binaries` OOM kills on `main` but can't account for outliers.

Linking these unit tests indeed peaks at about 30 times the on-disk footprint of their binaries, which embed the e2e framework and weigh 195MiB to 227MiB.

On the 32GiB `c5.4xlarge` runners used by Windows jobs, for instance, Bazel thus runs enough of these links at once to exhaust the commit limit.

### Describe how you validated your changes
`bazel aquery` shows `resources:memory=6144` on the `GoLink` actions of the 9 targets only, not on their compile or test actions.

With `--local_resources=memory=13000`, a Bazel profile of their 9 links shows at most 2 running concurrently instead of 6.

### Additional Notes
Bazel honors `resources:*` exec properties in local scheduling since 9.2.0 (bazelbuild/bazel#29284), overriding the action's `resource_set`.


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

Labels

community-reviewed Reviewed by a trusted community contributor team-Configurability platforms, toolchains, cquery, select(), config transitions team-Performance Issues for Performance teams

Projects

None yet

6 participants