Repository navigation
fix(opencode_agent): report unknown usage when a step was stopped - #6960
Conversation
OpenCode writes a step's token counts and `finish` field at the step's `step-finish` event, which comes after the step's tools return. When the agent timeout stops a session while a tool is running (for example, a `task` call in the root session waiting on a subagent), the step's message keeps the placeholder zeros that OpenCode created it with. The agent summed the response usage from the stored messages, so the sum omitted the tokens of a call that Gym had captured. The `rollout_token_count_mismatch` check then flagged the rollout. The agent now reports no response usage when any step was stopped this way and adds a `model_call_usage_unavailable` gap whose detail contains the message ID. Without response usage, the health check already reports the token-count comparison as unobserved; a new test covers this. The crewai agent already does the same when a run is interrupted during a model call. The OpenCode agent README describes the new behavior. In an OfficeQA Pro evaluation run (665 rollouts), all 8 rollouts flagged with a mismatch had been stopped by the 7200 s agent timeout during a tool call. In each case, the missing tokens equaled the usage of the calls in the stopped steps. Signed-off-by: Jarno Seppänen <[email protected]>
|
/ok to test 096d814 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE
I reviewed all four changed files and traced the SQLite export, session response and rollout-health consumers. I found no confirmed code defect, but the required real-rollout validation is still unresolved.
RISK: Provide representative smoke-rollout evidence from this head
Could you attach a real-model smoke run for 096d8148e33d00e21b73d319dea7b57c27ce46d7, including a step interrupted during a tool or subagent call? The supplied PR description says the 665 analyzed rollouts predate this change and a branch run has not been done. AGENTS.md requires representative model rollouts and inspection of agent and verifier behavior for behavior-changing agent work.
The new usage suppression removes the entire aggregate when a step is classified as stopped. That also makes the token comparison unobserved, so actual interrupted exports need validation beyond mocks. Please record the revision/configuration and agent/verifier outcomes, and show that an interrupted rollout returns usage: null, identifies the stopped message through model_call_usage_unavailable, and lists rollout_token_count_mismatch as unobserved. Include a completed control whose totals stay measured. Preserve grading, partial output and measured completed/failed-call counters. This asks for validation evidence, not a scoring change or a full benchmark rerun.
Validation
- I relied on the head’s successful
Lint check,Unit tests / Test,Unit tests / Server suite, four core shards, eight server shards and OpenCode conformance checks.Build Gym containerandUnit tests / Changed server testswere skipped, not passed. - CPU probes ran in
766267172432.dkr.ecr.us-east-1.amazonaws.com/gym:228a16b96df8f925220a7edbff2d7d22317c78fb, the default-branch CI image selected because this head’s build was skipped. Its root dependency inputs match the head. SQLite/export, public HTTP and health-control probes confirmed unknown usage for stopped steps, identifying gaps, preserved timeout status and continued detection of genuine measured mismatches.leader/usage_health_matrix.pypassed all four cases. - The new public HTTP regression test failed against the admitted base at the expected
usage is Noneassertion, confirming fail-before protection. I did not rerun CI-covered head suites or execute a real-model rollout.
I could not verify whether later PR discussion supplies the missing evidence: the comments read timed out, and subsequent read attempts returned HTTP 503. The evidence request above is based on the supplied PR description.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
|
Smoke-rollout evidence from a real-model run with this change. Revision and configuration. Gym Interrupted rollouts (24 of 40 in the run with this PR). Each has a root agent invocation with status
Some interrupted rollouts are still unhealthy because of Completed rollouts (16 of 40). All 16 have measured usage (for example, rollout 36-0: 220,913 input and 1,646 output tokens), no Control without this PR. 25 interrupted rollouts, all with summed usage and no gap; 5 have a A full OfficeQA Pro run (133 tasks × 5) on the same commit and checkpoint with the default 7200 s timeout had no interrupted rollouts. All 665 rollouts kept their measured usage, and the token check was observed on all 665 with no findings. |
ffrujeri
left a comment
There was a problem hiding this comment.
Thanks. A stopped step now leaves the usage unknown with a gap that names the message, instead of an undercounted sum, and a failed model call still counts as measured. The OfficeQA Pro smoke answers the bot's request: 24 interrupted rollouts with null usage and the gap, 16 completed controls still measured, and every row still verified. LGTM.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/46711318050 |
What does this PR do?
rollout_token_count_mismatchflags OpenCode rollouts in which the agent timeout stopped a step while a tool was running, even though the only tokens missing from the response usage are those of the stopped steps.OpenCode creates each assistant message with zero token counters and writes the step's usage and
finishfield at the step'sstep-finishevent, which comes after the step's tools return. When the OpenCode agent's timeout stops a session while a tool is running—for example, ataskcall in the root session waiting on a subagent—the step's message keeps the zero placeholders. Gym captures the step's model call, but because the agent sums the response usage from the stored messages, the response usage omits that call's tokens.With this PR, the OpenCode agent reports no response usage when any message's step never reached
step-finishand adds amodel_call_usage_unavailablegap whose detail contains the message ID. Such a message has nofinishfield and either has notime.completed(when the process was killed) or has aMessageAbortedError(when OpenCode cleaned up). The zero counters of a message from a failed model call still count as a measurement, as before. The health check is unchanged. The crewai agent already does the same when a run is interrupted during a model call. The OpenCode agent README describes the new behavior.Validation
test_a_step_stopped_before_step_finish_leaves_the_usage_unknown: a killed step or an aborted step makes the usageNone; with a finished step, a failed model call, or an export without step fields, the usage is summed.test_session_http_reports_a_stopped_step_as_usage_unavailable: for a subagent step stopped while a tool was running, the response has no usage and the agent adds onemodel_call_usage_unavailablegap containing the message ID.test_a_rollout_without_response_usage_leaves_the_token_comparison_unobserved: a rollout with that gap, no response usage, and captured calls with token counts gets norollout_token_count_mismatchfinding, and the check is listed as unobserved. This pins the existing health-check behavior that the agent change relies on.pytest responses_api_agents/opencode_agent/tests tests/unit_tests/rollouts: 4063 passed, 4 failed. The 4 failures are intests/unit_tests/rollouts/test_tool_telemetry.pyand also fail on unmodifiedmainin my environment.pre-commit run --files <changed files>: passed.Rollouts
This analysis uses an existing OfficeQA Pro run with the OpenCode harness (665 rollouts, 7200 s agent timeout), in which 8 rollouts were flagged with
rollout_token_count_mismatch. All 8 were stopped by the agent timeout during a tool call: cleanup reports a timeout with return code 143, and the trajectory hastool_completion_unavailablegaps. In each rollout, the captured calls hold more tokens than the response usage. The difference equals the usage of the last captured call in each session that was stopped mid-step:task)task,task,bash)task)task)task,task)task,task) and subagent (glob)task)task) and subagent (bash,bash,bash)Those rollouts predate this change, so they have no
model_call_usage_unavailablegap.To test the change end to end, I ran OfficeQA Pro on 40 tasks × 1 with the OpenCode agent timeout lowered from 7200 s to 300 s, so that most sessions are stopped mid-step. Both runs used the same SFT checkpoint and differ only in this PR (both include #6622):
rollout_token_count_mismatchfindingsmodel_call_usage_unavailablegaprollout_ended_on_failed_model_callmain+ #6622main+ #6622 + this PRA rollout stopped during a model call also gets the gap, because its in-flight message has no
finisheither.#6622 handles a related false positive separately:
rollout_tool_call_failedon OpenCode searches with a path that does not exist.Compatibility and benchmark impact
This change does not touch reward or scoring code. OpenCode rollouts stopped in the middle of a step lose their response usage, including the token totals of the steps that finished, and get
model_call_usage_unavailableandtoken_usage_detail_unavailablegaps. The health check reportsrollout_token_count_mismatchas unobserved for these rollouts instead of flagging them. The cline, crewai, and droid agents can already return a response without usage.Checklist
pre-commit run --all-files) (so CI lint/format checks pass). (run with--fileson the changed files)git commit -s) (so the DCO check passes).