Why coding agents fake benchmarks, and the Rust guardrail I built to stop them

Whenever someone ships an optimization harness for coding agents, the first question from experienced engineers is blunt: why would I install a tool instead of just telling Claude Code or Codex to profile the repo and run hyperfine?

I ran that exact prompt loop across C, C++20, Rust, Python, and TypeScript repositories before building oa. Without external mechanical enforcement, a coding agent fails in four repeatable ways:

  1. It loosens a test assertion or shrinks the benchmark workload so the timing drops while the real code barely changed.
  2. It runs baseline once, edits code, runs candidate once, and keeps a 4% difference that sits well inside CPU frequency scaling and thermal noise.
  3. It introduces a fast path that silently alters edge-case output, ANSI formatting, or boundary checks.
  4. It buys 10% faster wall time by caching unbounded structures and inflating Peak RSS by 40% or more.

Asking an LLM to "be careful and do statistical benchmarking" fails because the same model generating the edit is grading its own work. oa moves every grading decision outside the prompt into a single 1.6 MB Rust binary (#![forbid(unsafe_code)], two direct dependencies: serde and serde_json) that speaks both CLI and stdio MCP.

1. Five mechanical gates, in order

Every candidate edit passes through the same sequence before oa allows refs/oa/best to advance:

2. Why live peak-heap attribution matters

Linux perf page-faults is useful with zero setup, but page faults only fire the first time a virtual page is touched. Once an allocator arena grows and reuses freed pages, page faults go quiet even while a hot path allocates gigabytes of temporary buffers.

Passing --heap-track to oa profile or oa compare compiles a small C LD_PRELOAD interposer on demand, tracks live bytes across malloc, calloc, realloc, and free, records the exact allocation call stacks sitting live at the peak high-water mark, and resolves addresses to project file:line via addr2line.

Running oa compare --git main --check-output --heap-track on sharkdp/bat #4165 immediately exposed why bat --style=plain allocated over 1 MiB of live heap just to stream a file: eager compilation of 129 builtin globset regex DFAs on every startup and eager theme deserialization even when syntax highlighting was disabled. Replacing the 129 regex DFAs with compile-time FastMatcher and ASCII prefilters, lazily initializing themes with OnceCell, recycling line buffers, and buffering owned stdout writes (flushing per input file so I/O cycle detection stays intact) dropped plain/piped runtime from 11.49 ms to 3.90 ms (2.97x) and peak-live heap from 1,042.0 KiB to 117.7 KiB (-88.7%, with -94.3% total heap churn).

3. Real upstream PRs and what the guardrails rejected

Synthetic demos inside a tool's own repository prove very little. Below are real upstream pull requests measured with oa across Rust, C, C++20, and Python:

Repository & PR Status Wall (median) Memory / Heap Correctness check
sharkdp/bat #4154 Merged (v0.26.0) 49.42 -> 26.88 ms (1.80x) Unchanged Full suite + SHA-256
Delgan/loguru #1557 Merged (4 commits) 1.04x to 1.16x per commit -2.9% RSS 22/22 CI checks
AnyPS5 #28125 Approved (2 reviews) 617.3 -> 122.6 ms (3.26x to 5.03x) 164.9 -> 54.4 MiB (-67.0%) 36/36 CTests + exact ELF bytes
AnyPS5 #28223 Approved 109.66 -> 63.87 ms (1.70x) -0.3% to +1.3% RSS 472,032-vector differential oracle
sharkdp/bat #4165 Open (CI green) 11.49 -> 3.90 ms (2.97x plain), 1.70x full -88.7% / -37.0% peak-live heap 503/503 cargo tests + 5-mode SHA-256
bootandy/dust #664 Open (CI green) 1.56x default, 2.10x -D, 2.33x -t -56.6% to -72.6% Peak RSS 90/90 cargo tests + 16-flag SHA-256
jqlang/jq #3768 Open (CI green) 535.6 -> 4.3 ms (124.36x) -0.8% RSS 9/9 test suites + ASan/LSan/UBSan

Equally telling are the patches that failed the gate or review. On brave/adblock-rust (already tuned to 3.05 IPC), oa rejected two real regressions and two noise edits, keeping only a modest 1.05x win (142.7 to 136.1 ms, p = 0.0002). On Delgan/loguru #1557, splitting the branch into per-commit benchmarks let four safe allocation cuts merge while dropping a fifth commit that replaced _protected_lock() with a custom context manager vulnerable to CPython asynchronous KeyboardInterrupt lock leaks. On nodeca/js-yaml, oa blocked a "plausible" edit that measured p = 0.0404 against the 0.01 alpha gate.

4. What broke when I tested oa cold on unfamiliar repos

Before releasing v0.10.0, I ran install.sh inside an empty HOME directory against unfamiliar repositories (pallets/itsdangerous, hukkin/tomli, dtolnay/semver, BurntSushi/same-file, and antirez/sds) and logged every failure. That audit surfaced real defects that unit tests had missed:

5. Reproduce any comparison in one command

You do not need an agent or a session to use oa. Comparing your working tree against main (or ranking 3+ commits with --git-refs, gating declarative oa.toml budgets with oa suite and OA005, diffing hotspots with oa profile-diff, and isolating regressions with statistical oa bisect) with balanced interleaved pairs, stdout SHA-256 verification, live peak-heap diffing, and Markdown/HTML/CSV/SARIF 2.1.0 output is one command (verified by a 13.3k-case fuzz suite, with full reference pages via oa man):

# Install via Homebrew or the release script:
brew install alexander-src/tap/oa
# or: curl -fsSL https://raw.githubusercontent.com/alexander-src/oa/main/install.sh | sh

oa demo

oa compare --git main \
  --build "cargo build --release" \
  --bench "./target/release/my_cli input.dat" \
  --pairs 15 --check-output --heap-track --markdown

Limitations