Skip to content

Commit 8a0d305

Browse files
kylehgcclaude
andcommitted
fix(bench): pin the curl fixtures instead of fetching a random payload
The curl and wget cases fetched https://mockhttp.org/json/1, which returns a randomly chosen body per request: call 1: 152 bytes {"metrics":... call 2: 244 bytes {"config":... call 3: 102 bytes {"message":... bench() calls the raw command and the rtk command separately, so the two sides received different payloads and the ratio between them was noise. Whether the build passed was a coin flip on which pair it drew — it passed on develop at 3cb7107 and failed twice on the very next PR, which touched no filter code. That matters more now that CD's ci-gate blocks releases on CI: a third party's mock API sat in the critical path of every release. Points all three cases at pinned file:// fixtures. curl and the filter stay in the loop; only the nondeterminism goes. Note rtk passes JSON through unchanged, so these cases will now sit honestly at ~0% savings rather than swinging between a fake win and a build failure. There is no filter defect here: core::guard::never_worse already prevents rtk emitting more tokens than raw, and curl routes through it via emit_guarded. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent dedd23c commit 8a0d305

4 files changed

Lines changed: 30 additions & 5 deletions

File tree

‎.github/README.md‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@ When a coding agent runs `cargo test`, `git log`, `npm install`, or `pytest`, th
1616
output goes straight into its context window — thousands of lines of progress bars,
1717
timestamps, and repetition, most of which the model cannot use. rtk sits in front of
1818
those commands, runs them for real, and passes back a filtered version that keeps the
19-
errors, the failures, and the diagnostics while dropping the noise. Typical reduction
20-
is 60–90% of bash output.
19+
errors, the failures, and the diagnostics while dropping the noise. Across rtk's own
20+
benchmark suite — 73 cases, run with [`scripts/benchmark.sh`](../scripts/benchmark.sh) —
21+
aggregate output came to **541,111 → 123,205 tokens, a 77% reduction**. Individual
22+
commands vary enormously: some are cut by 90%, and some are passed through untouched
23+
because filtering them would lose information or gain nothing.
24+
25+
That is a measure of **bash output**, not of your bill, and rtk ships no tokenizer —
26+
it estimates tokens as bytes/4, so the ratios are sound and the absolute counts are
27+
approximate.
2128

2229
It is a transparent proxy: `rtk cargo test` runs `cargo test`, exits with the same
2330
status code, and works for commands it has no specific filter for. A hook can rewrite

‎scripts/benchmark.sh‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,17 +345,27 @@ bench "wc" "wc Cargo.toml src/main.rs" "$RTK wc Cargo.toml src/main.rs"
345345
# curl
346346
# ===================
347347
section "curl"
348+
# Pinned local fixtures, not a live host. These cases used to fetch
349+
# https://mockhttp.org/json/1, which returns a *randomly chosen* payload per
350+
# request — so the raw call and the rtk call received different bodies and the
351+
# ratio between them was noise. It failed the build at random, and since CD's
352+
# ci-gate blocks releases on CI, a third party's mock API could stop all
353+
# releases. file:// keeps curl and the filter in the loop while making the
354+
# comparison deterministic and offline.
355+
CURL_JSON_URL="file://$(pwd)/tests/fixtures/benchmark_curl.json"
356+
CURL_TEXT_URL="file://$(pwd)/tests/fixtures/benchmark_curl.txt"
348357
if command -v curl &> /dev/null; then
349-
bench "curl json" "curl -s https://mockhttp.org/json/1" "$RTK curl https://mockhttp.org/json/1"
350-
bench "curl text" "curl -s https://mockhttp.org/robots.txt" "$RTK curl https://mockhttp.org/robots.txt"
358+
bench "curl json" "curl -s $CURL_JSON_URL" "$RTK curl $CURL_JSON_URL"
359+
bench "curl text" "curl -s $CURL_TEXT_URL" "$RTK curl $CURL_TEXT_URL"
351360
fi
352361

353362
# ===================
354363
# wget
355364
# ===================
356365
if command -v wget &> /dev/null; then
357366
section "wget"
358-
bench "wget" "wget -qO- https://mockhttp.org/json/1" "$RTK wget https://mockhttp.org/json/1"
367+
# Same pinned fixture, same reason as the curl cases above.
368+
bench "wget" "wget -qO- $CURL_JSON_URL" "$RTK wget $CURL_JSON_URL"
359369
rm -f 1 2>/dev/null
360370
fi
361371

‎tests/fixtures/benchmark_curl.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"metrics":{"cpu":45.2,"memory":78.5,"disk":62.3,"network":{"inbound":"1.2MB/s","outbound":"0.8MB/s"},"uptime":"15 days","services":[{"name":"api","status":"healthy"},{"name":"database","status":"healthy"},{"name":"cache","status":"warning"}]},"config":{"theme":"dark","language":"en","notifications":{"email":true,"push":false,"sms":false},"privacy":{"profile":"public","activity":"friends"}},"message":"Hello from a pinned fixture","timestamp":"2026-08-01T00:00:00Z"}

‎tests/fixtures/benchmark_curl.txt‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
User-agent: *
2+
Disallow: /admin
3+
Disallow: /private
4+
Disallow: /internal
5+
Allow: /
6+
Crawl-delay: 10
7+
Sitemap: https://example.invalid/sitemap.xml

0 commit comments

Comments
 (0)