Skip to content

fix(tb4): score a killed mini-SWE agent as 0 - #5194

Merged
cmunley1 merged 3 commits into
mainfrom
flafrance/tb4-killed-agent-zero
Oct 30, 2026
Merged

cmunley1 merged 3 commits into
mainfrom
flafrance/tb4-killed-agent-zero

Conversation

@lafrancef

@lafrancef lafrancef commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

When the mini-SWE process is killed mid-run, TB4 now scores the rollout 0 instead of reporting an infrastructure error. The kill can come from a command the agent ran (for example pkill -f python) or from the kernel's per-process OOM killer (#4650). Until now the harness reported these as infrastructure_error: mini-SWE produced no trajectory, so they were left out of the pass-rate denominator and retried even though the agent ended its own attempt.

  • mini-SWE harness: a run that ends with a saved trajectory but no exit_status is reported as termination.reason: killed, with the command's exit code. mini-SWE records an exit status whenever its loop ends, even on an exception, so only a kill leaves a trajectory without one. A run with no saved trajectory (killed before its first step, or failed at startup) is still an infrastructure error. A kill is not relabeled as a timeout when collecting its artifacts runs past the agent deadline: the exit code it is read from came back before the deadline.
  • TB4 resources: a killed termination records NonZeroAgentExitCodeError and a completed reward: 0.0 with verifier_result.source: agent_killed. It skips the verifier, as the sandbox resource-limit grade from fix(tb4): grade sandbox resource exhaustion as zero #4733 does.

Harbor runs the verifier after a nonzero agent exit. TB4 doesn't for killed: once the process is gone, a self-kill can't be told apart from a per-process OOM kill, and an OOM is scored 0 without verification, as #4733 does for a sandbox that exceeds its memory limit.

Benchmark impact: TB4 and Terminal-Bench Science rollouts that ended with a killed agent now count as 0 in the pass rate instead of being excluded as infrastructure errors.

Compatibility: on the episode-session path (Harbor environment server), a killed turn is answered instead of refused with a 503, so the environment server verifies it rather than masking it.

Issue: none; follow-up to #4650 and #4733.

Rollout evidence: a live TB4 smoke of this PR's head and its base commit, with the same settings: Qwen3.6-35B-A3B through an OpenAI-compatible Responses endpoint, OpenSandbox CPU sandboxes, four CPU tasks with one attempt each, and a 50-step / 1200-second agent cap. A model can't be made to kill itself on demand, so for html-js-filter only, a test-only instruction (not part of this PR) was appended to the task prompt: run echo smoke-start, then kill -9 $PPID. The model followed it in both runs, so mini-SWE saved one step and was then killed.

Task Base This PR
html-js-filter (forced kill) infrastructure_error: mini-SWE produced no trajectory; verifier ran (1/2 tests); excluded from the score killed (exit 9); verifier skipped (agent_killed); counted as 0
interleaved-vigenere nonzero_exit (step limit); verified, 3/6 tests; 0 nonzero_exit (step limit); verified, 1/6 tests; 0
telecom-entity-resolution nonzero_exit (step limit); verified, 5/10 tests; 0 completed; verified, 4/10 tests; 0
vpp-loss-divergence nonzero_exit (step limit); verified, 4/5 tests; 0 nonzero_exit (step limit); verified, 4/5 tests; 0
Counted / excluded 3 / 1 4 / 0
Mean reward over counted rollouts 0.0 0.0

The only classification change is the killed rollout. The other rollouts differ only in what the model did, and each was verified as before. Every session closed its agent, verifier, and log-helper sandboxes with no cleanup errors. The new harness test also runs the real mini-SWE 2.4.6 CLI and has the model's command kill the agent process, both after a saved step and before any step was saved.

🤖 Generated with Claude Code

A mini-SWE run that exits nonzero with a saved trajectory but no exit
status was killed mid-run, by the agent's own command or by the
per-process OOM killer. The harness reports it as a killed termination,
and TB4 scores it 0 without the verifier instead of treating it as an
infrastructure error.

Signed-off-by: Frederic Lafrance <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers bug Something isn't working labels Oct 28, 2026
@lafrancef
lafrancef marked this pull request as ready for review October 28, 2026 22:55
@lafrancef

Copy link
Copy Markdown
Contributor Author

/ok to test 29028a1

@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 28, 2026 22:56
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 28, 2026

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

HOLD — one BLOCKER and one validation RISK remain.

RISK — Supply benchmark comparison and real-rollout evidence

This changes fixed-benchmark reward and denominator semantics in the killed-agent finalizer, shared by TB4 and Terminal-Bench Science. The PR supplies no before/after profiling numbers and explicitly marks real-model rollout evidence N/A. The deterministic CLI test is useful, but does not establish the aggregate scoring impact or validate the complete model→agent→resources path. The pinned rubric requires profiling evidence for fixed-benchmark reward changes, and the trusted AGENTS quality bar requires representative real smoke rollouts.

Correction: Add matched before/after profiling evidence to the PR: task/model/repeat configuration, mean reward and reward distribution, counted versus excluded rollout totals, and killed-attempt counts. Explain any shift attributable to the intended reclassification. Also provide a representative real-model smoke rollout with inspected agent, verifier, and cleanup artifacts; the live model need not reliably kill itself.

Preservation and acceptance: Normal completed, timeout, and nonzero-exit attempts must retain official verification; true startup/provider failures must remain excluded. Retain the deterministic saved-step kill→completed unmasked zero and no-saved-trajectory→infrastructure cases, and verify that the profiling comparison shows no unexplained changes outside the killed cohort. These are requested checks, not results obtained during this review.

All eight changed files and their directly affected harness, scoring, cleanup, and Harbor episode paths were inspected. Review was source-only; no tests or profiling runs were executed.

Note: formal approval is not available for this request, so this review is posted as a comment only.


Inline comments (escaped v1):

  • responses_api_agents/miniswe_sandboxed_agent/app.py line 473: BLOCKER — Preserve a confirmed kill when post-exit collection crosses the deadline

    A process killed shortly before its execution deadline can still be relabeled timeout here. MiniSWEHarness.execute() performs process cleanup and artifact downloads before returning the new killed outcome. If those operations finish after deadline, this assignment overwrites that outcome. TB4 then takes the ordinary timeout-verification path rather than the unconditional killed-agent zero. For example, an agent can leave a passing artifact, be killed just before its budget expires, and receive a positive verifier reward solely because artifact retrieval was slow. This silently violates the new scoring contract for near-deadline kills.

    Could you exempt the confirmed killed outcome from this post-return timeout normalization? The smallest correction at this condition is:

                            if monotonic() >= deadline and termination.reason != "killed":
    

    The invariant is that collection latency cannot turn an already-established kill into a verifier-eligible timeout. This preserves the existing deadline normalization for every other outcome; do not change genuine execution-timeout handling or the no-trajectory infrastructure classification.

    Proposed acceptance checks (not executed): In the existing agent/resources integration fixture, have the harness return HarnessOutcome(reason="killed", exit_code=-9) while advancing a patched clock past the execution deadline, representing delayed post-exit collection. Assert termination remains killed, reward is 0.0, evaluation is completed without an infrastructure marker, and the grader is not awaited. A completed outcome returned after the deadline must still become timeout and be verified; retain the existing ordinary-outcome grading assertions and both saved/no-saved-trajectory kill cases.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

lafrancef and others added 2 commits October 29, 2026 00:35
The harness reads a kill from an exit code the sandbox returned before the
agent deadline. Closing processes and downloading artifacts afterwards can
still cross it, which relabeled the kill as a timeout and sent it to the
verifier.

Signed-off-by: Frederic Lafrance <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Frederic Lafrance <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cmunley1

Copy link
Copy Markdown
Contributor

/ok to test 95b989a

@cmunley1

Copy link
Copy Markdown
Contributor

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

SHIP — no remaining eligible findings in this follow-up.

  • Prior BLOCKER resolved: deadline normalization now preserves a confirmed killed outcome after delayed collection. The new regression test asserts killed → completed zero without verification, while a completed outcome crossing the deadline still becomes a verified timeout. The resources finalizer retains the killed-zero contract and unconditional cleanup.
  • Prior validation RISK resolved: the PR description now reports matched four-task base/head model runs, per-task outcomes, counted/excluded totals of 3/1 → 4/0, unchanged mean reward of 0.0, one forced-kill attempt per run, and inspected verifier and cleanup behavior. These are author-reported results, not independently reproduced here.

Compared the fixes with the previous-review tree and traced their directly affected execution, scoring, and regression-test paths. No qualifying introduced regression found within the follow-up scope. Review was source-only; no tests or profiling runs were executed.

Review generated by codex. This was a findings-only review. Request a full review with /review reset=true.

@cmunley1
cmunley1 added this pull request to the merge queue Oct 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

Merged via the queue into main with commit 315edfd Oct 30, 2026
56 of 59 checks passed
@cmunley1
cmunley1 deleted the flafrance/tb4-killed-agent-zero branch October 30, 2026 23:57

This branch was previously deployed

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

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers bug Something isn't working 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