Skip to content

feat(agent): report native causes for shared grading policy - #4834

Merged
giuliolovisotto merged 14 commits into
mainfrom
glovisotto/env-reported-agent-failure
Oct 22, 2026
Merged

giuliolovisotto merged 14 commits into
mainfrom
glovisotto/env-reported-agent-failure

Conversation

@giuliolovisotto

@giuliolovisotto giuliolovisotto commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Provider failures returned as HTTP 200 with status="failed" can otherwise reach grading as task failures. Add an agent-reported cause and let single_agent_turn choose one action: verify, retry, or fail, preserving partial responses, observations and cleanup.

Fresh episode-routing comparison — 2026-10-22

The same 11 scripted tasks per revision ran through real Linux agent sessions and the collector: HTTP 400 and 401 for Pi, OpenCode, Hermes and Codex, plus persistent HTTP 503 for Pi, Hermes and Codex. A fresh collection was followed by two real resume passes with NEMO_GYM_MAX_ROLLOUT_ATTEMPTS=2; the final pass confirmed no third attempt. No policy overrides were used.

Source Exact revision Graded tasks Tasks actually retried Excluded from score
PR base (main) 92407083ba1a8373b96ae660cbd4404cd874169c 1/11 10/11 10/11
#4834 alone bcf9b15612021f9786d1a053f753cd40f6438f4b 3/11 5/11 8/11
Complete stack through #4740 38b08e2c2b4d1b8c068ea35c7b914b1c23f5c2a6 4/11 3/11 7/11

Retried and excluded overlap: a task can be retried and still end without a score. “Retried” here means an actual additional collector episode attempt, not native HTTP retries or merely a retryable flag. Graded tasks all reached the independent verifier and produced unmasked rollout rows.

Full per-harness results, limitations and excluded OpenCode HTTP-503 exploration: routing report. This is fresh routing evidence, not a new conformance-suite result.

Conformance result attribution (historical, not latest-head results)

