Skip to content

feat(eval): record the Claude tokens each scenario really spent - #5525

Merged
kovtcharov-amd merged 2 commits into
mainfrom
feat/eval-claude-usage
Oct 21, 2026
Merged

kovtcharov-amd merged 2 commits into
mainfrom
feat/eval-claude-usage

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

A flagship scenario that passed kept only the driver's own guess at its cost and threw away the token counts claude -p reports, so we could not say what a sweep costs, which categories drive it, or whether a change like prompt caching (#5493, section 6.4) actually saves anything. Every scenario now records its real Claude usage (input, output, cache read, cache write, API calls, list-price cost), and the scorecard, summary.md and the all-lanes CI summary add it up per category and per run.

The scenario's Claude session both plays the user and judges each turn, so its usage is filed under one driver role; the schema keeps a judge role for separate judge-only calls. Splitting the two needs scripted user turns first (#5493, cut c).

Test plan

  • pytest tests/unit/eval tests/test_eval.py tests/unit/test_eval_launch_contract.py: 1546 passed, 30 skipped
  • New tests/unit/eval/test_claude_usage.py uses payloads shaped like real claude -p output: success, quota-style zero-token failure, budget stop, unparseable output, a driver that forges its own usage, --iterations summing, and scorecard/lane totals
  • PYTHONPATH=src python util/lint.py --all clean for these files
  • First dispatched flagship run shows the Claude usage table in each category's summary.md and in the all-lanes summary

A passing scenario kept only the driver's own guess at its cost and dropped
the token counts claude -p reports, so nobody could say what a flagship sweep
cost or where its tokens went. Each scenario now records input, output, cache
read, cache write, API calls and list-price cost under `claude_usage`, summed
across --iterations attempts. The scorecard adds them up per category and per
run, summary.md shows the table, and the all-lanes CI summary adds the lanes.

Usage is filed by role. The scenario session is the `driver`, and it also
judges every turn, so its tokens cover both jobs; a separate judge-only call
files under `judge`. A scenario killed on timeout records nothing, and the
totals say how many scenarios they are missing.
@github-actions github-actions Bot added documentation Documentation changes eval Evaluation framework changes tests Test changes performance Performance-critical changes labels Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes

Recording the real Claude token counts per scenario is useful, and the per-category and per-run totals add up correctly. The problem is one import: it makes the all-lanes summary step in the flagship eval workflow crash on every run.

  • The all-lanes summary breaks in CI. That step runs the summary script as a plain file on a hosted runner where GAIA isn't installed, and the workflow comment says the script is stdlib-only by design. The PR makes it import GAIA's new usage module, so the step now fails with "No module named 'gaia'". The evidence run below reproduces this. Keep the script stdlib-only, for example by copying the two small helpers it needs into it. Then add a test that runs it the same way CI does, so this can't come back.

Real-world evidence

The evidence stage ran the summary script the way eval_flagship.yml runs it (stdlib only, no gaia on the path):

$ python -S src/gaia/eval/lane_summary.py --lanes-file eval/ci_lanes.json \
    --artifacts-dir $R/old --baseline-dir tests/fixtures/eval_baselines/gaia-flagship
Traceback (most recent call last):
  File "/home/runner/work/gaia/gaia/src/gaia/eval/lane_summary.py", line 53, in <module>
    from gaia.eval.claude_usage import add_usage, empty_usage
ModuleNotFoundError: No module named 'gaia'
exit=1

The pre-PR file exits 0 on the same command and renders the lanes table. The bundle's other results:

Surface Verdict
lane_summary.py run as CI runs it ❌ FAIL, regression from base
lane_summary.py with gaia importable, old scorecards ✅ output byte-identical to base
scorecard.json claude_usage and the summary.md section ✅ sums correct, lower-bound note shown
lane_summary.py "Claude usage" table ✅ per-lane rows and total correct
gaia eval agent end-of-run Claude: … line ⏸ pending strix-halo lane (needs a real claude -p driver)

This failure is why the verdict is Request changes. Nothing here exercised the end-of-run console line, so that part of the verdict comes from reading the code only.

🔍 Technical details

🔴 lane_summary.py is no longer stdlib-only (src/gaia/eval/lane_summary.py:53)

.github/workflows/eval_flagship.yml:2244-2246 runs python src/gaia/eval/lane_summary.py on a hosted runner with no install. Run that way, sys.path[0] is src/gaia/eval/, not src/, so from gaia.eval.claude_usage import … fails before main() runs. The step pipes into tee, so it may also lose the job summary. The script only needs empty_usage and add_usage, and both are about 10 lines of stdlib code. Inline them:

# Stdlib-only: CI runs this file directly with no gaia install. Keep in step
# with gaia.eval.claude_usage.
_USAGE_FIELDS = (
    "input_tokens",
    "output_tokens",
    "cache_read_input_tokens",
    "cache_creation_input_tokens",
    "calls",
    "cost_usd",
    "duration_api_ms",
)


def empty_usage() -> dict:
    record: dict = {field: 0 for field in _USAGE_FIELDS}
    record["cost_usd"] = 0.0
    return record


def add_usage(total: dict, record) -> dict:
    if not record:
        return total
    for field in _USAGE_FIELDS:
        total[field] = total.get(field, 0) + (record.get(field) or 0)
    return total

(The lane summary ignores models, so dropping that merge here is fine.) If you'd rather keep a single copy, a test that asserts lane_summary.empty_usage() keys equal claude_usage.USAGE_FIELDS will catch drift.

🟡 No test runs the script the way CI does (tests/unit/eval/test_lane_summary.py)

Every lane-summary test imports the module in-process, where gaia is always importable, so none of them could catch this. Add one that runs subprocess.run([sys.executable, "-S", str(REPO_ROOT / "src/gaia/eval/lane_summary.py"), "--lanes-file", …, "--artifacts-dir", tmp]) and asserts exit 0. That locks in the "stdlib-only by design" contract the workflow depends on.

Strengths

  • Usage belongs to the runner: the runner drops any claude_usage the driver's own JSON contains before it records the CLI's real counts, and a test covers that forgery case.
  • A role that didn't run is absent, not zero, and scenarios_without_usage / attempts_without_usage mark the totals as a lower bound when timeouts are missing. That's the fail-loudly approach to partial data.
  • The tests use payloads shaped like real claude -p output, including the zero-token quota failure, where calls is set to 0.

eval_flagship.yml runs lane_summary.py as a plain file on a hosted runner
with no GAIA install, and the new usage table imported gaia.eval.claude_usage,
so the summary step would fail on every run. The two helpers it needs are now
inlined (stdlib only), a test pins them to claude_usage's fields, and another
runs the file exactly as CI does (python -S, no gaia on the path).
@github-actions

Copy link
Copy Markdown
Contributor

Skill audit

Skill Verdict Claimed tier Cleared tiers Findings Rules
.claude/skills/gaia-release ✅ ALLOW experimental experimental, community none —

✅ All audited skills cleared the tier they claim.

Per-finding detail is withheld here on purpose. Read it in the Security > Code scanning tab, or download the skill-audit-reports artifact from this run. Offending source text is withheld from CI everywhere — reproduce it locally with gaia skill audit <dir> --show-snippets.

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

Fixed: the all-lanes summary script is stdlib-only again, so it runs on the hosted runner without GAIA installed.

🔍 Technical details
  • 9377bf2 inlines empty_usage / add_usage in lane_summary.py. A test pins its USAGE_FIELDS to claude_usage.USAGE_FIELDS.
  • test_the_lane_summary_runs_as_ci_runs_it runs the file with python -S and no PYTHONPATH, as eval_flagship.yml does, and checks the usage total row. The previous file fails that way with No module named 'gaia'; the fixed one exits 0.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 21, 2026
Merged via the queue into main with commit db8d173 Oct 21, 2026
38 of 42 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the feat/eval-claude-usage branch October 21, 2026 20:17
grtninja pushed a commit to grtninja/gaia that referenced this pull request Oct 22, 2026
…md#5533)

When the Claude account running a flagship eval ran out of quota, every
remaining scenario failed in seconds as an ordinary error and the run
still went green: v0.25.1-rc2 lost 68 of 343 scenarios that way (amd#5493,
section 6.4). Now the run stops the moment Claude's quota or credential
gives out (or Claude fails to answer two scenarios in a row): nothing
else is launched, the rest are recorded as `NOT_RUN` (never PASS, never
an ordinary error), and it exits 3 with the account, the reset time and
the command to finish it. `gaia eval agent --resume <run-dir>` then runs
only the scenarios without a result and merges them into the same
scorecard, each stamped with the commit and time it ran at.

Closes amd#5265. Stacked on amd#5525 (Claude usage); I'll rebase onto `main`
once that merges.

In CI a quota stop already ends the lane (any non-zero exit does), and
the integrity gate's `--fail-on-zero-token-errors` now also counts these
scenarios, so a dispatch still fails. The lane's run directory doesn't
survive the job, so CI re-dispatches the printed `-f scenarios=...` list
(amd#5513) rather than using `--resume`.

## Test plan
- [x] `pytest tests/unit/eval tests/test_eval.py
tests/unit/test_eval_launch_contract.py`: 1579 passed, 30 skipped
- [x] `tests/unit/eval/test_quota_resume.py` runs the real runner loop
against a fake `claude -p` that runs out of quota after N scenarios:
nothing is launched after it, the rest are `NOT_RUN`, exit code 3, the
message names account, reset and resume command, and the token never
reaches the log
- [x] Resume runs only the missing scenarios, keeps earlier results with
their commit and time, warns when commits differ, refuses a different
`--model`, stops again if the quota runs out again, and is a no-op on a
finished run
- [x] A single zero-token failure with no quota or credential wording
stays resumable but doesn't stop the run; two in a row do
- [x] A genuine FAIL, a timeout, a "rate limit" phrase inside a
transcript, the scenario's own budget cap, and a driver that forges
`claude_outage` or `NOT_RUN` never stop a run
- [x] Outage phrases checked against the strings in the installed
`claude` CLI (2.1.303): "You've hit your limit", "Usage limit reached",
"monthly spend limit", "limit resets"
- [x] `PYTHONPATH=src python util/lint.py --all` passes

<details>
<summary>🔍 Technical details</summary>

- `gaia.eval.claude_outage.classify_driver_failure` reads only the CLI's
`is_error` result, `api_error_status`, and stderr/stdout when there is
no JSON. Its phrase lists extend `judge_outage`'s with the subscription
CLI's wording. `util/classify_claude_probe.py` keeps its own copy
because it runs in the preflight before GAIA is installed.
- A failure with zero tokens and zero API time counts as an outage
("Claude never answered") even without a matching phrase. That was rc2's
signature, whose stored errors were cut before the CLI's message.
- The run loop moved into `AgentEvalRunner._execute`, which fresh and
resumed runs share. The `.progress.json` path it replaces could never
resume anything because every run got a new directory.
- `--resume` reads the run's own `scorecard.json`, which now carries
`config.plan`. CI uploads that file, so a lane that restores its
previous artifact could resume too.
</details>
grtninja pushed a commit to grtninja/gaia that referenced this pull request Oct 22, 2026
…#5535)

Every RC tag ran the whole flagship sweep: about 28 Strix Halo
machine-hours, 13 of 14 machines for 3.3 h, and an estimated 130M Claude
tokens, more than two accounts delivered on rc2. Now an RC runs a
30-scenario smoke tier on 3 machines, only the RC you nominate for
promotion runs the full sweep, and a final tag checks that sweep exists
instead of re-running it. The Strix Halo pool also starts scoring
Qwen3.6-35B-A3B, the model `gaia init` installs on that hardware,
against its own baseline. Implements the "Cost and tiering" section of
amd#5493.

| Per release cycle (3 RCs + final) | Before | After (amd#5493 estimates) |
|---|---|---|
| Strix Halo machine-hours | ~113 (4 full sweeps) | ~37 (2 smokes, 1
full sweep, 2 weekly backlog runs) |
| Claude tokens | ~520M | ~170M |
| A non-promoted RC | 13 machines, 3.3 h, ~130M tokens | 3 machines, ≤1
h target, ~19M tokens |

**Measured on rc2's commit:** the smoke took 3 machines, 2.0
machine-hours and 45 min wall time
([run](https://github.com/amd/gaia/actions/runs/39668506957)). rc2's own
full sweep took 13 machines, 22.1 machine-hours (cut short when the
quota ran out) and 2 h 38 min. The smoke ran before amd#5525 started
recording real Claude usage, so the token figures stay estimates; the
next tier run will measure them.

**Worth a look:** on Qwen the smoke passed 27 of 30. The 3 failures are
all protected refusal scenarios that pass at least 93% on Gemma:
`files_sandbox_refusal_system`, `mem_credential_refusal`,
`shell_denial_reported_as_denial`. It's one run, so re-run before
calling it a Qwen regression.

- **Tiers.** RC tag → smoke. `[full eval]` in an RC's annotated tag
message (or `-f tier=full`) → full sweep. Final tag → verify only.
`[skip eval]` still works.
- **Weekly backlog lane**, Sunday 06:17 UTC, 3 machines: the 26
non-protected always-fail scenarios (which leave the full sweep) plus
the 15 noisiest (which stay in it), with a rolling trend artifact so
progress toward 80% is visible. It skips itself while any other flagship
run holds the pool. Owner: @kovtcharov-amd.
- **Nothing drops out.** Protected scenarios (security, honesty,
injection, adversarial, error recovery, resilience) never leave the full
sweep, and a check proves smoke + full + backlog still cover all 343
runnable scenarios.
- **Qwen on Halo, compared only with Qwen.** Its baseline is empty until
a real full sweep fills it, so runs say "no Qwen baseline yet" and never
fall back to Gemma's. A dispatch can still pick `-f
model=Gemma-4-E4B-it-GGUF` to re-run part of a Gemma tag run, as rc3
does. Gemma moves to the Strix Point pool (amd#5511); the Halo full sweep
keeps no Gemma coverage by default.
- **Quota exhaustion fails every run now**, tag runs included (the
zero-token check from amd#5513).

## Test plan
- [x] `pytest tests/unit/eval tests/unit/test_eval_tag_gate.py
tests/test_eval.py`: 1686 passed, 30 skipped
- [x] `python util/eval_tiers.py check`: 343 of 343 runnable scenarios
covered; 18 never-in-CI scenarios listed with their reason
- [x] `python util/lint.py --all` passes; actionlint reports only the
existing runner-label notices
- [x] Tiny Qwen dispatch on rc2's commit
([run](https://github.com/amd/gaia/actions/runs/39660896807)): judged
PASS, session ran Qwen3.6 as pinned, compare reported "no Qwen baseline
yet". The first try caught a warm pull that never happened and stopped
in preflight; fixed in this PR
- [x] Smoke tier on rc2's commit 0b14d74 plus this PR's harness
commits ([run](https://github.com/amd/gaia/actions/runs/39668506957)): 3
machines, 45 min, 30 scenarios all on Qwen, no zero-token errors

<details>
<summary>🔍 Technical details</summary>

- The first commit is amd#5511's pin-and-refuse core, taken verbatim
(`eval_gaia_home.py pin-model`, `gaia eval agent --agent-model`,
`--compare` exit 3 on a model mismatch) so both branches carry one
implementation. amd#5511's Strix Point workflow, reusable lane and
lane-matrix changes are left to it. Whichever lands second drops the
duplicate hunks.
- `eval/ci_tiers.json` holds the smoke and backlog machines, each
scenario's `why` (pass rate, runs, timeouts, protected reason), the
model → baseline map, and the owner. `util/eval_tiers.py` decides the
tier, builds the matrix (reusing amd#5513's scenario selection), checks
coverage from the matrices it would emit, and verifies a final tag
through a 90-day `flagship-tier-full` marker artifact.
`util/eval_backlog_trend.py` rolls the trend forward.
- A smoke machine holds `memory` beside other non-gaia categories; the
job runs with memory off and turns the store on for `memory` alone
(`EVAL_MEMORY_CATEGORIES`), so no category runs under different
conditions than in the full sweep.
- Outcomes (`gaia eval tasks`) runs only with the full sweep, to keep
the smoke at 3 machines.
- Gemma on Strix Point: `python util/eval_tiers.py scenarios --tier
smoke` prints the same 30 ids. Point runs scenarios about 3x slower, so
the full smoke is roughly 4 h on one Point machine, or about 2 h for the
13 protected ones.
- rc3 is unaffected: a dispatch on `--ref v0.25.1-rc3` runs the workflow
as it is at that tag.
</details>
kovtcharov-amd added a commit that referenced this pull request Oct 30, 2026
The plan's cost-and-tiering section has largely landed since it was written: the RC smoke tier, nominated full sweep, weekly backlog lane and Qwen3.6 scoring (#5535), real Claude usage per scenario (#5525) and quota stop-and-resume (#5533). The status line, the implementation table and the stale "isn't recorded" and "v0.25.1 final" claims now say so, and two answered open questions are dropped.

Also fixes the two contradictions the review flagged: the scenario eval could have caught 2 escapes, not 3 (#5413 needs a scripted model), and item 3 adds re-runs to the existing Strix Halo eval.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation changes eval Evaluation framework changes performance Performance-critical changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant