# release-gates — TODO §65.3: a dependable release gate script ## Goal `cargo test --workspace` under `tools/guard.sh` kept hitting the guard's wall clock (2026-09-29 in `Doc-tests vlog_linter`, 2026-09-30 at the start of `tests/rename_implicit.rs`, 2026-10-07 launching `vlog_semantic/tests/struct_members`, 2026-10-14 in `vlog_refactor/tests/corpus.rs`), while every per-crate run passed. Name the cause, fix whatever part of it is ours, and replace the three-command gate in `tools/RELEASING.md` with `tools/gates.sh`: fmt, clippy, the test build, each crate's suites, the doc-tests, the corpus gate and the node tests as **separate guarded steps**, each with its own log, a kill retried once and shown as such, and a summary table — so a stall names the step it happened in instead of eating a 30-minute guard. ## Assumptions - The gates run on the release Mac (Apple Silicon, 10 cores, 64 GB), the same host the Gitea runner uses. The `-t`/`-m` limits are sized for it; a slower machine may need larger clocks (edit `limits()`). - No gate reads stdin; `gates.sh` gives every step `/dev/null`. - The corpus lives at `~/.cache/lucisv-corpus` as in CI (`.gitea/workflows/ci.yml`); `-c` points elsewhere. Absent → the step is skipped with a note, which does not fail the run (CI is where the corpus gate is mandatory). - The workspace `members` in the root `Cargo.toml` are all under `crates/`, one per line, and each member's first `name =` line is its package name. `gates.sh` reads the crate list from there. - A guard kill is identified by exit 137 **and** guard.sh's `killing` line in the step log; a 137 without that line (a test binary SIGKILLed by something else) is an ordinary failure and is not retried. ## Handshakes - **Consumes** `tools/guard.sh` (`-t`, `-m`, exit 137 + `guard.sh: … killing: …` on stderr), `scripts/corpus_gate.sh ` (needs `target/release/lucisv`, so the corpus step builds it first, as CI does), `node --test`, cargo. - **Changes `tools/guard.sh`** (two fixes, both ours, see Work log): a closed stdin no longer makes the command silently not run, and the memory limit now sees processes three or more levels down the tree. The second is a **behaviour change for every guarded command**: memory that was invisible (rustc/linker processes under cargo, binaries a test spawns, the corpus scorer's `lucisv` processes) is now summed, so a command whose real tree exceeded its `-m` and used to pass will now be killed. Measured peaks are below; a guard kill after this change is a finding, per CLAUDE.md, not a reason to raise the limit silently. - **Promises** `tools/gates.sh` exit 0 only if every selected step passed (or was the corpus step skipped for a missing corpus); logs kept under the log dir: `.log`, `.killed.log` for a first attempt the guard killed, `summary.txt`, `steps.tsv` (step, start, end epoch, result). - **CLAUDE.md request (the lead's file):** under "Rust standards", replace the first bullet's tail so it reads: > - `cargo fmt` clean, `cargo clippy --all-targets` clean (no `#[allow]` > without a comment explaining why), `cargo test` green — all three > before declaring any work finished. **Before a release, and whenever > the whole workspace is gated, run `tools/gates.sh`** (every gate as a > separate guarded step with kept logs; `--only`/`--skip` for a subset) > instead of a bare `cargo test --workspace`. and in "Runaway guard", after the first bullet: > - The release gate is `tools/gates.sh`, which guards each step with > its own limits; do not wrap it in another `guard.sh`. - **Request (root `README.md`, not this lane's file):** its build section (line ~1042) still shows `tools/guard.sh -- cargo test --workspace`; a pointer to `tools/gates.sh` there would match RELEASING.md. - **Request (lane A / `lucisv_server`, not this lane's file):** the wall-clock assertion in `crates/lucisv_server/src/large.rs:884` (`LOCATE_BUDGET_MS = 150`) flaked once under load (Work log); make it relative or widen it so the gate stays deterministic. ## Status / TODO - [x] investigate: stall reproduction attempt, syspolicyd, stuck tree - [x] doc-test stdin question: closed / `/dev/null` / pipe / tty / tty with job control, under the guard, in the background - [x] fix what is ours: guard.sh closed-stdin, guard.sh deep-tree memory - [x] `tools/gates.sh` with `--only`, `--skip`, `--list`, `-o`, `-c`, `--help` - [x] kill → retry path exercised (killed → pass, killed → killed, plain failure not retried, corpus skipped) - [x] two full runs recorded - [x] ten consecutive green runs (runs 3–12; thirteen green in all, no kills) - [x] `tools/RELEASING.md` step 3 points at `tools/gates.sh` - [ ] CLAUDE.md pointer (lead, at merge) ## Work log ### 2026-10-19 — investigation Base: master ec492cd (the worktree was created one commit behind it, at 75d2d37; fast-forwarded before any work). Lane A (§65.2) ran its own `lucisv_server` tests in another worktree throughout: load average 6–10 on 10 cores for the whole session, so every timing below was taken under a second, unrelated workload — the 2026-10-14 condition. **The stall did not reproduce.** The host had been up 1 h 13 min (rebooted that morning). `syspolicyd` sat at 0.0 % CPU at the start, never above 0.3 % in any 1 s sample across the twelve full gate runs, and showed nothing over 1 % in 0.2 s samples during a freshly-linked suite's first run. Five freshly linked unique binaries (`rustc` of a one-line `main`, each with a distinct constant, i.e. a distinct cdhash as a doc-test's `rust_out` has) launched in 10 ms the first time and 10 ms the second. `cargo clean -p lucisv_server` then a first and second run of its suites: 2.2 s and 2.2 s. So there was no stuck tree to inspect; the cause recorded on 2026-09-30 (syspolicyd stuck at ~100 % CPU on notarization lookups, `-67062`, for hours, each first launch of a new unsigned executable waiting on it) stands unrefuted and unreproduced, and it fits every recorded stall: each one sat at the **first launch of a freshly linked binary** — a test binary just rebuilt (`rename_implicit`, `struct_members`, `corpus.rs`) or the doc-test phase, where `vlog_linter`'s `lib.rs` example is the **only runnable doc-test in the workspace** (`cargo test --workspace --doc`: 1 test), and rustdoc links it into a new `rust_out` with a new hash on every run, so it can never hit syspolicyd's cache. That is why "Doc-tests vlog_linter" is where 2026-09-29 sat. Healthy after a reboot, sick after hours of uptime: the host fix (System Settings → Privacy & Security → Developer Tools: allow the terminal / Claude app, or restart syspolicyd) is the owner's, not the repo's. `DevToolsSecurity -status` reports developer mode disabled; `spctl --status`: assessments enabled. **The doc-test stdin question — not the cause.** `cargo test --workspace --doc` under `tools/guard.sh`, backgrounded, with each kind of stdin (script kept in the session scratchpad; results): | stdin | result | |---|---| | closed (`<&-`) | **exit 1 in 0 s, nothing ran** — `guard.sh: line 34: 0: Bad file descriptor`, then `3: Bad file descriptor` (a guard bug, fixed below) | | `/dev/null` | exit 0, 1 s, 1 passed | | a pipe whose writer never closes | exit 0, 1 s, 1 passed | | a pty (`script`), no job control | exit 0, 1 s, 1 passed | | a pty with job control (`set -m`: the job in a background process group, as `guard.sh … &` typed at a prompt) | exit 0, 1 s, 1 passed — no SIGTTIN stop | The harness never reads stdin: rustdoc feeds each doc-test to `rustc` over a pipe of its own and runs `rust_out` with `Command::output()`, which gives it `/dev/null`. No test in the workspace spawns a child that inherits stdin and reads it (every `spawn()` in `crates/*/tests` pipes stdin; the one inherited `status()`, `lucisv_server/tests/e2e.rs:571`, runs `lucisv check --fix `, which does not read it). **Fixed — ours, both in `tools/guard.sh`:** 1. *Closed stdin*: `exec 3<&0` failed, then `"$@" <&3` failed, so the command silently never ran (exit 1). Now `{ exec 3<&0; } 2>/dev/null || exec 3` after `cargo test --workspace --all-targets --no-run` recompiles a few crates (`crossbeam-utils`, `lsp-server`, `lucisv_server`: 16 s in run 1) because resolver 2 unifies features per selected package set; both variants are cached afterwards. The per-crate clocks allow for it. ### 2026-10-19 — `tools/gates.sh` Steps, logs, retry and summary as in the header comment and Handshakes. Design points: the command for each step is a bash array (no `eval`); the crate list comes from the root `members`, each member's `name`; a guard kill is exit 137 *and* the guard's line, retried once with the first log kept as `.killed.log`; every step gets `/dev/null` as stdin; node 22+ prints `ℹ pass N` rather than TAP's `# pass N` and both are counted; the corpus step builds `target/release/lucisv` first, as CI does; unknown step names are a usage error (exit 2). Exercised paths (a throwaway copy of the script with a 2 s clock on a `sleep 30`, deleted after): killed → retried → KILLED (exit 1), killed → retried → pass (a command that sleeps only on its first call; exit 0, first log kept), a plain failure (`node -e 'process.exit(3)'`) reported `fail` and not retried, the corpus step `SKIPPED (no corpus)` with `-c /nonexistent` and the run still green. Limits (`limits()`; measured 2026-10-19 from a cold `target/`, peak tree RSS sampled each second over the whole step tree): | step | measured cold | warm (runs 3–12) | peak RSS | `-t` / `-m` | |---|---|---|---|---| | fmt | 3 s | 2 s | 0.1 GB | 120 s / 2 GB | | clippy | 20 s | 1–2 s | 1.6 GB | 900 s / 6 GB | | build | 31 s | 1–2 s | 2.6 GB | 900 s / 8 GB | | suite: each small crate | ≤ 3 s | 1–4 s | ≤ 0.15 GB | 300 s / 4 GB | | suite:lucisv_server | 17–19 s (rebuild) | 2–4 s | 1.1 GB | 600 s / 4 GB | | suite:lucisv_mcp | 20–22 s | 12–15 s | 1.4 GB | 600 s / 4 GB | | docs | 1 s | 1 s | 0.1 GB | 300 s / 2 GB | | corpus (release build + score) | 30 s | 3–4 s | 1.2 GB | 900 s / 6 GB | | node | 1 s | 1 s | 0.3 GB | 120 s / 2 GB | The clocks are the cold time times twelve (the CPU-bound slowdown a sick syspolicyd was measured to cost) rounded up, with a two-minute floor: a real hang costs at most that step's clock twice, not 30 minutes; a stall that clears on the retry shows as `KILLED → retried → pass`. ### 2026-10-19 — runs Thirteen full runs, all `gates: PASS`, **zero kills, zero retries, zero failures**: run 1 (warm, before the deep-tree guard fix and with the first draft limits), run 2 (after `cargo clean`, limits as drafted), runs 3–12 (final limits, back to back: 33–38 s each), run 13 (the final script, after a summary-alignment change; default log dir). Runs 3–12 are §65.3's ten consecutive green runs. Honest caveat: the host was healthy all session (syspolicyd ≤ 0.3 %), so these runs prove the script and the gates, not immunity to the host fault — that would show as a `KILLED → retried` row. Run 2 (cold): ``` step result seconds passed/failed fmt pass 3 - clippy pass 20 - build pass 31 - suite:vlog_parser pass 3 505/0 suite:vlog_semantic pass 1 401/0 suite:vlog_refactor pass 1 727/0 suite:vlog_formatter pass 1 314/0 suite:vlog_linter pass 1 672/0 suite:lucisv_core pass 1 117/0 suite:lucisv pass 2 143/0 suite:lucisv_server pass 17 1862/0 suite:lucisv_mcp pass 22 383/0 docs pass 1 1/0 corpus pass 30 814/6 node pass 1 8/0 gates: PASS ``` Run 13 (final script, warm except clippy/build after `cargo clean -p lucisv_server`): fmt 2, clippy 9, build 14, suites 3/1/1/1/1/2/1/2/12, docs 1, corpus 3, node 1 s — the same counts, `gates: PASS`. The corpus "failed" column is total − passing (6 of 820, the documented ceiling). ## QA log ### 2026-10-19 — QA agent (Sonnet) **Verdict: PASS, no blocking findings; no files fixed (log only).** Host load average 5 to 19 (lane A running suites) throughout. Bash: only `/bin/bash` 3.2.57 exists (`which -a bash`), so `#!/usr/bin/env bash` runs 3.2; no bash-4 feature in either script (grep for `declare -A`, `mapfile`, `${v,,}`, `[[`, `+=`, `|&`: none). **guard.sh** (diff read line by line: three changes, stdin fallback, awk `" %s"`, `all="$all$next"`; nothing else touched). - Memory depth proof (`nest.sh N`: N nested bash layers, python holding 1.5 GB at the bottom, `-m 1 -t 40`; scratch `qaB65/nest.sh`): | depth | master guard | new guard | |---|---|---| | 1 | 137, killed in 3 s | 137, 3 s | | 2 | 137, 3 s | 137, 3 s | | 3 | **exit 0 after 31 s, no guard line (missed)** | 137, 4 s, guard line | | 4 | **exit 0 after 31 s (missed)** | 137, 2 s, guard line | No `nest.sh` survivors after any run. - Wall clock: `-t 3 -- sleep 30` gives 137 with the guard line in 6 s. TERM escalation: a script and a child both with `trap '' TERM`, `-t 3`: 137 in 6 s (3 s + 2 s grace + KILL), no survivors. - Stdin: `echo ... | guard.sh -- lucisv -` formats (foreground); formatted in the background with stdin from a file, from a pipe in a subshell, and from a pipe inside `bash -c '... &'`. Closed stdin (`<&-`): new guard runs the command (`echo` ran, `cat` exits 0); master guard prints "Bad file descriptor" twice and exits 1 without running it (confirmed). - `exit 3` passes through as 3. A 400-subshell fork storm of short-lived children (exiting mid-poll) under `-m 2`: exit 0, stderr empty. macOS pids are at most 99999, so the awk `index()` token match has no prefix-collision risk. - Cosmetic (info): on a kill the shell prints `tools/guard.sh: line 57: Terminated: 15 "$@" 0<&3` to stderr (seen in the retry logs). It is harmless and gates.sh matches the `guard.sh: ... killing` line instead. **gates.sh** - `--help` exit 0; `--list` prints the 15 steps; unknown flag exit 2; `--only nope`, `--skip suite:nope` exit 2 with "unknown step". `--only fmt,node`, `--only docs --skip corpus`, `--only corpus -c /nonexistent` (SKIPPED (no corpus), exit 0, note in corpus.log) all as documented. `-o "dir with space"` works (logs, summary.txt, steps.tsv created). - Scratch copies of the script: a failing node test gives `fail`, summary `gates: FAIL`, exit 1, and a single attempt (no `.killed.log`); a step killed twice (2 s clock on `sleep 30`) gives `KILLED → retried → KILLED`, exit 1, `node.killed.log` kept, `steps.tsv` row written; killed once then passing gives `KILLED → retried → pass`, exit 0, `.killed.log` kept. - Crate list: the real `members` (nine, one per line, no comments, no glob) parses to all nine and matches `--list`. - **Full gate, run once, not wrapped:** `tools/gates.sh` printed `gates: PASS`, 36 s wall, zero kills. Warm cache: fmt 2, clippy 1, build 1, suites 3/1/2/1/1/1/1/2/14 (parser, semantic, refactor, formatter, linter, core, lucisv, server, mcp), docs 1, corpus 3 (814/6), node 1 (8/0); counts identical to the dev's run 2 (505, 401, 727, 314, 672, 117, 143, 1862, 383, 1 doc-test). **Findings** (all low; none block) 1. **Low-medium, silent shrink of coverage.** `crates()` at `tools/gates.sh:74-79` drops members it cannot parse and still reports PASS. Reproduced in a scratch workspace: a trailing comment on a member line (`"crates/a", # note`) loses that crate (plus one `sed: ... No such file` on stderr); `members = ["crates/a", "crates/b"]` on one line yields no crates; `"crates/*"` yields no crates. In the last two cases the whole suite phase vanishes and the run is green. The README assumption names the layout, but nothing enforces it. Suggest: fail (exit 2) when `crates` is empty or its count differs from `cargo metadata --no-deps` members. Not a risk with today's Cargo.toml. 2. **Low.** `gates.sh:55-57` (`-o`, `-c`, `--only`, `--skip` as the last argument): `$2: unbound variable` under `set -u`, exit 1, not the documented usage error 2. Repro: `tools/gates.sh --only`. 3. **Low.** `--only ''` means no filter (all steps run), and a selection that matches nothing (`--only suites --skip suites`) prints an empty table and `gates: PASS`, exit 0. A zero-step run being green is misleading; suggest exit 2 or a "no steps selected" line. 4. **Info.** The corpus step is skipped green when `~/.cache/lucisv-corpus` is absent; documented, but a release run on a fresh host would pass without the corpus gate. `RELEASING.md` step 3 says so, which suffices. 5. **Info / behaviour change (already in Handshakes).** After the guard fix, memory is now enforced for deep trees. The full gate's peaks stayed under all `-m` limits in this run (no kills), so the limits are sound at least on this host. **Review of docs.** `tools/RELEASING.md` step 3 reads correctly and matches the script (steps, log names, retry wording, `--only`/`--skip`/`--list`). Minor: "a line in the release notes' working log" is vague (the repo has a CHANGELOG and README work logs). The proposed CLAUDE.md lines are sensible and consistent: `gates.sh` guards each step itself, so "do not wrap it in another guard.sh" is right (a nested guard would also hide per-step kills). ## Review **2026-10-19 — lead.** Accepted. The two `guard.sh` bugs were the real find: the memory limit never saw a process three or more levels down the tree (every cargo → rustc → linker chain), and a closed stdin skipped the command; QA re-proved both against master's guard. The stall itself is the host's (syspolicyd on fresh unsigned binaries; the owner's Developer Tools setting), and `gates.sh` now survives it by retrying a killed step once and saying so. QA's three lows are fixed by the lead in the worktree before merge: the crate list drops comments and handles a one-line list and a glob, and an empty list is a usage error (exit 2) instead of a green run with no suites; a missing or empty option value is exit 2; a selection that runs no step is exit 2. Granted: the CLAUDE.md lines (Rust standards and Runaway guard) and the root README's Building section now point at `tools/gates.sh`. The ten green runs were on a healthy host — the first `KILLED → retried` row on a stalled one is the evidence still to come.