Skip to content

refactor(agent): move Claude Code, Codex and OpenCode to the outcome ladder - #5877

Open
yaoyu-33 wants to merge 14 commits into
feat/agent-outcome-ladderfrom
refactor/outcome-ladder-claude-codex-opencode
Open

yaoyu-33 wants to merge 14 commits into
feat/agent-outcome-ladderfrom
refactor/outcome-ladder-claude-codex-opencode

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Stacks on #5870 (the shared outcome ladder). The base branch is feat/agent-outcome-ladder, so this diff shows only the three adapters. Retarget to main after #5870 merges.

What and why

Claude Code, Codex and OpenCode each decided their own response status and chose between HTTP 200, 500 and 502 for the same event. Their sandbox sessions now fill a RunEvidence from their own records and return finish_response(...) with HTTP 200. Only lifecycle failures stay typed 5xx raises (NgFailureEvent(boundary="harness", failure_kind="agent_route_failed")): a supervisor error, an unreadable export, required MCP tools that did not start. No adapter raises a bare 502 any more.

All three now report a 4xx other than 408, 425 and 429 before any model reply as model_request_rejected (decision 4).

Claude Code (parsing.py, app.py)

  • parse_stream_json records model_replied (any assistant message that is not Claude Code's own <synthetic> error message, subagents included) and api_error_status. The status comes from the API Error: <status> <body> message the run ended on, and only when the is_error result repeats that text.
  • classify_outcome turns that status into model_request_error through the shared model_http_error_outcome, which reports a 400 whose body is the model server's context-overflow envelope (code context_length_exceeded) as model_context_limit. The status is found anywhere in the error text: Claude Code 2.1.108 prefixes a 401 with "Failed to authenticate. ". It reuses the classifier approach of draft PR fix(claude): retain helper and failed-call evidence #5807 (root synthetic message plus matching result), but not that PR's rule that refusals and process exits report unknown.
  • _run_evidence:
    • a usage-policy refusal is completed and graded (decision 5);
    • error_max_turns is incomplete;
    • another error result is unknown;
    • a nonzero exit or a missing result is agent_run_error.
  • _invocation_outcome becomes invocation_error_type, which keeps the observations' own labels (process_exit_N, refusal, ...). The local host path's response is unchanged: it still returns no status, and only its observation status follows the ladder.
  • A failed response keeps Claude Code's own text as its error.message.

Codex (app.py)

  • The forwarder's attempt record (model_attempts.jsonl) stays evidence. It records each attempt's start as well as its result. A whole 200 reply counts as a model reply; a 200 that Codex hung up on before it arrived is recorded cancelled and does not.
  • Deadline rule: a timed-out run sets infra_fault when the last recorded forwarded attempt failed to connect (status: null), was cut short (transport_error), or answered 408, 425, 429 or a 5xx. The run is then failed with that kind and retried. An attempt still in flight at the deadline (a start without a result, such as the retry after a 429) and a failure that a later attempt recovered from leave the deadline to the model, so the run is graded. A last attempt Codex hung up on is a transport fault only when Codex reported an endpoint failure after its last model output (a stalled or broken stream) and the runner saw that report after the attempt started (start records carry the sandbox clock that stamps the CLI events). This replaces the 502 that any failed turn caused.
  • classify_outcome passes the turn.failed message, which is the endpoint's body, to model_http_error_outcome, so a propagated context overflow is a graded incomplete context limit. An incomplete response no longer carries the reported error.
  • A run without a usable result is agent_run_error (was 502). A supervisor error in the receipt is a typed harness failure (was 502).
  • verify_after_agent_error no longer decides the status. A run that died while its sandbox still runs is failed with agent_run_error, like any run without a usable result. The flag runs the liveness probe, labels the run with metadata.graded_agent_error, and keeps the usage of its unfinished turn. Whether the run is graded is the Environment Server's outcome policy. On main the run was failed with no kind. See "Decision: verify_after_agent_error" below.
  • report_rollout_stop and report_outcome are replaced by finish_response. The invocation's observed status now follows the response, rollout stops included.

OpenCode (continuation.py, app.py)

  • classify_opencode_run fills RunEvidence:
  • A deadline before any assistant message keeps its retry (retry_deadline_before_reply=True, only in exactly the case that was a 502). A resumable continuation checkpoint and an unfinished assistant placeholder stay graded, as before.
  • After a reply, a deadline is graded unless the model error OpenCode recorded last is a transport failure or 408/425/429/5xx (infra_fault).
  • No usable result is agent_run_error (was 502). The OOM response and the pre-launch timeout go through the ladder. incomplete_details is now set for single-turn length and content-filter stops too.

No separate issue: this is the adapter half of the outcome-ladder step that #5870 starts.

Disposition by event

Action = what the Environment Server does with the response under the default policy (verify = graded, retry = new episode attempt, fail = neither). Bold rows change disposition. The main cells come from reading the adapters at acb67734cc (unchanged by #5870). The tests this PR updates pinned them, and each updated test says why.

Claude Code (sandbox session)

Event main this PR
context overflow as API Error: 400 after a reply (propagate flag on) 200 failed, no kind → verify 200 incomplete → verify
context overflow on the first request 200 failed, no kind → verify 200 incomplete → verify
deadline before any reply 200 incomplete → verify 200 incomplete → verify
deadline after a reply 200 incomplete → verify 200 incomplete → verify
no result event, exit 0 200 incomplete → verify 200 failed agent_run_error → retry
nonzero exit 200 failed, no kind → verify 200 failed agent_run_error → retry
runner wrote no events.jsonl 500 → retry 500 → retry
persistent 429 / 5xx 200 failed, no kind → verify 200 failed model_request_error 429/5xx → retry
401 200 failed, no kind → verify 200 failed model_request_rejected (before a reply) or model_request_error 401 → fail
other 4xx before a reply 200 failed, no kind → verify 200 failed model_request_rejected → fail
refusal 200 failed, no kind → verify 200 completed → verify
error result without a status (agent_error, error_during_execution) 200 failed, no kind → verify 200 failed unknown → retry
error_max_turns 200 incomplete → verify 200 incomplete → verify

Codex (sandbox session)

Event main this PR
context overflow as a 400 after a reply (propagate flag on) 200 failed model_request_error 400 → verify 200 incomplete → verify
context overflow on the first request 200 failed model_request_error 400 → verify 200 incomplete → verify
output-limit stop (default vLLM path) 200 incomplete → verify same
deadline, no failed turn, last forwarded attempt answered or in flight 200 incomplete → verify same
deadline, no failed turn, last forwarded attempt failed (transport, 408/425/429/5xx) 200 incomplete → verify 200 failed model_transport_error / model_request_error → retry
deadline after a failed turn or error item, last attempt not an endpoint fault 502 → retry 200 incomplete → verify
deadline after a stream Codex gave up on (idle or broken stream reported, no retry started) 502 → retry 200 failed model_transport_error → retry
deadline while a retry is in flight (after a 429 or 503) 200 incomplete → verify, or 502 → retry after a failed turn 200 incomplete → verify
no usable result (nonzero exit, failed turn, no turn.completed) 502 → retry 200 failed agent_run_error → retry
same with verify_after_agent_error and a live sandbox 200 failed, no kind → verify 200 failed agent_run_error (labeled graded_agent_error) → retry; verify where the policy maps agent_run_error to verify (the TB-science profile does)
supervisor error in the receipt 502 → retry 500 typed agent_route_failed → retry
reported 429 / 5xx (turn.failed, exit 1) 200 failed model_request_error → retry same
killed while retrying an endpoint failure 502 → retry 200 failed agent_run_error → retry
401 200 failed model_request_error 401 → fail 200 failed model_request_rejected (before a reply) → fail
other 4xx before a reply 200 failed model_request_error 400 → verify 200 failed model_request_rejected → fail
refusal not classified (an ordinary answer) same

OpenCode (sandbox session)

Event main this PR
ContextOverflowError 200 incomplete → verify same
deadline before any assistant message 502 → retry 200 failed unknown → retry
deadline during the first model call (unfinished assistant message) 200 incomplete → verify same
deadline after a reply, no recorded error 200 incomplete → verify same
deadline with a recorded transport / 408 / 425 / 429 / 5xx error 502 → retry 200 failed with that kind → retry
deadline with another recorded error (a 400, an error without a status) 502 → retry 200 incomplete → verify
no usable result (nonzero exit, non-stop finish, no assistant) 502 → retry 200 failed agent_run_error → retry
unreadable export, required MCP tools not started or not confirmed, supervisor error 502 → retry 500 typed agent_route_failed → retry
reported 429 / 5xx (APIError) 200 failed model_request_error → retry same
401 200 failed model_request_error 401 → fail 200 failed model_request_rejected (before a reply) → fail
other 4xx before a reply (400, 413) 200 failed model_request_error → verify 200 failed model_request_rejected → fail
sandbox OOM (report_agent_sandbox_oom) 200 failed provider_oom_killed → verify same
refusal not classified same

Score impact: Claude Code changes the most: provider errors, nonzero exits, missing results and unclassified error results were graded and are now retried, failed or rejected. Codex and OpenCode change only for a first-request 4xx and for deadlines (graded unless an endpoint fault was recorded). Codex also changes for a run verify_after_agent_error labels, under the default policy only; the one profile on this branch that sets the flag keeps grading it (see the decision below). Row counts on real runs come with the smoke and A/B phase.

Decision: verify_after_agent_error (2026-11-19)

A Codex run that dies while its sandbox still runs is failed with agent_run_error, not completed. This is the "no usable result" rule: no adapter flag changes a status. Harbor's grade-after-any-exit behaviour comes from the Environment Server's outcome policy. Commit eb43d5d876:

  • Codex (app.py): a labeled run no longer gets has_result=True. verify_after_agent_error still runs the liveness probe, writes metadata.graded_agent_error and reads the unfinished turn's usage from the session transcript. It no longer changes the status. README and config comments say so.
  • Terminal-Bench-Science (benchmarks/terminal_bench_science/codex.yaml): this is the only config on this branch that sets the flag. Its environment server gets agent_outcome_policy.by_failure_kind: {agent_run_error: ${oc.select:tbsci_agent_run_error_action,verify}}. The other kinds keep their defaults. To retry these runs instead, pass ++tbsci_agent_run_error_action=retry; it replaces ++tbsci_verify_after_agent_error=false, which now only drops the label and the transcript usage.
  • TB4 (the resources server TB-science uses): a failed response is again termination nonzero_exit, as on main. The graded_agent_error branch added on 2026-11-17 (c3dfcda816) is removed, along with its test rows and README line.

Disposition of a Codex run under the TB-science profile:

Codex run main this PR before now
died while the sandbox answers the probe (labeled) 200 failed, no kind → verify 200 completed → verify 200 failed agent_run_error → verify
same, at the time limit 200 incomplete → verify same same
sandbox stopped or silent after Codex exited 502 → retry 200 failed agent_run_error → retry 200 failed agent_run_error → verify
ended by an endpoint error Codex did not report as a provider failure (killed while retrying) 502 → retry 200 failed agent_run_error → retry 200 failed agent_run_error → verify
failed before its first turn (for example a required MCP server did not connect) 502 → retry 200 failed agent_run_error → retry 200 failed agent_run_error → verify
unconfirmed cleanup, supervisor error 502 → retry 500 typed agent_route_failed → retry same
reported provider failure (turn.failed) classified → policy same same

The labeled run, the case the profile was written for, scores as on main. TB4 records the same nonzero_exit termination for it.

Liveness probe. The probe no longer changes how a row is handled. The policy grades every agent_run_error, so the three bold rows above are now graded where main retried them. Not checked here: how TB4's verifier answers when the task sandbox has stopped. The probe's split between infrastructure and agent failures now survives only as data. A graded row carries metadata.graded_agent_error only when all of these hold: Codex started a turn, its cleanup was confirmed, no endpoint error ended the run, and the probe found a live sandbox. The split can be read from the rows, but it no longer routes them. One way to keep it in routing: Codex could report the unlabeled cases with their own kinds, model_transport_error for an endpoint error that ended the run and a provider_* kind for a sandbox that stopped answering. The default policy already retries those kinds, so agent_run_error: verify would then reach only agent exits. That change is not made here.

Not on this branch. main also sets verify_after_agent_error: true in environments/ui_generation_agentic/codex.yaml (#6012), which is not on this branch yet. When this branch next merges main (after #5870), that environment server (ui_generation_agentic_environment_server) needs the same agent_run_error: verify override. Without it, its failed Codex runs are retried instead of graded.

Validation (Linux workstation, Python 3.13.14; imports confirmed from each tree), c3dfcda816 → eb43d5d876:

  • responses_api_agents/codex_agent/tests: 618 passed, 6 skipped → 618 passed, 6 skipped.
  • terminal_bench_4/tests/test_resources_sessions.py plus test_terminal_bench_science.py: 82 passed → 82 passed. Two reverted TB4 rows were replaced by the two new profile cases.
  • The changed tests run against c3dfcda816's code: 8 fail, as they should. They are:
    • Codex labeled rows (process killed, failed turn);
    • the recovered-retries-then-agent-error row;
    • the collector-through-environment recipe with the override;
    • native usage (2 cases);
    • the new TB-science policy test (2 cases).
  • The TB-science environment-server block, resolved from codex_deepseek_flash.yaml, validates as a single_agent_turn_legacy config. agent_run_error resolves to verify, or to retry with the knob, and the other 16 kinds keep their defaults.
  • pre-commit run --files <changed files>: passed.
  • No new smoke. Only the labeled run changes status. The recipe test covers it end to end: a collector, the real single_agent_turn_legacy server with the override, the real Codex session lifecycle, and a stubbed resources server.

For review

  • Decision 6 (harness retries): Codex's forwarder retries only 429, twice, with at most 30 s of Retry-After, which complies. OpenCode retries failed model calls inside the pinned CLI with no limit of its own, bounded only by the deadline. Claude Code's own CLI retries were not audited. Neither is changed here.

Validation

  • pytest responses_api_agents/{claude_code_agent,codex_agent,opencode_agent}/tests (macOS, worktree on PYTHONPATH): 1495 passed, 128 skipped, 1 failed. The failure is test_opensandbox_sdk_is_available_in_agent_environment: the local venv lacks the SDK, and it fails on feat(agent): add the shared outcome ladder for harness runs #5870 too.
  • These suites plus scripts/harness_conformance/tests, tests/unit_tests/rollouts/harness_capabilities and tests/unit_tests/agents: 2529 passed, with 4 baseline failures (the same opensandbox test and three cloudpickle imports, also failing on feat(agent): add the shared outcome ladder for harness runs #5870). The OpenCode suite alone, run serially: 786 passed, 60 skipped.
  • 52 new test cases.
  • tests/unit_tests/test_public_api_facades.py and tests/unit_tests/test_import_linter_coverage.py: 856 passed.
  • New tests:
    • claude_code_agent/tests/test_outcome_ladder.py: parser evidence; text that must not classify; one row per event through _sandbox_response, checking status, kind and policy action.
    • opencode_agent/tests/test_outcome_ladder.py: RunEvidence from classify_opencode_run; one row per event through an HTTP session.
    • In Codex test_sandbox_sessions.py: the deadline rule (_deadline_model_fault) and one row per event through an HTTP session.
    • In OpenCode test_continuation.py: a continuation deadline with a 503 or a 400 error event.
  • Updated tests that pinned 502s, _invocation_outcome and first-request 400s. 25 Codex tests on feat(agent): add the shared outcome ladder for harness runs #5870's head imported agent_outcome_policy from environment_servers.single_agent_turn.app, which feat(agent): add the shared outcome ladder for harness runs #5870 no longer exports. They now import from nemo_gym.agents.
  • Under parallel pytest -n 4/-n 6 on this loaded machine, an OpenCode session test occasionally fails, a different one each run. The cause is a KeyError('') in the test fake's bash-based params reader, or a timing check. feat(agent): add the shared outcome ladder for harness runs #5870 shows the same, and each test passes when re-run alone.
  • Linux-only tests (runtime installers, runners, exec transport, five Codex sandbox-lifecycle tests) were skipped on macOS. The later Linux A/B below runs the Claude Code and Codex suites with them, and they pass. OpenCode's Linux-only tests were not run.
  • Context and 401 fixes, A/B on a Linux host against the previous head. No failures on either side:
    • claude_code_agent/tests: 225 → 224 passed (one classifier test folded into a table);
    • codex_agent/tests plus tests/unit_tests/agents/test_outcome_ladder.py: 555 → 616 passed, 6 skipped (2 new Codex tests, plus the ladder file in the same run).
  • pre-commit run --files <touched files>: passed.

Smoke evidence

Scripted-model smokes on a Linux host, with no real model. Gym's real vllm_model (propagate_context_overflow_errors: true) sits in front of a scripted upstream. The Environment Server action is what agent_response_action returns under the default policy.

Codex and OpenCode: the harness conformance scenarios, A → B.

Scenario Codex OpenCode
model_error (400 before a reply) failed model_request_error 400 → verify ⇒ failed model_request_rejected → fail same
context_overflow failed model_request_error 400 → verify on A and B; B′ (6204710bf4): 200 incomplete → verify, outcome.target passes incomplete → verify, unchanged
context_overflow_length incomplete → verify, unchanged same
deadline_before_reply, deadline_after_reply incomplete → verify, unchanged same
harness_no_result 502 → retry ⇒ 200 failed agent_run_error → retry same
model_401 failed model_request_error 401 → fail ⇒ failed model_request_rejected → fail same
model_503 failed model_request_error 503 → retry, unchanged incomplete → verify on both sides (see the decision 6 note below)

Each harness changes one disposition (model_error). No episode had an execution error.

Claude Code 2.1.108. Claude Code is not in the conformance registry, so a driver ran the session routes (seed, activation, close) against the local sandbox provider.

Event A B B′
ok completed → verify same same
400 on the first request failed → verify failed model_request_rejected → fail same
400 after a reply failed → verify failed model_request_error 400 → verify not rerun
401 failed → verify failed unknown → retry failed model_request_rejected → fail
503 failed → verify failed model_request_error 503 → retry not rerun
context overflow, first request failed → verify failed model_request_rejected → fail incomplete → verify
context overflow after a reply failed → verify failed model_request_error 400 → verify incomplete → verify
model never answers, 30 s deadline incomplete → verify same not rerun
CLI killed failed → verify failed agent_run_error → retry not rerun

Counts: A verify 9; B′ verify 5, retry 2, fail 2. The 401 and context rows of B are what the fixes in this PR correct. The test fixtures now use the exact 2.1.108 texts from this smoke.

Decision 6 (harness retries), found by the smokes and not changed here:

  • OpenCode retries a 503 inside the pinned CLI with no limit of its own: 362 attempts in 38 s until the 45 s run deadline (370 on A). The run then ends incomplete and is graded instead of retried.
  • Codex retries a 401 six times.
  • Claude Code retries a 401 itself, 11 calls over about 180 s.

Not verified here:

  • What Claude Code 2.1.108 reports for a context overflow on the default vLLM length path. The smoke used the propagate flag.

Stack merge and CI repair (2026-11-16)

Merged current main (5d6429f5b1362af47954d8cf72f03cbe443ff941) into #5870 with signed merge commit 94d20acf69ef5dff3c0c3616d77e1c0e09c9a7dd, then merged that base here as 1924564f104e736b2846f673a64d353b29855d03. Both pushes were fast-forwards; this PR remains based on feat/agent-outcome-ladder.

Conflict resolution keeps the image-input guard from #5960, OpenCode v2 from #6001, and the step-limit marker from #5719. In particular, Codex runs that omit required prompt images still fail before grading; they now use the typed HTTP 500 agent_route_failed lifecycle path rather than the prior bare 502. The image-retention matrix checks failed observations, the typed cause, normal completion, output limits, deadlines and model errors. OpenCode v2 tests now check RunEvidence via the ladder and the typed required-MCP failure.

Workstation validation (Python 3.13.14, source imports verified against the intended worktree):

  • Lower merge: pytest tests/unit_tests/agents/test_outcome_ladder.py tests/unit_tests/agents/test_outcome_response.py resources_servers/ui_generation/tests -q: 180 passed; scoped pre-commit passed.
  • Initial merged three-adapter suites plus both outcome core files: 1913 passed, 36 failed, 15 skipped. Seven failures exposed the image guard integration and v2 test-contract updates, now repaired.
  • Final pytest responses_api_agents/codex_agent/tests/test_sandbox_sessions.py responses_api_agents/opencode_agent/tests/test_opencode2_session.py responses_api_agents/opencode_agent/tests/test_opencode2_store.py -q: 392 passed.
  • All remaining 29 failures reproduced on base 94d20acf6 using the same environment: 27 config tests reject installed OpenAI 2.45.0 against the 2.44.0 pin, one lacks OpenSandbox, and one workstation shell returns exit 2 rather than 126 for invalid executable bytes. Installing 2.44.0 separately also fails to import the base because PromptCacheOptions is absent. These baseline/dependency issues were not changed here.
  • pre-commit run --files <all 22 PR files> and git diff --check origin/feat/agent-outcome-ladder: passed.

No new real-model rollout was run during this merge repair. The earlier scripted-model evidence above remains revision-bound; this is not a new smoke qualification. CI authorized on both new heads. The main pipeline for this head is 43998457482; completion is pending.

Review fixes and CI repair (2026-11-17)

No merge was needed: the branch already contains feat/agent-outcome-ladder at 94d20acf69. Six commits on top of 1924564f10.

CI causes. Five checks failed on 1924564f10. Two root causes; the others were their aggregates.

  • Core tests (shard 1): test_every_recorded_name_still_resolves_at_its_old_path. feat(agent): add the shared outcome ladder for harness runs #5870's behavior.py stopped importing MODEL_REQUEST_ERROR, which the import surface records at its old path. Fixed with a MOVED_NAMES entry and moved_names_getattr in behavior.py (nemo_gym/_moved_paths.py, nemo_gym/rollouts/harness_capabilities/behavior.py). feat(agent): add the shared outcome ladder for harness runs #5870 fails the same test.
  • codex and opencode conformance probes (exit 2): the model_error scenario's P0 health check rollout_token_count_mismatch was unobserved, expected healthy. A rejected first request is now model_request_rejected, which the Environment Server fails, so the episode ends as a failure row with no response. _transcript_tokens (nemo_gym/rollouts/health/checks.py) now reads the failure row's _ng_failure_partial_response, as rollout recovery already does. New test test_failure_row_accounts_tokens_from_its_partial_response; rollout-health.mdx says so.
  • Environment Server compliance (non-blocking): rule A1 (run() defined) on Claude Code and Codex. main has the same run() methods; not changed here.

Review fixes (team review with Codex cross-check; the four earlier bot findings were all still present):

  • Codex sandbox_launcher.mjs, sandbox.py, app.py (_deadline_model_fault): attempt starts recorded, so a retry in flight at the deadline no longer selects the earlier 429/503; a cancelled 200 is no model reply, so a 400 after it is model_request_rejected; a deadline after a stream Codex gave up on (reported idle or broken stream after that attempt started, no retry started) is a transport fault and retried, as the base's 502 was; a healthy retry the deadline kills stays graded. A cancelled stream gives no compaction evidence.
  • OpenCode continuation.py: a timed-out continuation records the last error event, not the first.
  • OpenCode app.py: the required-MCP check runs on every run the ladder would grade, including a deadline after a reply with a recorded 400; an expired session counts as stopped before the status is decided, so the invocation status matches the response.
  • TB4 _termination_from_response: a response with graded_agent_error (Codex verify_after_agent_error, then completed or incomplete) keeps the nonzero_exit termination it had as failed, so the resume rule does not reuse it as a normal finish. TB4 and TB-science READMEs updated. (Removed on 2026-11-19: the run is failed again, see the decision above.)
  • Tests: in-flight and cancelled rows in the Codex tables and launcher tests, a stalled-stream deadline row, OpenCode last-error-event, errored-deadline MCP and statusless transport-deadline rows. Each new test fails on 1924564f10.
  • Docs: Codex README (deadline rule, missing images are a typed 500), OpenCode README, add-or-update-a-harness.mdx (stop route uses finish_response).

Validation (Linux workstation, Python 3.13.14, Node 22):

  • pytest on the three adapter suites, scripts/harness_conformance/tests, tests/unit_tests/rollouts, tests/unit_tests/agents, tests/unit_tests/test_moved_paths.py: 5714 passed, 29 skipped, 8 failed. The same 8 fail on 1924564f10 in that environment (test_tool_telemetry ×4, test_outcome_policy upload evidence ×3, OpenCode test_pinned exit-code check).
  • The CI conformance job reproduced with python -m scripts.run_harness_conformance: codex and opencode fulfilled, all 9 scenarios, model_error delivered as a failure record.
  • pre-commit run --files <changed files>: passed.

Smoke: outcome classes (Codex, real pinned CLI, scripted model through the conformance provider; no real model):

Scenario Row Reward / metrics
tool_success completed 1.0, scored
retry_500 (one 500, then recovery) completed 1.0, scored
verifier_failure (task failure) completed 0.0, scored
model_error (400 on the first request) failure row, model_request_rejected, terminal not scored
endpoint outage (every request 503; scratch scenario, not committed) failure row, model_request_error 503, retryable; 30 forwarded attempts masked, not counted as zero

Left for the author:

  • Claude Code: an is_error result without API Error: <status> (for example a status-less context overflow) is unknown and retried; main graded it. Unverified on 2.1.108's default vLLM path.
  • Claude Code and OpenCode retry a failing endpoint inside the CLI until the deadline without recording an error, so such an outage is still graded (decision 6, unchanged from main).
  • verify_after_agent_error: decided on 2026-11-19 (failed with agent_run_error, graded by the profile's policy). See the decision above.
  • The _moved_paths.py and behavior.py part of b9249e3a68 fixes a test feat(agent): add the shared outcome ladder for harness runs #5870 fails too; cherry-picking it into feat(agent): add the shared outcome ladder for harness runs #5870 lets that PR's CI pass, and the identical change then merges cleanly here.

🤖 Generated with Claude Code

…ladder

Each of the three CLI adapters decided its own response status and chose between
a 200, a 500 and a 502. Their sandbox sessions now fill a RunEvidence from their
own records and return finish_response(...) with HTTP 200; only lifecycle
failures stay typed 5xx raises.

Claude Code: parse_stream_json records whether the policy model replied and the
HTTP status of the "API Error: <status>" message the run ended on (Claude Code
2.1.108's own message, which the is_error result repeats); classify_outcome
turns it into model_request_error. A refusal is graded as completed, a nonzero
exit or missing result is agent_run_error, another error result is unknown,
error_max_turns is incomplete. The classifier follows the approach of draft PR
5807.

Codex: the forwarder's attempt record stays evidence. A timed-out run whose
last forwarded model attempt failed to connect, was cut short, or answered 408,
425, 429 or a 5xx carries that fault as infra_fault, so it is retried; any other
deadline is graded (it was a 502 when a turn had failed). A run without a usable
result is agent_run_error (was 502); a supervisor error is a typed harness
failure. verify_after_agent_error now marks the run as having a result, so a
graded agent error is completed instead of failed without a kind. The
report_rollout_stop and report_outcome calls are replaced by finish_response.

OpenCode: classify_opencode_run fills RunEvidence; model_replied is whether a
saved assistant turn finished without an error (the idea of PR 5798). A deadline
before any assistant message keeps its retry (retry_deadline_before_reply). A
deadline after a reply is graded unless the last recorded model error names an
unavailable endpoint. No usable result is agent_run_error (was 502); required
MCP tools that did not start, an unreadable export and a supervisor error are
typed harness failures (were 502). The OOM response goes through the ladder.

A 4xx other than 408, 425 and 429 before any model reply is
model_request_rejected for all three.

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

copy-pr-bot Bot commented Nov 9, 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.

…refactor/outcome-ladder-claude-codex-opencode

Signed-off-by: yaoyu-33 <[email protected]>
…-claude-codex-opencode

Keeps this branch's module-level imports in the Codex outcome tests over the
base's interim per-test import fix.

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

@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 WITH CARE — four outcome-classification risks and missing smoke-rollout evidence.

The inline findings cover Codex's attempt evidence and OpenCode's deadline classification and required-tool checks. I inspected all 20 changed files and traced the affected paths through response finalization and the Environment Server's grading/retry policy.

RISK — Provide representative smoke evidence for all three runtimes

The PR explicitly leaves smoke validation pending. The trusted AGENTS.md requires representative model rollouts for behavior-changing agent work; mocked unit tests don't establish the native event shapes on which these new grading decisions depend. In particular, Claude's tests construct the synthetic error frames themselves (fixture), while the description says that shape hasn't been verified against the pinned binary.

Could you run each pinned runtime through a representative task with model and tool work, inspect the verifier result, and attach the commands, versions and retained artifacts? Add controlled first-request rejection and deadline cases to validate the changed dispositions. Acceptance should show: successful tool work remains completed and verified; an initial nonretryable 4xx becomes model_request_rejected without verification or retry; a deadline with no terminal endpoint fault remains gradable under the adapter's documented exceptions; and a recorded terminal 503 remains retryable for Codex/OpenCode. Preserve partial output and confirm required-tool initialization and cleanup in those artifacts. For Claude, retain the native assistant/result records demonstrating the status-text association rather than only a reconstructed fixture. This is a validation request, not a claim that those runtime cases fail.

I couldn't execute tests or model rollouts in this read-only review. The PR's reported test results and baseline-failure attribution weren't independently verified. All regression checks below are proposed checks based on inspected source.

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

"""
if not attempts:
return None
last = attempts[-1]

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 — An in-flight retry leaves the previous endpoint fault selected.

Have the forwarder receive a 429, finish its retry delay, and start another request that remains in flight until the supervisor deadline. The second request leaves no record, so attempts[-1] is still the 429. _deadline_model_fault supplies infra_fault, and the response becomes failed/RETRY instead of the documented incomplete/VERIFY for a final in-flight attempt. The producer records failures or finished responses, but not attempt starts. The new consumer therefore cannot distinguish a terminal failure from a stale failure preceding a pending retry. This affects timed-out Codex episodes after a transient endpoint failure.

Could you retain start/completion evidence for the latest actual attempt in forward, carry it through artifact collection, and make _deadline_model_fault return no fault when that latest attempt remains in flight? Preserve the completed-attempt records used by classify_outcome, usage handling and compaction association. Don't append an ordinary status: null start record: existing consumers interpret that as a connection failure. The representation needs a coordinated producer/consumer change; a consumer-only patch cannot recover the missing distinction.

Proposed acceptance: use an upstream that returns 429 with Retry-After: 0, then holds the retry open. At the run deadline, expect HTTP 200, incomplete, no ng_agent_outcome, policy VERIFY and matching invocation status. Retain the existing deadline cases: a terminal completed 429/503 or transport failure → failed/RETRY; [503, 200] → incomplete/VERIFY. Also retain an in-flight first request → incomplete/VERIFY and verify that compaction records still associate correctly. These checks haven't been executed.

Comment thread responses_api_agents/codex_agent/app.py Outdated
has_result=error is None,
timed_out=timed_out,
model_replied=any(_is_model_output(event) for _, event in events)
or any(attempt.get("status") == 200 and "transport_error" not in attempt for attempt in attempts),

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 — A cancelled HTTP 200 stream is counted as a model reply.

This predicate assumes every recorded 200 without transport_error represents a whole reply. However, relay deliberately returns null when Codex cancels the stream. The existing hang-up test expects [{"status": 200}] even when Codex disconnects before the upstream response starts. If that attempt is followed by a reported 400 with no model-output events, the new predicate sets model_replied=True; the ladder verifies model_request_error:400 instead of returning model_request_rejected/FAIL.

Could you return downstream cancellation separately from successful body delivery in relay, persist a distinct cancellation marker in forward, and exclude cancelled attempts from this predicate? For example, if the marker is cancelled, replace the forwarder-based term here with:

or any(
    attempt.get("status") == 200
    and "transport_error" not in attempt
    and not attempt.get("cancelled")
    for attempt in attempts
)

That consumer change requires the producer marker too. Keep downstream cancellation distinct from an upstream transport failure; treating cancellation as transport_error would incorrectly retry model-owned deadlines. Only fully delivered responses should supply this reply evidence or completed compaction evidence. Verify the suggestion before adopting it.

Proposed acceptance: extend the hang-up test to assert the cancellation marker, then add a session with cancelled-200 → 400 and no output events; expect model_request_rejected/FAIL. Preserve complete-200 → 400 as model_request_error:400/VERIFY, upstream-truncated 200 as model_transport_error/RETRY, and a deadline after downstream cancellation without an endpoint fault as incomplete/VERIFY. These checks haven't been executed.

@@ -1804,14 +1845,15 @@ async def _session_response(
if (
mcp_unconfirmed
and not (error or failure or reported_error)

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 — Recheck required tools when an errored deadline becomes gradable.

Seed a required task_tools grant, leave mcp-status.json as null, use rejected_events(after_work=True) with a final HTTP 400, and set timed_out=True, return_code=-9. Here outcome.error makes error truthy, so MCP confirmation is skipped. The new evidence branch then turns that deadline into incomplete, which the default policy verifies despite the unconfirmed required tools. The base returned 502 for this combination. This changes an ungradable MCP session into scored work without restoring the required-tool guarantee.

Could you construct the final evidence before this guard and preserve an earlier error only when it still prevents grading? Apply finish_response's rollout-stop normalization before deciding eligibility, so a stopped run isn't mistaken for a retryable infrastructure deadline:

if state.session.expired and evidence.timed_out:
    evidence = replace(evidence, stopped=True)
if (
    mcp_unconfirmed
    and not (failure or reported_error)
    and (model_called or evidence.has_result)
    and (not error or decide_outcome(evidence).status != "failed")
):
    error = lifecycle_error = mcp_unconfirmed

Move the existing reported-error/deadline evidence construction above this block. The invariant is that the new timeout policy must not bypass required-tool confirmation for work it newly makes gradable. Retain the existing reported-provider-error exemptions and deadlines without model work. Verify the suggested code before adopting it.

Proposed acceptance: extend the MCP regressions with the setup above; expect a typed HTTP 500 harness failure naming unconfirmed tools. Preserve completed model work with missing status → 500; empty-placeholder timeout → incomplete; no-assistant timeout → failed unknown; recorded-503 timeout → failed model_request_error 503; non-timeout unclassified model error → failed agent_run_error. A rollout stop with model work and missing required-tool confirmation must also fail closed. These checks haven't been executed.

if continuation and timed_out and (event := opencode_error_event(stdout)) is not None:
error = error or f"OpenCode emitted an error event: {event}"
recorded_error = {"error": message["info"]["error"]}
if continuation and timed_out and (event := _first_error_event(stdout)) is not None:

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 — The new deadline classifier reads the first error instead of the last.

For a timed-out continuation with a saved assistant message, supply two JSONL error events: {"type":"error","error":{"name":"APIError","data":{"statusCode":400}}} followed by the same shape with status 503. This assignment uses _first_error_event, so recorded_error becomes 400. Deadline attribution consequently finds no endpoint fault and returns gradable incomplete, despite the last recorded error being retryable 503. Reversing the sequence wrongly retains the earlier 503. Previously either sequence failed the activation; the new status-sensitive decision makes event ordering material.

Could you select the last explicit error event? Rename the private helper and its caller to _last_error_event, update the docstring, and replace the helper's iteration with:

for line in reversed(stdout.splitlines()):

Keep the existing JSON parsing and event-shape guards, and retain the saved-assistant-error fallback when no usable error event exists. This restores the stated contract that deadline attribution uses the model error recorded last without changing single-error or error-free checkpoint behavior. Verify the suggestion before adopting it.

Proposed acceptance: extend the continuation deadline test: 400→503 must return failed model_request_error 503/RETRY; 503→400 must return incomplete/VERIFY. Retain single-503 failure, single-400 graded deadline, malformed-line handling, bare-error behavior and an error-free resumable checkpoint. This is a static counterexample in the accepted log format, not an executed test or a claim that a captured native run emitted this sequence.

…ladder decides

Claude Code 2.1.108 prefixes a 401's "API Error: 401 ..." text with "Failed to authenticate. ", so the
start-anchored status match missed it and the run was failed `unknown` (retried) instead of
`model_request_rejected`. The parser now finds the status anywhere in the terminal error text, which is
already restricted to Claude Code's own error message that the is_error result repeats.

A context overflow the model server propagates reaches Claude Code as an HTTP 400 whose raw JSON body keeps
the OpenAI code `context_length_exceeded`. The parser keeps that code as `api_error_code`, and
`classify_outcome` reports it as `model_context_limit`, so the ladder answers `incomplete` and the run is
graded, before or after the first reply (decision 1). It was `model_request_rejected` on the first request
and `model_request_error` 400 after a reply.

The fixtures use the exact texts from a scripted-model smoke of 2.1.108 through Gym's vLLM model server.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
yaoyu-33 and others added 2 commits November 9, 2026 16:13
Both adapters now classify a failed model request with the shared `model_http_error_outcome`, so a 400
whose body is the model server's context-overflow envelope (code `context_length_exceeded`) is
`model_context_limit`: `incomplete` and graded, before or after the first reply (decision 1).

- Claude Code keeps the body it printed after the status (`api_error_body`) in place of its own code
  parser.
- Codex passes its `turn.failed` message, which is the endpoint's body. A scripted-model smoke showed
  Codex reporting the overflow as `model_request_error` 400, and the first request would have been
  `model_request_rejected`. Its incomplete response no longer carries the reported error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added support User questions, support, or maintenance requests area:agent Agent harnesses and Responses API agent behavior needs-review PR is ready for code review and waiting on a reviewer labels Nov 16, 2026
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 1924564

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 17, 2026 01:50
yaoyu-33 and others added 6 commits November 17, 2026 16:16
…e row

The outcome ladder reports a 4xx before any model reply as
model_request_rejected, which the Environment Server fails instead of
grading. The episode then ends as a failure row whose failed response is
`_ng_failure_partial_response`, so `rollout_token_count_mismatch` found no
transcript usage and reported the harness-conformance `model_error`
scenario as unobserved instead of healthy. Read the partial response when
the row has no `response`, as rollout recovery already does.

The terminal-error behavior check no longer imports MODEL_REQUEST_ERROR,
so serve that name at its old module path through MOVED_NAMES.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…t side of the ladder

Codex:
- The forwarder records each upstream attempt's start as well as its
  result. A deadline is an endpoint fault only when every started attempt
  finished and the last one failed; a retry still in flight (after a 429
  wait, or Codex's own retry of a 503) leaves the deadline graded.
- A 200 that Codex hung up on before it arrived is recorded as cancelled
  and no longer counts as a model reply, so a 400 that follows is a
  rejected first request. A cancelled stream gives no compaction evidence.

OpenCode:
- A timed-out continuation records the last error event, not the first.
- The required-tool check runs on every run the ladder would grade,
  including a deadline after a reply that recorded a non-endpoint error;
  an expired session is counted as stopped before the status is decided,
  as finish_response does.
- Cover a deadline whose last model call failed without a status.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
A stalled or broken reply that Codex hangs up on is recorded as a
cancelled 200. When Codex reported that endpoint failure after its last
model output and no retry had started before the deadline, the deadline
was spent on the endpoint: report it as a transport fault, retried, as
the base's 502 was. A hang-up without a reported failure (the deadline
killing Codex mid-reply) stays graded.

Also correct the Codex README's missing-image outcome (a typed 500, not
502) and note in the OpenCode README that an outage OpenCode keeps
retrying until the deadline is graded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
… after

A healthy retry that the deadline kills is also recorded as a cancelled
200, and Codex's earlier "Reconnecting" notice is then still its last
event. Time each attempt's start on the sandbox clock that stamps the CLI
events, and count a reported stream failure against the cancelled last
attempt only when the runner saw it after that attempt started.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
On the outcome ladder, a Codex run that died while its sandbox still runs
(verify_after_agent_error) is completed or incomplete with
`graded_agent_error` in its metadata, not failed. Read that marker so TB4
still records the Harbor-parity `nonzero_exit` termination, and the
resume rule does not reuse the attempt as a normal finish. Update the
TB-science README for a first-request rejection, now failed ungraded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test c3dfcda

@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 18, 2026 00:49
yaoyu-33 added a commit that referenced this pull request Nov 18, 2026
…e row

This PR reports a 4xx before any model reply as model_request_rejected,
which the Environment Server fails instead of grading. The episode then
ends as a failure row whose failed response is
`_ng_failure_partial_response`, so `rollout_token_count_mismatch` found no
transcript usage and the Hermes and Stirrup conformance `model_error`
scenarios reported it unobserved instead of healthy (P0). Read the partial
response when the row has no `response`, as rollout recovery already does.

Same change as b9249e3 on #5877 (its health-check part), so the two
branches merge cleanly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

verify_after_agent_error no longer turns a Codex run that died while its
sandbox still runs into a completed response. The run stays failed with
agent_run_error, like any run that leaves no usable result, and the
Environment Server's outcome policy decides whether it is graded. The
flag now only labels the run (metadata.graded_agent_error) after the
liveness probe, and keeps the usage of its unfinished turn.

Terminal-Bench-Science's Codex profile, the config that sets the flag,
maps agent_run_error to verify in its environment server, so those runs
are graded as Harbor grades them; ++tbsci_agent_run_error_action=retry
retries them. TB4 again reads the failed status as its nonzero_exit
termination, so the graded_agent_error branch from the previous commit
is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test eb43d5d

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:high Autobot PR risk: high label Nov 20, 2026

This branch was previously deployed

1 inactive (outdated) deployment
public — 6204710b Deployed Nov 10, 2026 by yaoyu-33 via release / finalize / notify #11248
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior needs-review PR is ready for code review and waiting on a reviewer risk:high Autobot PR risk: high support User questions, support, or maintenance requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants