Skip to content

fix(health): skip failed calls without a generation in token-count checks - #4229

Merged
giuliolovisotto merged 2 commits into
mainfrom
glovisotto/health-failed-call-tokens
Oct 8, 2026
Merged

giuliolovisotto merged 2 commits into
mainfrom
glovisotto/health-failed-call-tokens

Conversation

@giuliolovisotto

@giuliolovisotto giuliolovisotto commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What changed

model_call_missing_token_counts and model_call_zero_completion_tokens now skip a failed model call that produced no generation: a cancelled call or an HTTP error reply, which has no finish reason. rollout_token_count_mismatch no longer becomes unobserved because of such a call; it contributes zero tokens to the sum.

Why

A failed attempt has no usage to account for, so missing token counts on it say nothing about token accounting. Before this change, a rollout that hit a failed call and then retried successfully was still unhealthy because of the failed attempt's null counts. #3769 had already stopped calling these rollouts "ended on a failed call".

Observed on a Terminal-Bench 2.1 run with Terminus 2: each model call has a 600 s client limit, after which the call is cancelled and retried. 373 cancelled calls across 183 rollouts; about 115 of those rollouts recovered and were unhealthy only through model_call_missing_token_counts. Controlled conformance scenarios show the same pattern for HTTP 429/500 retries in OpenCode and Codex.

What stays the same

  • A rollout that ends on a failed call stays unhealthy through rollout_ended_on_failed_model_call (fix(health): stop flagging recovered model calls #3769). Whether a rollout recovered is decided there, per model and in start-time order; this change does not infer retries.
  • A failed call that did generate (it has a finish reason) keeps every check. This preserves fix(health): stop flagging recovered model calls #3769's rule that an empty length-limited generation without explicit overflow evidence keeps its quality findings (test_uncertain_or_real_generations_keep_quality_checks is unchanged).
  • A 2xx body that capture could not parse (capture_parse_error) is a capture defect, not a failed call, and stays checked.
  • A missing count on a successful call is still a finding.
  • run.stats.model_call_errors still counts every failed attempt.

Capture stores an HTTP error reply's JSON body as the call's response, so the rule keys on the missing finish reason rather than on a missing response.

Issue

No public issue; this follows #3769.

Validation

  • pytest tests/unit_tests/test_rollout_health.py responses_api_agents/opencode_agent/tests/test_trajectory.py: 169 passed.
  • New tests cover a cancelled, HTTP 429 and HTTP 500 attempt followed by a successful call (healthy, with missing or zero counts), a rollout ending on each of them (unhealthy for rollout_ended_on_failed_model_call only), and an unparsed capture body (still flagged). Nine of the ten fail without the fix; the capture_parse_error test pins unchanged behaviour.
  • test_invocation_bound_failed_call_remains_evaluable (OpenCode) expected a token finding on a 503 without a generation; it now asserts the final-call finding and no token findings.
  • scripts/harness_conformance/scenarios.py: the retry_429 and retry_500 scenarios now expect a healthy rollout. model_error keeps rollout_ended_on_failed_model_call and an unobserved token reconciliation, and no longer expects a missing-token finding. pytest tests/unit_tests/harness_capabilities passes with these expectations.
  • pytest tests/unit_tests/test_rollout_collection.py tests/unit_tests/test_cli_main.py: 654 passed.
  • pre-commit run on the changed files: passed.
  • Not run locally: the Terminus 2 and mini-SWE observability tests (their dependencies are not installed here). Their expectations only require the token checks to be evaluated, which they still are.

Rollout evidence

Health-only rerun of the saved Terminal-Bench 2.1 run with Terminus 2 described above: 712 rollouts, 89.3 GiB. No model compute: the same saved records were judged three times. Fields that no health check reads (request payloads, turn inputs, raw capture) were dropped to make the file portable. Health at the run's own Gym commit (832d1cb) still reproduces the run's original result exactly, so the trimming did not change any verdict.

main (ea8c013f4) this PR
unhealthy 183 68
unobserved 529 644
healthy 0 0
rollout_ended_on_failed_model_call findings 68 68
model_call_missing_token_counts findings 373 0
run.stats.model_call_errors 373 calls / 183 rollouts unchanged
  • The 68 rollouts that ended on a cancelled call stay unhealthy. They are the same 68, flagged only by rollout_ended_on_failed_model_call.
  • The 115 that recovered are no longer unhealthy. They become unobserved, not healthy, because their only open check is rollout_token_count_mismatch. This adapter does not link turns to model calls, so token reconciliation is unavailable, and the other 529 rollouts are unobserved for the same reason.
  • No other rollout changed verdict. The other 597 rollouts have the same verdict under main and this PR.

Compatibility

Health verdicts only: fewer model_call_missing_token_counts / model_call_zero_completion_tokens findings on failed attempts, and fewer rollout_token_count_mismatch unobserved results. Rewards, collection outputs and aggregate metrics are unchanged.

🤖 Generated with Claude Code

@giuliolovisotto giuliolovisotto added bug Something isn't working area:evaluation Evaluation, rollout collection, reward profiling, comparison, and exporters labels Oct 8, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@giuliolovisotto
giuliolovisotto marked this pull request as ready for review October 8, 2026 14:51
@giuliolovisotto giuliolovisotto added the needs-review PR is ready for code review and waiting on a reviewer label Oct 8, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 8, 2026 14:52
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

mlazuka
mlazuka previously approved these changes Oct 8, 2026

@mlazuka mlazuka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:)

…ecks

A cancelled call or an HTTP error reply produced no generation, so it has no
tokens to account for. model_call_missing_token_counts and
model_call_zero_completion_tokens still flagged such attempts, which made a
rollout unhealthy even when the client retried successfully. Skip them there
and in rollout_token_count_mismatch's completeness gate. A rollout that ends
on a failed call stays unhealthy through rollout_ended_on_failed_model_call.

A failed call that did generate (it has a finish reason) keeps every check,
preserving the uncertain-overflow behaviour, and a body capture could not
parse stays checked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Giulio Lovisotto <[email protected]>
@yaoyu-33 yaoyu-33 added the complexity:low Localized change in one scope with a small, straightforward review surface label Oct 8, 2026
…ance scenarios

The retry_429 and retry_500 scenarios recover after the failed attempts,
which have no tokens to account for, so they now expect a healthy rollout.
model_error still expects rollout_ended_on_failed_model_call and an
unobserved token reconciliation, but no missing-token finding.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Giulio Lovisotto <[email protected]>
@giuliolovisotto
giuliolovisotto added this pull request to the merge queue Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/37822038576

Merged via the queue into main with commit 75ccb1e Oct 8, 2026
44 checks passed
@giuliolovisotto
giuliolovisotto deleted the glovisotto/health-failed-call-tokens branch October 8, 2026 18:25
giuliolovisotto added a commit that referenced this pull request Oct 9, 2026
…en-total rule

Health gains run.stats.model_call_errors.usage_unknown: failed calls with no
finished response and no token counts. The token checks skip these calls
(#4229), so any tokens the server spent on them were counted nowhere.

The docs now state the token-total rule: response usage counts tokens from
responses that finished, so a rollout whose every call was rejected reports
zero, and only lost usage of a finished response leaves the comparison
unobserved. The _is_failed_attempt docstring no longer claims a skipped call
generated nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Giulio Lovisotto <[email protected]>
ehosseiniasl pushed a commit to ehosseiniasl/Gym that referenced this pull request Oct 9, 2026
…en-total rule (NVIDIA-NeMo#4287)

## What changed

- **New run statistic `run.stats.model_call_errors.usage_unknown`.** It
counts failed calls that returned no finished response and carry no
token counts. Since NVIDIA-NeMo#4229 the token checks skip these calls, so any
tokens the server spent on them (a cancelled or timed-out call may have
generated before it was cut) were not counted anywhere.
- **Docs: the token-total rule.**
- The agent's top-level response `usage` counts tokens from model
responses that finished.
- A rollout whose every call was rejected reports usage of zero, not
missing usage.
- Missing usage means a finished response's usage was lost, and only
that makes `rollout_token_count_mismatch` unobserved.

It is stated in the custom-agent guide
(`observability/rollout-evidence`) and next to the check
(`evaluation/rollout-health`).
- **`_is_failed_attempt` docstring.** It no longer claims a skipped call
generated nothing; it means the client got no finished response.

## Why

The same rejected model call leaves different evidence depending on the
harness. In the conformance scenario's scripted HTTP 400, Pi and
OpenCode report the agent's usage as zero, while Hermes, NOOA and Simple
Agent leave it missing. Health therefore gives different token verdicts
for the same failure: healthy for the first group, unobserved for the
second.

This PR writes down one rule that harness adapters and the conformance
scenario can target. Per-harness fixes and the strict conformance
expectation follow separately; until then, NVIDIA-NeMo#4286 accepts either verdict.

## Split from

The failure-record half of the original NVIDIA-NeMo#4287 is now a separate PR,
because it needs reviewers from the rollout-collection side: NVIDIA-NeMo#4292. The
two PRs are independent and can merge in either order.

## What stays the same

- No health verdict changes: the token checks behave exactly as after
NVIDIA-NeMo#4229.
- The existing `model_call_errors` fields are unchanged.

## Not done

- **Re-applying the token checks to a cancelled stream that had already
delivered output.** The only "output arrived" signal capture records is
the time to the first byte. In Responses-API streams the first event
(`response.created`) arrives before any token is generated, so this
would flag recovered retries again. All 373 cancelled calls in the
Terminal-Bench 2.1 run that motivated NVIDIA-NeMo#4229 were cut before any byte
arrived, and no harness is known to keep partial output.

## Issue

No public issue; follows NVIDIA-NeMo#4229.

## Validation

- `usage_unknown` assertions in the NVIDIA-NeMo#4229 health tests: counted for a
skipped attempt, and not for a body capture could not parse.
- `pytest tests/unit_tests/test_rollout_health.py
tests/unit_tests/test_rollout_collection.py
tests/unit_tests/harness_capabilities`: 760 passed.
- **Full `tests/unit_tests` locally, before the split:** 7554 passed, 25
failed plus 1 collection error. None are in the changed areas: they are
sandbox, telemetry, dataset and exporter tests that need dependencies or
services not available locally. The same set failed locally for NVIDIA-NeMo#4229
and passed on CI.
- `pre-commit run` on the changed files: passed.

## Rollout evidence

N/A: a new run statistic and documentation only. No health verdict,
check or rollout output changes, so there is nothing for a rollout to
exercise.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Giulio Lovisotto <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 26487f5d Deployed Oct 8, 2026 by copy-pr-bot[bot] via release / finalize / notify #4724
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:evaluation Evaluation, rollout collection, reward profiling, comparison, and exporters bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants