# linux-test-portability ## Goal Every suite had only ever run on macOS arm64. Make `cargo clippy --all-targets -- -D warnings` and `cargo test --workspace` pass on Linux x86-64 — in the CI job image, as root (how the runner's jobs run) and as an unprivileged user — while staying green on macOS, and do one cleaning round on the test code that the Linux runs drive (TODO §70). Test code only: where a platform or user genuinely cannot exercise what a test is about, the test detects it at run time and stops with a message; it never asserts the opposite and never weakens the assertion where it *can* run. ## Assumptions - Root (CAP_DAC_OVERRIDE / CAP_DAC_READ_SEARCH) ignores file modes, so the unreadable- and unwritable-path tests cannot build their path as root. Not assumed from the uid: each test probes the exact behaviour it needs (a mode-000 directory refuses `read_dir`, a mode-000 file refuses `open`, a mode-555 directory refuses a new file) in a scratch path of its own, then restores the mode. - Case sensitivity is a property of the filesystem, not the OS. The one runtime-probed case test (`file_ops.rs`) asks the filesystem (`DEFS.svh` is a file when only `defs.svh` was written); the existing `#[cfg(any(target_os = "macos", target_os = "windows"))]` case tests keep their compile-time scope, whose reason is written at each. - A skipped test still reports `ok` in `cargo test`; the `skipped: …` line on stderr (visible with `--nocapture`) is how a run says so. std has no runtime-skip outcome, and no dependency is added for one. - The linear-time tests' bound is a ratio between sizes measured in the same process moments apart, so it does not depend on the machine's speed; it does assume load from the tests running beside it does not inflate the largest size's *fastest of five* by more than ~3x relative to the smallest's. ## Handshakes - Consumes nothing new from production code. No production file, no `verify.rs`, no workflow, version file or changelog changes — **except** the round 2 product fix the lead granted (2026-11-19): `crates/lucisv_mcp/src/project/files.rs` and its test fixture `project/tests.rs`. `Stamp`'s public shape changed (`identity` is now `Option`, new `read_mono`); its only users are inside `lucisv_mcp::project`, nothing outside the crate sees it. - `tools/linux_check.sh` (the lead's): used as written in round 1; changed in the fix round (QA finding 5, see the work log). Its usage line gained `--dry-run`; the single-string form is unchanged. - Scope extension granted by the lead in the fix round: `crates/lucisv_server/src/server/tests/scan_trace.rs` (test file only). - Requests: none (round 1). - **Round 2 request: a product bug, not a test flake. Owner: `lucisv_mcp`.** `crates/lucisv_mcp/src/project/files.rs:166-184`, `Stamp::check`. The racy rule (`mtime + RACY > read_at`, line 175) covers the mtime only. The ctime half of `identity` (line 214) has no racy rule. On Linux 6.8 (luhpe: ext4 under overlayfs, `CONFIG_HZ=1000`) the kernel stamps ctime from the coarse clock, in 1 ms steps. Suppose a file's ctime moves (here a rename-over), the server stats and reads it, and the file is rewritten at the same size with its old mtime put back (`cp -p`, `rsync -t`, `touch -r`), all within the same 1 ms tick. Then size, mtime, ctime and inode all match the stamp. The check answers `Same`, and the stale contents are served **for good**, because every later stat says the same. - Reproduction: `tools/linux_check.sh 'for i in $(seq 150); do cargo test -q -p lucisv_mcp --test qa_m1 qa_rework_a_rename_over_with_an_old_mtime_and_the_same_size_is_seen -- --exact; done'`. Result: 12/150 failed as root with nothing else running, and 39/300 in an earlier loop. It also failed once in the full suite as `--user` before this round. - Instrumented, by printing `(ctime, ctime_nsec, ino)` of `c.sv` after the rename and after the rewrite (a temporary edit, since reverted). Every failure had the two identical to the nanosecond. In every pass (261 printed) they were 1 or 2 ms apart, never 0. The `find` between them took 0.44–0.66 ms. The failing answer was ``no declaration named `chyrlie`.`` - macOS: APFS ctime comes from a fine clock, so it always moves, and the test has never failed there. - **Resolved in round 2 by the lead's scope extension** (work log, "the stamp fix"). The suggestion was: give ctime the racy rule mtime has. A stamp whose ctime is within `RACY` of `read_at` is `Suspect`, so it is re-read and re-hashed until it is older. The same argument as git's racily-clean entries. - The test was **left unchanged** on purpose, and still is. It is right, and making it wait for the clock to tick would hide the bug. Before the fix it failed about 1 in 10 runs alone on that box. Under load it fails less often, because the `find` then takes longer than a tick: 0/200 under 8 busy loops. ## Status / TODO - [x] Clippy clean on Linux and macOS: the three unused imports were the only reports. - [x] The eight permission-denied tests probe whether modes bind and stop with a message when they do not. - [x] The case-mismatch test probes the filesystem's case sensitivity. - [x] The two linear-time tests bound growth, not wall-clock; shown to trip on the quadratic conversion on macOS and on the Linux runner. - [x] Cleaning round (see work log). - [x] Linux suite green as root (twice) and as `--user`. Observed: root once green; `--user` once with one failure, the new flake `scan_trace::the_stages_add_up_to_the_scan_they_describe` (open, see the work log); the second root run and the flake's diagnosis were cut off when ssh to luhpe stopped working. Done in Round 2: 10 of 10 green as root and 10 of 10 as `--user` (dev), 6 of 6 each (QA) — work log and QA log. - [x] `tools/gates.sh` green on macOS (see the work log for each run). - [x] Fix round: `scan_trace` lower bound on the best of three sessions; linear-time tests best of five; `tools/linux_check.sh` hardened. - [ ] Open follow-up (QA finding 4, not changed on purpose): `large.rs` `references_on_one_giant_line_locate_their_hits_in_linear_time` times a copy of the `Server::large_scan` loop, not the production loop at `server/large_file.rs:151`, so a per-hit rescan reintroduced there would not be caught. Needs a test that drives the production path. - [x] Re-run on Linux once ssh to luhpe is back. Done in round 2, against 0.65.6 plus this round (see the round 2 work log). ### Round 2 (flakes on Linux) - [x] Census: 2 090 single-test iterations on Linux (alone and under load) and 57 whole-suite runs (Linux root and `--user`, macOS under load). Every test that failed even once is in the table in the work log. - [x] stdin `BrokenPipe` on a child that exits before reading: `cli.rs` (both stdin helpers) and `qa_m8.rs` (`run`) tolerate that one error and still assert on the exit code and output. - [x] `e2e.rs` didOpen budget: a multiple of one parse of the same buffer measured in the same process, instead of a fixed 200 ms. - [x] `qa_m3.rs` CLI-while-formatting hang on macOS (an inherited pipe): the server is spawned before the checker thread starts. - [x] Every other wall-clock assertion reviewed; each left as it was, with the reason (work log). - [x] **Product bug, fixed (scope extended by the lead):** `qa_m1.rs` `qa_rework_a_rename_over_with_an_old_mtime_and_the_same_size_is_seen` failed on Linux about 1 run in 10 alone — a real staleness bug in `Stamp::check` (Handshakes). The racy rule now covers the ctime, the window is 3 s, and a wall clock stepped back distrusts every stamp; the test itself is unchanged. - [x] Audit of the other caches for the same hole: none has it (work log). - [x] Deterministic unit tests of the racy decision; mutations shown. ## Work log **2026-11-19 (dev).** Baselines at 88546c8 (before any change). macOS `cargo test --workspace`: 93 result lines, **5307 passed, 0 failed, 57 ignored** (5364). Linux as uid 1001 (`tools/linux_check.sh --user`): **5298 passed, 3 failed, 57 ignored** — the case-mismatch test and the two linear-time tests; every permission test passed, which confirms the lead's hypothesis 1 (they fail only as root). The Linux total is 6 lower than macOS's because six tests are compiled only on macOS/Windows. Causes, per failure: 1. *Clippy, three unused imports* (`hover.rs` `qa_hover_declarations`: `FromStr`; `includes.rs` `qa_round2`: `super::*`, `fs`): their only users are `#[cfg(any(target_os = "macos", target_os = "windows"))]` tests. `qa_round2` holds nothing else, so the cfg moved onto the module (with the reason as its doc comment) and off its two tests; in `hover.rs` the `FromStr` import carries the same cfg as its one user. 2. *Eight permission tests* (hypothesis 1, confirmed): root opens, lists and writes whatever the mode says. Each gets a probe of the behaviour it relies on and returns early, saying `skipped: …`, when the probe is not refused: - `crates/lucisv/tests/cli.rs` — `listing_is_refused()` (mode-000 dir), used by both walk-warning tests. - `crates/lucisv_core/src/walk.rs` — `reading_is_refused(rel)` (mode-000 directory or file), used by the unreadable-directory and unreadable-`.gitignore` tests. - `crates/lucisv_mcp/src/apply.rs` — `creating_is_refused(dir)` (mode-555 dir). Only the *second* half of `a_write_that_fails_after_another_landed_says_what_was_written` needs it: the read-only-file refusal before it is decided from the mode bits (`Permissions::readonly`), holds as root, and is still asserted there. The same file is compiled into `tests/qa_m3.rs` via `#[path]`, so the fix covers both targets. - `crates/lucisv_mcp/tests/cache.rs` — `creating_is_refused` (mode 555, the unwritable cache directory). - `crates/lucisv_mcp/tests/qa_m6.rs` — `listing_is_refused` (mode 000). - `crates/lucisv_server/src/state/tests/filelist.rs` — `listing_is_refused()` (mode 000). 3. *Case-mismatch include* (hypothesis 2, confirmed: "must narrow in: []" on Linux): on a case-sensitive filesystem `DEFS.svh` names no file, so there is nothing to narrow in. The test now writes `defs.svh`, asks whether `DEFS.svh` is a file, and stops with a message when it is not; the reason is in its doc comment. On macOS it runs in full as before. 4. *Two `…_in_linear_time` tests* (hypothesis 3, confirmed, with a correction). Not superlinear product code: run alone on the Linux runner both are exactly 2x per 2x (locate 13.5 / 27.0 / 54.3 / 108.7 ms, colour 22.1 / 44.2 / 89.5 / 182.1 ms; three runs within 3%), and on macOS the same (locate 3.4 / 6.7 / 13.6 / 26.2 ms, colour 5.6 / 11.0 / 22.6 / 44.7 ms). The trial's 4x for 100 → 200 hits (20.6 → 81.4 ms) and its 781 ms colour sample came from the full suite: the tests ran beside ~1 900 others on a 4-CPU cap, and a single sample per size took whatever load it landed on. Alone on the runner they would even have met the old budgets (108 < 150, 182 < 350 ms); in the suite they do not. The references test's input grows hits *and* line length together, so the walker's work (each byte once) is linear in `width` and the per-hit rescan's quadratic — the test bounds the right thing. Rewrite (`crates/lucisv_server/src/large.rs`): the fixtures are built first; `fastest_of_three` times every size in three interleaved rounds and keeps each size's minimum (load slows one sample of each size, not every sample of one); `assert_grows_linearly` fails when the largest size (8x the input) costs more than `GROWTH_SLACK` (3) × 8 = 24x the smallest. The absolute `COLOUR_BUDGET_MS`/`LOCATE_BUDGET_MS` constants are gone. The per-size `eprintln!` stays (the lex timing it also printed is dropped — it was never asserted). **Shown to trip.** Temporarily put the per-call converter back — `positions.position(..)` for `walker.position(..)` at both sites in `tokens::flatten` (`tokens.rs`), and `positions.range(*hit)` for `walker.range(*hit)` in the references test's loop — and ran `cargo test -p lucisv_server --bin lucisv-server large::tests:: -- --nocapture`: - macOS: both FAILED — locate 6.3 / 24.9 / 99.1 / 395.8 ms, **62.8x**; colour 34.3 / 129.2 / 511.9 / 2 060 ms, **60.0x** (limit 24x). - Linux runner (root): both FAILED — locate 87.1 / 346.6 / 1 368.5 / 5 507.7 ms, **63.2x**; colour 383.9 / 1 539.2 / 6 503.1 / 27 667.6 ms, **72.1x**. Then restored both files from copies taken before the edit; `git status` shows `tokens.rs` unmodified. With the walker: 8.0x / 8.0x on macOS, 8.0x / 8.2x on Linux. Margin: ~3x on each side of the limit. Cleaning round (test code only, driven by the tool reports): - The unused imports above were everything clippy reported on either platform; `cargo build`/`cargo test` reported no other test warnings. - `walk.rs`'s `TempTree` was documented "removed on drop" but had no `Drop` impl, so every walk test left its tree in the temp dir; added the three-line `Drop` the comment describes (the test trees restore their modes before returning, so removal succeeds). - The other wall-clock assertions in the suites (`server/tests/startup.rs`, `tests/e2e.rs`'s grace checks, `vlog_semantic/tests/workspace.rs`'s 5 s build bound) passed on every Linux run here and are left as they are; `large.rs`'s hundred-megabyte probe is `#[ignore]`d. Final runs, all against the finished tree (every change above, including `#[track_caller]` on `assert_grows_linearly`; nothing in `crates/` changed after them, only this README and TODO.md): - macOS `cargo test --workspace` (guarded): 93 result lines, **5307 passed, 0 failed, 57 ignored** — the baseline's count exactly. - Linux root, then `--user` (2026-11-19, both finished before the ~05:00 ssh outage), root: `cargo clippy --all-targets -- -D warnings` exit 0, no diagnostics; `cargo test --workspace --no-fail-fast`: 93 result lines, **5301 passed, 0 failed, 57 ignored**. - Linux `--user` (right after): clippy exit 0, no diagnostics; tests **5300 passed, 1 failed, 57 ignored** — the failure is `server::tests::scan_trace::the_stages_add_up_to_the_scan_they_describe` at `crates/lucisv_server/src/server/tests/scan_trace.rs:163`, the `sum >= total * 0.5` assertion (the stages a `--verbose` scan's trace names must cover at least half its wall-clock total). It passed in the root run, in the lead's 88546c8 `--user` run, and 15 times out of 15 run alone as `--user`; a repeat of the whole `lucisv_server` binary to catch its numbers was cut off by the ssh outage (exit 137 from the ssh side, not a guard kill). Reading: a wall-clock ratio over a ~20 ms scan, where a preemption landing in the deliberately unattributed loop time (progress callbacks, staging pushes) on the 4-CPU runner under the full suite's load can tip it below half. **Open, not changed**: without its failing numbers any change to the 0.5 would be a weakening without evidence. - Not done: the second Linux root run the brief asks for. - macOS after trunk's fast-forward to 0.65.2 (e9f5090; touched no file this lane edits): `cargo fmt --all -- --check` exit 0, clippy clean, `tools/gates.sh` **PASS** (`target/gates/20261119-050602/`: every step pass; suites vlog_parser 521, vlog_semantic 418, vlog_refactor 743, vlog_formatter 352, vlog_linter 672, lucisv_core 117, lucisv 143, lucisv_server 1957, lucisv_mcp 383, all 0 failed; corpus 814/6, node 12/0). An earlier gates run (03:58) was cut off mid-`lucisv_mcp` when the session restarted — not a guard kill — and is not counted. The Linux runs above were against 88546c8 + this lane, not against 0.65.2. **2026-11-19 (dev, fix round after QA's PASS WITH FINDINGS).** Tree: trunk 948f8a0 (0.65.3) + this lane. ssh to luhpe is down, so nothing in this round ran on Linux. 1. *scan_trace flake* (QA finding 2). `the_stages_add_up_to_the_scan_they_describe` now runs three verbose sessions over the same 40-file tree. It asserts `total > 0` and `sum <= total * 1.02` on **every** session (structural: the stages are disjoint pieces of the scan), and `sum/total >= 0.5` on the **best** of the three (a stall in the ~35% unattributed loop time spoils one sample, not all three). The reason is in the test's comment. The stage list moved to a helper, `named_stage_sum`. - Unmutated, macOS: 3 sample ratios 0.64 / 0.68 / 0.69. - *Does it still bite?* Temporary production mutations, each built into a copied test binary and then restored from a copy (`git status` clean for both files after): - `scan_trace.rs:321`, the `read` stage not recorded: 30/30 runs of the copied binary FAILED (best 0.41–0.47). Of 3 runs through cargo, one passed: the first, run just after the build. - `state/rescan.rs:358`, the `parse` stage not recorded: **27/30** FAILED (best 0.38–0.49), 3 passed. A per-sample count of the same mutant (what the old single-session assertion would have checked): 87/90 samples under 0.5. So best of three trades some sensitivity to one dropped mid-sized stage (~97% → 90% for `parse`, about a fifth of the scan) for not flaking under load. A dropped stage under ~17% of the scan is invisible to a 0.5 bound either way, as before. - *Under load*, the way QA did it (guarded; the test binary looped 200x while the whole `lucisv_server` binary looped beside it): 0/200 failed; a second 200x run, with 8 full-suite iterations counted alongside: 0/200. 2. *`tools/linux_check.sh`* (QA finding 5). - `set -o pipefail`, and tar's stderr is no longer hidden. - One argument is a command line as before. Several are quoted with `printf '%q '`, so `linux_check.sh grep -rn "two words" crates` keeps `two words` whole. - A fixed container name, `--name lucisv-linux-check`, so a second concurrent run is refused by Docker; exit 125 prints a hint. - The header says that untracked non-ignored files are sent and that runs are one at a time. - New `--dry-run`: builds the archive locally, prints its size and the remote command, and contacts nothing. Tested locally: - `bash -n` ok (shellcheck is not installed). - `--help` prints the whole header. - `--dry-run` with one string and with several arguments: the remote `CMD` shows the quoting kept. - `LUCISV_LINUX_HOST=nonexistent.invalid`: exit 255, ssh's error shown. - In a throwaway git repo with a tracked file deleted: `--dry-run` exit 1 and the real path exit non-zero, with `tar: b.txt: Cannot stat` shown; restoring the file makes the dry run pass. **The remote half is untested since this change**: the `--name` refusal, the 125 hint, and the multi-argument `CMD` reaching `bash -c` on luhpe. 3. *Linear-time headroom* (QA finding 3). `fastest_of_three` → `fastest_of_five`; `GROWTH_SLACK` unchanged. QA's loaded loop (30 runs, 36 busy loops on 18 CPUs, load average ~40, guarded): 30/30 passed. Worst ratios: colour **10.8x**, locate **8.5x** (limit 24x; QA saw 18.2x at three rounds). Cost: on the quadratic code a failing run now takes 5/3 as long (Linux root colour ~3 min, from the round-1 measurements). Checks this round (macOS, tree 948f8a0 + lane): - `cargo fmt --all -- --check` exit 0. - `cargo clippy --all-targets -- -D warnings` exit 0. - `tools/guard.sh -- cargo test -p lucisv_server`: 1848 + 106 + 3 + 0 passed, 0 failed (36 + 3 + 0 + 2 ignored). - `tools/gates.sh` **PASS** (`target/gates/20261119-053236/`): every step pass; suites 521/418/743/352/672/117/143/1957/383, all 0 failed; corpus 814/6; node 37/0. Unverified on Linux (all of it rests on round 1, against 88546c8 + lane): - the `scan_trace.rs` rewrite; - best of five in `large.rs`; - the new `linux_check.sh`; - QA's `qa_m6.rs` doc-comment move; - everything trunk added in 0.65.2 and 0.65.3; - the second root run, which never happened in round 1 either. ### Round 2 **2026-11-19 (dev, round 2: the Linux flakes).** Tree: 58d3db3 (0.65.6) plus this round, in `lucisv-wt/70b`. The brief reported master's record on Linux as 9 full runs, 3 with a failure, each from a different test. Linux means `tools/linux_check.sh` on luhpe: the CI job image, 4-CPU cap, kernel 6.8.0, ext4 under overlayfs, `CONFIG_HZ=1000`, debug build. macOS means arm64 with 18 CPUs; another lane was running there too. Every macOS `cargo test` went through `tools/guard.sh`, and there was no guard kill. *Method.* - Loops of the single test, in the job image, run alone and then under 8 busy loops on the 4-CPU cap. The baseline was rebuilt in the same container with `git apply -R` of this round's patch, so before and after share one build cache and one box. - Whole-suite runs with `--no-fail-fast`. Each one keeps its result totals and every failing test's output. - Temporary instrumentation where the output was not enough. It was taken out again, and each touched file was restored from a copy and checked with `cmp`. **Flake census** | test | platform | before | cause | fix | after | |---|---|---|---|---|---| | `lucisv/tests/cli.rs` `stdin_and_lines_are_usage_errors_with_a_filelist` | Linux root | 2/9 master runs; 1/5 baseline runs; loop 0/200 alone, **42/200 loaded** | `run_with_stdin` `expect`ed the stdin write. A usage error exits before reading, so the write races the exit and gets `BrokenPipe`. | Both stdin helpers write through `feed`, which ignores `BrokenPipe` only; `run_with_stdin` is now `run_with_stdin_raw` plus `--no-cache`. | loop 0/200 alone, **0/200 loaded**; 0 in 30 Linux suite runs | | `lucisv_mcp/tests/qa_m8.rs` `qa_argument_order_and_repetition_cannot_undo_read_only` | Linux root | 1/5 baseline runs; loop 0/200 alone, **37/100 loaded** | Same race: `run` `unwrap`ped `writeln!` to a server that refuses `--read-only=false` and friends with exit 2. Found by the census; not in the brief. | `run` stops writing on `BrokenPipe` and `unwrap`s any other error. | loop 0/200 alone, **0/100 loaded**; 0 in 30 suite runs | | `lucisv_server/tests/e2e.rs` `opening_a_two_thousand_line_buffer_does_not_delay_the_request_behind_it` | Linux root | 2/9 master runs (205.15 ms against 200) | A fixed 200 ms against a measured floor of 146–179 ms best of three, quiet. Under 8 busy loops the open took 0.5–1.1 s, so the old bound would fail every time. | The budget is `OPEN_OVER_PARSE` (6) times the best of 5 in-process tolerant parses of the same buffer, interleaved with the 5 opens. | 0/20 alone, 0/20 loaded; 0 in 30 suite runs | | `lucisv_mcp/tests/qa_m1.rs` `qa_rework_a_rename_over_with_an_old_mtime_and_the_same_size_is_seen` | Linux | 1/9 master runs (`--user`); loop **39/300 and 12/150 alone**, 0/200 loaded | **A product bug** (Handshakes): ctime moves in 1 ms ticks, and a same-size rewrite with the old mtime put back inside the tick is invisible to `Stamp::check`. All 12 instrumented failures had identical `(ctime, nsec, ino)`; all 261 instrumented passes were 1–2 ms apart. | **None, on purpose.** The test is right. | unchanged: 0 in the last 30 Linux suite runs, but about 1 in 10 alone | | `lucisv_mcp/tests/qa_m3.rs` `qa_lucisv_check_over_the_same_tree_while_the_server_formats` | macOS, under 18 busy loops | **hung** once in 2 runs (still running after 9 min) | `sample` showed the checker thread in `Command::output` → `read`, with no `lucisv` child alive. `lsof` showed the test's `lucisv-mcp` server holding the other end of that pipe: it had inherited the pipe when it was spawned while the checker was making one (macOS has no `pipe2`). `join` waited on the checker, and the server lived until the test ended. Found by the census. | The server is spawned before the checker thread starts. | 0 hangs in 20 macOS runs under load; 0 in 20 Linux runs | Nothing else failed in any run: Linux root 5 baseline runs, then 10 + 10 on the fixed tree; Linux `--user` 10; macOS 2 + 20 under load (the second batch under 9 busy loops, since 18 put one suite run over 20 min). Round 1's `scan_trace` and `large.rs` fixes ran on Linux in all of them and never failed. **The wall-clock assertions** (an inventory of every test-code assertion on measured time): - **Changed:** e2e.rs didOpen (above). - **Ratios already:** `large.rs` `assert_grows_linearly` (round 1); `lens.rs:756` (`whole_file * 10 < walk`); `scan_trace.rs` (round 1). - **Algorithmic guards with absolute bounds, left as they are:** `pairs.rs:1159/1171/1190` (2 s, ~45x the honest 5–44 ms, against 7–17 s quadratic); `regex.rs:631` (500 ms against microseconds, exponential matcher far past it); `lexer.rs:1313` (5 s, "three orders of magnitude" in either build); `e2e.rs:5780` (10 s, 25x the measured 0.4 s). The regression each one guards is two or more orders of magnitude past its bound, and the honest cost is one or more below it, so a ratio would buy nothing. None failed in any run. - **"Nothing was waited for" bounds, left as they are:** `startup.rs:488` and `:1071` (< 1 s, against a 2 s bound and a 25 ms bound), `startup.rs:528` (< 5 s against a 30 s bound), `e2e.rs:9118/9130` (< 1 s against the 1.5 s grace). Each has to stay under the wait it proves was skipped, so raising it is not free, and none failed. - **Lower bounds** (`e2e.rs:9096/9193`, `startup.rs:182`): load can only make them pass. - **Corpus-only latency budgets**: `hierarchy.rs:1123`, `lens.rs:754`, `type_hierarchy.rs:1289/1291`, `completion/mod.rs:787-789/856`, `vlog_refactor/tests/corpus.rs:100/175`, `vlog_semantic/tests/workspace.rs:977`. These skip without `corpus/`, which the Linux tree does not have. They are budgets for a known machine. Not changed, and not exercised on Linux. - **`#[ignore]`d:** `large.rs:727-735`, `:764`. **The mtime/sleep review.** - `set_modified` users: - `wire.rs:1250`, `qa_m6.rs:568` and `qa_f1.rs:666` set an hour-old mtime on purpose. They do not rely on it moving. - `qa_m1.rs:588`, a rename-then-recreate, gets a new inode. - `qa_m1.rs:605`, a same-mtime rewrite, rests on the racy rule. - `qa_m1.rs:617` restores an old mtime. Its ctime moves across a process spawn and two calls, far more than a tick. - `qa_m1.rs:936` is the product bug above. - Sleeps: `qa_m3.rs:598/622`, `e2e.rs:9151` (the 1.7 s that outlasts the 1.5 s grace) and `cancel.rs:347`. None failed, so all are left. **Stdin writers reviewed.** Every test that writes to a child's stdin was checked: - The interactive sessions (`cache`, `qa_m2/3/4/6`, `qa_f1/f2`, `attacks`, `read_only`, `wire`, `opentitan*`, `e2e`'s `Live`) only write to a server the test expects to be alive. A `BrokenPipe` there means the server died, which is a failure, so those writes stay strict. - The one-shot sessions write to a server that reads to EOF and exits only when told to, so the strict write stays: `e2e.rs` `talk_with`, `ifdef_folding.rs` `talk`, `qa_m7.rs`, `hierarchy_cap.rs`. - `qa_m1.rs` `one_shot` already ignored write errors. **Evidence the stdin fixes neither hide anything nor weaken anything** (macOS): - With a 300 ms sleep before the write (the race made certain), the **old** helpers fail 1/1 with `BrokenPipe` (`cli.rs:104`, `qa_m8.rs:117`). The fixed ones pass, and so does the whole of `cli` (113/113) and `qa_m8` (6/6) with the sleep in. So no test needed the write to succeed. It never meant the child had read anything: every input is far smaller than a pipe buffer. - Sleeps removed; both files compared with `cmp` against copies. **Mutation table** (production sabotage on macOS, restored from a copy and checked with `cmp` / `git status`): | test | sabotage | failed? | restored | |---|---|---|---| | cli `stdin_and_lines_are_usage_errors_with_a_filelist` | `args.rs:486` `if false && …` (accept `-` with `-f`) | yes, cli.rs:1942 `left: 0, right: 2` | yes | | qa_m8 `qa_argument_order_and_repetition_cannot_undo_read_only` | `lucisv_mcp/src/main.rs:93` accept `--readonly` as `--read-only` | yes, qa_m8.rs:342 "started a server" | yes | | e2e didOpen | `server/notification.rs` didOpen: parse the buffer 4 extra times | yes, 3/3 at 6.94x (84 ms; the old 200 ms would pass) | yes | | e2e didOpen (sensitivity) | the same, 3 extra times | no, 3/3 passed at 5.82–5.97x | yes | | qa_m3 `qa_lucisv_check_over_the_same_tree_while_the_server_formats` | `apply.rs` `commit` writes `after` plus `"\n"` | yes, qa_m3.rs:745 `m00.sv` | yes; then 3/3 pass | *The didOpen ratio, measured.* | where | load | best open | best parse | ratio | |---|---|---|---|---| | macOS | quiet, 8 runs | 31 ms | 11 ms | 2.66–2.77x | | macOS | 36 busy loops on 18 CPUs, 15 runs | 34–41 ms | 12–14 ms | 2.48–3.15x | | Linux root | quiet, 20 runs | 146–179 ms | 50–73 ms | 2.29–3.55x | | Linux root | 8 busy loops on 4 CPUs, 20 runs | 0.50–1.12 s | 188–394 ms | 2.50–3.29x | The wall clock moves 6x and the ratio stays in 2.3–3.6x, so 6 has about 1.7x headroom over the worst ratio seen. - What it buys: on this Mac the new bound is *stricter* than the old one. Four extra parses fail it at 84 ms, where 200 ms needed about 15 extra. - What it costs: on the quiet Linux runner it is looser. There the old bound sat at the box's floor, which is why it flaked. - What it still cannot catch: the §46 defect itself, at this fixture's size, as the test's doc comment always said. **Counts.** - `#[test]` attributes: 5 471 at HEAD and in this tree. No test was added or removed. - macOS whole suite: 97 result lines, **5413 passed, 0 failed, 64 ignored** on every run here. - Linux: **5407 passed, 0 failed, 64 ignored**. The six macOS/Windows-only tests are not compiled there. **Final runs on the final tree** (Linux, all of the above changes): - root: `cargo clippy --all-targets -- -D warnings` exit 0; `cargo test --workspace --no-fail-fast` green **10 consecutive runs of 10**, each 97 result lines, 5407 passed, 0 failed, 64 ignored. - `--user`: clippy exit 0; tests green **10 consecutive runs of 10**, the same totals. - macOS, after the last `crates/` edit: `tools/gates.sh` **PASS** (`target/gates/20261119-111810/`). That covers fmt, clippy, build and docs, suites 521/435/743/376/672/119/151/2011/384 all with 0 failed, corpus 814/6 and node 37/0. The 20 loaded macOS runs above were also on this tree. - No guard kill anywhere. The `lucisv-wt/70b/.lane70b/` probe scripts the Linux runs used are deleted from the tree; copies are in the session scratchpad. Not done or not verified: - The `qa_m1` product bug: reported, not fixed. Its test still fails about 1 run in 10 on Linux when run alone. - The `qa_m3` fix is argued, and the `lsof` evidence shows the mechanism, but the hang has no deterministic reproduction. - The corpus-only budgets never ran on Linux. **2026-11-19 (dev, round 2 continued: the stamp fix; scope extended by the lead to `lucisv_mcp/src/project/files.rs`).** *How the stamp works.* - `read_source` stats a file, notes the time, reads it and hashes it. That gives the `Stamp`: size, mtime, hash, `read_at` and `identity`. `identity` was the `(ctime, ctime_nsec, ino)` triple on Unix and zeros elsewhere. - `Project::refresh` calls `check` on every file per tool call. `Same` means the file is skipped. `Suspect` means `reread`: read and hash it again, re-index only when the hash moved, and replace the stamp. - So an extra `Suspect` costs one read and one hash. A missed change costs stale answers, and stale *edit plans* in a tool agents use to write files. - The racy rule before: `current mtime + 2 s > read_at`. Nothing for the ctime. *What git does.* An index entry whose mtime is not older than the index file itself is "racily clean": stat data cannot prove it unchanged, so it is compared by content. The same idea applies to every timestamp the stat comparison trusts. *The fix* (`files.rs`, production lines ~150 → ~240): - **Invariant**, as it is written in `Stamp::racy`: a stamp is trusted on a later match only if every timestamp it trusts (the mtime, and the ctime where there is one) is at least `RACY` older than the moment the stamp was taken. A missing timestamp counts as racy, and so does one later than the read. - The test runs on the stamp's own values. On a match they equal the current ones; on a mismatch the answer is `Suspect` anyway. All the arithmetic is `checked_*`: the old `mtime + RACY` could panic on an absurd mtime. - **`RACY` 2 s → 3 s.** The window has to outlast the coarsest timestamp plus the filesystem clock's lag behind `read_at`'s clock: - Linux ticks (1–4 ms) and 1 s stamps (ext3, many NFS/SMB mounts) fit in 2 s. - FAT's 2 s stamps do not. Take a timestamp `T` and a read at `T + 2 s`. A write a tick later, from a coarse clock that lags, can truncate to the same `T`. 3 s leaves a second of margin. - Cost: a just-changed file is re-read on every call for 3 s instead of 2. - Not covered: a file server whose clock is more than ~1 s *behind* ours. Git has the same assumption. - **A wall clock stepped back** (new): after the read, a step back can give a new write the very timestamp the stamp holds. - The stamp now also keeps `read_mono` (an `Instant` taken with `read_at`). - `check` distrusts any stamp whose wall clock is now more than `STEP_BACK` (100 ms) behind where the monotonic clock says it should be. That holds until the file is re-read. - A wall clock that ran *ahead*, as across a suspend the monotonic clock slept through, is not doubted. - A step back smaller than 100 ms stays inside `RACY`'s one-second margin. - **`identity` is `Option, ino }>`.** `None` off Unix; a ctime that does not fit a `SystemTime` is racy. - **The decision is a pure function**, `Stamp::compare(Seen, Clocks)`. `check` is one `stat`, then `compare(Seen::of(meta), Clocks::now())`. That is what lets the unit tests feed values without a file or a clock. - **Off Unix** (no ctime in std on Windows): the racy rule still applies to the mtime. The hole that remains there is old: a same-size rewrite that restores an old mtime *outside* the window is invisible. There is nothing else in the stat to see it with, as the `identity` doc says. - **Test fixtures**: `project/tests.rs` `settle` and the existing `a_stamp_sees_an_edit…` used to age a stamp by moving `read_at` alone. That now looks exactly like a clock stepped back. They use the new `#[cfg(test)] Stamp::taken_later`, which moves both clocks. *New unit tests* (`project::files::tests`, deterministic, no file): - `a_match_is_trusted_only_when_every_timestamp_was_settled_at_the_read`: neither racy, mtime, ctime, both, `RACY − 1 ns` (suspect) and exactly `RACY` old (same). - `a_timestamp_later_than_the_read_or_missing_is_racy`: ctime after the read, ctime `None`, mtime `None`, and off-Unix `identity: None` (mtime decides). - `a_wall_clock_stepped_back_since_the_read_distrusts_the_stamp`: stepped back, behind the read, ahead (suspend), jitter under the tolerance, and a stamp aged on both clocks. - `any_moved_field_is_suspect_however_settled`: size, mtime, inode and ctime each moved on a settled stamp. *Mutations* (copies restored, `cmp` clean): | sabotage | result | |---|---| | ctime dropped from the trusted list (`[Some(self.mtime), None]`) | FAILED: `…every_timestamp_was_settled…` at "ctime racy" (`Same` ≠ `Suspect`), and `…later_than_the_read…` | | `clock_stepped_back` never consulted | FAILED: `a_wall_clock_stepped_back…` | *The other caches, audited for the same hole* (none has it, so nothing was stopped on): - **Language server views** (`state/views.rs` `file_view`): no stamp at all. A view is dropped on `set_document`, `close_document`, `update_one`, `rebuild_index_with` and `begin_widen`, that is, on notifications. A disk change no one reports is stale by design, as its doc says, with `hover`'s `spells_exactly` guard. It never trusts a timestamp, so a same-tick rewrite does nothing worse to it than any unreported write. - **Persistent index cache** (`index_cache.rs`, `known_facts` → `facts_now`/`facts_for`): keyed by `content_hash` of the text about to be indexed. The bytes are always read, so there is no timestamp to fool. - **MCP own store** (`lucisv_mcp/src/cache.rs`, `Records::take(path, hash)`): by content hash, after `read_source` read the bytes. Its one `modified()` only ages temporary files for removal. `Project::analysis` reads the file every time and caches by hash. - **CLI format cache** (`lucisv_core/src/cache.rs`): `Entry.content` is the FNV-1a of the bytes, read on every run; no mtime. - No `modified()`/ctime freshness check exists anywhere else outside tests (`rg modified\(\)|mtime` over `lucisv_server`, `vlog_semantic`, `lucisv_core` and `lucisv` sources). *Performance* (temporary `eprintln!` of stat checks and suspects per `refresh` in `project/mod.rs`, one binary before and one after, the source restored with `cmp`; driver `drive.py` in the session scratchpad, guarded): | session | calls | stat checks | re-reads before | re-reads after | |---|---|---|---|---| | OpenTitan `hw/ip`, 37 read calls (find/outline ×18, hierarchy) | 37 | 78 498 | 0 | 0 | | copy of `hw/ip/uart`, 3 rounds of `format` then 8 reads | 33 | 1 120 | 120 | 120 | | copy of `hw/ip/uart`, `chmod` every file, 8 calls at once, 3.5 s pause, 4 calls | 13 | 420 | 35 | **315** | - Ordinary reads never re-read. An edit already makes the mtime fresh, so it costs the same as before. - The extra re-reads come only from a file whose ctime moved while its mtime stayed old (`chmod`, `cp -p`, `touch -r`, rename-over). Each such file is re-read on every call for 3 s, then never again. - A re-read whose hash did not move re-indexes nothing. *Checks, final tree.* - macOS: - `cargo fmt --all -- --check` exit 0. - `cargo clippy --all-targets -- -D warnings` clean. - `tools/guard.sh -- cargo test -p lucisv_mcp`: all pass, 388 tests, 4 of them new. - `tools/gates.sh` **PASS** (`target/gates/20261119-114518/`): suites 521/435/743/376/672/119/151/2011/388, all with 0 failed; corpus 814/6; node 37/0. - Cross-check, the lead's command, for `-p lucisv -p lucisv_mcp`, on both `x86_64-pc-windows-gnu` and `x86_64-unknown-linux-musl`, including `lucisv_mcp`'s unit tests (`--profile test --bin lucisv-mcp`): clean, no warning. - `-p lucisv_server` fails on Windows at `state/incremental.rs:161` (E0507, `dir_id` moved in a closure). That is the bug 0.65.7 fixed on master, in a file this lane does not touch. - `--all-targets` on Windows also fails in `tests/qa_m3.rs`, which uses `std::os::unix` without a cfg. That predates this lane, and gates' `cross` step does not build tests. - Linux: - the qa_m1 test alone: **0/300 failed as root and 0/300 as `--user`** (before the fix: 39/300 and 12/150 as root). - root: clippy exit 0; whole suite green **10 consecutive runs of 10**, each 97 result lines, 5411 passed, 0 failed, 64 ignored. That is 5407 plus the 4 new unit tests. - `--user`: clippy exit 0; green **10 of 10**, the same totals. - The probe scripts are deleted from the tree again; copies are in the session scratchpad. *Changelog paragraph (for the lead):* > **lucisv-mcp no longer serves stale contents after a same-size rewrite > that restores an old mtime.** On Linux, ctime moves in 1 ms ticks. A > file whose ctime had just moved (a rename-over, say), read by the server > and then rewritten at the same size with its old mtime put back (`cp -p`, > `rsync -t`, `touch -r`) inside the same tick, matched its stamp in every > field. The server then answered from the old text until the file changed > again. The "racy" rule now covers every timestamp the stamp trusts, > ctime as well as mtime. Its window is 3 s (it was 2 s, too close to FAT's > 2-second timestamps). A wall clock stepped back since a read now > distrusts the stamp. Re-reads rise only for files whose metadata changed > in the last 3 s. **Tests:** the suite is now stable on Linux. > - Two stdin helpers tolerate a child that exits before reading. > - The didOpen latency test measures its budget against a parse of the > same buffer instead of a fixed 200 ms. > - A macOS-only hang in an MCP concurrency test (a pipe inherited across > threads) is fixed. ## QA log **2026-11-19 (QA, macOS arm64, 18 CPUs; tree = 948f8a0 + this lane).** Verdict: **PASS WITH FINDINGS.** Linux was **not** independently verified. *Scope.* Every hunk of `git diff -- crates/` is inside a `#[cfg(test)]` module or a `tests/` file: `cli.rs`, `cache.rs`, `qa_m6.rs` (integration tests), `walk.rs`/`apply.rs`/`file_ops.rs`/`large.rs` (inside `mod tests`), `filelist.rs` (under `state/tests/`), `hover.rs` (an import in the `#[cfg(test)] mod qa_hover_declarations`), `includes.rs` (the `#[cfg(test)] mod qa_round2` attribute widened to `all(test, any(macos, windows))`, the two per-test cfgs dropped — same compiled set). `walk.rs`'s new `Drop for TempTree` sits in `mod tests` (the struct is test-only). No `verify.rs`, no production line, `tokens.rs` and `convert.rs` unmodified. *No skip on macOS.* All 11 tests (plus `apply`'s copy in `tests/qa_m3.rs` and `--bin lucisv-mcp`) run with `--nocapture`: all `ok`, no `skipped:` line. *Mutations* (copies in the scratchpad, restored with `cp`; `git diff --stat` and the full `git diff` compared byte-for-byte with the pre-mutation capture: identical): | test | mutation | failed? | restored | |---|---|---|---| | cli `an_unreadable_directory_is_a_warning…` | `walk.rs` `entries`: `Err(_) => return` (no warning) | yes, cli.rs:2277 | yes | | cli `the_walks_warnings_leave_check_modes…` | same | yes, cli.rs:2296 | yes | | walk `an_unreadable_directory_is_skipped…` | same | yes, walk.rs:847 | yes | | filelist `an_unreadable_directory_is_said_once…` | same | yes, filelist.rs:106 | yes | | walk `an_unreadable_ignore_file_is_said…` | `walk.rs` `push_ignore`: drop the `say` | yes, walk.rs:864 | yes | | apply `a_write_that_fails_after…` (bin + qa_m3) | `apply.rs:192` message `written`→`wrote` | yes, both targets, apply.rs:322 (the post-probe half) | yes | | cache `an_unwritable_cache_directory…` | asserted count 1→2 | yes, cache.rs:276 | yes | | qa_m6 `qa_a_cache_directory_without_permission…` | asserted count 1→2 | yes, qa_m6.rs:485 | yes | | file_ops `a_case_mismatched_include…` | `read.contains` inverted | yes, file_ops.rs:729 | yes | | large colour / locate | own mutation: a fresh walker per piece in `tokens::flatten`, a fresh walker per hit in the test's loop | yes: **74.0x** and **64.5x** (limit 24x) | yes; `tokens.rs` no diff; pass again at 8.1x/8.1x | *Probe attacks.* No false skip found: every probe builds its scratch path next to (same filesystem as) the test's own, under a pid(+counter)-unique name (`filelist.rs`'s `modeprobe` is pid-only but has one caller); a setup failure panics (`expect`/`unwrap`) instead of returning "not refused"; a spurious error can only read as "refused", which runs the test (a loud failure, not a masked one); there is no panic path between the chmod and its restore; probes remove their paths (Drop or `remove_dir_all`). Root with DAC capabilities gets "not refused" (dev-observed on Linux, not re-run). 20 loops of the eight affected targets (cli walk, core walk, mcp bin + qa_m3 apply, cache, qa_m6, server filelist, server file_ops): **0/160 failures**, and no `lucisv*` temp dir or mode-000/555 path left behind (walk.rs's new `Drop` works; before it, 18 walk dirs per run were left in `$TMPDIR`). *Linear-time tests.* Under load, best of three interleaved: 30 runs while a release `cargo build` ran: 0/30 failed, ratios 7.9–8.5x; 30 runs with 36 busy loops on 18 CPUs (load ~30) as well: 0/30 failed, ratios **up to 18.2x (colour) and 13.9x (locate)**, so only ~1.3x left under the 24x limit at 2x oversubscription. Judgement: a constant-factor regression of any size (2.9x or 100x) passes by design: the ratio cannot see it, and the old absolute budgets that could were dropped on purpose. n·log n passes (~9.9x). A mixed cost slips through when its quadratic part is under ~28% of the smallest size's cost (`8(1-q)+64q ≤ 24`). That is acceptable for a test named "linear time" that guards against the per-call converter coming back (60–74x). *scan_trace flake (dev's open item) — reproduced on macOS.* I built an instrumented test binary (a temporary `eprintln!` of sum/total, source restored at once, `git diff` clean) and ran the test 200x under 36 busy loops: 0/200 failed, sum/total 0.62–0.69, total 2.1–4.4 ms. Then 200x while the whole `lucisv_server` suite looped beside it: **1/200 failed**: stages **2.21 ms of total 5.10 ms (0.43)**. Two more runs came in at 0.54 and 0.67 with totals of 4.8 and 2.7 ms. Analysis: `total_ms` runs from `ScanTrace::new` in `begin_scan` to `landed`. The named stages are disjoint sub-intervals of it, so `sum ≤ total` is deterministic (up to `{:.2}` rounding, 19 × 0.005 ms). But ~35% of an unloaded scan is deliberately unattributed: the server's per-step `watching` callbacks, progress/log sends and loop overhead in `server/index.rs` `scan_once`. A stall that lands there grows `total` and no stage. The failing sample is exactly that: the stage sum is normal (2.21 ms) and the 2.9 ms extra sits outside every stage. With U≈0.35·T, one stall longer than ~0.3·T in unattributed code trips the bound: ~0.75 ms on macOS, ~6 ms on the Linux runner's ~20 ms scan, where CFS quota throttling under `--cpus` gives stalls of tens of ms. So the lower bound is a statistical claim and is unsound under load on any machine. **Recommended change** (outside this lane's files, not made here): keep `sum <= total * 1.02` per scan, and assert the lower bound on the best of three sessions. Run `Session::verbose_wide` three times and require `max(sum/total) >= 0.5`, the same "load slows one sample, not every sample" argument as `fastest_of_three`. The alternative is to drop the lower bound and assert only that the CPU-bound stages (`discovery`, `read`, `parse`) are each > 0. *Gates (macOS, `tools/gates.sh`, `target/gates/20261119-052309/`):* PASS — fmt, clippy, build, docs pass; suites vlog_parser 521/0, vlog_semantic 418/0, vlog_refactor 743/0, vlog_formatter 352/0, vlog_linter 672/0, lucisv_core 117/0, lucisv 143/0, lucisv_server 1957/0, lucisv_mcp 383/0; corpus 814/6; node 37/0. Separately `cargo fmt --all -- --check` exit 0, `cargo clippy --all-targets -- -D warnings` exit 0 (only cargo's pre-existing manifest `authors` notice), guarded `cargo test --workspace --no-fail-fast`: 93 result lines, **5307 passed, 0 failed, 57 ignored**, the dev's count exactly. *Linux: NOT verified by QA.* `tools/linux_check.sh 'echo ok'` (once): `Permission denied (publickey)`, exit 255; not retried. These results rest on the dev's word alone: root clippy clean and 5301 passed/0 failed; `--user` clippy clean and 5300 passed/1 failed (the scan_trace flake, which is now reproduced on macOS). The second root run was never done. Nothing here has run on Linux since the 0.65.2/0.65.3 fast-forwards. *Findings.* 1. (low, fixed by QA) `crates/lucisv_mcp/tests/qa_m6.rs:447`: the new helper was inserted between the test's doc comment and the test, so `qa_a_cache_directory_without_permission…`'s four-line doc comment had become the head of `listing_is_refused`'s doc. I moved it back above the test; the diff now only adds the helper and the guard. 2. (medium, open, outside scope) `server/tests/scan_trace.rs:163`: the flake above, with its reproduction and the recommended change. 3. (low) `large.rs` linear-time margin under heavy oversubscription: 18.2x of 24x seen. Watch it on the 4-CPU runner; if it flakes, raise the number of rounds, not `GROWTH_SLACK`. 4. (low, pre-existing) `large.rs` `references_on_one_giant_line…` times a copy of the `Server::large_scan` loop (`server/large_file.rs:151`), not the production code, so a regression there is not caught. The mutation had to go into the test's own loop. 5. (low) `tools/linux_check.sh` review: - The pipeline has no `pipefail`, and tar's stderr goes to `/dev/null`. A local `git ls-files`/tar failure, or a file that vanished, gives a silently partial tree, and the run is judged on it. A missing archive does fail remotely (`tar xzf` under `set -e`). - `cmd=$*` drops argument quoting (`linux_check.sh grep "a b" f` runs `grep a b f`). The documented single-string form is fine. - `--others --exclude-standard` ships any untracked, non-ignored file (a stray `.env`, key or dump) to luhpe, though only into a `--rm` container, not the volume. Today that is just this README and the script itself (16 KiB). - Not safe to run concurrently: two runs share the `lucisv-linux-check` volume, so they race on a cold rustup install into `/cache`. A `--user` run's `chown -R /cache` flips ownership under a running root build, and one run can execute test binaries the other rebuilt from a different tree. A host-side `flock`, or a fixed `docker run --name` so a second run fails fast, would close this. - The remote quoting is right: one `%q` for the one shell level on the host, and `docker exec`/`docker run` pass argv with no shell. Exit status propagates through ssh → docker → `bash -c`. *Fixed by QA:* finding 1 only. *Unverified:* everything on Linux, as above. ### Round 2 QA **2026-11-19 (QA, round 2; tree = 934d472 + f910554 in `lucisv-wt/70b`; macOS arm64 18 CPUs, Linux = `tools/linux_check.sh` on luhpe).** Verdict: **PASS WITH FINDINGS.** No stale read that the invariant claims to prevent, no panic, no test that passes without testing, no Linux failure. *Baseline (macOS).* `cargo fmt --all -- --check` exit 0. Guarded `cargo test -p lucisv_mcp -p lucisv -p lucisv_server`: 24 result lines, 2569 passed, 0 failed, 53 ignored. Full `tools/gates.sh` **PASS** (fmt, clippy, build, suites 521/435/743/376/672/119/151/2030/388, docs, corpus 814/6, node 37/0, cross). (`lucisv_server` is 2030 here, not the dev's 2011: the dev measured on 0.65.6; 934d472 adds 19.) `#[test]` counts vs 934d472: `cli.rs` 113→113, `e2e.rs` 109→109, `qa_m3.rs` 31→31, `qa_m8.rs` 6→6, `project/tests.rs` 3→3, `files.rs` 3→7. The only removed assertion is e2e's `best <= 200 ms`, replaced by the ratio. Cross, `--all-targets`, for `lucisv_mcp`: linux-musl clean. Windows fails only in `tests/qa_m3.rs` (12 errors, `std::os::unix` and `PermissionsExt` with no cfg). That is pre-existing: the same 8 `std::os::unix` uses are at 934d472. Every other target builds for Windows (`--bins --profile test` plus every `--test` except `qa_m3`), including `files.rs`'s unit tests. *PART 2: the stamp.* - **Real files, the real binary.** A driver (`stale.py`, kept in the session scratchpad) speaks MCP stdio to `lucisv-mcp` and asks `find` for the new module name and then the old one. It covers 11 operations: in-place same-size rewrite plus `utime(old)`; the same with `touch -r`; rename-over of a same-size, old-mtime file; hard-link swap; `cp -p`-style `O_TRUNC` rewrite plus `utime` plus `chmod`; truncate-and-rewrite plus `utime`; mmap write plus msync, unmap and `utime`; vim-style write-beside, rename and `utime`; replacing the file with a symlink to a same-size file; `chmod` alone (expect the old content); and a directory rename that brings in another same-size, old-mtime `c.sv`. It runs each at delays of 0, 1 ms, 10 ms, 1 s, 2.9 s, 3.1 s and 10 s after the server's read, with two preparations: stamp settled (ctime > 4 s old) and the original hole (ctime made fresh by `utime(old)` just before the read). That is 154 cases per run. | platform / fs | cases | stale | |---|---|---| | macOS APFS | 154 | 0 | | Linux root, overlayfs (`/w`) | 154 | 0 | | Linux root, overlayfs `/tmp` | 154 | 0 | | Linux root, tmpfs `/dev/shm` | 154 | 0 | | Linux `--user`, the same three | 3 × 154 | 0 | - **The exact hole, hit on purpose.** A sequential loop does `utime(old)`, then `find` (the read), then a same-size rewrite plus `utime(old)` immediately. It counts the runs whose stat after the write equals the stat at the read: size, mtime, ctime and ino all identical. | binary | fs | runs | stat-identical | stale | |---|---|---|---|---| | **934d472 (before)** | overlayfs | 300 | 65 | **65** | | **934d472 (before)** | tmpfs | 300 | 87 | **87** | | this lane, root | overlayfs | 300 | 65 | 0 | | this lane, root | tmpfs | 300 | 125 | 0 | | this lane, `--user` | overlayfs | 300 | 52 | 0 | | this lane, `--user` | tmpfs | 300 | 106 | 0 | | this lane, macOS | APFS | 100 | 0 | 0 | So the driver does detect the bug. The old code is stale exactly when the stat is identical, and the fix is fresh in every one of those runs. - **Property test of `compare`.** I wrote my own xorshift generator and included it temporarily in `files.rs` by `#[path]` from the scratchpad. `files.rs` was restored from a copy and `cmp`-checked; `git status` is clean. It ran **3 000 000 cases**: moved 970 519, racy 2 449 889, clock step 677 250, and **232 760 cases where nothing doubted → all `Same`** (no needless re-read). No `Same` was returned for any moved, racy or stepped case. There was no panic, including at u64/i64 extremes, the epoch, times before 1970, `RACY ± 1 ns`, `STEP_BACK ± 1 ns` and an `Instant` behind the read. (Raw nsec ≥ 1e9 cannot be built as a `SystemTime`. By reading `identity()`: `i64::MAX` s plus `i64::MAX` ns fits a `Duration`, so the sum does not panic, and an out-of-range result becomes `None`, which counts as racy.) Each of these mutations fails it: ctime dropped, step check dropped, `>` → `>=`, identity ignored. - **Clocks.** From the std 1.100 docs: `Instant` is `CLOCK_UPTIME_RAW` on Darwin and `CLOCK_MONOTONIC` on Linux, both stopped in suspend; Windows uses QPC. Through `compare` with injected clocks: - 1 h suspend: `Same`, and also `Same` if `Instant` counts the suspend. - 5 s backwards step: `Suspect`. After that one re-read: `Same`. A file written 2 s before the step and read after it: `Suspect`. - 5 s forwards step: `Same`, which is safe locally because the next write is stamped after the step. - Drift: 99 ms → `Same`, 115 ms → `Suspect`. - On Linux NTP slews `CLOCK_MONOTONIC` along with the wall clock, so only steps diverge. On macOS `UPTIME_RAW` is not slewed. Measured here, the wall clock runs **ahead** of it by +6.37 ppm (stable over 300 s), so the step rule never fires. A Mac drifting the other way at that rate would distrust stamps older than ~4.4 h once: one re-read of each, with no re-index. Benign. - **TOCTOU.** The stat comes before `Clocks::now()`, which comes before the read. A write between the stat and the read leaves an old stat with new bytes, and the next stat differs, so this is safe. A write after the read in the same tick is covered by the racy rule. `read_at` is earlier than the read itself, which errs toward racy. - **Skew tolerance** (by arithmetic). A later write can only carry the stamp's timestamp if `RACY ≥ granularity + (local clock − file server clock)`. That gives FAT (2 s) 1 s, 1 s filesystems (HFS+, ext3, NFSv2/SMB1) 2 s, and ns filesystems ~3 s. Past that skew, an *ordinary* same-size edit inside one server tick is invisible, not only an mtime-restoring one. Not testable here (no FAT/NFS). - **Audit of the other caches: confirmed.** The server's `file_view` (`state/views.rs:74`) has no stamp. `index_cache.rs:226/298` is keyed by `content_hash`. MCP `Records::take(path, hash)` (`cache.rs:110`) is too. `Project::analysis` re-reads every call (`mod.rs:301`), so `read` and `outline` were never exposed; only index answers (`find`, hierarchy, names) were. The only other `metadata` uses outside tests are `walk.rs:194` `(dev, ino)` for cycles and MCP temp-file aging. Experiment: the CLI format cache with a formatted file, `--check` (from cache), then a same-size unformatted rewrite with the mtime restored, then `--check`. Result: "would reformat", exit 1. Correct. *PART 1.* - None of the four tests skips on macOS (`--nocapture`). My own mutations (copies restored, `git status` clean): | test | mutation | result | |---|---|---| | cli `stdin_and_lines…` | `args.rs:487` message reworded | FAILED cli.rs:1943 | | qa_m8 `qa_argument_order…` | `main.rs:94` "unknown flag" | FAILED qa_m8.rs:345 | | e2e didOpen | 100 ms sleep in the didOpen arm | FAILED 10.63x (142 ms; old 200 ms would pass) | | qa_m3 CLI-while-formatting | CLI `--check` exits 3 instead of 1 | FAILED qa_m3.rs:743 | - **BrokenPipe callers.** There are 22 `run_with_stdin(_raw)` callers. Each asserts the exit code and/or output, except `cli.rs:2149-2150`, which asserts only `stdout == ""` (finding 4). `qa_m8` `run` has 5 callers. Each asserts the status or reads answers by id, so a server that died leaves a missing answer and the test fails. - **Ratio, 50× under load each.** macOS (36 busy loops): 0/50 failed, 2.40–3.09x. Linux root (8 busy loops, opens ~1 s): 0/50 failed, **2.25–4.09x**. The worst is above the dev's 3.55; headroom to 6 is 1.47x. The blind spot of three extra parses is acceptable for a test named for unbounded delay (see finding 5 for the machine dependence). - **qa_m3.** The `lsof`/`sample` evidence fits the mechanism. On macOS std creates pipes with `pipe()` and then sets `FD_CLOEXEC`. The fix removes the only intra-test overlap: the main thread spawns nothing while the checker runs. **100/100 green on macOS under 36 busy loops**, no hang. Grep: `qa_m3.rs:721` is the only test thread that spawns children in a loop; every other `thread::spawn` near a `Command` is a stdout pump. Parallel *tests* in one binary can still inherit each other's pipes on macOS, but the wait is bounded by the other test's lifetime, not a deadlock. *Linux, independently.* - Root: clippy `--all-targets -D warnings` exit 0. Whole suite `--no-fail-fast` **6/6 green**, each 97 result lines, 5430 passed, 0 failed, 65 ignored. - `--user`: clippy exit 0. **6/6 green**, the same totals. - `qa_m1` `qa_rework_a_rename_over…` alone, root: **0/300 failed**. - No guard kill anywhere on macOS. *Findings* (none is a FAIL): 1. (medium, documented-limit class) **A writable mmap kept open serves stale contents indefinitely on Linux.** Map the file, store into it (this sets mtime and ctime), wait 4 s, let the server read, then store into the same already-dirty page. The stat is unchanged after the store, after `msync` and after `munmap` (overlayfs and tmpfs, root and `--user`), and `find` stays stale. On macOS it is stale until `msync`. The kernel exposes nothing, so no stamp can see it (git has the same limit). Repro: `stale.py BIN DIR mmap`. Suggest stating it in Assumptions. Editors do not write through mmap. 2. (low, perf) **A future mtime makes a file racy forever**, so it is re-read and re-hashed on every call (no re-index). Release binary, macOS: - 4 000 small files: 6.8 → **67.5 ms** median per `find`. - A copy of OpenTitan `hw/`: 21 → **126 ms**. - Fresh copy of `hw/` (every ctime new): burst median 58 ms against 33 ms settled, for ~3 s only. Usable, but the cost lasts for as long as the clock stays behind. The lead should decide whether a timestamp far in the future (> 1 day, say) should stop counting as racy. 3. (low, docs) `docs/features/mcp-transport/README.md:53-58` still says the 2 s window and mtime-only racy, and that identity is "0" elsewhere. It is outside this lane's files: a Handshake request. The non-unix hole is real: a same-size rewrite that restores the mtime ≥ 3 s after the read is invisible, since std has no ctime and no stable `file_index`. It is stated only in `files.rs` and this README, not where a Windows user would see it (`docs/site/src/content/docs/guides/agents.md`). macOS `setattrlist(ATTR_CMN_CHGTIME)` returns 0 but leaves ctime unchanged, so an unprivileged ctime restore is not possible there. 4. (low, pre-existing) `crates/lucisv/tests/cli.rs:2149-2150` asserts only that stdout is empty, so a child that crashes (before or after reading) passes. The BrokenPipe tolerance does not materially widen this: the inputs fit in the pipe buffer. 5. (info) The ratio test's sensitivity depends on the machine. A 100 ms didOpen stall is 10.6x on this Mac but would be ~3–4x on the Linux runner (parse 50–70 ms), which passes. *Fixed by QA:* nothing. *Unverified:* FAT, NFS and SMB (skew arithmetic only); Windows at run time (compile only); a real suspend or NTP step (injected clocks only). ## Review **Lead, 2026-11-19.** Accepted on macOS evidence; Linux line left open. - Test code only, and QA checked every hunk for that. The risk in a lane like this is a test that passes by no longer testing: QA's mutation table (every modified test made to fail, every file restored byte-identically) and the "none prints `skipped:` on macOS" run are what make it acceptable. - I was wrong about the references test: I read 100→200 hits costing 4x as a possible superlinear product bug and told the dev so. Measured alone it doubles per doubling on both platforms; the 4x was the parallel suite. The ratio assertion that replaced the wall-clock budget is the better test, and it was shown to trip at ~60–74x on a quadratic implementation by dev and QA independently. - `scan_trace` was a pre-existing fragile test that Linux exposed and QA then reproduced on macOS (2.21 ms of 5.10 ms). I extended scope to fix it. The best-of-three lower bound costs sensitivity (the dev measured ~97% → ~90% on a dropped `parse` stage) — accepted and written down, not hidden. - **Not verified on Linux**: everything since round 1 — the `scan_trace` rewrite, best-of-five in `large.rs`, the rewritten `tools/linux_check.sh` (its remote half has never run), and all of 0.65.2–0.65.4. The owner's ssh key expired mid-lane. TODO §70's Linux line and the `ci.yml` job stay unticked until that run happens; the Linux job is not added blind. - Open follow-up, recorded under Status: the references linear-time test times a copy of `Server::large_scan`'s loop, not the production code. **Lead, 2026-11-19 — Round 2.** Accepted for 0.65.9; §70 closed. - Round 1 was accepted on macOS evidence with the Linux line open, and the first Linux runs after ssh came back showed why that line mattered: clean once, then 3 failing runs in 9. The dev's census (57 whole-suite runs, 2 090 loop iterations) is the right way to chase flakes — a ~10% flake does not show in three runs. - The dev stopped on the mtime test instead of loosening it, and it was a real bug: `lucisv-mcp` could serve stale contents indefinitely. I extended scope to fix it. QA reproduced the hole on purpose on the old binary (65/65 and 87/87 stale when the stat was identical) and got 0 on the new one across overlayfs, tmpfs and APFS, then property-tested `compare` with three million cases under four mutations. That is the evidence. - The `qa_m3` hang is the same test the guard killed in the 0.65.5 release gates and in 71.7's QA; it now has a cause (a pipe inherited across threads on macOS) and a fix, though no deterministic reproduction. - `ci.yml` gains the `linux` job in this change, as §70 planned. It installs Rust per job and builds cold — a few minutes; acceptable for now. - Open, filed in TODO: future-mtime trees re-read on every call; the mmap limit and the Windows gap are now written in `docs/features/mcp-transport`; a weak assertion in `cli.rs`; `qa_m3.rs` does not compile for Windows.