Skip to content

Stop every gate step from rebuilding stage2 and relinking the compiler (#1157) - #1185

Merged
ehartford merged 2 commits into
mainfrom
fix-1157-gate-relink
Sep 18, 2026
Merged

ehartford merged 2 commits into
mainfrom
fix-1157-gate-relink

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Closes #1157.

Root cause

Every seed-driven gate step rebuilt stage2 and relinked the compiler that build had just produced (~142 s in each of :fixpoint, :test, :move-audit, :drop-audit, :last-green).

with build --explain pcre2-wo-install-o:

freshness: stale: output missing: $HOME/.local/with-wo/pcre2/darwin_aarch64-…/pcre2.o

The Install kind's freshness check tested its output path literally, while the install operation expands $HOME. The file exists; the check could never see it, so all twelve bundle install targets were permanently stale. The stage compiles depended on the bundle group, which carries those installs, so each invocation re-ran them and rewrote out/stage/lib/embedded_objects.o with identical content (same sha256) and a new mtime, which made stage2 and link-compiler stale. Found by hashing stage2's 305 declared inputs before and after one gate step: that file was the only one that moved.

Fix

  1. Compiler (BuildGraphSupport/Cache/Ops): one build_graph_expand_install_path, used by both the install operation and the freshness check. Takes effect when a seed carrying it is pinned — the pinned seed's build-graph code is frozen.
  2. Build layer (effective under today's seed): stage compiles and the embedded blobs depend on <name>-wo-build, whose out/wo/ outputs are all they read (the compiler never reads the store; it is a cross-tree cache for the bundle build). The store installs hang off the millisecond build stamp step.
  3. :test-with-audits: the tests and both ownership audits in one invocation. drop-audit is flagged allow_parallel (it writes only out/drop-audit), and the group lists the audits before the tests so they share the behaviour tests' pooled run. Separate invocations cannot overlap: the repo lock serializes them.

Measured (pinned seed v0.15.2.0, darwin arm64)

step before after
:fixpoint after build 250 s 104 s (6.5 s when nothing changed)
:move-audit 175 s 11 s (the audit itself is 3.1 s)
:drop-audit 275 s 108 s
:last-green 167 s 13 s
full battery with both audits, warm compile ~38.5 min incl. an 8-min compile 956 s; zero stage2/link rebuilds in every step

:test-with-audits A/B on one commit, identical cold prep (test pass records cleared, the audits' outputs removed, no forced actions; stage2 rebuilt in neither arm; behaviour tests 0 cached, 1041 ran in both): sequential 888 s, combined 803 s. One sample each; the saving (85 s, ~10%) is near run-to-run noise because the audits and the behaviour tests compete for the same cores.

Two earlier attempts at that A/B were discarded: one served the tests from cache, one used WITH_BUILD_ACTION_FORCE=1, which forces every Action in the chain and rebuilt the stages per invocation.

Battery

build, :fixpoint, :test, :move-audit, :drop-audit, :test-green, :last-green all rc=0 on the compiler change; :test-with-audits, :fixpoint, :test-green, :last-green rc=0 on the final commit.

Not in this PR

About ten :test targets are not flagged parallel and drain the worker pool (emit-c-smoke 101 s, the four bundle drift checks, the C-migrator suites, selfcheck; stdlib-complexity is serial on purpose). Last-green evidence is keyed on the stamped binary, so a squash merge of a byte-identical tree still needs a full battery. The pinned seed compiles the compiler in ~289 s where a current compiler takes ~72 s.

Eric Hartford added 2 commits September 18, 2026 13:13
The Install kind's freshness check tested its output path literally, so
'$HOME/.local/with-wo/...' never existed and every bundle install target was
permanently stale (--explain: 'stale: output missing: $HOME/...'). The stage
compiles depended on the bundle group that carries those installs, so each
invocation re-ran them, rewrote out/stage/lib/embedded_objects.o with
identical content and a new mtime, and rebuilt stage2 and link-compiler:
~142 s in each of :fixpoint, :test, :move-audit, :drop-audit and :last-green.

The install operation and the freshness check now share one path expansion
(BuildGraphSupport). That takes effect once a seed carrying it is pinned, so
the build layer also moves the dependency now: stage compiles and the
embedded blobs depend on <name>-wo-build, whose out/wo/ outputs are all they
read, and the store installs hang off the millisecond stamp step.

Measured under the pinned seed after a build: :fixpoint 250 s -> 104 s,
:move-audit 175 s -> 11 s, zero stage2/link-compiler rebuilds. #1157
…ocation

drop-audit is flagged allow_parallel (it writes only out/drop-audit), and the
group lists the audits before the tests so they share the behaviour tests'
pooled run instead of queueing behind the repo lock as separate invocations.
#1157
@ehartford
ehartford merged commit 6c6d7cd into main Sep 18, 2026
5 checks passed
@ehartford
ehartford deleted the fix-1157-gate-relink branch September 18, 2026 22:10
ehartford added a commit that referenced this pull request Sep 20, 2026
…s which part changed (#1225)

Every action's signature carried the fingerprint of the binary orchestrating
the build (:WITH:). Our workflow alternates orchestrators all day: the
iterate tier uses the installed compiler, the battery the pinned seed, corpus
promotion the release compiler. With the seed held fixed (WITH=src/main) and
only the orchestrator changed, --explain reported stage1, stage2,
link-compiler, the runtime objects and the bundle builds all "stale: action
signature changed": a full compiler rebuild, about 4.5 minutes, per switch.
(:zlib-promote spent 270 s rebuilding stage1, stage2 and link-compiler right
after a build had produced them.)

The orchestrator produces a target's output only when it compiles it itself:
the compile kinds, and an action with no `compiler=` (a workspace compile
runs in the driver's compiler). An action that names its compiler is produced
by that compiler; a tree compiler is already hashed by the stage-target block
and `compiler=seed` is the seed WITH names. Such an action now keys on the
seed (build_cache_producer_fingerprint). Go, Zig and Rust all key on the
producing tool, never on the build driver. With WITH=src/main driven by
src/main the signature text is unchanged, so seed-driven batteries stay warm.

The state file held the signature as one hash, so "signature changed" could
not say what changed. It now records each component's hash (target, producer,
action-code or build-graph, compiler-source, compiler) and the stale reason
names the ones that differ; WITH_BUILD_CACHE_TRACE=<target> prints them.

Evidence, two binaries with different sha256 (release 32543048…, stage2
0dbd11f3…) over one seed, after a build orchestrated by the first: stage1,
stage2, link-compiler, rt-core-object and zlib-wo-build are fresh under both.
libc-surface-check (no compiler=, so the driver is its producer) is fresh
under the first and "stale: action signature changed (producer)" under the
second. The pinned seed (v0.15.2.0) still disagrees with a current compiler:
it predates #1151/#1185/#1191's changes to this code and records no component
hashes; that ends at the next seed.

Co-authored-by: Eric Hartford <[email protected]>
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.

build: the seed-driven gates relink stage2 + the release compiler on every step (~2.5–3.5 min each; only /Brepro keeps it byte-identical)

1 participant