roadmap BUILT

287. script/bootstrap installs a working QEMU on Linux, instead of printing how to

This is AGENTS.md's third principle failing, and the tell is that the fix for it had already been written once. A newcomer must be able to succeed without asking anyone. Milestone 117's second stranger run found that script/setup could not complete on a stock Linux box. The remedy applied was a better error message. The message never printed, would have been the ladder's floor if it had, and named two commands that could not work. notes/stranger-test.md recorded it as fixed and stayed wrong for twenty-eight days, which that note now says out loud.

What was actually broken, measured rather than recalled

On a stock Ubuntu box, before this milestone:

$ qemu-system-aarch64 --version
QEMU emulator version 8.2.2 (Debian 1:8.2.2+ds-0ubuntu1.18)
$ qemu-system-riscv64 -device help 2>&1 | grep -c riscv-iommu
0
$ script/qemu-check; echo $?
qemu-check: QEMU 8.2.2 is missing: riscv-iommu-pci(riscv64)
1

That part is not the bug. .qemu-version pins 11.0.2, no Ubuntu release ships a QEMU with riscv-iommu-pci, and apt-get install already fetches the newest package for the release, so there is nothing better for apt to get. script/ci-qemu's header has had this right all along, and the tempting workaround (drop the IOMMU device when QEMU lacks it) stays rejected: it would let the DMA-confinement tests pass while testing nothing.

Three defects sat on top of it, and each one hid the next, which is why a milestone was spent here rather than a patch.

One: the Linux branch was dead. script/bootstrap guarded its advice with [ "$os" = linux ] while os="$(uname -s)" produces Linux. Milestone 117's message had never once reached a reader; bootstrap simply exited 1 with no Linux advice at all. Nothing caught it because nothing on Linux ran bootstrap from cold again.

Two: printing is rung four. Even working, a script that knows the next two commands and asks a human to type them is describing a mechanism instead of being one.

Three, and this is the load-bearing one: the printed remedy looped. script/ci-qemu installs into ${QEMU_PREFIX:-$HOME/.cache/nife-qemu}. The only thing in the entire tree that ever put that prefix on PATH was .github/workflows/ci.yml, at three separate $GITHUB_PATH lines. Nothing in script/, nothing in helpers/, nothing in xtask. So a Linux developer following the instructions verbatim spent twelve minutes building the right QEMU, re-ran script/setup as told, and qemu-check's command -v qemu-system-aarch64 found /usr/bin's 8.2.2 again. Same failure, same message, same remedy, forever.

Why nobody met it. Every contributor's machine was warm, and CI sets the PATH itself, so the only configuration that exercises this path is a cold Linux clone. Exactly what the stranger test exists to be, and exactly what the fix it prompted was never run against.

Who owns the PATH, which was the real question

The emulator is invoked by bare name from 38 sites across 16 files, in three languages: exec qemu-system-aarch64 at the bottom of helpers/qemu-runner-aarch64.sh, the riscv64 and x86_64 runners beside it, helpers/qemu-uefi-x86_64.sh, a subprocess argument list in script/netboot-rehearsal. Probe lines in script/gates and script/cpu-matrix, and script/qemu-check itself. So the mechanism is PATH inherited by children, not one spawn site to patch. Four options were priced.

Refused: export PATH from bootstrap and setup for their own children. It is the cheapest thing that makes script/setup finish, and it is disqualified on behavior rather than on effort: a process cannot edit its parent's environment, so the developer's next script/test in a fresh terminal gets 8.2.2 again. That is the same loop one turn later, and script/test does not call bootstrap (by design; notes/scripts.md says why).

Refused: resolve the emulator at each call site. Thirty-eight copies of one fact, in shell and Python, and every future site a chance to forget. script/ci-qemu's own header already argues against exactly this shape for exactly this reason, about the device list: "Two copies of 'what QEMU must provide' would drift, and the copy in CI is the one nobody reads."

Refused: put the resolution in xtask, on the grounds that xtask is where QEMU is launched. This was the first recommendation and the premise is false. cargo xtask spawns the runner shells, so it would cover script/test and its siblings, but it reaches neither script/qemu-check nor script/cpu-matrix's direct probe nor script/netboot-rehearsal. Covering those as well would mean two mechanisms, and the Rust one would need its own copy of "where is the prefix and is it the pinned version", which is the drift above.

