notes

ripgrep on nife: what a stranger's program actually hits

(Milestone 121 (ripgrep), and design/fatal-risks/README.md risk 1's decisive experiment. First run 2026-08-31 against ripgrep 14.1.1 from crates.io; the search, the refusal and the measurement 2026-10-07 (UTC) by lane lane/121-ripgrep.)

Risk 1 says the platform "can run hand-written Rust and nothing else, so every piece of software anyone wants has to be rewritten." It is the most dangerous of the nine because no amount of kernel work fixes "nothing runs here". ripgrep was chosen as the falsifier because it is not a toy: forty transitive crates, a filesystem walk, gitignore semantics, memory maps, and threads.

The answer, in one paragraph

Unmodified ripgrep searches a directory it was granted, on all three architectures, with no change to its own source. One dependency carries one patch, ignore's parallel walker (below). Told rg --threads 1 --no-mmap --stats 'walk entry' over milestone 121's priced tree, it finds the 138 matches in 141 files that are there, reads all 333,984 bytes, and prints 3,813 bytes that are byte for byte what the same rg prints on macOS. Through a grant that lacks ENUMERATE it says the capability does not carry the right, searches nothing, and prints no match. On the same HVF machine the search takes about 1.5 times what it takes on Linux. It needs no --no-mmap, and serially it fits in the 256-page heap the harness gives it with room to spare. Without --threads 1 it walks on one thread per core, and the kernel counts them (below).

`rg --threads 1 --no-mmap --stats 'walk entry'` printed 3813 bytes and spent 65 heap pages
    | 138 matches
    | 138 matched lines
    | 138 files contained matches
    | 141 files searched
    | 3644 bytes printed
    | 333984 bytes searched

How it runs, and where it does not yet

Through the kernel harness, not the prompt. system_tests/src/user/ripgrep_tests.rs spawns rg with fs_service::start_std_narrowed. It puts a heap budget at slot 0, an output endpoint at slot 1, a caretaker narrowing walk/ to the rights under test at slot 4, and the argv at slot 8. The argv is built from a line typed as it would be at the prompt, by grant_plan::write_argument_page, the function swish uses. It is placed as the progenitor places it: a READ frame mapped read-only at ARGS_PAGE (milestone 205 (how a foreign program is told what to do)). The image loads at its own link address since milestone 206 (a program image has under 896 KiB) moved the ceiling to 496 MiB.

rg reaches that archive only after cargo xtask basalt-fetch, which takes the program member of basalt's published package, accepted under the digest basalt's recipe records at the commit xtask/basalt-pin pins (milestone 810 (ripgrep is packaged in basalt and installed with jig)). CI's rg-threads and swish-check rows run it. It is never part of the base image: calef ruled on 2026-10-07 (UTC) that rg is installed with jig from a package in nifeos/basalt, and swish-check types jig install ripgrep then rg --version against the same package.

By its path it runs too (milestone 595 (the shell runs a std program)). basalt's build links a manifest note into rg (cargo xtask foreign-note), and script/swish-check copies the package's rg to its disk as installed/rg without its symbol table. Typed /installed/rg needle docs ../hay/secret.txt, it finds the needle in the granted docs and cannot open the path outside it, on all three architectures. The lines skip, and say so, only where nothing was fetched.

Parity (DECISIONS §19)

Target ELF the search the refusal the control
aarch64-unknown-nife 5.0 MB 138 / 141 / 333,984 refused, 0 searched found
riscv64-unknown-nife 11.5 MB the same the same the same
x86_64-unknown-nife 4.4 MB the same the same the same

Run 2026-10-07 with script/test --arch <arch> --test ripgrep, debug kernel under TCG, with rg built from the same 14.1.1 source and flags basalt's recipe uses. All eight tests in the file pass on each. x86_64's OVMF leg has no RedoxFS disk and skips them, as it skips the walk tests.

The riscv64 ELF is larger from file padding and section alignment rather than code (.text 1.23 MiB against aarch64's 1.37). PT_RISCV_ATTRIBUTES at virtual address 0 is not a PT_LOAD, so the loader ignores it, as it does for std_exerciser.

Building it

basalt builds it: recipes/ripgrep.toml and helpers/packages.py in nifeos/basalt download the published crate and build every target in one pass against a pinned nife, with no vendored copy and no fork. ripgrep is untouched. One dependency is patched: ignore 0.4.23, fetched from crates.io by its checksum and given basalt's patches/ripgrep-ignore-walk.patch, about ten lines. Milestone 812 (std::thread::spawn runs real threads in one address space) gave rg threads, so it walks in parallel, and ignore's parallel walker answered "unsupported platform" for every path on a target that is neither unix nor windows. calef ruled the patch on pull request #1892; BUGS has its upkeep. What else differs from a Linux build is on the command line: the target spec (panic=abort), -Zbuild-std against the patched std (notes/std.md), the link script, and -Copt-level=s -Cstrip=debuginfo. That last is because ripgrep's own release profile sets debug = 1 and a 25 MB ELF rides into RAM in the initrd. About 25 seconds a target from cold.

Every crate compiles, including the four milestone 64 (enough std to run somebody else's crate) flagged (ignore, crossbeam-deque, memmap2, walkdir). Two resolve to non-Unix implementations without being asked: memmap2 compiles its stub.rs, and std::sys::args compiles nife's own args/nife.rs.

Threads: it asks, and since milestone 812 it gets more than one

ripgrep does not assume parallelism, it asks. crates/core/flags/hiargs.rs sets its default thread count to available_parallelism().map_or(1, |n| n.get()).min(12). Until milestone 812 (std::thread::spawn runs real threads in one address space) nife's PAL answered Ok(1), so rg took its serial walker and never called thread::spawn. Since 2026-10-10 (UTC) the answer is the online core count, and rg takes ignore's parallel walker: std::thread::scope and one worker per thread, each walking and searching, while the main thread waits.

Measured 2026-10-12 (UTC) by system_tests/src/user/ripgrep_threads_tests.rs (lane milestone/121-rg-threads), with QEMU at -smp 4 on each architecture. The test runs rg as a process, built the way the progenitor builds a std job, and reads the kernel's count of threads that process ever started (started on the process page, sched::process_threads_started). Nothing in rg is asked to say how many threads it ran.

-smp 4, TCG rg --no-mmap --stats 'walk entry' rg --threads 4 ... heap pages
aarch64 5 threads started 5 269
riscv64 5 5 267
x86_64 (PVH leg) 5 5 269

Five is the main thread and four workers, asserted exactly; a serial walk reads 1. Both lines print the fixture's 138 match lines, each once and in whatever order the workers finished, and the test holds them to fixture::walk::rg_match_path's list. The host's rg, run over the same staged tree with the same two lines, is held to the same list by walk_pricing's the_hosts_parallel_rg_prints_the_fixture_lines, so nife and macOS agree byte for byte once both are sorted.

Four workers spend 269 heap pages against the serial walk's 65, about 51 pages a worker. At the 256 pages ripgrep_tests gives the serial walk, the fourth spawn was refused for want of a page for its thread control block, so the threaded tests give rg 512. CI's rg-threads rows run them on every pull request (script/ci-build).

The first full x86_64 suite hung the four-thread test past its 90 s ceiling at two cores. The PAL held a spinlock on its one file page across each CALL, so idle workers spun while the holder waited on the caretaker. It is std's address wait mutex now (sys/fs/nife/page.rs), and the test takes about 0.5 s there. The comparison with Linux below stays serial on both sides.

The refusal, through rg

rg: ./: IO error for operation on ./: this directory capability does not carry the right that verb needs
rg: No files were searched, which means ripgrep probably applied a filter you didn't expect.
...
0 files searched

The words after ./: are the PAL's, for the FS server's EPERM. §47 (a directory capability carries six rights) chose a refusal over an empty listing. It survives the caretaker, std's read_dir and ignore's walker to reach a person as an error. The control holds the same READ | DESCEND grant and is told rg 'walk entry' narrow/n000, and finds its line, so the refusal is about enumeration alone.

The walk at the prompt

script/swish-check stages a copy of crates/ at /search/crates on the first boot when rg was fetched. The second boot inherits the disk, installs rg with jig install ripgrep from the index basalt publishes, and types this in /search by the bare name (milestone 121's exit 4). caps rg BUGS crates first shows the grant: crates alone, read-only, which is ENUMERATE | READ | DESCEND and nothing else.

$ rg BUGS crates
  crates/moho_abi/src/lib.rs:    /// # BUGS
crates/moho_abi/src/lib.rs:    /// # BUGS
...

The gate holds no list of matches. cargo xtask basalt-fetch also fetches ripgrep's own 14.1.1 build for the host, pinned by SHA-256, and staging runs it over the same copy (--no-config --no-ignore-parent, so the host sees what the guest sees) into target/ripgrep-walk-expected.txt. The answer must hold every line of that, as often, and nothing else, in any order, since RedoxFS and APFS list a directory differently. On 2026-10-07 that was 349 lines from 136 files, matched on all three architectures, in 14.9 s (aarch64, HVF), 40.8 s (riscv64) and 345.8 s (x86_64, both TCG). The bounds and their table are beside RG_WALK_SECONDS in xtask/src/swish_check/launch.rs.

The walk exposed three faults, each fixed in the same change, among them swish-check's image growing to 32 MiB (SWISH_CHECK_DISK_MEBIBYTES); walk-faults.md has all three.

The heap and --no-mmap, decided by measurement

The search against Linux

rg_search in script/bench --real --release --smp (release kernel under HVF, four cores) runs the line above six times through the caretaker grant and keeps the median of the last five. bench/host/run_linux_rg.sh boots the Alpine virt kernel on the same virt,accel=hvf machine, -cpu host -m 256M -smp 4, with walk_pricing's rg_host example as PID 1. It stages the same tree, splits the same line with grant_plan::for_each_word, and runs a static Linux rg built from the same source with the same flags, six times, keeping the last five.

2026-10-07, M-series host rg's own clock, median of 5 spawn to exit
nife, four boots 1.24 to 1.33 ms 1.91 to 2.07 ms
Linux (Alpine 3.20 virt), four boots 0.82 to 0.87 ms 1.23 to 1.44 ms (one boot)
macOS, APFS, native, reference only 4.5 to 9.0 ms 7.5 to 14 ms
fs_walk on the same nife boots, for calibration 0.52 to 0.54 ms

About 1.5x Linux. Read it with these caveats:

The walk alone is about 0.1 ms slower than Linux's (fs_walk 0.52 ms against 0.41 ms in notes/walk-cost.md), so most of the 0.45 ms gap is in what rg does beyond walk_pricing's walk. Not measured yet: each directory costs ripgrep failed opens for .gitignore, .ignore and .rgignore, and each is a round trip through the caretaker. The bound grant, which skips the caretaker, made the walk 0.35 ms, and nothing here runs rg through it.

cargo xtask basalt-fetch              # basalt's rg for all three targets, and the host's reference
script/test --arch aarch64 --test ripgrep
script/bench --real --release --smp   # rg_search, beside fs_walk
sh bench/host/run_linux_rg.sh         # needs rustup target add aarch64-unknown-linux-musl

BUGS