Skip to content

Say when a git-derived version needs stamping, and check what the stamp costs - #50

Open
anakanemison wants to merge 2 commits into
mschaller/u14-configure-step-strategiesfrom
mschaller/u15-version-stamp
Open

anakanemison wants to merge 2 commits into
mschaller/u14-configure-step-strategiesfrom
mschaller/u15-version-stamp

Conversation

@anakanemison

@anakanemison anakanemison commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

When the reference build reads a value from the repository (git describe, a commit hash), Bazel loses it unless it goes through workspace status, and the action graph doesn't reflect the loss. "Create initial BUILD.bazel files" now says when to reproduce it, how to keep the stamp narrow, and how to check what it costs. scripts/stamp_scope.py reads an unfiltered bazel aquery and reports what reruns when the workspace status changes.

In any2bazel-lab, both OpenTTD migrations made before this change produced a binary reporting "norev0000" while reporting success. With the first wording of this change, eight migrations of four projects carried correct values through.

That first wording also resulted in many migrations over-invalidating with new commits. In those eight migrations, an empty commit in the project repository caused rebuilds under Bazel that recompiled: 1 file on OpenTTD, equal to its original build; 2 files on xbmc and 8 to 10 on CMake, whose original builds rebuild nothing because they read git only when they configure; and on one QGIS migration, 1,701 Qt moc actions ran, each of which listed the stamped header as an input.

The current wording, and the added script, are designed to prevent that. The paragraph asks first when the original build reads the value: if only when it configures, it says to stamp only under --stamp. It then has the agent check the stamp's scope with the script before reporting. We re-ran the same four projects with the current wording, OpenTTD and CMake twice each, plus two projects whose builds read nothing from git. After an empty commit, both CMake migrations and the xbmc migration recompile and relink nothing by default, and carry the right commit when built with --stamp; both OpenTTD migrations recompile 1 file, as before; the QGIS migration recompiles 4 files, where its original build recompiles 6, and reruns no moc action; and the two other projects gained no stamping. Every agent that stamped ran the script before reporting.

Stacked on #49 (tracking issue: #35). pytest tests/: 196 passed (132 on main). Lab proposal: P19.

🤖 Generated with Claude Code

A project that derives its version from the repository at configure or
build time (git describe, a commit hash, a build date) loses it under
Bazel unless the migration wires it through workspace status: a genrule
cannot see .git from the sandbox, the generator still runs on both sides,
and the output has the same shape, so the action graph cannot tell.

Measured in any2bazel-lab: both OpenTTD migrations, with
and without the skill, produced a binary reporting "norev0000", "unknown"
and 1970, the project's own fallbacks for "no git information", while
reporting success; the skill-guided one printed CONVERGED errors=0
warnings=0. Other migrations kept the version (a Bitcoin Core one through
--workspace_status_command and a stamp = 1 genrule, as did a pono one), so
it is not a capability gap: nothing in the procedure asks for it.

Adds one paragraph to "Create initial BUILD.bazel files": the failure mode
and the Bazel mechanism that preserves the value. The byte comparison that
catches its absence is the one the convergence-boundary list already asks
for on every generated file.

In the lab's later OpenTTD run with this change, the binary reported the
revision, through --workspace_status_command.

Lab-Proposal: P19

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

These types of actions can be expensive if not handled well, as it can invalidate large parts of a build graph with every commit. I suggest doing a little more due diligence on this one before adding guidance.

The paragraph on values read from the repository said to feed them through
--workspace_status_command to a stamped rule, with no condition and no cost.
A stamp is paid for on every commit: every action that reads the stable
status file reruns when a STABLE_ value changes, and so does every action
that reads an output that changed.

The paragraph now applies only when the reference build reads such a value.
It asks first when the reference reads it: on every build, or only when it
is configured, in which case a new commit rebuilds nothing there and the
stamp belongs under --stamp. It says to give the status file only to the
rule that needs it, to write the value into the one generated file the
reference writes it into, and to check the scope with a new script.

scripts/stamp_scope.py reads an unfiltered `bazel aquery --output=jsonproto`
and runs no build. It reports the stamped actions; the actions that read a
stamped output and will rerun with it (exact); the compiles that list a
stamped header and may rerun (an upper bound, since a compile reruns only if
it included the header); and everything downstream. `--fail-over N` makes
the exact count a check. Its --help says how to measure where it can only
bound: build, one empty commit, build again.

Tried in any2bazel-lab on eight migrations made with the earlier wording of
this paragraph. "Measured" is what one empty commit rebuilt.

  OpenTTD, value in generated/rev.cpp: 1 will rerun. Measured: 1 compile,
    as in OpenTTD's own build.
  xbmc (two migrations), value in CompileInfo.cpp: 2 will rerun. Measured
    on the one that builds: 2 compiles.
  CMake (three migrations), value in the header cmVersionConfig.h: 557 to
    1052 compiles may rerun. Measured: 8 to 10 compiles and up to 14 links.
    CMake's own build rebuilt nothing after the same commit: it reads git
    only when it configures.
  QGIS, value in the header qgsversion.h, first migration: 3123 compiles
    may rerun. Measured: 4 compiles and 41 links.
  QGIS, second migration: 1701 Qt moc actions will rerun, because each
    lists the header as an input. Measured: 1701 moc actions, 4 compiles and
    46 links, on every commit.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@anakanemison anakanemison changed the title Say that a git-derived version stamp is lost unless stamped Say when a git-derived version needs stamping, and check what the stamp costs Nov 19, 2026
@anakanemison

Copy link
Copy Markdown
Contributor Author

These types of actions can be expensive if not handled well, as it can invalidate large parts of a build graph with every commit. I suggest doing a little more due diligence on this one before adding guidance.

Your suspicion was right on! The first version of this change fixed the lack of stamping in migrated projects but the agents weren't careful and their migrations over-invalidated on empty commits.

This PR now includes another commit that changes the instructions to make the agent more discerning about when to apply the technique and how to scope it. It includes a tool agents can use to find what actions are stamped.

I ran new migration tests using the current version, looking at four projects whose CMake builds stamped and two that didn't. The agent using the current version implemented stamping in Bazel only where it was used in CMake, and none of them over-invalidate. I'll upload the detailed records of those runs to the appropriate repo soon.

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.

2 participants