Skip to content

fix(eval): retry Terminal-Bench 4 infra failures as Terminal-Bench does, in evaluation - #4846

Closed
AdamRajfer wants to merge 3 commits into
NVIDIA-NeMo:arajfer/stack/scoring-defaultsfrom
AdamRajfer:eval/infra-masks
Closed

AdamRajfer wants to merge 3 commits into
NVIDIA-NeMo:arajfer/stack/scoring-defaultsfrom
AdamRajfer:eval/infra-masks

Conversation

@AdamRajfer

@AdamRajfer AdamRajfer commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Part 4 of 9, merge in order. Stacked on #4845; the diff shows only this part's changes. The verifier-mask changes moved unchanged to #4868 (part 4b, merge right after this one), so this PR now holds only the evaluation-mode flag and Terminal-Bench 4. The move is the last commit, ce50174.

What and why. gym eval run marks its servers with nemo_gym_eval_mode, read through is_eval_mode(), so evaluation-only failure handling applies there while training and RL keep their behaviour. Terminal-Bench 4 uses it: a verifier sandbox that misses its start deadline (VerifierStartTimeoutError) and an agent harness failure such as a mini-SWE run with no trajectory (AgentInfrastructureError) are retried. A trial that leaves no reward file stays a final 0, and so does a nonzero agent exit.

Methodology. Terminal-Bench retries a trial whose environment or verifier sandbox did not start, and scores a trial that left no reward file as 0.

Eval scores. Terminal-Bench 4 runs with verifier start timeouts or harness failures move up once retries succeed.

Training and RL: no change. The Terminal-Bench 4 changes are behind is_eval_mode(), which training and RL do not set.

Unit tests. tests/unit_tests/test_global_config.py::TestEvalMode, test_failure_retry_rule.py::test_terminal_bench_exits_split_by_who_failed, test_failure_retry_rule_evidence.py (the Terminal-Bench names), resources_servers/terminal_bench_4/tests/test_verified_response.py and test_lifecycle_failures.py (both modes).

🤖 Generated with Claude Code

…ench 4 failures

A verifier that masks a row because the environment or a service failed
gives no measurement, but the row stayed scored or left the score. In
evaluation a masked result that names infra becomes a `masked_sample`
failure, is retried, and counts as 0 at the attempt cap. A mask for the
model's own budget is unchanged. SWE-bench Pro masks a verification with
no verdict and a patch the task sandbox could not return; a test run
that outlived its limit is scored as unresolved and is not rerun.
OSWorld names its environment, evaluator, model-call and task-timeout
masks. verifiers_agent masks a rollout whose policy call failed and was
swallowed. `gym eval run` marks its servers with `nemo_gym_eval_mode`,
and these server changes apply only there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
@AdamRajfer AdamRajfer self-assigned this Oct 21, 2026
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

/ok to test c6fd664

@copy-pr-bot

copy-pr-bot Bot commented Oct 21, 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.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:evaluation Evaluation, rollout collection, reward profiling, comparison, and exporters bug Something isn't working labels Oct 21, 2026
@AdamRajfer
AdamRajfer changed the base branch from main to arajfer/stack/scoring-defaults October 21, 2026 14:48
@AdamRajfer
AdamRajfer marked this pull request as ready for review October 21, 2026 15:00
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 21, 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 — 2 BLOCKERs and 3 RISKs in failure classification.

The SWE-bench timeout paths can both finalize infrastructure failures as model failures and retry model test overruns as infrastructure failures. Policy-outage detection also depends on observability, patch extraction misses returned sandbox errors, and OSWorld grants infrastructure retries to context-budget exhaustion.

Reviewed all 20 changed files and their directly affected configuration, provider, collector, resume, and aggregation paths. Static review only; tests were not executed. Suggested code below must be verified before adoption.

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

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

Comment thread resources_servers/swebench_pro/app.py Outdated
f"umask 077; git -C /app add -N . && git -C /app --no-pager diff {quote(base_commit)}"
f" > {quote(patch_path)}"
)
except Exception as exc:

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.

RISK — Recognize sandbox execution errors returned without an exception

Failure: _extract_model_patch() only creates SandboxPatchExtractionError when exec() raises. Providers can instead return SandboxExecResult(return_code=125, error_type="sandbox"); this explicitly means no process verdict (result contract, Docker implementation). That result currently becomes an ordinary RuntimeError at line 480. verify() then grades an empty patch and can return an unmasked 0 rather than the intended retryable infrastructure mask.

Correction: Before the ordinary nonzero-exit check, add:

if getattr(result, "error_type", None):
    raise SandboxPatchExtractionError(
        result.stderr or f"git diff execution failed: {result.error_type}"
    )

The invariant is that a runtime failure to execute/read the extraction is distinct from a command that actually ran and failed.

Preservation: Keep error_type=None Git failures, such as fatal: not a git repository, as the existing model-side 0; do not wrap every nonzero exit. Retain byte-download extraction, pristine-file filtering, cancellation propagation, and cleanup. Training must remain unmasked in both error cases.

Acceptance (proposed, not run): Return a sandbox-error result from the first extraction exec, allow cleanup, and have the verifier return a completed unresolved result for the empty patch. Evaluation must still return mask_sample=true and provider_unavailable; training must remain unmasked. A genuine Git exit 1 with no error_type must remain unmasked in both modes. Retain the exact-byte and cleanup assertions in the extraction regressions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed yet, on purpose. This depends on an open methodology decision: is a sandbox failure after the agent has run commands retried as infra, or scored as the model's unresolved task? The official SWE-bench Pro and Terminal-Bench harnesses score it as unresolved. We'll settle that rule first and then apply it here; follow-up in this thread.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Decided: no change here. An error while extracting the patch, after the agent has run, stays the model's empty patch (0), unless the platform reports the failure; those platform-evidence retries come in a follow-up PR on top of this series.

Comment thread resources_servers/swebench_pro/app.py Outdated
print("Failed to stop verification sandbox", format_exc(), file=sys.stderr)

reason = inconclusive_reason(result)
if reason is not None and result.timed_out and is_eval_mode():

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.

BLOCKER — Do not treat sandbox-operation timeouts as test verdicts

Failure: result.timed_out does not prove the test command exceeded evaluation_timeout. run_verification() sets it for any raised TimeoutError, including SandboxOperationTimeoutError from an exhausted OpenSandbox status-poll request (provider timeout, status polling). If that happens while running the entryscript, this branch now stops verification retries, and line 617 suppresses the infrastructure mask. A service timeout with no verdict becomes a permanent scored 0.

Correction: Change the timeout provenance contract between run_verification() and verify(): only a confirmed test-command deadline may take this final-zero branch. In evaluation, a SandboxOperationTimeoutError must remain a verdictless infrastructure failure. Some providers expose ambiguous bare timeouts, so the complete implementation needs an explicit distinction rather than a blanket isinstance(TimeoutError) rule; I cannot safely prescribe one replacement for every provider from the current contract.

Preservation: Structured command-deadline results must still score 0, unmasked, without evaluation reruns. Preserve required-test failures parsed after a genuine command timeout, and retain training's existing timeout/retry behavior.

Acceptance (proposed, not run): Drive run_verification() with successful setup, an entryscript exec() raising SandboxOperationTimeoutError("command status"), and no conclusive test output. Evaluation must return an infrastructure mask and remain collector-retryable. Separately return error_type="timeout" for a confirmed command deadline: expect reward 0, no mask, and one evaluation attempt. Retain the partial-required-test assertions in test_timeout_only_scores_an_explicit_required_test_failure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed yet, on purpose. Whether a sandbox timeout during the agent's turn or the tests is retried or scored as unresolved is an open methodology decision; the official SWE-bench Pro and Terminal-Bench harnesses score it as unresolved. We'll settle the rule first and apply it here; follow-up in this thread.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Decided: no change here. A sandbox timeout during the tests stays unresolved (0), as the official SWE-bench Pro and Terminal-Bench harnesses score it. A sandbox failure with independent platform evidence (an eviction, node loss) will be retried; that comes in a follow-up PR on top of this series.

Comment thread resources_servers/swebench_pro/app.py Outdated
"log_dir": str(run_log_dir),
}
# Evaluation only: training keeps the sample unmasked, as it always was.
if is_eval_mode() and ((reason is not None and not result.timed_out) or extraction_failed_in_sandbox):

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.

BLOCKER — Reconcile the surrounding deadlines with the test deadline

Failure: The shipped SWE-bench configuration sets evaluation_timeout=3600, but verification_attempt_timeout=1200 and verification_total_timeout=2700 (configuration). With immediate provisioning and a model patch that makes tests hang, the surrounding asyncio.timeout cancels verification before its test deadline. The exception handler creates a result with timed_out=false; this new branch consequently labels it provider_unavailable. Thus the normal configuration cannot reach the advertised final-zero timeout handling for these runs and instead permits another model rollout on resume.

Correction: Coordinate verify()'s stage/deadline handling and the shipped timeout settings so an executing test gets its declared command budget, while provisioning and transport work remain separately bounded. A confirmed test overrun must be an unresolved 0, not an infrastructure mask. Simply marking every outer timeout as timed_out=true would incorrectly finalize sandbox-creation failures. The exact budget allocation is a configuration/API decision, so no blanket timeout patch is safe here.

Preservation: Keep sandbox creation hangs retryable and bounded; retain the existing training ceilings and inconclusive-verification retries. Keep genuine evaluator command timeouts final and ordinary completed failing/empty test reports scored as before.

Acceptance (proposed, not run): Add an evaluation test with immediate sandbox creation and a test command that runs beyond the surrounding attempt ceiling, using scaled-down deadlines. Verify that it receives its full declared command budget and ultimately returns reward 0, eval_timed_out=true, no mask, and no model-rollout retry. A separate creation hang must still produce a retryable infrastructure mask within its bound. Retain the one-attempt evaluation/three-attempt training assertion in the existing timeout test; its mocked result currently bypasses this deadline interaction.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed yet, on purpose. This belongs to the same open decision on sandbox failures and timeouts during the tests: retry them, or score the task unresolved as the official harness does. The two deadlines will be aligned once that rule is settled; follow-up in this thread.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in #4868, where the SWE-bench Pro masks now live: e41ffe7 (fix(swebench_pro): let a hung test reach its own deadline inside the verification ceilings), with a test that fails without the fix. The test timeout (3600 s) is unchanged; the attempt and total ceilings now sit above it, so a hung test ends at its own deadline and is unresolved.

# OSWorld masks only for its environment, evaluator, model-call or task-timeout failures; the model's
# own FAIL, horizon and unparseable answers stay unmasked. Name the mask so Gym retries it.
# Evaluation only: training sees the mask exactly as before, with no failure kind.
if self.mask_sample and self.failure_kind is None and is_eval_mode():

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.

RISK — Exclude confirmed context-budget exhaustion from infrastructure retries

Failure: Not every existing OSWorld mask is an infrastructure failure. An exhausted HTTP-400 context-overflow response is classified as model_context_overflow, with model_call_completed=false (adapter classification and stop facts). The runner then collapses that into the masked model_call_failed outcome (runner). This new unconditional assignment changes that model-budget mask into provider_unavailable, so the collector grants another rollout attempt instead of retaining the previous budget-mask treatment. The context may depend on earlier sampled actions, so rerunning the whole episode is not equivalent to retrying a failed service call.

Correction: Preserve the terminal model-failure provenance through _build_response() and consult it before naming an infrastructure mask. Confirmed model_context_overflow must not acquire a retryable infrastructure kind. Do not exempt all model_call_failed outcomes: real connection failures use that same admission reason. The existing admission reason alone is insufficient, so this needs the retained terminal agent outcome/parse-failure fact, not just a different constant here.

Preservation: Training's masks and rewards must remain unchanged. Actual policy transport failures and environment/evaluator failures must still become retryable masks in evaluation. Completed malformed samples, explicit FAIL, and horizon exhaustion must retain their existing unmasked treatment. An evaluator failure following a context overflow must still be classified as an evaluator failure.

Acceptance (proposed, not run): Feed the runner an exhausted context-overflow model call, pass its result through _build_response() and collector classification, and assert that evaluation does not assign masked_sample or retry the rollout. Repeat with a connection failure and expect provider_unavailable plus retry eligibility. Retain the completed-invalid-sample, transport-failure, and explicit-FAIL cases in the runner regressions, distinguishing context overflow from actual transport failure rather than treating both as the same fixture.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed yet, on purpose. How a context overflow is scored is an open methodology decision. OSWorld itself ends the episode and scores the task; matching that needs the agent's stop reason carried to the response. We'll keep the current behaviour until it's decided; follow-up in this thread.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in #4868: 128a8dd (fix(osworld): do not name an exhausted context budget as infra), and in #4847: 3653f26 (fix(osworld): count an exhausted context budget as 0 in evaluation), each with a test that fails without the fix. OSWorld ends the episode and scores the task, so evaluation now counts it as the model's budget; training is unchanged.

…s off

Bot finding 4339108828, PR NVIDIA-NeMo#4846 (part 4, infra masks). Without model-call capture (observability
off) the agent used the shared plain client, which records nothing, so a policy outage verifiers
swallowed came back as a scored 0 even in evaluation. Evaluation now gets a per-rollout recording
client over a copy of the shared transport, with the same URL and SDK settings; training keeps the
shared client.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>

@lafrancef lafrancef 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.

Approved for tb4

@AdamRajfer
AdamRajfer removed the request for review from ananthsub October 21, 2026 18:29
This part now keeps the evaluation-mode flag and Terminal-Bench 4's
failure handling. The verifier-mask rule (`masked_sample`) and the
SWE-bench Pro, OSWorld and verifiers_agent masks move unchanged to the
next part of the stack, so each part covers one review scope.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
@AdamRajfer AdamRajfer changed the title fix(eval): retry verifier masks that name infra, and split Terminal-Bench 4 failures fix(eval): retry Terminal-Bench 4 infra failures as Terminal-Bench does, in evaluation Oct 21, 2026
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

/ok to test ce50174

@AdamRajfer

Copy link
Copy Markdown
Contributor Author

/review reset=true

@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 — 1 BLOCKER in Terminal-Bench 4 timeout classification.

Reviewed all 11 changed files and directly affected configuration inheritance, finalization, retry/resume, and scoring paths. Earlier verifier-mask findings concern changes absent from the current diff; they are not reported as fixes here.

Static review only; tests were not executed. The suggested patch must be verified before adoption.

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

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

# The verifier sandbox missed its start deadline: Terminal-Bench retries the trial, so evaluation
# names it for the retry rule. Outside evaluation the recorded type stays TimeoutError.
if is_eval_mode():
exception(session, exc, "VerifierStartTimeoutError")

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.

BLOCKER — Preserve verifier-start retry eligibility after an agent exit

Failure: In evaluation, let a started agent terminate with reason="timeout" or "nonzero_exit", then make verifier_environment.start() exceed its build deadline. The earlier termination branch has already recorded AgentTimeoutError or NonZeroAgentExitCodeError. This new call cannot replace it because exception() uses setdefault. Consequently, _verified_response() exports the agent-exit type rather than VerifierStartTimeoutError. Resume permanently gates terminal rows, so this verdictless trial scores a final zero instead of remaining retryable. This affects TB4 evaluations where verifier provisioning fails after an agent exit; that exit alone cannot establish the official reward.

Correction: Make this evaluation-only verifier-start failure the primary exception while retaining the earlier termination and diagnostic history. A minimal replacement for lines 235–236 is:

if is_eval_mode():
    session.result.pop("exception_info", None)
    exception(session, exc, "VerifierStartTimeoutError")

Keep the following raise. The previous error is already retained in session.diagnostics; do not change exception() globally. The invariant is that a verifier-start timeout with no official verdict remains retryable regardless of the preceding agent exit.

Preservation: Leave training's first-error behavior unchanged. An agent timeout/nonzero exit followed by successful verification must retain its official reward without acquiring a failure marker. Missing reward files and verifier-execution timeouts must remain final, harness infrastructure failures must remain retryable, and explicit sandbox resource-limit deaths must retain their early completed-zero path without starting a verifier.

Acceptance — proposed, not run: Extend the new lifecycle regression with timeout and nonzero_exit terminations. In evaluation, serialize the actual result through _verified_response() and assert _ng_failure_type == "VerifierStartTimeoutError", is_terminal_failure(...) is False, and resume includes that row below the attempt cap. In training, retain AgentTimeoutError/NonZeroAgentExitCodeError respectively. Also check successful verification after either exit with rewards 0 and 1: preserve the exact reward and no failure marker. Retain final classification for RewardFileNotFoundError/VerifierTimeoutError, retry eligibility for the existing no-trajectory case, and the resource-limit completed-zero/no-verifier behavior.

@AdamRajfer

Copy link
Copy Markdown
Contributor Author

Closing this version to consolidate review on #5072 (failure reporting) and #5073 (saved-state recovery). This does not mean those PRs implement every proposal from this earlier stack; scoring policy and persistence follow-ups remain separate.

@AdamRajfer AdamRajfer closed this Oct 26, 2026

This branch was previously deployed

1 inactive deployment
public — ce50174f Deployed Oct 21, 2026 by copy-pr-bot[bot] via release / finalize / notify #6369
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 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