bazelbuild / bazelbuild/bazel

BES not including `TargetConfigured`/`TargetCompleted` events for transitive targets

Open
#22,922 3 comments 0 reactions 0 assignees View on GitHub
team-Core type: bug untriaged
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

> Note: Having the exact same issue as https://github.com/bazelbuild/bazel/issues/8570 (opening a new issue to avoid necrobumping a 5 year old thread).

In summary: `TargetConfigured` and `TargetCompleted` events are not sent on the Build Event Stream for indirect targets, even if they are built. Events are only sent for the targets directly requested. The `bazel build` fully executes the indirect targets, and treats them as "configured", but no events are sent.

The suggested solution from #8570 of `--build_event_publish_all_actions` does not help. It results in the `ActionExecuted` events that correspond to the indirect targets getting streamed, but results in no further `TargetConfigured` or `TargetCompleted` events.

### Which category does this issue belong to?

Core, Local Execution, Remote Execution

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

1. Create some fake targets
```starlark
# //blah/BUILD.bazel

genrule(
name = "A",
outs = ["A.txt"],
cmd = "echo 'a' > $@",
)

genrule(
name = "B",
srcs = [":A"],
outs = ["B.txt"],
cmd = "echo 'b' > $@",
)
```

2. Start a BES server that logs events

```rust
// some_file.rs that does the BES server/event parsing/etc

match (id, payload) {
(Id::ActionCompleted(id), Payload::Action(payload)) => {
println!("Action Completed:");
println!("\t{id:?}");
println!("\t{payload:?}");
}
(Id::TargetCompleted(id), Payload::Completed(payload)) => {
println!("Target Completed:");
println!("\t{id:?}");
println!("\t{payload:?}");
}
(Id::TargetConfigured(id), Payload::Configured(payload)) => {
println!("Target Configured:");
println!("\t{id:?}");
println!("\t{payload:?}");
}
_ => ()
}
```

3. Building `//blah:B` results in `TargetConfigured`/`TargetCompleted` events for just `B`. Notice that the CLI output from the `bazel build` command says "`2 targets configured`"

```shell
bazel build --bes_backend=grpc://127.0.0.1:54321 //blah:B

INFO: Invocation ID: a95f8073-793d-4764-a290-b8ce096b8bce
INFO: Analyzed target //blah:B (1 packages loaded, 2 targets configured).
INFO: Found 1 target...
Target //blah:B up-to-date:
bazel-bin/blah/B.txt
...
```

```
(edited to shorten each packet)

Target Configured:
TargetConfiguredId { label: "//blah:B", aspect: "" }
TargetConfigured { target_kind: "genrule rule", test_size: Unknown, tag: [] }
Target Completed:
TargetCompletedId { label: "//blah:B", ... }
TargetComplete { success: true, target_kind: "", ... }
```

4. Building `//blah/...` results in `TargetConfigured`/`TargetCompleted` events for both `A` and `B`

```shell
bazel build --bes_backend=grpc://127.0.0.1:54321 //blah/...

INFO: Invocation ID: 8a80e899-c90b-43f6-a496-ed9b46376729
INFO: Analyzed 2 targets (1 packages loaded, 2 targets configured).
INFO: Found 2 targets...
Target //blah:B up-to-date:
bazel-bin/blah/B.txt
Target //blah:A up-to-date:
bazel-bin/blah/A.txt
...
```

```
(edited to shorten each packet)

Target Configured:
TargetConfiguredId { label: "//blah:A", aspect: "" }
TargetConfigured { target_kind: "genrule rule", test_size: Unknown, tag: [] }
Target Configured:
TargetConfiguredId { label: "//blah:B", aspect: "" }
TargetConfigured { target_kind: "genrule rule", test_size: Unknown, tag: [] }
Target Completed:
TargetCompletedId { label: "//blah:A", ... }
TargetComplete { success: true, target_kind: "", ... }
Target Completed:
TargetCompletedId { label: "//blah:A", ... }
TargetComplete { success: true, target_kind: "", ... }
```

5. Building `--build_event_publish_all_actions //blah:B` results in `TargetConfigured`/`TargetCompleted` events for just `B`, but `ActionCompleted` events for both `A` and `B`

```shell
$ bazel build --bes_backend=grpc://127.0.0.1:54321 --build_event_publish_all_actions //blah:B

INFO: Invocation ID: 53ef230f-20fa-4b2e-8a71-bee331741cc6
INFO: Analyzed target //blah:B (1 packages loaded, 2 targets configured).
INFO: Found 1 target...
Target //blah:B up-to-date:
bazel-bin/blah/B.txt
...
```

```
(edited to shorten each packet)

Target Configured:
TargetConfiguredId { label: "//blah:B", aspect: "" }
TargetConfigured { target_kind: "genrule rule", test_size: Unknown, tag: [] }
Action Completed:
ActionCompletedId { primary_output: "bazel-out/stable-status.txt", label: "", ... }
ActionExecuted { success: true, r#type: "BazelWorkspaceStatusAction", exit_code: 0, stdout: None, stderr: None, label: "", ... }
Action Completed:
ActionCompletedId { primary_output: "bazel-out/darwin_arm64-fastbuild/bin/blah/A.txt", label: "//blah:B", ... }
ActionExecuted { success: true, r#type: "Genrule", exit_code: 0, stdout: None, stderr: None, label: "//blah:B", ... }
Action Completed:
ActionCompletedId { primary_output: "bazel-out/darwin_arm64-fastbuild/bin/blah/B.txt", label: "//blah:B", ... }
ActionExecuted { success: true, r#type: "Genrule", exit_code: 0, stdout: None, stderr: None, label: "//blah:B", ... }
Target Completed:
TargetCompletedId { label: "//blah:B", ... }
TargetComplete { success: true, target_kind: "", ... }
```

### Which operating system are you running Bazel on?

macOS 14.5 (23F79)

### What is the output of `bazel info release`?

release 7.1.1

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

_No response_

### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

_No response_

### Have you found anything relevant by searching the web?

https://github.com/bazelbuild/bazel/issues/8570

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the behavior with the minimal BUILD.bazel containing genrules A and B, using the BES gRPC setup shown in some_file.rs. Compare `bazel build //blah:B` with `bazel build //blah/...` and inspect the Build Event Stream entry points. Done means transitive targets emit TargetConfigured and TargetCompleted events while preserving the existing direct-target behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.