Taken: one sourced fragment, helpers/qemu-path.sh, read by every entry point that can reach an emulator. It has no shebang because it is sourced rather than executed: it exists to edit the caller's PATH, which an executed script cannot do. One copy of the logic, one line per entry point, and every one of the 38 bare-name invocations gets the right emulator without being touched.

Would we still choose it if the options cost the same? Yes, and that is the honest answer rather than a convenient one. Against the call-site option it has fewer moving parts and fewer places to be wrong, which is what this project means by elegance. Against the xtask option it is one mechanism instead of two with a duplicated fact between them. The export PATH option is cheaper than all of them and loses on a measurement, not on taste.

What was built

The version gate, and the demotion it prevents

Prepending unconditionally would let a prefix left over from an older pin beat a system QEMU that is perfectly good, which would have been a regression this change introduced on any distribution that ships a new enough emulator. The fragment reads .qemu-version and prepends only on an exact match. That is a third reader of the pin, not a fourth copy of the number: the file stays the single source of truth, which is the distinction script/qemu-check's header draws.

It finds the pin by walking up from $PWD rather than reading it from the current directory. Every script/ entry point cds to the root as its first act except script/crate-probes, which keeps a $ROOT and never cds, so a contract spelled "be at the root" would have had exactly one exception on the day it was written. Four lines removed the exception instead of documenting it.

The gate is mechanical, and it over-approximates on purpose

script/apropos and script/crate-probes shell into cargo xtask and boot nothing today. They take the line anyway. The alternative is a judgment call per file plus an allow-list, which is the shape script/lint check 5 and milestone 283 both refuse to grow, and the line costs them nothing.

A backticked mention is prose, not a call, which is milestone 283's rule reused rather than reinvented: these headers discuss cargo xtask constantly. Stripping backticked spans is what keeps script/lint (whose only raw hit is a sentence inside a Python heredoc) and script/board-netboot out without either needing an exemption. script/lint still trips the rule through the regex in the check's own source, because a checker necessarily carries every pattern it looks for; it takes the line rather than an exemption.

Verified in both directions. Four faults were injected one at a time, and the gate watched to fire on each. The source line dropped from script/test; the fragment deleted; a new entry point that runs cargo xtask and forgets; and a backticked mention that must stay quiet (it did).

Proof, because the point of this milestone is that reasoning was not enough last time

Reproduced first, on this Ubuntu box with apt's 8.2.2 on /usr/bin: script/qemu-check exit 1, riscv-iommu-pci absent. Then, after the change:

And a control run, because two numbers are worth more than one. This box is a headless sandbox, so five post-run checks fail on both architectures: three scanout (no monitor for a screendump) and inbound/multicast (host networking). Those are not this change: the same script/test --arch aarch64 with QEMU_PREFIX pointed at an empty directory, so the fragment no-ops and 8.2.2 is used, fails with exactly the same five. The guest-side assertions pass in every run ("the compositor test passed", "the display test passed"); what cannot be observed is host-side. See notes/load-sensitive-assertions.md.

What is deliberately not claimed: script/test does not exit 0 on this box, and it is not this change. crates/elf fails twenty of twenty-five host tests here, the host pass runs before the kernel legs, so the suite stops there. It reproduces on main and this milestone's diff contains no .rs and no .toml. The kernel legs above were reached with --test, which skips the host pass by design. The diagnosis is in the follow-on, and it is the honest shape of this result: the emulator half is fixed and proven, and a different wall is standing behind it.

BUGS

Follow-on

Index row

Reproduced whole on a stock Ubuntu box. Milestone 117 (the stranger test)'s stranger run found script/setup could not complete on cold Linux; the remedy applied was a better error message, and three defects sat on it. The message never printed ([ "$os" = linux ], while uname -s says Linux). Printing is rung four. And the two commands it printed looped: script/ci-qemu installs into $HOME/.cache/nife-qemu and the only thing in the tree that ever put that on PATH was ci.yml, so twelve minutes of building ended at /usr/bin's 8.2.2 again, forever. notes/stranger-test.md had recorded it fixed and was wrong for twenty-eight days. bootstrap now runs ci-qemu itself; helpers/qemu-path.sh (name provisional) is the PATH half, sourced rather than executed because the emulator is named bare from 38 sites and inheritance reaches them all; script/lint gates that every entry point resolves it.