Tested changes Exact revision Hermes scenarios passed
This policy PR (#4834) alone c998df7b6c1dff9c2401f744da57cc57aad0b2c5 4/7
Policy plus Hermes adapter fixes (#4742) 04498f0c5c9546f7e283d1ad571618cb6559accb 7/7
Rebased policy PR (#4834) alone a928f859ec3a2202e65c508d9e9aa6f267093482 4/7
Combined four-harness stack e5240e16e 7/7 Hermes; 28/28 across four harnesses

The improvement from 4/7 to 7/7 belongs to the Hermes fixes in #4742, not to #4834 alone. On the standalone policy revision, retry_429 and retry_500 lacked ownership evidence, while model_error also lacked required usage/health evidence. All seven episodes reached verification in both historical comparisons: scenario conformance counts are not graded/retried/excluded episode counts. These results do not claim fresh conformance validation of today's heads.

Validation on bcf9b15 (2026-10-22)

96 SingleAgentTurn tests passed, including verification of incomplete context-limit responses under fail/retry defaults; scoped pre-commit and Fern check passed (0 errors, 1 warning). Context-limit stops retain the model_context_limit reason and are incomplete, so partial work is verified without entering the failed-response policy. HTTP 400/413 alone does not imply context overflow.

Rebase validation before the label/formatter follow-up: the combined tip e5240e16e passed 28/28 Linux conformance scenarios, seven per harness. The policy-only head a928f859e passed 4/7 Hermes scenarios; the dependent stack fixes its evidence gaps. Both returned seven Hermes rollout records with no episode-failure rows; these scenarios do not establish exhausted-provider retry counts. These results are pinned to those revisions, not a claim of fresh CI or a new live-model run on the latest heads.

SimpleResponsesAPIAgent provides classify_outcome() and report_outcome(). AgentOutcome.failure_kind accepts registered names from failure_kinds.py plus unknown; classification travels in existing response metadata. This repairs the agent-session migration in #4489; no separate issue is needed.

Default policy for classified failed responses:

Cause Action
Invalid output, agent limit, or model HTTP 400/413/422 verify
Model transport errors, unknown, or HTTP 408/425/429/5xx retry
Other failures, including 401/403/404, or malformed metadata fail

agent_outcome_policy config overrides entries through by_status_code, by_failure_kind, and default_action. Supplied entries merge over defaults; status rules take precedence. Malformed metadata remains ungraded and nonretryable. No GDPVal-specific overrides are included. Collector retry budgets still apply; retry does not resend a model request directly.

Missing classification metadata retains existing behavior; completed/incomplete responses remain gradable and bypass these overrides. For the four agent-session adapters, reported 401/403/404 errors, unmatched failure kinds and malformed metadata become terminal and ungraded where they previously surfaced as retryable agent HTTP 500/502 errors; reported unknown remains retryable. Other Environment Servers and legacy /run grading policy are unchanged.

Stack dependency

Stack: #4834 (policy) → #4742 (Hermes) → #4739 (Pi) → #4741 (OpenCode) → #4740 (Codex), registered as GitHub stack #4899. These changes must land together. Do not merge #4834 alone: the Hermes and Codex classifier fixes are in #4742 and #4740.

Hermes and Codex classifier repairs live in the dependent PRs; the policy PR is not safe to land alone.

Validation on c998df7

  • 165 tests passed across test_agent_outcome.py, test_failure_kinds.py, test_base_responses_api_agent.py, and SingleAgentTurn test_app.py; scoped pre-commit passed.
  • Fresh Linux Hermes conformance on this PR alone: 4/7. retry_429 and retry_500 fail failed-call ownership; model_error also fails token/health evidence. All seven episodes reached verification, with no excluded episode failures.
  • The same suite on fix(hermes): retain session evidence and report provider errors #4742 at 04498f0: 7/7, also seven verified episodes. Its fresh live-model rollout completed verification with reward 1. These are dependent-branch results, not validation of this PR alone.
  • Unit tests cover unknown retry defaults, explicit overrides, malformed metadata, status precedence, retained evidence and cleanup. The seven scenarios do not establish exhausted-provider retry behavior by themselves.

Historical CI for c998df7b6; see individual job outcomes rather than treating prior combined runs as current-head CI.

Portable live-model smoke reproduction for the combined stack is available here; the latest follow-up is limited to agent sessions, with legacy execution explicitly outside scope.

@giuliolovisotto giuliolovisotto added area:env-infra Shared environment framework, lifecycle, registry, scaffolding, and validation area:agent Agent harnesses and Responses API agent behavior labels Oct 21, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 21, 2026 09:08
@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer labels Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

lafrancef
lafrancef previously approved these changes Oct 22, 2026

@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 the changes outside of agents, one optional suggestion.

)


class OutcomeAction(StrEnum):

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.

Should this and below be outside of single_agent_turn? Seems generic to all env servers.

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.

Agreed this is reusable. I propose keeping the policy in single_agent_turn for this PR and extracting it into shared code in a follow-up.

@giuliolovisotto

Copy link
Copy Markdown
Contributor Author

The documentation, compatibility notes and stack landing requirements from this review are addressed, with native Codex/Hermes classification fixes in the dependent PRs; the requested before/after counts of graded, retried and excluded episodes under exhausted provider failures remain outstanding.

@giuliolovisotto

Copy link
Copy Markdown
Contributor Author

@yaoyu-33 — corrected the historical 4/7 versus 7/7 attribution in the PR body and measured the before/after episode routing separately on the current policy head.

Fresh episode-routing comparison — 2026-10-22

The same 11 scripted tasks per revision ran through real Linux agent sessions and the collector: HTTP 400 and 401 for Pi, OpenCode, Hermes and Codex, plus persistent HTTP 503 for Pi, Hermes and Codex. A fresh collection was followed by two real resume passes with NEMO_GYM_MAX_ROLLOUT_ATTEMPTS=2; the final pass confirmed no third attempt. No policy overrides were used.

Source Exact revision Graded tasks Tasks actually retried Excluded from score
PR base (main) 92407083ba1a8373b96ae660cbd4404cd874169c 1/11 10/11 10/11
#4834 alone bcf9b15612021f9786d1a053f753cd40f6438f4b 3/11 5/11 8/11
Complete stack through #4740 38b08e2c2b4d1b8c068ea35c7b914b1c23f5c2a6 4/11 3/11 7/11

Retried and excluded overlap: a task can be retried and still end without a score. “Retried” here means an actual additional collector episode attempt, not native HTTP retries or merely a retryable flag. Graded tasks all reached the independent verifier and produced unmasked rollout rows.

Injected error / harness main #4834 alone Complete stack
HTTP 400 / pi_agent Retry once; excluded after budget Verify Verify
HTTP 400 / opencode_agent Retry once; excluded after budget Verify Verify
HTTP 400 / hermes_agent Verify Verify Verify
HTTP 400 / codex_agent Retry once; excluded after budget Retry once; excluded after budget Verify
HTTP 401 / pi_agent Retry once; excluded after budget Exclude without retry Exclude without retry
HTTP 401 / opencode_agent Retry once; excluded after budget Exclude without retry Exclude without retry
HTTP 401 / hermes_agent Retry once; excluded after budget Retry once; excluded after budget Exclude without retry
HTTP 401 / codex_agent Retry once; excluded after budget Exclude without retry Exclude without retry
HTTP 503 / pi_agent Retry once; excluded after budget Retry once; excluded after budget Retry once; excluded after budget
HTTP 503 / hermes_agent Retry once; excluded after budget Retry once; excluded after budget Retry once; excluded after budget
HTTP 503 / codex_agent Retry once; excluded after budget Retry once; excluded after budget Retry once; excluded after budget

Attribution: #4834 alone fixes Pi/OpenCode rejection routing, but Codex's HTTP 400 still retries and Hermes's HTTP 401 still retries on that head. The dependent native classifier fixes in #4740 and #4742 are needed for the final behavior. Persistent 503 remains retryable for Pi/Hermes/Codex in all three snapshots.

Excluded exploratory case: OpenCode persistently retries HTTP 503 inside the harness instead of returning an exhausted error. The main probe reached its 300-second deadline and the comparison driver timed out during resume; the other two exploratory runs were stopped. None enters the 11-task denominator. This is not evidence about OpenCode's exhausted-503 classification and does not weaken the provider-error expectation.

This is a controlled routing comparison, not a production GDPVal score comparison or a new seven-scenario conformance run. It does not establish production error frequency, every HTTP status, transport-disconnect handling, malformed-metadata handling, or recovery on a later episode. All measured work used committed snapshots; unrelated local edits were excluded.

@mlazuka mlazuka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CI/CD fixes but besides that looks good

@giuliolovisotto
giuliolovisotto added this pull request to the merge queue Oct 22, 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/39782165420

Merged via the queue into main with commit 18d88fd Oct 22, 2026
53 of 57 checks passed
@giuliolovisotto
giuliolovisotto deleted the glovisotto/env-reported-agent-failure branch October 22, 2026 13:43
khazic pushed a commit to khazic/Gym-lao that referenced this pull request Oct 30, 2026
…eMo#5219)

* feat(responses): opt-in keepalive events for long streaming responses

Streaming /v1/responses requests are buffered: the converted response is
re-emitted as SSE only once responses() returns, so the client sees no
event while a long generation runs. A client that bounds the silence
between events abandons the turn and re-sends it. The Codex CLI does
this after stream_idle_timeout_ms (300 s by default), which a high
reasoning effort turn can easily outlast. SSE comments, which the chat
streaming path sends, do not help here: Codex's event parser drops them
before its idle timer sees them.

Add stream_keepalive_s to BaseResponsesAPIModelConfig (default null,
today's behavior). When set and a call is still running after that many
seconds, the stream opens with response.created and then carries
response.in_progress every interval for the same placeholder response
id. Once responses() returns, the item and terminal events follow
exactly as the buffered path sends them, minus the response.created the
keepalives already sent.

A call that finishes within the first interval streams exactly as
before, HTTP error statuses included. A failure after the stream opened
ends with response.failed for the announced response id, carrying what
the client would have seen before the stream opened: a refusal the
server propagates keeps its OpenAI code (context_length_exceeded), an
upstream HTTP error follows the server's propagation policy, and no
upstream request URL is reported.

Model-call capture measured time to first token from the first body
chunk, which with keepalives would be the opening response.created one
interval in. The Responses lifecycle events (response.created and
response.in_progress) carry no model output, so they no longer count
toward it; on the buffered path they are sent in the same instant as the
first item, so its measurement is unchanged.

Signed-off-by: gwarmstrong <[email protected]>

* feat(vllm_model): accept unlisted reasoning efforts and all_turns context

The Codex CLI sends reasoning efforts its model catalog offers, and a
catalog may offer one the pinned OpenAI SDK does not list, such as
"max". Request validation types reasoning.effort with the SDK's literal,
so vllm_model answers such a request with 422 before any conversion,
although the engine behind the chat route accepts the level.

Add forward_unvalidated_reasoning_effort to VLLMModelConfig (default
false, today's behavior; requires is_responses_native=false). When set,
a string effort the SDK does not list is taken out of the raw Responses
body before validation and put verbatim on the converted chat request
as reasoning_effort; the engine validates it. Efforts the SDK lists,
"none" included, keep their existing path, and an empty effort is still
refused.

Codex also sends reasoning.context "all_turns" when its catalog enables
reasoning context, which drop_unrepresentable_request_fields still
refuses. The conversion passes every reasoning item the request carries
to the engine and leaves what is rendered to its chat template, which is
what "all_turns" (render them all) and "auto" (the provider's choice)
ask for. With drop_unrepresentable_request_fields those two values are
now dropped like the summary fields. "current_turn" asks for earlier
turns' reasoning to be left out, which the conversion does not do, so
it is still refused, and every value is still refused by default.

Signed-off-by: gwarmstrong <[email protected]>

* feat(vllm_model): bridge custom tools and inline tool output images

Two things the Codex CLI sends cannot reach a vLLM chat route through
the Responses to Chat Completions conversion today.

Codex's apply_patch is a Responses custom (freeform) tool with a lark
grammar. The conversion forwards it as a Chat Completions custom tool,
which a vLLM chat route rejects, so the only option was
drop_custom_tools: the model then has no apply_patch, tries it in the
shell, and falls back to editing with sed.

Add custom_tools_as_functions (VLLMModelConfig and ResponsesConverter,
default false). Each custom tool is presented to the engine as a
function tool with one required string parameter, input; its
description is the tool's description, a note to pass the raw input as
input, and the grammar when the tool has one, since a string parameter
cannot constrain the input. The engine's calls to that function come
back as custom_tool_call items (call_id, name, input, status) on the
non-streaming and the streaming path alike. Arguments that are not an
object with a string input are passed through as the input, so the
client's tool reports the bad call to the model. Replayed
custom_tool_call and custom_tool_call_output items become the chat tool
call (arguments {"input": ...}) and tool message, on the same assistant
turn as the replayed reasoning. A named tool_choice of a custom tool
selects its function. The option takes precedence over
drop_custom_tools, and a custom tool named like a function tool fails
the request. It needs is_responses_native=false and
return_token_id_information=false: custom_tool_call has no variant that
carries token IDs. Saved model-call records now list custom_tool_call
items among a response's tool calls.

When the model catalog lists image input, Codex offers view_image,
whose output is a function_call_output holding an input_image part.
Chat tool messages accept image parts since NVIDIA-NeMo#4688, but the conversion
still refuses the part, or replaces it with a text placeholder under
drop_unrepresentable_request_fields, so the model never sees the image.

Add inline_tool_output_images (VLLMModelConfig and ResponsesConverter,
default false; needs is_responses_native=false). Each image part of a
tool call output becomes an image_url part of the chat tool message,
which vLLM accepts and leaves to the chat template, and it takes
precedence over the placeholder. Detail "original", which Codex sends
when the model asks view_image for full resolution and which chat
lacks, goes as "high". Other part types a tool message cannot carry
are still refused.

Signed-off-by: gwarmstrong <[email protected]>

* fix(vllm_model): reject forward_unvalidated_reasoning_effort where it cannot apply

The completions path builds its body from a fixed list of chat fields, and
reasoning_effort is not one of them, so with use_completions_api=true the
forwarded effort was dropped without a word. The compaction server has its
own dispatch, which never sets the unlisted effort aside. Both now refuse
the option at startup instead of ignoring it.

Signed-off-by: gwarmstrong <[email protected]>

* feat(codex): opt-ins to launch Codex in a sandbox as a plain codex exec does

Evaluating Codex in a task sandbox should send the requests the Codex
CLI sends when a harness such as Harbor 0.24 launches `codex exec`
directly in the task container. Sandbox sessions refuse extra_config, so
add explicit settings. Every default keeps the current behavior:

- model_server_forwards_reasoning_effort: sandbox sessions keep
  rejecting reasoning_effort by default, because most Gym model servers
  cannot guarantee it reaches the backend. The flag records the
  operator's check that the model server forwards Codex's `reasoning`
  field unchanged; the effective value is then visible in captured model
  calls.
- inherit_sandbox_environment: give Codex the sandbox's whole
  environment instead of PATH, the locale, HOME and the XDG directories,
  keeping only CODEX_HOME private. Task images set variables such as
  VIRTUAL_ENV, PYTHONHASHSEED or OMP_NUM_THREADS that a harness started
  in the container sees. Intended for remote providers, where that
  environment is the task's.
- features: the generated [features] table, which turns off multi_agent
  and code_mode by default. A null entry is left out, so the CLI default
  applies, as in a launch without a Gym config.
- ephemeral: false drops --ephemeral, so Codex keeps session state and
  offers its goal tools (create_goal, get_goal, update_goal). A correlated
  local rollout no longer tries to remove a flag that is not there.
- request_max_retries, stream_max_retries: the provider's resends before
  a stream starts and reconnects after one drops, beside
  stream_idle_timeout_ms; null leaves Codex's own defaults.

Signed-off-by: gwarmstrong <[email protected]>

* feat(codex): grade a failed run while its sandbox still runs

Harbor runs the verifier after any agent exit that is not a timeout: a
trial whose agent died while its sandbox still answers is graded, not
rerun. codex_agent instead raised an execution error for every failed
Codex run, so the Environment Server skipped verification and the
episode was retried from scratch: an agent the kernel's OOM kill hit
(once the sandbox kills a single process instead of itself), an agent
whose own pkill hit the runner, or a Codex exit 1.

verify_after_agent_error (off by default) returns such a run as a
`failed` response, with the error in metadata.graded_agent_error, which
Resources grades as a nonzero agent exit. It applies only when the
supervisor confirmed cleanup, the failure that ended the run names no
model-endpoint transport or 429/5xx error, and the sandbox still
reports running and answers a probe command. A lost or unresponsive
sandbox, an unconfirmed cleanup and an endpoint outage stay execution
errors and are retried.

The endpoint check reads only the terminal failure after the run's last
model output (turn.failed and the last error event before it, or the
last event when Codex was killed without turn.failed), so a retry that
recovered no longer turns a later unrelated failure into a rerun. It
recognizes Codex 0.154.0's messages: unexpected status 429/5xx, the
"high demand" message for a 500, exceeded retry limit, the
waiting-for-network notice, and stream disconnects from a transport
error, a closed stream, a failed send or the SSE idle timeout. The
output-cap disconnect (reason: max_output_tokens) stays gradable.

raise_oom_score_adj (off by default) makes Codex the OOM killer's
preferred victim in its sandbox. In Docker, the leaderboard's runtime,
the daemon that runs the agent lives outside the container's memory
cgroup, so an OOM kill can only pick the agent's own processes. In an
OpenSandbox sandbox the exec daemon and Gym's supervisor share the
cgroup and the oom_score_adj with Codex. The runner raises its own
score, which Codex and every tool inherit, to 1000, or to 0 when the
sandbox starts it below zero (a Guaranteed pod's -997), so the sandbox
never becomes the node's first victim in a global OOM. The exec daemon
and the supervisor keep the sandbox's own score.

TB4's resources-session test covers the `failed` response status: it is
graded as a nonzero agent exit.

Signed-off-by: gwarmstrong <[email protected]>

* feat(codex): keep session rollouts in the trial dir

codex_agent removes its session directory, and with it CODEX_HOME, when
a sandbox session closes. Without the model-call capture, Gym then keeps
no per-call token counts for a Codex run: the response usage comes from
turn.completed, which a run stopped at its time limit never emits. With
the capture on, every request payload is also copied into the rollout
row (one image-heavy trial's row was 2.5 GB after 20 minutes), which a
full 210-trial run cannot hold in memory or on disk.

New sandbox_logs_dir setting: after Codex stops, the session rollouts
(CODEX_HOME/sessions/**/rollout-*.jsonl, with per-call token counts and
timestamps) are copied to <sandbox_logs_dir>/sessions before the session
directory is removed. A failed copy is logged and never fails
collection. Harbor's Codex agent copies them to /logs/agent/sessions the
same way; with /logs/agent, the TB4 resources server copies them into
the trial directory (agent/sessions/). It only acts without --ephemeral.

Signed-off-by: gwarmstrong <[email protected]>

* fix(codex): run tasks whose workdir is the root

A task image without WORKDIR (some Terminal-Bench-Science tasks) lends "/"
as its workdir. codex_agent refused it with HTTP 422 ("runtime/session
files must be outside SandboxAccess.workdir"), so every trial of those
tasks failed at session start, while Harbor runs the agent there.

The root holds every path, so it is accepted. The runtime and session
files stay under /tmp, and any other workdir must still be disjoint from
them: /tmp itself and paths under the adapter's /tmp prefixes are refused
as before, and the in-sandbox check still rejects a workdir that contains
or lies inside an adapter path after resolving symlinks.

Tests: six new cases in codex_agent/tests/test_sandbox_sessions.py cover
the root workdir (in-sandbox check and seeding) and the workdirs that are
still refused.

Signed-off-by: gwarmstrong <[email protected]>

* refactor(vllm_model): use main's function bridge for custom tools

NVIDIA-NeMo#4880 added custom_tool_strategy: function_bridge, which lowers each
Responses custom tool to a function tool with one string input and lifts
the calls back, on the same conversion this branch extended. Drop this
branch's custom_tools_as_functions, which did the same job: the config
field, the converter helpers and restore step, the name-clash check,
the streaming drop override and their tests.

The Codex tests now run apply_patch through function_bridge, streaming
and non-streaming, with drop_custom_tools off: it is still the kill
switch and would drop the tool before the bridge sees it.

Saved model-call records keep listing custom_tool_call items, which the
bridge returns too.

Signed-off-by: gwarmstrong <[email protected]>

* fix(codex): drop the ephemeral setting now that sandbox sessions keep session state

Main's sandbox sessions always run Codex without --ephemeral, to keep its
native session transcript, so the setting no longer changes them. Local runs
keep main's --ephemeral.

Signed-off-by: gwarmstrong <[email protected]>

* feat(tb4): lend task sandboxes through SandboxAccess sessions

Serve the shared resources-session protocol so harnesses that borrow a
task sandbox (codex_agent behind single_agent_turn or
single_agent_turn_legacy) can run TB4-pinned datasets, as NVIDIA-NeMo#3902 does for
Terminal-Bench 2.1:

- /seed_session with a ResourcesSeedSessionRequest provisions the task
  through TB4's existing seed lifecycle and returns SandboxAccess: a
  direct connection through the new `sandbox_provider_ref` block and the
  task workdir as its user sees it. Seeds are idempotent per
  resources_session_id.
- /verify with the task row and the agent response grades once through
  the existing finalizer (artifact collection, separate offline verifier,
  test counts and partial credit, EFS logs) and replays the verdict on
  identical retries. Termination follows response.status.
- /close_session fences the session before it waits, as Terminal-Bench
  2.1 does: a seed still provisioning releases its sandboxes instead of
  lending them, even when the close's caller gives up. It then waits for
  provisioning or grading, releases anything still running without
  grading, fences late seeds, and fails (keeping the fence) when a
  sandbox cannot be stopped.
- Completed close records expire after
  session_close_retry_window_seconds (default 300, the Terminal-Bench
  2.1 setting), so the fence set no longer grows with every episode.
  Failed or pending cleanup never expires, and close retries do not
  extend the window.

Tasks that declare agent.user are rejected, since the borrower runs as
the sandbox default user. TB4's own mini-SWE seed/verify contract is
unchanged.

Signed-off-by: gwarmstrong <[email protected]>
(cherry picked from commit 1775136793828102e9826467f67736d9849b1ef8)
Signed-off-by: gwarmstrong <[email protected]>

* docs(tb4): grade an agent that died while its sandbox runs as a nonzero exit

A harness that returns a failed response while its sandbox still runs
(codex_agent's verify_after_agent_error) is graded with termination
nonzero_exit. Document it and cover it in the sessions test.

Signed-off-by: gwarmstrong <[email protected]>
(cherry picked from commit a61790adffe459b9c1153887134f1f4cd78c065c)
Signed-off-by: gwarmstrong <[email protected]>

* feat(terminal-bench-science): add a Codex profile and a DeepSeek V4.1 Flash run config

The public leaderboard's DeepSeek V4.1 Flash and GPT-6 Astra rows ran
Codex at reasoning effort max. Add `terminal_bench_science/codex`: the
resources server lends each task sandbox through SandboxAccess,
codex_agent installs and runs Codex 0.155.1 there, and
single_agent_turn_legacy seeds both, closes Codex before grading, then
closes Resources. Grading, partial credit, artifacts and EFS logs are
the same as for mini-SWE.

- Codex's timeout is the task's 8-hour agent budget; prepare_codex.py
  checks that every selected task has it. The episode deadline covers
  provisioning, installation, the budget and the slowest verifier.
- Codex sees the task image's environment and HOME, as in Harbor.
- The model name Codex sees, its version and its reasoning effort are
  run overrides; effort also needs model_server_forwards_reasoning_effort.
  Codex's provider retries keep the CLI defaults unless
  tbsci_codex_request_max_retries / tbsci_codex_stream_max_retries set
  them.
- A Codex run that dies while its sandbox still runs is graded as a
  nonzero agent exit, as Harbor grades it; Codex and its tools are the
  OOM killer's preferred victims; and without --ephemeral Codex's
  session rollouts are kept under /logs/agent/sessions, which the trial
  directory collects.
- prepare_codex.py writes rows whose prompt is the package's
  instruction.md, read and hash-checked by the resources server's
  loader, because an Environment Server passes the row's prompt to the
  agent. prepare.py now exposes its task selection.

codex_deepseek_flash.yaml is the run config for the leaderboard's
DeepSeek V4.1 Flash / Codex / effort max row with a self-hosted model:
Codex 0.154.0 with no model catalog, effort max, the full 28800 s
budget, and an OpenAI Responses endpoint serving deepseek-flash in
front of a chat-completions server; the endpoint URL and its key are
overrides (--model-url; POLICY_API_KEY or ++tbsci_model_api_key_env).
openai_model relays Codex's requests unchanged and adds no time limit of
its own, and the agent keeps Codex's feature defaults and session state,
so the first request matches a plain `codex exec` launch as Harbor 0.24
starts it: same instructions, input items, reasoning settings and tools,
including the multi-agent and goal tools.

The README documents both setups, including the leaderboard's catalog
model and effort max through openai_model's
responses_stream_passthrough.

Signed-off-by: gwarmstrong <[email protected]>
(cherry picked from commit d131d1d30391cefb7c2c2ca0a4b17758501ba6db)
Signed-off-by: gwarmstrong <[email protected]>

* fix(terminal-bench-science): match the Codex profile to the updated agents

- Run one trial per task by default, as the mini-SWE profile does; ++num_repeats=3 runs the
  leaderboard's three.
- Drop codex_agent's ephemeral setting: sandbox sessions always run Codex without --ephemeral.
- Name the vllm_model settings Codex needs, with NVIDIA-NeMo#4880's custom_tool_strategy: function_bridge.
- Describe how a provider failure Codex reports itself reaches the outcome policy (NVIDIA-NeMo#4834).
- Check the Codex manifest against its runtime composition.

Signed-off-by: gwarmstrong <[email protected]>
(cherry picked from commit 34cb6349bb10531fdc28f66a50a928fbdaf894a7)
Signed-off-by: gwarmstrong <[email protected]>

* feat(terminal-bench-science): serve the DeepSeek Codex run through vllm_model

Signed-off-by: gwarmstrong <[email protected]>

* fix(vllm_model): measure context with the reasoning effort generation forwards

Signed-off-by: gwarmstrong <[email protected]>

* fix(codex_agent): retry Codex's capacity and request-timeout endpoint errors

Signed-off-by: gwarmstrong <[email protected]>

* fix(codex_agent): keep usage and observations of a graded failed run

Signed-off-by: gwarmstrong <[email protected]>

* fix(codex_agent): fit the session rollout copy inside the capture budget

Signed-off-by: gwarmstrong <[email protected]>

* fix(checkpoint): treat Responses lifecycle events as liveness

Signed-off-by: gwarmstrong <[email protected]>

* test(vllm_model): let Responses lifecycle events precede publication

Signed-off-by: gwarmstrong <[email protected]>

* fix(model): keep one response id across a keepalive stream

Signed-off-by: gwarmstrong <[email protected]>

* fix(genrm_model): forward inline_tool_output_images to the converter

Signed-off-by: gwarmstrong <[email protected]>

* fix(terminal_bench_4): finish close cleanup after its caller disconnects

Signed-off-by: gwarmstrong <[email protected]>

* fix(terminal_bench_4): retry a failed sandbox teardown on the next close

Signed-off-by: gwarmstrong <[email protected]>

* fix(terminal_bench_4): mask the verify of a lost or expired resources session

Signed-off-by: gwarmstrong <[email protected]>

* docs(terminal_bench_4): describe close teardown retries

Signed-off-by: gwarmstrong <[email protected]>

* docs: link the Terminal-Bench-Science Codex profile from the harness guide

Signed-off-by: gwarmstrong <[email protected]>

* docs(terminal_bench_science): replace a PR placeholder with NVIDIA-NeMo#5155

Signed-off-by: gwarmstrong <[email protected]>

* fix(terminal_bench_science): prepare Codex rows through gym eval prepare

Without pathspec, which Gym's own environment leaves out, prepare_codex runs itself in the terminal_bench_4 server's environment, setting that up first as gym env start does. The selection is checked before the hand-off.

Signed-off-by: gwarmstrong <[email protected]>

---------

Signed-off-by: gwarmstrong <[email protected]>
Co-authored-by: gwarmstrong <[email protected]>

This branch was previously deployed

1 inactive deployment
public — bcf9b156 Deployed Oct 22, 2026 by copy-pr-bot[bot] via release / finalize / notify #6597
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 area:env-infra Shared environment framework, lifecycle, registry, scaffolding, and validation feature New capabilities, enhancements, or enablement work 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.

5 participants