Skip to content

Record per-arm bench cost and apply the cost check - #1981

Merged
remigiusz-antczak merged 1 commit into
mainfrom
land/1962c
Oct 24, 2026
Merged

remigiusz-antczak merged 1 commit into
mainfrom
land/1962c

Conversation

@remigiusz-antczak

Copy link
Copy Markdown
Collaborator

Supersedes #1980 and #1962. The same change, rebuilt as one commit on current main, with three fixes from an independent review of #1980.

The bench recorded spend_usd: 0.0 for every arm, so the cost half of the keep rule could never be applied.

  • scripts/rival_eval_cost.py (new) wraps the hash-pinned scripts/rival_eval.py. It records prompt and completion tokens per item, and spend in USD when the provider reports it. An arm counts as measured only when every item has usage. Unlike Record per-arm bench cost and apply the cost check #1962, rival_eval.py itself is left unchanged, so its pinned hash still holds.
  • scripts/bench_verdict.py --cost results.json reports the Perun-to-rival cost ratio. It exits 0 when Perun costs no more than the rival, 1 when it costs more, 2 on a usage error and 3 when either arm is unmeasured, the units differ, or the rival cost is zero. Older results read as unmeasured.
  • scripts/rival-eval-premerge.sh calls the wrapper. docs/perun-vs-rivals.md documents the harness entry point.
  • Tests live in scripts/test_bench_cost_capture.py and run from scripts/ci-tests.d/bench-cost-capture.sh.

The review of #1962 found one 🔴: a partial run could read as measured. It is fixed here, because every item must carry usage. The review of #1980 found three 🟡, also fixed here:

  • A retried call was billed but only the last attempt's usage was kept. Usage now adds up across attempts, and an attempt with unknown usage (for example a timeout) leaves the item unmeasured.
  • Zero cost on both arms passed the cost check. It now reads unmeasured (exit 3).
  • A missing or malformed results file raised a traceback and exited 1, which reads as "Perun costs more". It now exits 3.

Tests: 21/21 in scripts/test_bench_cost_capture.py.

Local CI repro on this commit: size-ratchet ok against main, mustload ok, and every scripts/ci-tests.d hook passes. run-ledger.sh failed once only because a second copy ran at the same time; run alone it passes 26/26. test-ci-gates.sh shows 295 passed and 9 failed. The 9 are the known sandbox-only failures (dcr-gates opt-in, peer pains, reap_own pgrep, tracker socket bind).

🤖 Generated with Claude Code

https://claude.ai/code/session_014QNFFPWVcPUbeuvwM5fk2Z

rival_eval_cost.py (a wrapper around the unchanged, hash-pinned rival_eval.py; rival-eval-premerge.sh now runs it) writes cost_per_arm (prompt_tokens, completion_tokens, spend_usd) taken from the PCSS response or claude -p JSON, never estimated, with a per-output sidecar so resumed runs keep it. bench_verdict.py --cost prints per-arm cost per item and the Perun/rival ratio; exit 0 Perun cost <= rival, 1 Perun costs more, 2 usage error, 3 unmeasured.

A billed retry adds to the item's usage, and an attempt with unknown usage leaves the item unmeasured. Zero cost on both arms reads unmeasured, and an unreadable results file exits 3.

Tests: 21/21 (test_bench_cost_capture)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014QNFFPWVcPUbeuvwM5fk2Z
@remigiusz-antczak
remigiusz-antczak merged commit 9855461 into main Oct 24, 2026
1 check passed
@remigiusz-antczak
remigiusz-antczak deleted the land/1962c branch October 24, 2026 13:09
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.

1 participant