aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / benchmarks / headstart / README.md
| 1 | # Headstart M0: stable Rust build baselines |
| 2 | |
| 3 | Tracking issue: #532. This directory holds the instructions and the record |
| 4 | schema for the stable-toolchain build baselines that later Headstart work |
| 5 | (#536) compares against. It is measurement only: the runner never edits |
| 6 | `Cargo.toml`, `rust-toolchain.toml`, CI, compiler flags or the caller's |
| 7 | checkout. |
| 8 | |
| 9 | | Path | What it is | |
| 10 | | --- | --- | |
| 11 | | `scripts/bench/headstart-aien.sh` | the runner (bash) | |
| 12 | | `scripts/bench/headstart-summarize.sh` | summarizer and Cargo timings extractor (bash + jq) | |
| 13 | | `scripts/bench/headstart-selftest.sh` | self-test on a throwaway fixture workspace, with negative cases | |
| 14 | | `benchmarks/headstart/schema.json` | JSON Schema for `manifest.json` and each `samples.jsonl` line | |
| 15 | | `benchmarks/data/headstart/baseline-<date>-<short>/` | one run: raw samples, manifest, summary, timings extract, log tails | |
| 16 | |
| 17 | No Python is used anywhere. Requirements: bash, git, jq, awk, sed, pgrep, |
| 18 | cargo through rustup, and GNU `/usr/bin/time` for max RSS and CPU% (when it |
| 19 | is missing the samples record `time_v.available: false` instead of numbers). |
| 20 | |
| 21 | ## How a run works |
| 22 | |
| 23 | 1. `setup`: `git worktree add --detach $HS_WORK/src <commit>` outside the |
| 24 | caller checkout (refused when `HS_WORK` is inside it), its own |
| 25 | `CARGO_TARGET_DIR=$HS_WORK/target`, then `cargo fetch --locked` once so the |
| 26 | cargo registry and git caches are warm. Writes `manifest.json` (commit, |
| 27 | `rustc -vV`, `cargo -V`, arch, nproc, CPU models, MemTotal/MemAvailable, |
| 28 | features, profiles, target dir, jobs, build env, date). |
| 29 | 2. `timings`: one cold `cargo build --workspace --timings`. The `UNIT_DATA` |
| 30 | block of `cargo-timing.html` is cut out with sed and validated with jq |
| 31 | (`timings/units.json`), the observed critical path and the upper-bound |
| 32 | estimate are computed into `timings/critical-path.json`, the package graph |
| 33 | from `cargo metadata --filter-platform <host> --locked --offline` goes to |
| 34 | `timings/graph.json`, the realistic estimate (list-schedule replay) goes |
| 35 | to `timings/replay.json`, and the report is kept gzipped. |
| 36 | 3. `cold`: interleaved rounds. Each round runs, in order: cold check (arm A or |
| 37 | B), cold build workspace, cold build `spark-harness`, cold test |
| 38 | `--no-run`, cold check (the other arm), cold build `spark-supervisor`, cold |
| 39 | build `aien-runtime`. The A/B arm order swaps every round; the two arms of |
| 40 | the same command are the A/A noise estimate. "Cold" means the target dir |
| 41 | is deleted before every attempt while the registry stays warm. If a cold |
| 42 | workspace sample in round 1 exceeds 1200 s the run drops to 3 rounds and |
| 43 | says so in `manifest.protocol.samples_reduced`. |
| 44 | 4. `incr`: prime `cargo check --workspace --all-targets`, three no-op checks, |
| 45 | then for each series a 10-step body-only edit and a 10-step |
| 46 | interface-changing edit (each step reverts the previous edit first, so |
| 47 | every step is a fresh one-edit change). After every series the edit is |
| 48 | reverted, `git diff --quiet` is verified (abort when not clean) and an |
| 49 | untimed-for-stats `incr_settle` check brings the target dir back to the |
| 50 | pristine source. Two series per kind run as body, iface, body, iface. |
| 51 | 5. `cleanup`: deletes the target dir, the raw logs and the worktree. |
| 52 | |
| 53 | Before every sample the runner first waits while the host's shared quiet |
| 54 | flag is held by another job (`quietlock check`, tool name `HS_QUIETLOCK_BIN`; |
| 55 | disable with `HS_QUIETLOCK=0`). The wait is capped at `HS_QUIET_WAIT_CAP_S` |
| 56 | (default 3600 s) so a stale flag cannot hang the run; on the cap the runner |
| 57 | logs a line and proceeds. Each sample records `quiet_flag_checked`, |
| 58 | `quiet_flag_wait_s` and `quiet_flag_wait_capped`. The manifest's |
| 59 | `protocol.quiet_flag` records `enabled`, `tool`, `available` (the tool was |
| 60 | found), `respected` (enabled and available) and `wait_cap_s`, so a host |
| 61 | without the tool reads `respected: false`. Then the runner waits until the |
| 62 | 1-minute load average is below `HS_LOAD_MAX` (cap `HS_WAIT_CAP_S`), records |
| 63 | load before and after, and lists foreign compiler processes at the start, |
| 64 | every `HS_MON_INTERVAL_S` seconds (default 3) while the command runs, and once |
| 65 | more right after it ends (`foreign.at_end`). A foreign process is a `cargo` |
| 66 | process, or a `rustc` / `clippy-driver` / `rustdoc` process with |
| 67 | `--crate-name` (an actual compile), that is not in the runner's process tree. |
| 68 | |
| 69 | A sample is `contaminated: true` when `contamination_reasons` is non-empty: |
| 70 | `foreign_at_start`, `foreign_during`, `foreign_at_end`, `load_wait_capped` |
| 71 | (the load never dropped below the limit within the cap) or |
| 72 | `quiet_flag_wait_capped`. Contaminated samples are re-run up to |
| 73 | `HS_MAX_RERUNS` times; earlier attempts stay in `samples.jsonl` with |
| 74 | `final: false`. |
| 75 | |
| 76 | Every command's exit status is recorded. A failed build is a failure |
| 77 | (`ok: false`, with the last 80 log lines kept); it is never counted in a |
| 78 | median and never replaced by a smaller workload. |
| 79 | |
| 80 | ## A/B stages for one toolchain with two arm environments (M5, #536) |
| 81 | |
| 82 | The same runner measures one toolchain with a feature off and on. It takes |
| 83 | the toolchain from `HS_CARGO` (replaces the leading `cargo` of every scenario |
| 84 | command) and `HS_RUSTC` (exported as `RUSTC` to every sample), and the arm |
| 85 | environments from `HS_ARM_ENV_OFF` and `HS_ARM_ENV_ON` (space-separated |
| 86 | `KEY=VALUE` words, both required and different, or the stage aborts). Each |
| 87 | arm has its own `CARGO_TARGET_DIR` (`<target>-<arm>`), so arms never share |
| 88 | build state. Every sample records `cargo_bin` and `env_words`; `setup` |
| 89 | records the sha256 of cargo, rustc and the `librustc_driver-*.so` in the |
| 90 | rustc sysroot under `manifest.toolchain.binaries`. |
| 91 | |
| 92 | - `ab`: `HS_SAMPLES` rounds of cold check, cold build and cold |
| 93 | `test --no-run`, OFF and ON alternating (the arm that goes first swaps |
| 94 | every round), plus an A/A pair: cold check twice with the OFF environment |
| 95 | (arms A and B, `aa_noise` in the summary). `HS_AB_JOBS="4 8 16"` adds cold |
| 96 | workspace builds at those `-j` values, `HS_AB_JOBS_SAMPLES` rounds each. |
| 97 | - `abincr`: the `incr` edit series, but both arms check the same source after |
| 98 | every edit (OFF first on odd steps, ON first on even steps), each on its own |
| 99 | incremental target dir. A failed check is recorded with its exit status and |
| 100 | log tail and the series continues; it is never counted as a time. |
| 101 | - `abverify`: per arm, a cold `cargo check --workspace --all-targets |
| 102 | --message-format=json` and `cargo test -p <HS_VERIFY_TEST_PKGS> --lib |
| 103 | --bins --tests -- --test-threads=1` (no doctests: those run `rustdoc`, |
| 104 | and a stage-1 `compiler library` build ships none, so the rustup rustdoc |
| 105 | would be mixed in), compared in `verify.json`: exit codes, diagnostics |
| 106 | normalized for event order (each `compiler-message` reduced to level, code, |
| 107 | message and primary spans, then sorted) and test result lines (timing |
| 108 | suffix removed). With `HS_VERIFY_ENV_ON` set, one more cold |
| 109 | `cargo build --workspace` runs with the ON environment plus those words. |
| 110 | `verdict` is `match` only when everything is equal, both arms exit 0 and |
| 111 | that extra build exits 0. |
| 112 | |
| 113 | With `HS_HOLD=1` every sample also holds the host quiet flag for itself: |
| 114 | after the usual `quietlock check` queue wait, the runner takes it with |
| 115 | `quietlock hold --owner <HS_HOLD_OWNER> --minutes <HS_HOLD_MINUTES> --reason |
| 116 | <HS_HOLD_REASON>`, keeps it through the load wait and the timed command, and |
| 117 | releases it before the next sample, so other jobs (chip gates, a paused |
| 118 | tokenizer) get the flag between samples. A refused hold (exit 75: another |
| 119 | job took the flag first) queues again within `HS_QUIET_WAIT_CAP_S`; a hold |
| 120 | that is not taken marks the sample contaminated (`quiet_hold_not_taken`). |
| 121 | Each sample records `quiet_hold` (requested, held, hold id, seconds to |
| 122 | acquire, refusals) and the manifest lists `protocol.quiet_hold.samples_held` |
| 123 | and `samples_unheld`. |
| 124 | |
| 125 | A failed sample's log tail starts with the error lines of the full log |
| 126 | (cargo prints its manifest warnings last, so the last lines alone can miss |
| 127 | the cause). When rustc panics it leaves `rustc-ice-*.txt` in the worktree |
| 128 | root; the runner appends each report's head (up to the backtrace) to the |
| 129 | tail, deletes the file and records `ice_reports`. |
| 130 | |
| 131 | The summary gains an `ab` section (only when OFF/ON samples exist, so older |
| 132 | summaries reproduce byte for byte): per scenario the OFF and ON wall time |
| 133 | stats, `delta_s` (ON minus OFF), `saving_pct` ((OFF - ON) / OFF), failures |
| 134 | per arm, median max RSS and median CPU seconds (user + sys) per arm and |
| 135 | their deltas. |
| 136 | |
| 137 | ## M5 result (patched-20261015-4c83e38): REJECTED, Headstart stays disabled |
| 138 | |
| 139 | **Verdict: REJECTED.** The promotion gate fails on the crash below. |
| 140 | Further timing was stopped by Drake's decision (via the orchestrator, |
| 141 | 2026-10-16), so speed cells beyond the clean held samples are NOT_MEASURED. |
| 142 | The gate needs zero unexplained crashes; Headstart ON crashes the compiler |
| 143 | on every incremental edit, so it fails whatever the speed. |
| 144 | No "Optional local invocation" section is added. Default builds are |
| 145 | unchanged: nothing in this repository enables `-Zheadstart` or |
| 146 | `-Zearly-metadata`. |
| 147 | |
| 148 | The toolchain was local only: built under a disposable directory outside |
| 149 | the repository, never vendored or committed (the upstream patches carry no |
| 150 | license), never installed into rustup or `~/.cargo/bin`, and never used by |
| 151 | CI, release, signing or spark-rsi. Only digests and my own scripts are kept |
| 152 | (`toolchain/digests.txt`, `toolchain/*.sh`). |
| 153 | |
| 154 | Pins: upstream headstart `ff81bfecda2116d54776a7fec538fc2f4e349d1f`, rustc |
| 155 | submodule `6006fd03947bd7b04ae5cb5f7f9bb66b44dc8c6e`, cargo submodule |
| 156 | `4f3fb2428282fb2467c4bb5be0163d2f42a31491`; sha256 of the stage-1 rustc, |
| 157 | `librustc_driver-*.so`, cargo and each patch in `toolchain/digests.txt` and |
| 158 | `manifest.toolchain.binaries`. AIEN source: `4c83e38`. |
| 159 | |
| 160 | **Crash (observed, the gate failure).** In the `abincr` stage every check |
| 161 | after an edit failed with exit 101 when ON, and every one passed when OFF: |
| 162 | |
| 163 | | check after edit | OFF exit 0 | ON exit 101 | |
| 164 | |---|---|---| |
| 165 | | body edit (20 steps) | 20 of 20 | 20 of 20 | |
| 166 | | interface edit (20 steps) | 20 of 20 | 20 of 20 | |
| 167 | | settle after revert (4) | 4 of 4 | 4 of 4 | |
| 168 | |
| 169 | No-op checks and the cold prime passed in both arms. The run left 46 rustc |
| 170 | ICE reports, all the same panic (`logs/abincr-run1-ice-heads.txt`). One |
| 171 | untimed diagnostic (`diag-once/`: prime, the step-1 body edit, one |
| 172 | incremental ON check, `-j 8`, under `quietlock run`) reproduced it; full |
| 173 | stderr in `diag-once/incr-on.stderr.log`: |
| 174 | |
| 175 | ``` |
| 176 | thread 'rustc' (586269) panicked at compiler/rustc_metadata/src/rmeta/encoder.rs:2837:29: |
| 177 | assertion `left == right` failed: early and full metadata disagree on the SVH |
| 178 | note: compiler flags: --crate-type lib -Z early-metadata -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] |
| 179 | error: could not compile `aien-runtime` (lib) |
| 180 | ``` |
| 181 | |
| 182 | The crate that panics is `aien-runtime`, which depends on the edited |
| 183 | `cortex-rs` (`crates/aien-runtime/Cargo.toml`). This matches the upstream |
| 184 | note `docs/ice-early-metadata-svh.md` at the pinned commit: same assertion |
| 185 | and file, during incremental `cargo check` runs, "It's not fixed yet", and |
| 186 | "Every later build fails the same way, even with the edit reverted", which |
| 187 | is what the settle checks show. |
| 188 | |
| 189 | **Correctness of cold builds (observed).** `verify.json` verdict `match`: |
| 190 | same exit codes, same normalized diagnostics, same results for the 115 |
| 191 | tests of `spark-harness` and `aien-proof` in both arms, and the |
| 192 | `-Zearly-metadata-verify` cold build exited 0. |
| 193 | |
| 194 | **Cold timings (observed, INDICATIVE: n=2 to 3 clean held samples per |
| 195 | arm, under the planned 5).** Same patched toolchain, OFF vs ON, default |
| 196 | `-j` (20), per-sample quiet-flag hold, arms alternating. The rerun was |
| 197 | stopped by Drake's decision during round 3; the remaining rounds are |
| 198 | NOT_MEASURED. |
| 199 | |
| 200 | | workload | OFF median (n) | ON median (n) | saving | max RSS | CPU (user+sys) | |
| 201 | |---|---|---|---|---|---| |
| 202 | | cold `check --workspace --all-targets` | 38.117 s (2) | 31.643 s (3) | 16.98 % | -3.05 % | +1.92 % | |
| 203 | | cold `build --workspace` | 52.793 s (2) | 42.596 s (3) | 19.31 % | +0.00 % | +4.62 % | |
| 204 | | cold `test --workspace --no-run` | 79.933 s (3) | 73.493 s (2) | 8.06 % | -0.12 % | +6.76 % | |
| 205 | | A/A cold check (OFF vs OFF) | 37.895 s (3) | 37.566 s (2) | 0.87 % | | | |
| 206 | |
| 207 | The OFF and ON ranges do not overlap in any of the three workloads |
| 208 | (`summary.json` `.ab[].wall_s_off/on`). One OFF check was contaminated and |
| 209 | is excluded. NOT_MEASURED (stopped by decision): jobs 4/8/16 (NOT_RUN), |
| 210 | rounds 4 and 5 of the cold A/B, every incremental ON timing (no ON check |
| 211 | after an edit succeeded). NOT_RUN: the upstream unit tests (`x test |
| 212 | tests/run-make/early-metadata tests/ui/rmeta`, cargo headstart tests). The |
| 213 | upstream check scripts (smoke, check-swap, check-errors, check-incremental |
| 214 | check and build) all exited 0 (`upstream-tests/results.txt`). |
| 215 | |
| 216 | **Stable reference (M0, kept separate).** The stable 1.98.1 medians are |
| 217 | 20.367 s (cold check), 31.054 s (cold build) and 56.387 s (test --no-run). |
| 218 | The patched stage-1 compiler is a different, slower build (OFF takes 1.42 |
| 219 | to 1.87 times the stable median, ON 1.30 to 1.55 times), so patched and |
| 220 | stable times are not comparable. The M0 schedule replay **estimated** 14.5 % (realistic) and |
| 221 | 15.7 % (upper) for the cold build; that is an estimate, separate from the |
| 222 | 19.31 % observed above on the patched toolchain. |
| 223 | |
| 224 | The first cold A/B run (before the per-sample hold) was stopped after |
| 225 | round 1 on a contaminated host; its samples are kept apart in |
| 226 | `samples-ab-run1-interrupted-unheld.jsonl` and used nowhere. |
| 227 | |
| 228 | **Next:** the M0 critical path shows the `aws-lc-sys` build script (run) at |
| 229 | 13.08 s of the 31.5 s cold build (`baseline-20261015-4c83e38/timings/critical-path.json`). |
| 230 | The follow-up is a native fix of that bottleneck, in a separate issue. |
| 231 | |
| 232 | ## Running it |
| 233 | |
| 234 | From the repository root, with the stable toolchain pinned by |
| 235 | `rust-toolchain.toml`: |
| 236 | |
| 237 | ```bash |
| 238 | bash scripts/bench/headstart-selftest.sh # about a minute, must print 0 failed |
| 239 | HS_COMMIT=<sha> \ |
| 240 | HS_BODY_FILE=<repo-relative .rs file> HS_BODY_ANCHOR='<exact fn opening line>' \ |
| 241 | HS_IFACE_FILE=<repo-relative lib.rs> HS_EDIT_REASON='<why these targets>' \ |
| 242 | bash scripts/bench/headstart-aien.sh # setup timings cold incr cleanup |
| 243 | ``` |
| 244 | |
| 245 | Stages can be run separately (`setup timings`, then `cold incr cleanup`) |
| 246 | against the same `HS_WORK` and `HS_OUT`, which is how the edit targets were |
| 247 | chosen from the measured critical path before the incremental stage. The |
| 248 | other knobs are listed at the top of the runner. |
| 249 | |
| 250 | ## Known quirks of the committed run (baseline-20261015-4c83e38) |
| 251 | |
| 252 | That run used the earlier runner (commit afa4316). Its data is kept as |
| 253 | recorded; what it can and cannot show: |
| 254 | |
| 255 | - Foreign compiles were checked at sample start and then every 30 s |
| 256 | (`protocol.foreign_monitor_interval_s: 30`), with no end-of-sample check. |
| 257 | 74 of the 84 counted samples finished before the first tick |
| 258 | (`foreign.monitor_ticks: 0`), so for them only the start was checked. The |
| 259 | data supports "no foreign compile at sample start, nor at any 30 s tick |
| 260 | that occurred", not "none during the sample". |
| 261 | - `load_wait_capped` did not mark a sample contaminated then. Three attempts |
| 262 | hit the cap; all three were also contaminated by a foreign process and |
| 263 | re-run, so no counted sample has `load_wait_capped: true`. The highest |
| 264 | `loadavg_before` (1-minute) of a counted sample is 1.99. |
| 265 | - The quiet-flag wait was uncapped and the manifest has only `respected: |
| 266 | true`; there is no `available` field. The tool was present on that host: |
| 267 | one sample waited 20 s for the flag (`quiet_flag_wait_s`), which only a |
| 268 | working `quietlock check` can produce. |
| 269 | - The timings stage ran before the quiet-flag check was added, so its three |
| 270 | samples have no `quiet_flag_wait_s`. |
| 271 | - `timings/graph.json` and `timings/replay.json` were derived after the run, |
| 272 | from `cargo metadata --filter-platform aarch64-unknown-linux-gnu --locked |
| 273 | --offline` in a checkout whose `Cargo.lock`, `Cargo.toml` files and crate |
| 274 | sources are identical to 4c83e38, and from the committed `units.json`. No |
| 275 | build was re-run. `critical-path.json` was regenerated from the same |
| 276 | `units.json` by the current summarizer; only its `estimate` block changed. |
| 277 | - In that run both settle checks of a series shared one `sample_id` (step 0), |
| 278 | so the first settle log tail of each series was overwritten (85 tail files |
| 279 | for 87 lines). Settle samples are not measurements. The runner now numbers |
| 280 | them step 1 (after body) and 2 (after iface), and the self-test checks that |
| 281 | sample ids are unique. |
| 282 | - Log tails are named `*.tail.log`, which the root `.gitignore` ignores; they |
| 283 | were committed with `git add -f`. |
| 284 | |
| 285 | ## Reproducing the summary |
| 286 | |
| 287 | `summary.json` is a pure function of `samples.jsonl`: |
| 288 | |
| 289 | ```bash |
| 290 | D=benchmarks/data/headstart/baseline-<date>-<short> |
| 291 | bash scripts/bench/headstart-summarize.sh samples $D/samples.jsonl | cmp - $D/summary.json && echo identical |
| 292 | ``` |
| 293 | |
| 294 | Per scenario and arm it reports `wall_s` (counted samples: final attempt and |
| 295 | exit 0) and `wall_s_clean` (counted and not contaminated), each with n, |
| 296 | median, min, max, MAD (median absolute deviation) and sample stdev, plus |
| 297 | failures with exit status, superseded attempts, median max RSS and median |
| 298 | CPU%. `aa_noise` gives the A/A median difference in seconds and percent. |
| 299 | |
| 300 | Max RSS comes from `/usr/bin/time -v`, which reports `ru_maxrss` of the |
| 301 | waited process tree: per getrusage(2) that is the largest single process, not |
| 302 | the sum over parallel rustc jobs. |
| 303 | |
| 304 | ## Critical path and the estimate |
| 305 | |
| 306 | `critical-path.json` walks back from the last unit to finish along the edge |
| 307 | that unblocked each unit: cargo records, per unit, which units became |
| 308 | runnable when it finished (`unblocked_units`) or when its metadata was ready |
| 309 | (`unblocked_rmeta_units`), and `sections[frontend].end` marks when the |
| 310 | metadata was ready. That chain is the observed critical path of that one |
| 311 | build (scheduling delays included). |
| 312 | |
| 313 | Two estimates, both labeled ESTIMATE and both covering the cold |
| 314 | `cargo build --workspace` only, of what a metadata-pipelining compiler change |
| 315 | (removing the wait for a dependency's metadata) could save on that build: |
| 316 | |
| 317 | - upper bound (`critical-path.json`, `estimate`) = min(sum of predecessor |
| 318 | frontend time on rmeta-gated links of the chain, build end minus floor), |
| 319 | where floor = max(longest single unit, sum of unit durations / jobs). |
| 320 | Full-gated links (build scripts, proc macros, linked binaries) need |
| 321 | finished artifacts and are not shortened. This ignores that the critical |
| 322 | path may move to another chain. |
| 323 | - realistic estimate (`replay.json`) = a list-schedule replay of the |
| 324 | measured unit durations at the build's job count (nproc), with unit edges |
| 325 | rebuilt from the package graph (`graph.json`). Stable cargo has no unit |
| 326 | graph (`--unit-graph` is unstable), so the edges follow cargo's rules: a |
| 327 | build-script compile needs its build-deps' libs; a build-script run needs |
| 328 | its own compile and the build-script run of any normal dependency that |
| 329 | declares `links`; a lib needs its own build-script run and its normal |
| 330 | dependencies' metadata (full artifact for proc macros); a bin needs its |
| 331 | own lib and its normal dependencies in full. Units start in observed start |
| 332 | order whenever a job slot is free. `baseline` treats a metadata edge as |
| 333 | ready at the dependency's frontend end; `no_rmeta_wait` treats it as ready |
| 334 | when the dependency starts. The saving is `baseline - no_rmeta_wait`, both |
| 335 | from the same model, and `model_error_pct` compares `baseline` with the |
| 336 | observed build end. Feature variants of one package are grouped |
| 337 | conservatively (every variant waits for every variant of its dependency). |
| 338 | |
| 339 | For the committed run: observed build 31.50 s, replay baseline 31.35 s |
| 340 | (model error -0.48%), no-metadata-wait 26.79 s, realistic saving 4.56 s |
| 341 | (14.5%); upper bound 4.94 s (15.7%). |