Skip to content

fix(setup): report BUILD_USER alongside the commit and CI metadata - #1487

Closed
joshcbarnes wants to merge 1 commit into
mainfrom
josh/workspace-data-build-user
Closed

joshcbarnes wants to merge 1 commit into
mainfrom
josh/workspace-data-build-user

Conversation

@joshcbarnes

Copy link
Copy Markdown
Contributor

Problem

aspect setup workspace-data replaces Bazel's own default workspace status script, and that default is the sole source of BUILD_USER, BUILD_HOST and BUILD_TIMESTAMP. So pointing --workspace_status_command at this task blanked out the User row in the Web UI's Bazel details block, which reads BUILD_USER straight off the workspace_status event with no fallback (bazel_results.axl:3484).

Change

Collect BUILD_USER in get_build_metadata, so it reaches both consumers — the workspace status lines and the --build_metadata flags — from the one dict they share.

It stays distinct from USER, which continues to prefer the commit author or CI actor. That distinction is the point, and it's the one bazel_results.axl:3481 already documents:

USER Greg Magolan          # commit author
BUILD_USER joshbarnes      # the OS account the build ran under

Resolution is USER → LOGNAME → USERNAME (Windows), from the environment only. No process spawn: this runs at the start of every Bazel invocation, and Bazel fails the build outright when the status command exits non-zero, so shelling out to id/whoami to cover the last edge case would buy a marginal gain for a new way to take down every build in the workspace. Where nothing names the account, the key is dropped by the existing empty-value filter rather than emitted bare.

Not addressed

BUILD_HOST is lost the same way, so the Host name row next to User is still blank. It needs a different mechanism — there's no reliable env var for the hostname (HOSTNAME is bash-specific, HOST zsh) — so it would require exactly the spawn this avoids. Worth deciding separately.

Tests

Adds crates/aspect-cli/tests/workspace_data.rs and its rust_test target — the first coverage for this task. Five cases: each fallback, the USER/BUILD_USER distinction, and the drop-the-key case.

The AXL entry point takes a std handle and has no fake, so .aspect/axl.axl can only reach the file's pure helpers; running the real binary is the only thing that exercises this path.

Per CLAUDE.md, confirmed the tests fail with the change reverted — 4 of 5 fail, the fifth being the negative case that correctly passes either way. Green under both cargo test and bazel test, along with tests axl (991 cases), the template snapshots, and the rest of the aspect-cli Rust suite.

One wrinkle worth flagging for reviewers: the test helper pins ASPECT_CREDENTIALS_FILE to a temp path. Naming a CI host in the environment turns on CI detection, and with it the Deployment feature's auto endpoint wiring, which calls ctx.aspect.auth.list() and reaches the real keyring — a hard failure under Bazel's sandbox (A default keychain could not be found). Same isolation auth_status.rs documents, and pre-existing behavior rather than anything this change introduces.

🤖 Generated with Claude Code

`aspect setup workspace-data` replaces Bazel's own default workspace
status script, which is the sole source of BUILD_USER. Pointing
--workspace_status_command at it therefore blanked out the "User" row in
the Web UI's Bazel details block, which reads BUILD_USER from the
workspace_status event with no fallback.

Collect it in `get_build_metadata`, so it reaches both consumers — the
workspace status lines and the `--build_metadata` flags — from the one
dict they share. It stays distinct from USER, which continues to prefer
the commit author or CI actor: BUILD_USER is where the build physically
ran.

Resolution is USER -> LOGNAME -> USERNAME, from the environment only.
This runs at the start of every Bazel invocation and Bazel fails the
build outright when the status command exits non-zero, so a process
spawn to cover the last edge case is the wrong trade; where nothing
names the account the key is dropped by the existing empty-value filter.

BUILD_HOST is lost the same way and is not addressed here — there is no
reliable environment variable for the hostname, so it needs the spawn
this deliberately avoids.

Adds tests/workspace_data.rs, the first coverage for this task. The AXL
entry point takes a `std` handle and has no fake, so running the real
binary is the only thing that exercises the path. The helper pins
ASPECT_CREDENTIALS_FILE because naming a CI host turns on the Deployment
feature's `auto` endpoint wiring, which reaches the real keyring and
fails under Bazel's sandbox.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: f60bcf5b-b8d7-4e36-a97c-3393d6d7492c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@aspect-workflows

aspect-workflows Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Aspect Workflows Tasks

📅 Mon Sep 21 17:51:02 UTC 2026

Task Results

Reproduce

❌ delivery (delivery-uncacheable · delivery-gha-debug · delivery-gha)

# --mode=always --track-state=false for off-runner with no state backend.
aspect delivery \
  --commit-sha=b70eb1e37e61dd5d00941171696ec1644c721849 \
  --mode=always \
  --track-state=false \
  --dry-run=true

Install aspect: aspect.build/docs/cli/install


⏱ Last updated Mon Sep 21 17:59:32 UTC 2026 · 📊 GitHub API quota 2,281/7,700 (30% used, resets in 4m)
🚀 Powered by Aspect CLI (v0.0.0-dev)  |  Aspect Build · X · LinkedIn · YouTube

@joshcbarnes

Copy link
Copy Markdown
Contributor Author

Closing this — the premise is wrong, and the change would have been a regression.

I claimed aspect setup workspace-data replaces Bazel's default workspace status script and therefore loses BUILD_USER. It does not. --workspace_status_command output is merged on top of Bazel's built-ins, not substituted for them.

Tested on Bazel 9.0.1, with a status script emitting only MY_CUSTOM_KEY:

=== stable-status.txt
BUILD_EMBED_LABEL
BUILD_HOST MacBook-Pro.local
BUILD_USER joshbarnes
=== volatile-status.txt
BUILD_TIMESTAMP 1790013636
FORMATTED_DATE 2026 Sep 21 18 00 36 Mon
MY_CUSTOM_KEY hello

All five built-ins survive. There was never a gap to fill — the Web UI's "User" row was being populated by Bazel all along.

Worse, emitting the key doesn't add a duplicate, it overrides the built-in, and Bazel routes it to stable-status.txt:

=== stable-status.txt
BUILD_USER aspect-emitted     <- ours, overriding Bazel's
=== volatile-status.txt
MY_CUSTOM_KEY hello

That breaks the invariant workspace_data.axl states in its own docstring — unprefixed keys land in volatile status so they never invalidate a stamped action. Confirmed the cost: changing the script's BUILD_USER re-executed a stamped genrule, while changing only MY_CUSTOM_KEY left it fully cached.

So the change traded Bazel's authoritative OS-user value for one guessed from $USER/$LOGNAME/$USERNAME, and moved it into stable status where it can thrash every stamped action. Adding BUILD_HOST would have done the same thing for the same non-existent gap.

For anyone who lands here later: Bazel always supplies BUILD_EMBED_LABEL, BUILD_HOST, BUILD_USER (stable) and BUILD_TIMESTAMP, FORMATTED_DATE (volatile). The wrapper-script pattern in the workspace_data.axl docstring is about composing with a repo's own second status script, since Bazel accepts only one --workspace_status_command — not about recovering Bazel's defaults, which are never at risk.

@joshcbarnes
joshcbarnes deleted the josh/workspace-data-build-user branch September 21, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant