Repository navigation
fix(tier3): count token usage per case correctly and keep the terminal token notes accurate - #546
Merged
Merged
Conversation
A case's expected attempts came from pass@k's k minus the attempts skipped after a pass. Under a run budget the collector plans fewer than k attempts for a case and records the refused ones as neither skipped nor missing, so the case row read as partial with missing attempts while its agent row was complete. Take a case's expected attempts from its pass@k counters instead: scored plus recovered plus missing attempts, which leave out attempts skipped after a pass and attempts the budget refused. A record without those counters still gives k minus the skipped attempts. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…token usage The loader reads a trajectory's counters into each reward's token summary, where an invalid value becomes absent, the same as the cache counter Harbor leaves out when it is zero. Token usage then read an invalid cache counter of a scored attempt as 0 and counted the attempt as measured, both in a succeeded arm and in an arm whose scores are withheld. Only attempts without a reward were left unmeasured. The loader now names the counters a trajectory recorded with an invalid value, never their values. A report trial lists them in invalid_token_counters next to its unchanged tokens, and usage-only attempts carry the same field. Token usage counts such an attempt as unmeasured with the invalid_token_counters reason. The resources totals, which read only prompt and completion, are unchanged. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
An attempt without a scored reward took its token usage case from the task directory its Harbor result names. A native task may set its own [metadata] entry_id, so its directory is not its case ID, and its unscored attempts landed in a separate case row. The arms then looked like they ran different cases, and a case row left out the attempt's tokens. The collector maps each Harbor task to its case with the run's trusted selector mapping. It now records that case in the unscored attempt's failure.json as entry_id, and the report loader prefers it. Runs without the record keep the directory and trial name fallback. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…opped them When the report payload has to make room, it drops the token usage case rows of every agent, and every report reads that payload. The validate and tier3 evaluate terminal tables still pointed readers at the reports for the case rows and then said the rows were left out of "this report", which contradicts itself. Once the payload dropped the case rows, the terminal tables now say that they were left out of every report and that the agent sums cover every attempt, instead of naming the report files. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
tier3 evaluate printed the token usage table only with the score tables, which a run without a usable arm never shows. A run whose every attempt hit the agent timeout used tokens like any other, and the report step recorded its sums, but the terminal showed only the panel that says the evaluation did not complete. Print the agent token sums for such a run too, after that panel and under the same rule as the score tables: always when there is no case summary to show. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nfig The collector read an unscored trial's case only from its Harbor result.json. A trial that stopped before Harbor wrote its result still has its config.json, which names the same task, so the collector now falls back to it. Without the record, a native task attempt whose directory differs from its entry_id landed in a case row of its own. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add a Fixed entry for the token usage fixes that follow up #427, say in the reports reference that a case expects only the attempts its pass@k record planned, and reflow the invalid counter paragraph. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Fixed changelog entry said `tier3 evaluate --verbose` prints the agent token sums for a run whose arms all failed. A run without a usable arm never shows a case summary, so the table prints with or without --verbose, as docs/reports.mdx already says. The entry now names plain `tier3 evaluate`, and its lead sentence says each attempt is counted in the case it belongs to rather than "in its own case", which read like the separate row the fix removes. Rewrap the token usage bullet in docs/reports.mdx that had one line of 96 characters. The docs and changelog contract test now checks the entry's wording and that no line of the token usage section is wider than 80 characters. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
The loader marks the token counters that a scored attempt's trajectory recorded with an invalid value under an internal reward key. It never cleared that key from the reward.json it loaded, so a results directory whose reward.json held it kept the file's list whenever the trajectory was valid. A list that mixed types made loading fail on sorting it, and a list of names marked a valid attempt unmeasured or put any name the file held into the report trial's invalid_token_counters. The loader now drops the key from each loaded reward before it reads the trajectory. Report trials and usage-only attempts keep only names of token counters, in prompt, completion and cached order, so both list the same counters the same way. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bring the branch up to date with main after the v0.9.0 release. Move the token usage changelog entry from the released 0.9.0 Fixed section, where the merge placed it, to the Fixed section under Unreleased. The docs and changelog contract test keeps main's search for the token usage Added entry in any release and checks the Fixed entry under Unreleased. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
… map The collector recorded the case of an unscored attempt in failure.json only when the run passed the trusted task selector map. The NeMo Gym backend collects without that map, so an unscored attempt of a native task whose [metadata] entry_id differs from its directory still took the task directory as its case: token usage split the case into two rows and left the attempt's tokens out of the real case row. Without the selector map, the collector now resolves the case of an unscored trial from its result.json or config.json with the arm's suffix and staged task entry IDs, the same way it resolves a scored trial, and records it only when that case is authoritative. The reader keeps its task directory fallback otherwise. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
The CHANGELOG check of the token usage contract read the Fixed entry only from the first release section. Once Unreleased becomes a numbered release, a new Unreleased section without a Fixed subsection raises IndexError, and one with a Fixed subsection that lacks this entry fails the single-entry unpack. Search the Fixed subsection of every release section instead, as the Added check in the same test already does, and keep the content assertions on the entry it finds. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bring the branch up to date with main, which now validates token usage case rows against the evaluation dataset's case IDs. Token usage keeps main's dataset matching for every attempt and reads each attempt's tokens with its invalid_token_counters. A case's expected attempts come from main's merged pass@k record per case and still count its scored, recovered and missing attempts. The terminal pointer says no report has the case rows once the payload dropped them, and keeps main's note about case IDs the dataset does not name. The changelog takes main's file and adds the token usage entry to the Fixed section under Unreleased. The docs and changelog test keeps both the Fixed entry check and main's new tests. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the blank line at the end of the token usage test module so that ruff format --check passes on it. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
rng1995
requested review from
chrisknvidia,
mosheabr and
rmalani-nv
as code owners
November 14, 2026 04:22
rng1995
commented
Nov 14, 2026
rng1995
left a comment
Collaborator
Author
There was a problem hiding this comment.
I reviewed the per-case attribution of scored, unscored, config-only and native-task attempts (with and without a selector map), the _case_expected counts under run budgets, stop-on-pass and recovered timeouts, the handling of invalid counters in the trials, the usage-only rows and the terminal notes, the totals the terminal prints for a run whose arms all failed, and whether the docs and CHANGELOG match the code. Apart from one minor terminal pointer issue, explained inline, they match. The token usage test modules (126) and 9 related collector, NeMo Gym, display and budget modules (709 passed, 5 skipped) pass on this head.
The tier3 evaluate token table always said the case rows are in report.html and tier3-benchmark.md. Only the Harbor runner writes the benchmark; a NeMo Gym run writes report.html alone, and a run whose report step failed writes neither. The pointer now follows the paths the runner recorded: benchmark_path names both files, report_path alone names report.html, and without either no file is named. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #427 (merged through #407), which added Tier 3 token usage per case, per agent and over all agents. On current main, five problems still give wrong numbers, a missing table or a note that contradicts itself: the terminal tables point at case rows that no report has, an unscored native task attempt lands in a case row of its own, an invalid cache counter on a scored attempt counts as 0,
tier3 evaluateprints no token table for a run whose arms all failed, and a case that a run budget cut short reads as partial. This PR fixes each one and adds a regression test for it.Changes
validateandtier3 evaluateterminal tables still named the report files that hold the case rows and then said the rows were left out of "this report". They now say that the case rows were left out of every report to keep the reports within their size limits, and that the agent sums cover every attempt. The note that names case IDs the evaluation dataset does not have still follows.[metadata] entry_id, so its unscored attempts formed a separate row (marked as an unverified case ID when the report has the dataset's case IDs), the agent note said the arms ran different cases (case_scope_mismatch), and the case row left out the attempt's tokens. The collector now records the attempt's case asentry_idin the unscored trial'sfailure.json. It reads the task from the trial'sresult.json, or fromconfig.jsonfor a trial that stopped before Harbor wrote a result. A Harbor run maps that task to its case with the run's trusted selector mapping. A NeMo Gym run has no such mapping, so the collector resolves the case from the arm's staged task files, the way it resolves a scored attempt, and records it only when that case is authoritative. The loader prefers the recorded case and keeps the task directory and trial name fallback for runs without it.total_cached_tokens(negative, fractional, a string or a bool, or above2^53 - 1) into an absent counter when it read a scored attempt's trajectory, and token usage then read the absent cache as Harbor's omitted zero. The attempt counted as measured withcached_tokens: 0, in a succeeded arm and in an arm whose scores are withheld, while the same counter on an unscored attempt left it unmeasured. The loader now names the counters a trajectory recorded with an invalid value, never the values. A report trial lists them in a new optionalinvalid_token_countersfield next to its unchangedtokens, usage-only attempts carry the same field, and token usage leaves such an attempt unmeasured with theinvalid_token_countersreason. Only the trajectory names these counters: the loader drops the internal key that carries them from eachreward.jsonit reads, and both fields keep onlyprompt_tokens,completion_tokensandcached_tokens, in that order. Theresourcestotals, which read only prompt and completion, are unchanged.tier3 evaluateprinted no token usage for a run whose arms all failed. The token table was printed only with the score tables, which a run without a usable arm never shows, although the report step recorded the run's token sums. It is now printed after the panel that says the evaluation did not complete, with or without--verbose.kminus the attempts skipped after a pass. Under--max-attempts-total,--max-agent-tokensor--max-cost-usdthe collector plans fewer thankattempts for a case and counts the refused ones as neither skipped nor missing, so the case row waspartialwithmissing_attemptsand no change while its agent row was complete. A case now expects its pass@k record's scored, recovered and missing attempts, which leave out both skipped and refused attempts, and never fewer than it observed. A result file without those counters still giveskminus the skipped attempts.docs/reports.mdxdescribes the recorded case with either backend,invalid_token_counters, the planned attempts a case expects and both terminal behaviors.CHANGELOG.mdhas one Fixed entry under Unreleased.Known trade-offs
invalid_token_counterslist, and an unscored trial'sfailure.jsongains an optionalentry_id. Both are additive; readers that ignore unknown fields are unaffected.invalid_token_countersinstead ofmissing_token_counters, the same code a scored attempt gets. The existing test for it asserts the new code.entry_idinfailure.json, so their unscored native task attempts keep the task directory fallback until they are collected again.Tests
tests/tier3/test_token_usage.pyandtests/reporting/test_tier3_token_usage_reports.py: 126 passed on this branch. With the same test files on main c19b5d7, 27 fail and 99 pass:test_terminals_say_no_report_has_the_case_rows_the_payload_left_out(1), with the payload that the report step fitted fortier3 evaluateand the onevalidatefits.test_the_collector_records_the_case_of_an_unscored_native_task_attempt(2: fromresult.jsonand fromconfig.json) andtest_an_unscored_attempt_takes_the_case_its_failure_record_names(1).test_a_scored_attempt_whose_arm_failed_with_invalid_cached_tokens_is_not_measured(5),test_a_scored_attempt_with_invalid_cached_tokens_is_not_measured_and_resources_keep_it(5),test_a_counter_the_trajectory_recorded_invalid_is_rejected_although_tokens_leave_it_out(1),test_report_trials_and_usage_only_attempts_name_only_token_counters_in_one_order(1), the 3 invalid-cache cases oftest_only_the_trajectory_names_the_invalid_token_counters_of_a_scored_attempt, and the 5 existing cases oftest_unscored_attempt_with_invalid_cached_tokens_is_not_measured, which now also assert theinvalid_token_countersreason (main reportsmissing_token_counters). The 3 valid-cache cases of the trajectory-only test pass on main and guard that areward.jsonholding the internal key keeps a valid attempt measured and loads.test_tier3_evaluate_terminal_prints_the_token_usage_of_a_run_whose_arms_all_failed(1), with the failed engine result thatrender_agent_eval_html_report()records into.test_a_case_that_a_run_budget_cut_short_expects_only_the_attempts_it_admitted(1). On main the case row ispartialwithmissing_attempts. The newcollectorcase oftest_an_attempt_that_never_ran_leaves_the_arm_partialpasses on both and guards that an attempt that never ran is still missing.test_docs_and_changelog_describe_the_token_usage_contract(1) finds the entry in the Fixed subsection of any release section and checks that no line of the token usage section indocs/reports.mdxis wider than 80 characters. Against a copy ofCHANGELOG.mdwith## Unreleasedrenamed to a numbered release under a new Unreleased section, a check of only the first section raisedIndexError(new section without Fixed) orValueError(new Fixed subsection without the entry); this check passes in both.tests/test_nemo_gym_backend.py::test_an_unscored_gym_attempt_of_a_native_task_counts_its_tokens_in_its_casefails on main c19b5d7 (KeyError: 'entry_id': the failed trials'failure.jsonhas no case) and passes on this branch. It writes NeMo Gym rollouts withwrite_job_from_rolloutsfor a native task staged with its ownentry_id, one scored and one failed attempt per arm, and collects them without a selector mapping. On this branch each arm has oneauth-loginrow of 15,200 tokens; main splits each arm into anauth-loginrow of 1,100 tokens and alogin-taskrow of 14,100.tests/test_ci_workflows.py,tests/test_oss_packaging.py,tests/test_ci_change_classifier.pyandtests/tier3/test_verifier_python39_syntax.py(100 modules): 6836 passed, 9 skipped, 99 failed. 89 of them fail the same way on main c19b5d7 in this environment, whose installed Harbor package predates the pinned version: most are Bedrock preflight probe tests and tests that need newer Harbor APIs, plus the Harbor keyword argument contract check and three NeMo Gym CLI probe timeout tests. The other 10 are Bedrock preflight probe, Harbor bounded-process timeout and CI helper tests that failed under load; rerun alone on this branch they pass. None is in the token usage test modules.ruff checkandruff format --checkpass on the changed Python files. The OSS boundary scan passes.git merge-tree --write-treeof this branch and main c19b5d7 is clean, and main is an ancestor of the branch.🤖 Generated with Claude Code