Skip to content

fix(benchmark): avoid negative curl/cargo cases that fail the benchmark job - #3430

Merged
KuSh merged 6 commits into
rtk-ai:developfrom
ousamabenyounes:fix/benchmark-negative-curl-cargo
Aug 17, 2026
Merged

KuSh merged 6 commits into
rtk-ai:developfrom
ousamabenyounes:fix/benchmark-negative-curl-cargo

Conversation

@ousamabenyounes

@ousamabenyounes ousamabenyounes commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The shared benchmark CI job (scripts/benchmark.sh) fails with BENCHMARK FAILED: N filter(s) produced more tokens than raw output on develop:

  • cargo build: 18 → 25 tokens for an already-small successful build.
  • curl json: negative on and off against https://mockhttp.org/json/1 — the endpoint is a network dependency and its payload varies, so the result is not reproducible.

Because this lives in the shared benchmark script, every branch based on develop inherits the red job regardless of its own diff.

Fix

  • scripts/benchmark.sh: serve deterministic local fixtures from a loopback python3 -m http.server for both curl and wget — fully offline, and the JSON is pretty-printed and served with a real Content-Type: application/json so rtk wget actually exercises JSON minification (47 → 12, +74%).
    • Binds http.server 0 (kernel-picked port) and reads the chosen port back from the server log, so a busy port cannot fail the run.
    • cleanup_net_fixtures is failure-tolerant: it runs from an EXIT trap under set -e, where [ -n "$PID" ] && kill … aborted the handler whenever kill failed and leaked the fixture dir and downloads.
    • The wget case prints an explicit skip line instead of silently disappearing when no local server is available (wget rejects file://, so there is no offline fallback URL).
  • src/cmds/rust/cargo_cmd.rs: guard the streamed and non-streamed cargo build success summaries, and the cargo test summary, with core::guard::never_worse(raw, summary). The test-summary path extracts a private compute_test_summary and applies the guard at the call site.

Test plan

  • cargo fmt --all && cargo clippy --all-targets -- -D warnings && cargo test --all
  • ./scripts/benchmark.sh

Test verification (RED → GREEN)

RED — new cargo guard test on upstream develop (32c83cc):

---- cmds::rust::cargo_cmd::tests::test_cargo_test_summary_uses_raw_when_summary_is_larger stdout ----
assertion `left == right` failed
  left: Some("cargo test: 1 errors, 0 warnings (0 crates)\nerror[E0433]: failed to resolve: use of undeclared type `Foo`\n")
 right: Some("error[E0433]: failed to resolve: use of undeclared type `Foo`\n")
test result: FAILED. 0 passed; 1 failed

RED — benchmark script asks, driven against the pre-fix script:

=== cleanup must complete under 'set -e' even when kill fails ===
RED: /tmp/tmp.jOVSnnPPUe NOT removed
=== server must come up even when port 8899 is taken ===
RED: server unusable

RED — benchmark job on upstream develop (32c83cc, run 31976715084):

🔴 find --max 10   40 → 48 (-20%)     <- pre-existing, untouched by this PR
🔴 curl json       26 → 38 (-46%)
BENCHMARK FAILED: 2 filter(s) produced more tokens than raw output

GREEN — this branch:

test_filter_cargo_build_success_uses_raw_when_summary_is_larger ... ok
test_cargo_build_stream_success_uses_raw_when_summary_is_larger ... ok
test_cargo_test_summary_uses_raw_when_summary_is_larger ... ok
2612 unit tests + 78 integration tests passed, 0 failed
cargo fmt --all -- --check: passed
cargo clippy --all-targets -- -D warnings: passed
test presence: passed
benchmark: 0 negative caused by this PR
=== cleanup must complete under 'set -e' even when kill fails ===
GREEN: fixture dir removed
=== server must come up even when port 8899 is taken ===
GREEN: server reachable at http://127.0.0.1:33793 (ephemeral port, 8899 still busy)

Remote CI on this branch matches the develop baseline except that the two negatives this PR targets are gone. The single remaining benchmark negative (find --max 10, 40 → 48) is pre-existing and reproduces identically on develop's own run for the same base commit.

@aeppling

aeppling commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Hey @ousamabenyounes , thanks for this, actually @KuSh already opened an issue on mockhttp repo and this should be solved now that it is merged , jaredwray/mockhttp#181 , so apparently we should get a stable /json/1

@KuSh

KuSh commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Still missing a release on mockhttp side for the stable endpoint to be available though

@ousamabenyounes
ousamabenyounes force-pushed the fix/benchmark-negative-curl-cargo branch from 74e8221 to 6c7df92 Compare August 13, 2026 12:50
@ousamabenyounes

Copy link
Copy Markdown
Contributor Author

Rebased this PR onto the latest develop and rechecked the suggested upstream endpoint fix. The endpoint is now stable, but the real benchmark still reproduces the negative curl case (38 → 61 tokens), so the deterministic local fixture remains necessary. The cargo guard also fixes the independent 18 → 25 negative case.

Validation: upstream local benchmark RED with the two affected negatives; focused cargo regressions GREEN (2/2); full local replay GREEN with 2,593 unit tests plus integrations, fmt, clippy, test-presence, benchmark (0 negatives), and changed-line coverage. Remote CI passes every check except the pre-existing unrelated find --max 10 benchmark negative (40 → 48), which is identical on current develop run 31653356311 and this PR run 31701940437.

Force-pushed the rebased branch (74e8221 → 6c7df92).

@KuSh

KuSh commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

mockhttp responses still aren't stable as there wasn't any release since the fix was merged

Comment thread scripts/benchmark.sh Resolved

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  1. The mockhttp part should not be needed even if frustrating atm. I hope they’ll release a new mockhttp version soon. But if not, benchmark.sh should be made fully offline, not just for JSON, and preserve everything that was tested before.

  2. The cargo part looks OK to me but:

  • You should apply the same guards elsewhere in the file (CargoTestHandler for example)
  • It would also be great to fix the fact that we don’t compact tiny cargo success build output; that doesn’t seem too difficult.

Comment thread scripts/benchmark.sh Resolved
@ousamabenyounes
ousamabenyounes force-pushed the fix/benchmark-negative-curl-cargo branch from 6c7df92 to a59a37d Compare August 15, 2026 22:47
@ousamabenyounes

Copy link
Copy Markdown
Contributor Author

Pushed a follow-up addressing both review points:

Fully offline & deterministic — dropped the remaining mockhttp.org calls (curl robots.txt, wget /json). Both curl and wget now hit a loopback python3 -m http.server serving fixed local fixtures, so there is no network dependency and no random response. curl falls back to file:// if python3 is unavailable.

Exercises JSON minification — the fixture is pretty-printed and served with a real Content-Type: application/json, so rtk actually compacts it: wget 47 → 12 (+74%). That was the path the earlier file:// fixture skipped.

Local replay against target/release/rtk:

✅ 35 good  ⚠️ 27 warn  🔴 0 negative  ❌ 0 fail    (exit 0)

The 56% good line is a non-fatal WARNING; the job only fails on negatives or empty output, both now 0.

Also applied the same never_worse guard to CargoTestHandler::format_summary so a tiny cargo test run can never produce a summary larger than its raw output (matching CargoBuildHandler). cargo fmt --check clean, cargo tests green.

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this is going in the right direction, but it needs a bit more work

Comment thread scripts/benchmark.sh Resolved
Comment thread scripts/benchmark.sh Resolved
Comment thread src/cmds/rust/cargo_cmd.rs Resolved
Comment thread src/cmds/rust/cargo_cmd.rs Resolved
Comment thread scripts/benchmark.sh Resolved
….org

The remaining online calls (curl robots.txt + wget /json on mockhttp.org)
were both a network dependency and non-deterministic. Serve fixed local
fixtures over a loopback http.server so curl and wget get real
Content-Type headers (exercising JSON minification), fully offline. curl
falls back to file:// when python3 is unavailable. Clean up the server,
temp fixtures, and the ./data.json download on exit.
CargoTestHandler.format_summary could emit a compacted summary larger than
the raw output on tiny runs, same failure mode CargoBuildHandler already
guards. Wrap all return paths with never_worse so the raw output wins when
the summary would be bigger.
…et -e safe

Review follow-up on rtk-ai#3430:

- Bind `python3 -m http.server 0` so the kernel picks a free port and read the
  chosen one from the (unbuffered) server log, instead of hardcoding 8899 which
  fails needlessly when that port is already in use.
- Make `cleanup_net_fixtures` failure-tolerant: it runs from an EXIT trap under
  `set -e`, so `[ -n "$PID" ] && kill ...` aborted the whole handler whenever
  `kill` failed (server already dead), leaking the fixture dir and downloads.
- Give the wget case an explicit skip line instead of silently disappearing.
  wget rejects `file://` ("Unsupported scheme"), so there is no offline URL to
  fall back to when the loopback server is unavailable.

RED (PR HEAD): fixture dir NOT removed when kill fails; server unusable with
8899 taken. GREEN: fixture dir removed; server up on an ephemeral port.
…se guard

Review follow-up on rtk-ai#3430:

- Replace the IIFE closure in `CargoTestHandler::format_summary` with a private
  `compute_test_summary` on the existing `impl CargoTestHandler`, and apply
  `never_worse` at the call site, as suggested.
- Add `test_cargo_test_summary_uses_raw_when_summary_is_larger`: a one-line
  compile failure whose "cargo test: N errors, ..." header is larger than the
  raw output, so the guard must return the raw output.

RED→GREEN: the new test fails on upstream develop (returns the 105-byte header
form instead of the 62-byte raw), passes here. Full suite: 2612 unit + 78
integration tests pass; benchmark 0 negative (develop baseline: 1).
@ousamabenyounes
ousamabenyounes force-pushed the fix/benchmark-negative-curl-cargo branch from c4ac631 to d003920 Compare August 17, 2026 00:31
@ousamabenyounes

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review @KuSh — all five points are addressed in 7f6156f + d003920 (rebased onto develop 32c83cc, force-push c4ac631 → d003920). Replies are in each thread; summary:

scripts/benchmark.sh

  • Fixed port 8899 → python3 -u -m http.server 0, and the benchmark reads the kernel-picked port back from the server log. -u is required or that line stays block-buffered when stdout is a file.
  • Cleanup under set -e → [ -n "$PID" ] && kill … returned 1 whenever kill failed, aborting the trap before rm -rf. Every step is now || true / if-guarded.
  • wget "no fallback" → wget rejects file:// outright (Unsupported scheme.), so there is no offline URL to fall back to. What I did fix is that the case silently vanished from the report; it now always prints a section plus ⏭️ wget (no local HTTP server available, skipped). Left that thread open in case you had a different fallback in mind.

src/cmds/rust/cargo_cmd.rs

  • IIFE → replaced by a private compute_test_summary on the existing impl CargoTestHandler, guard applied at the call site, exactly as you sketched.
  • Untested guard → test_cargo_test_summary_uses_raw_when_summary_is_larger: a one-line compile failure whose unguarded summary (105 B) is larger than the raw output (62 B). It asserts both that the unguarded summary really is larger and that format_summary returns raw. Fails on develop, passes here.

Validation

RED (before), on the shell asks:

=== cleanup must complete under 'set -e' even when kill fails ===
RED: /tmp/tmp.jOVSnnPPUe NOT removed
=== server must come up even when port 8899 is taken ===
RED: server unusable

RED (before), on the cargo ask, run on upstream develop:

---- test_cargo_test_summary_uses_raw_when_summary_is_larger stdout ----
assertion `left == right` failed
  left: Some("cargo test: 1 errors, 0 warnings (0 crates)\nerror[E0433]: ...")
 right: Some("error[E0433]: ...")

GREEN (after), full local CI replay:

PASS  test presence
PASS  fmt
PASS  clippy
PASS  test           2612 unit + 78 integration, 0 failed
PASS  build release
benchmark            0 negative (develop baseline on 32c83cc: 2 negative)

Remote CI on d003920: everything green except benchmark, which is down to the single pre-existing find --max 10 negative (40 → 48) — identical on develop's own run for the same base commit (run 31976715084, which additionally had the curl json negative this PR removes).

Unrelated heads-up while I was in there: benchmark.sh sets BENCH_DIR="$(pwd)/scripts/benchmark" and does rm -rf "$BENCH_DIR" when $CI is unset — so running it locally deletes the tracked scripts/benchmark/*.ts VM-harness. Not touching it here to keep this PR to one concern, but happy to open a separate PR if useful.

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! Don’t hesitate to push a follow-up PR to fix the broken BENCH_DIR cleanup

@KuSh
KuSh merged commit ba7a9ce into rtk-ai:develop Aug 17, 2026
20 of 22 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Aug 17, 2026
KuSh pushed a commit that referenced this pull request Aug 20, 2026
…arness

`BENCH_DIR="$(pwd)/scripts/benchmark"` is a tracked directory: besides the
gitignored `unix/`, `rtk/` and `diff/` output dirs it holds the TypeScript
VM-benchmark harness (`run.ts`, `cleanup.ts`, `rebuild.ts`, `lib/*.ts`,
`cloud-init.yaml`). `rm -rf "$BENCH_DIR"` therefore wiped all 7 tracked files
from the working tree on every local run (`$CI` unset), which is exactly when
a contributor runs the benchmark before pushing.

Wipe only the three gitignored output subdirectories instead. Stale output is
still cleared between runs; the harness survives.

Follow-up to #3430 (#3430 review).
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
rtk 0.46.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## [0.46.0](rtk-ai/rtk@v0.45.0...v0.46.0) (2026-08-26)


### Features

- find: dispatch on find's grammar; compress find output for unmodeled predicates ([#3603](rtk-ai/rtk#3603))
- find: tee tail hint when rtk imposes the result cap ([#3603](rtk-ai/rtk#3603))

### Bug Fixes

- find: never-worse guard, recovery hint, and dispatch on find's grammar ([#3603](rtk-ai/rtk#3603))
- git: don't misdetect a value-taking option's argument as a patch flag ([#3575](rtk-ai/rtk#3575))
- cicd: stop benchmark.sh deleting the tracked scripts/benchmark harness ([#3595](rtk-ai/rtk#3595))
- tee: hash long recovery-file slugs to prevent collisions and shorten hints ([#3266](rtk-ai/rtk#3266))
- benchmark: avoid negative curl/cargo cases that fail the benchmark job ([#3430](rtk-ai/rtk#3430))
- test: accept both Ask and Allow verdicts in rewrite tests ([#3147](rtk-ai/rtk#3147)) — Closes [#3146](rtk-ai/rtk#3146)
- core: decode process output using Windows console code page ([#2717](rtk-ai/rtk#2717)) — Closes [#2452](rtk-ai/rtk#2452)
- git: preserve patch output from log commands ([#2951](rtk-ai/rtk#2951)) — Closes [#2944](rtk-ai/rtk#2944)
- discover: sanitize drive-letter colon so Windows discover finds sessions ([#2952](rtk-ai/rtk#2952)) — Closes [#2919](rtk-ai/rtk#2919)
- stream: decode lossily instead of dropping lines on invalid UTF-8 ([#2997](rtk-ai/rtk#2997)) — Closes [#2994](rtk-ai/rtk#2994)

### Other

- test(find): use the platform temp dir instead of /tmp ([#3717](https://github.com/rtk-ai/rtk/pull/3717))</pre>
  <p>View the full release notes at <a href="https://github.com/rtk-ai/rtk/releases/tag/v0.46.0">https://github.com/rtk-ai/rtk/releases/tag/v0.46.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!17826
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants