Skip to content

fix(failures): a policy timeout on a queueing model server is the server's - #5686

Merged
AdamRajfer merged 8 commits into
mainfrom
arajfer/queue-timeout-classification
Nov 16, 2026
Merged

AdamRajfer merged 8 commits into
mainfrom
arajfer/queue-timeout-classification

Conversation

@AdamRajfer

@AdamRajfer AdamRajfer commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

A policy request that times out after its upload is recorded as model_policy_response_timeout, which a run can count as a zero, although on a saturated vLLM server the request may still have been waiting in the server's queue. The vLLM client now reads the server's queue from /metrics when a request times out, bounded to 2 s, and records the waiting and running counts on the attempt. If every attempt of a timed-out call saw requests waiting, Simple Agent reports the new model_server_queue_timeout, which is retried and never counted as a zero, while an idle queue or a missing reading keeps the old kind. The reading is server-wide, so on a saturated server a slow model's timeouts are also retried. Unit tests cover the client reading, the metrics parser, the retry path, the connection release and the classification, and a small run against a real vLLM server showed the queued, idle and no-metrics cases; no linked issue.

…ver's

A policy request that timed out after its upload was always the model's
result, `model_policy_response_timeout`, which a run can count as a zero.
When the model server was saturated, the request was still waiting in the
server's queue when it timed out, so the zero measured the server's
capacity, not the model.

When a request to a vLLM model server times out waiting for its response,
the client now reads that server's queue from its `/metrics` page at the
timeout and records `server_requests_waiting` and `server_requests_running`
on the attempt's failure. It records an empty queue too, and records
nothing when the server publishes no queue metrics. If every attempt of
the timed-out call saw requests waiting, Simple Agent reports the new
`model_server_queue_timeout`, an evaluation-side server fault that is
retried and never counted as the model's zero. Every other timeout keeps
`model_policy_response_timeout` and its current handling.

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

Copy link
Copy Markdown
Contributor Author

/ok to test eb233de

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

@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

Queued timeouts become terminal failures in the default session-based Environment Server path, rather than remaining retryable. The inline findings include a focused correction and regression checks.

RISK — Representative real rollout evidence is missing. The supplied validation lists unit suites, but no real model smoke rollout. The trusted AGENTS.md requires representative model rollouts for behavior-changing agent work; this change affects retries and scoring.

Could you attach a small vLLM rollout through Simple Agent and the Environment Server, recording the model, concurrency, request timeout, queue readings, selected kind and terminality? An all-attempts-queued timeout should be retryable and ungraded; a successful retry should reach verification. Include idle-queue and unavailable-metrics controls that retain ordinary policy-timeout handling, including the configured count-as-zero case. Preserve a healthy rollout's output and verifier result. This requests missing validation evidence, not an assertion that a smoke run failed.

I inspected all 12 changed files and the affected client, session, outcome-policy and gate paths. Two delegated result payloads weren't available, so I checked those assigned client and agent paths directly. I couldn't execute tests in this read-only review.

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

… and the count-as-zero test setup

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

Copy link
Copy Markdown
Contributor Author

On the real-rollout evidence: no live vLLM rollout was run for this PR. The queue-reading branches and the retry path are covered by unit tests, including the idle-queue and missing-reading controls.

AdamRajfer added a commit that referenced this pull request Nov 5, 2026
Signed-off-by: Adam Rajfer <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
@oyilmaz-nvidia

Copy link
Copy Markdown
Contributor

/review model=claude

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

I reviewed the timeout reclassification, the documented whole-server/replica limitations, and the follow-up fixes for retry defaults and metrics parsing. I am holding approval until the main-branch conflicts are resolved and the behavior-changing vLLM/agent path has representative live rollout evidence, as required by the repository quality bar. The current discussion explicitly says no live vLLM rollout was run. Please include queued, idle and unavailable-metrics controls and inspect the final retry/grading outcome; public-safe summaries are sufficient here. Unit tests are useful evidence for the individual branches but do not establish that the deployed endpoint and metrics refer to the intended serving process. I have not executed this head locally.

The policy-timeout failure is now built in one place (policy_timeout_failure in
nemo_gym/agents/agent_outcome.py), so the queued-timeout classification moves there:
a timeout where every attempt waited in the model server's queue gets
MODEL_SERVER_QUEUE_TIMEOUT, every other one MODEL_POLICY_RESPONSE_TIMEOUT.

Signed-off-by: Adam Rajfer <[email protected]>
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

Branch is now merged with current main (d794f1b, no conflicts; unit suites for this change and pre-commit pass). Live rollout evidence below.

Setup. Qwen2.5-1.5B-Instruct served by vLLM 0.17.0 on one GPU (--max-num-seqs 2, hermes tool parser). Gym vllm_model plus simple_agent through the single-agent-turn Environment Server, example_single_tool_call as the task. 40 tasks per run, each asking for about 250 words and then a get_weather call; max_output_tokens 600. Retries are the collector's resume of non-terminal failures. Mean rewards are low because this is a 1.5B model on a tool task, and only the failure handling is under test.

Healthy baseline (concurrency 1, 120 s timeout): 40/40 completed, 0 failures, mean reward 0.25.

Queued (concurrency 32, request_timeout_seconds 3): 27 completed, 13 failed. All 13 were recorded as model_server_queue_timeout, non-terminal, not counted as zero. Each attempt's recorded reading had requests waiting (for example 17 waiting/0 running, 13/1, 6/2, 1/0). After resuming with a 120 s timeout all 13 were retried and completed: 40/40, 0 failed, mean reward 0.275.

Idle server (concurrency 1, timeout 0.5 s, shorter than one generation): 23 completed, 17 timed out. All 17 kept model_policy_response_timeout (waiting was 0 on every attempt; running 0 or 1), non-terminal under the default policy. Resumed with 120 s: 40/40, 0 failed, mean reward 0.25.

Metrics unavailable (same load as the queued run, but the model server's base URL points at a pass-through that answers 404 on /metrics): 10 completed, 30 timed out. All 30 kept model_policy_response_timeout with no queue reading on any attempt, i.e. ordinary handling. Resumed with 120 s: 40/40, 0 failed, mean reward 0.2.

Not exercised here: the count-as-zero setting (final_on_model_timeout) end to end; that stays covered by the unit tests.

Conclusion: with a real vLLM server, a timeout is reclassified and retried only when every attempt saw a queue; an empty queue or a missing reading keeps the old classification, and retried work finished with normal grading in every control.

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

Reviewed the timeout reclassification and connected client, agent and Environment Server retry/scoring paths at d794f1b. One connection-lifecycle issue needs fixing; see the inline finding.

Validation: reproduced the connection retention using the exact _server_queue function against a local aiohttp server returning a 503 with a 1 MiB body. With a one-connection pool, the helper returned None but the connection remained acquired beyond the metrics timeout, and a subsequent healthy request timed out waiting for a pool slot. The five focused test files could not collect because my local aiohttp lacks UploadTracker; this is a local dependency limitation, not a reported test failure in this PR.

Comment thread nemo_gym/client/openai_client.py Resolved
…e read

A non-200 /metrics reply with a body larger than aiohttp's read buffer left
the response unread, so its connection stayed acquired in the shared pool and
later requests could time out waiting for a slot. _server_queue now closes the
response in a finally block (non-200, read error, timeout, cancellation).

The regression test sends a 503 with a 1 MiB body and then reads healthy
metrics through a one-connection pool.

Signed-off-by: Adam Rajfer <[email protected]>
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 13, 2026 12:32
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

Closing: no observed case needs this change right now.

@AdamRajfer AdamRajfer closed this Nov 14, 2026
@AdamRajfer AdamRajfer reopened this Nov 15, 2026
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

Reopened: the review was nearly done. The requested change, releasing the /metrics connection on every exit of the queue read, is in ab80b96 with a regression test (head cd9e5f2), and every other thread has an answer.

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

Re-reviewed d794f1b..cd9e5f2. The response is now closed in a finally block, and the new large-503-body regression test exercises reuse of the same one-connection pool. The connection-retention finding from my previous review is addressed.

I reran the isolated reproducer using the exact updated helper: the pool had zero acquired connections after the failed metrics read, and the subsequent healthy request succeeded. Isolated checks also confirmed response cleanup on body-read errors, timeouts and cancellation. No new findings in these two commits.

This is a delta review following my earlier review. I have not rerun the full unit suite; the earlier local aiohttp/UploadTracker dependency limitation remains.

@AdamRajfer
AdamRajfer added this pull request to the merge queue Nov 16, 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/43872017496

Merged via the queue into main with commit 63226ff Nov 16, 2026
225 of 230 checks passed
@AdamRajfer
AdamRajfer deleted the arajfer/queue-timeout-classification branch November 16, 2026 13:16
yfw added a commit that referenced this pull request Nov 16, 2026
Main's #5686 makes policy_timeout_failure return model_server_queue_timeout when every attempt waited in the
model server's queue, and simple_agent's session branch now reports the failure's own kind. The agent still
reported model_policy_response_timeout, which no longer matches the cause its report selects, so the Environment
Server would fail the reply instead of applying the queue timeout's rule (retry by default). The agent now reports
the timeout's own kind, as simple_agent does.

The timeout test covers a report without a queue reading, with an empty queue, and with requests waiting; the
queued case fails without this change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
pzelasko pushed a commit to pzelasko/Gym that referenced this pull request Nov 16, 2026
…ough agent sessions (NVIDIA-NeMo#5720)

* feat(core): let a tool reply return images to the model

A resources-server tool can list images under tool_output_images, each a data URL with an optional label. Gym's
MCP layer returns them as MCP image content after the reply's text, each after its label. simple_agent shows them
to the model in a user message after the turn's tool outputs, since a Chat Completions tool message carries only
text.

A result with images carries no structured content unless the tool declares an output schema. OpenCode 1.17.11
replaces an MCP result's content with its structured content when that is present, which would drop the images.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* feat(core): add LentSandboxes, a shared helper for the sandbox a resources server lends

Nine servers lend a per-episode sandbox, and each writes its own code to start it from config, describe it as
SandboxAccess, stop it at close (keeping it when the stop fails, so close can retry) and stop the rest at shutdown.
LentSandboxes holds that part. The server keeps its own ResourcesSessionFence and any other session state, and
calls lend() in its typed seed and release() in its typed close. Files are optional, so the same call lends a
sandbox with the task files or an empty one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* feat(opencode_agent): allow compaction.auto and agent.build.steps in a session's config

Training on OpenCode rollouts needs one chain of model calls per rollout, and a fair comparison
with other harnesses needs a step budget. The session path accepted only permission and tools,
so neither could be set.

A session's opencode_config now also accepts compaction.auto (a boolean) and agent.build.steps
(a positive integer), and still refuses everything else, including compaction.prune (it rewrites
old tool output, which breaks the token prefix) and other agent fields (they would replace the
adapter's prompt, model or sampling). The replacement system prompt and the request sampling now
join each agent's entry instead of overwriting it, and the session copies opencode_config instead
of mutating the shared one.

Tests: the allowlist, both prompt modes, request sampling beside a step limit, and the real
OpenCode 1.17.11 binary reading steps from the session config (GYM_TEST_OPENCODE_BINARY).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* docs(core): name ResourcesSessionLocks in the LentSandboxes docstring

Main split ResourcesSessionFence into ResourcesSessionLocks and ResourcesSessionFences (NVIDIA-NeMo#5083).
A server holds the session's ResourcesSessionLocks lock around lend() and release().

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(core): finish LentSandboxes stops under cancellation and lend an operate descriptor

A lent sandbox now stops as SandboxSessionResourcesServer's do:

- Every stop is shielded from the cancellation of its request and bounded by STOP_TIMEOUT_S, so a close whose
  client disconnects still stops the sandbox, and a hung provider does not hold the close forever.
- release_all() stops the sandboxes concurrently, at most SHUTDOWN_STOP_CONCURRENCY at a time, because the
  supervisor gives a server about a second to exit.
- The harness gets an operate descriptor (serialize(scope="operate")): it may use the sandbox but not destroy it.

Each new test fails without its change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* docs(core): say that providers without leases ignore the operate scope of a lent sandbox

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(opencode_agent): refuse agent.build.steps with token capture, and describe the step limit as OpenCode applies it

From the call at the step limit on, OpenCode 1.17.11 adds an assistant message (MAX_STEPS_PROMPT) to each request.
The fingerprint join of token capture finds no earlier call for such a request and records a capture failure, so
NeMo-RL drops the rollout as poisoned, with only the finalize/capture_poisoned_rollouts metric to show it. With
forest training the call starts a new chain instead, the same break that compaction.auto: false avoids. So with token
capture on, a session's seed now refuses agent.build.steps with 422. Eval without token capture is unchanged.

OpenCode also still offers the tools at the limit, with tool_choice auto, so a model that keeps calling them runs past
it. The docstring and the README now say so instead of "caps the model calls". The harness guide's OpenCode row lists
the session keys the README lists.

Test: with token capture on, a seed with agent.build.steps gets 422 and starts nothing; compaction.auto alone still
seeds. The test fails on the previous code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(core): read a null tool_output_images as no images, and keep a tool reply's JSON format

- A reply model may declare an optional image list, so FastAPI sends "tool_output_images": null in a reply without
  images. split_tool_output_images raised on it: simple_agent failed the rollout with HTTP 500, and MCP returned an
  error result for every call without an image. Null now means no images.
- simple_agent wrote the rest of an image reply with json.dumps defaults (spaces, \uXXXX escapes). It now uses the
  compact UTF-8 form FastAPI sends, so a tool's text is the same with and without images, and the same as the MCP
  tool result.
- The module docstring names the two readers of the key (simple_agent and the MCP endpoint), says where each puts
  the label and the image, and says that an agent that does not read the key passes the base64 data as text.

Tests: a null image list; the JSON format of an image reply; a plain-text or nested tool output that only names the
key stays unchanged (the JSONDecodeError and top-level-key fallbacks). The first two fail on the previous code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* test(core): cover the shielded stop of a lend that cannot describe its sandbox

lend() stops a new sandbox when serialize fails or the seed is cancelled while it runs. No test failed if that stop
went back to an unshielded sandbox.stop(): a cancelled seed then left the sandbox running until ttl_s, and
release_all() could not stop it because lend() had not stored it. The new test cancels the seed during serialize
and fails with that change.

The docstring now says "episode seed" and "episode close", the glossary names, and says what a stop does: it goes
on when its request is cancelled and gives up after STOP_TIMEOUT_S.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* docs(core): document tool_output_images on the MCP Resources Server page

A new section says how a tool returns images (the key, ToolOutputImage, a short example), what the model gets from
the /mcp endpoint, from simple_agent and from an agent that does not read the key, that null means no images, and
that an agent which puts the images inside its tool output (Codex) needs inline_tool_output_images on vllm_model.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(opencode): accept NeMo RL's row output limit when OpenCode stays within it

NeMo RL sets max_output_tokens on every row (its generation limit). An OpenCode sandbox
session refused the field, so an OpenCode training run under NeMo RL failed its first
episode with 422 "does not support request field max_output_tokens", and RL stopped the run.

A session now accepts max_output_tokens when it is at least the configured
max_output_tokens, which is OpenCode's own limit for each model call. A smaller value is
still refused, so nothing is silently ignored.

Test: a NeMo RL row (temperature 1.0, top_p 1.0, max_output_tokens 4096 or 16384 with a
configured limit of 4096) passes, and OpenCode keeps the limit of 4096. The test fails
without this change. The existing refusal of max_output_tokens 123 still passes.
819 OpenCode tests pass. The same change ran in the run C and D smokes (3 steps each).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* feat(core): let LentSandboxes lend a sandbox that reaches only the model server

A harness that creates its own sandbox can set network_access model_only, so the sandbox reaches only the model
server. A sandbox that a resources server lends kept the provider's network, and the harness that borrows it cannot
change that, so a lent sandbox could reach the internet.

LentSandboxes now takes network_access ("inherit" by default, or "model_only") and model_server. With model_only,
lend() adds the same egress rule that an agent-owned sandbox gets: deny by default, and allow the model server's host
on every port. A provider without network policies, or a model server on a loopback address, refuses the seed with
HTTP 422 before any sandbox starts. Setting model_only together with an explicit
sandbox_config.provider_options.network_policy is a configuration error.

restricted_network_policy and its host check move from nemo_gym.agents.agent_tools to nemo_gym.utils.network_policy,
since server_runtime sits below agents in the package layers. agent_tools imports them, so the old names still work.

Test: tests/unit_tests/server_runtime/test_sandbox_lending.py (13 passed), the agents and server_runtime unit tests,
and the import-linter hook.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
(cherry picked from commit b0abe8e)

* feat(opencode_agent): mark a response whose prompt reached OpenCode's step limit

With agent.build.steps set, OpenCode 1.17.11's `opencode run` appends a note that asks for a final
answer from call number `steps` on. It still offers the tools, so the model may answer or keep calling
tools. An environment whose own agent scores an episode that runs out of rounds as 0 needs to know
when a rollout reached the limit, because otherwise the harness rewards long tool loops: a policy
trained with the answer at the limit scored learned to use every step.

The OpenCode agent now sets response metadata `harness_step_limit_reached: "true"` when the last
prompt made at least `steps` model calls (one saved assistant message per call). The new
HARNESS_STEP_LIMIT_METADATA_KEY in nemo_gym.agents names it for any harness adapter. The mark only
reports the limit; the environment decides how to score it.

Tests: opencode_agent 825 passed, 23 skipped (new: the mark at, above and below the limit, and
counting only the last prompt). tests/unit_tests/agents and test_public_api: 660 passed; the 3
test_outcome_policy failures need cloudpickle, which the local environment lacks, and fail the same
without this change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(opencode_agent): allow agent.build.steps with token capture when Gym NVIDIA-NeMo#5833's capture fix is installed

A seed with token capture refused agent.build.steps, because OpenCode's step-limit note made capture poison the
next call. Gym NVIDIA-NeMo#5833 fixes that in token capture and adds nemo_gym/models/token_capture/harness_notes.py. The seed
now refuses the setting only when that file is missing, so a branch that merges both PRs can train with a step
limit. The check reads the installed package's files and imports nothing.

TODO: remove the check once NVIDIA-NeMo#5833 is on main.

Tests: the refusal without the fix, the acceptance with it, and the file check. opencode_agent: 832 passed,
23 skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* feat(opencode_agent): return a session's own turns at close by default

return_session_trajectory now defaults to true, in the agent config class and in configs/opencode_agent.yaml.
Close then returns OpenCode's own turns (one per saved assistant reply, compaction summaries left out), so rollout
collection joins each captured model call to the step that made it. With false, every call is reported as an
unmatched assistant message and the harness evidence checks become noise. Training data does not change, because
training uses the captured calls.

Tests: the default in the config class and the shipped config; the existing parametrized test keeps both values.
opencode_agent, rollouts and the repo session contract: 3428 passed, 23 skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* feat(sandbox): let a lent sandbox reach the servers whose tools the harness calls

LentSandboxes takes network_access="model_and_tools" with tool_servers,
as agent-owned sandboxes already do. The egress rule allows the model
server's host and the host of each tool server, such as the resources
server that serves its tools over MCP. Before, a lent sandbox whose
harness calls MCP tools could only keep the provider's network.

tool_servers is refused without model_and_tools, and model_and_tools is
refused without tool_servers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(opencode_agent): find Gym NVIDIA-NeMo#5833's harness notes by import, in either layout

The check for NVIDIA-NeMo#5833's capture fix probed for nemo_gym/models/token_capture/harness_notes.py. NVIDIA-NeMo#5833 now keeps the
notes in a harness_notes/ package, so the probe returned False even with the fix installed, and a seed with token
capture would refuse agent.build.steps for good. The check now imports the module and looks for an OpenCode entry in
HARNESS_NOTES, which works for a module or a package and does not turn on for an unrelated file at that path.

Tests: no module; a module or a package with an OpenCode note, a Pi note only, or no notes. Checked by hand against
NVIDIA-NeMo#5833's package at 1c0cd40: False without it, True with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(core): check a tool's images as prompt images are checked

ToolOutputImage checked only the data URL's prefix, so invalid base64 or JPEG bytes labeled image/png passed and
failed later, at the model server or in the harness, as a rollout error. It now decodes the URL with
MediaFile.from_data_uri, the rule for prompt images: valid base64 holding a PNG, JPEG, GIF or WebP image, any case,
image/jpg allowed. The URL is written again from the content, so its label always matches the bytes. A bad image is
again a ValidationError, an error of the tool.

Tests: invalid base64, base64 that is not an image, and a PNG signature without IHDR are refused; a mislabeled JPEG
and image/JPG are relabeled. Tool-image fixtures use a real 1x1 PNG. The MCP page says how images are checked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* chore(opencode_agent): say what return_session_trajectory false costs, and drop agentic_if's copy of the default

The opencode_agent config's comment now says what false costs: one turn per captured call, so evidence checks report
every call as unmatched, and compaction summaries count as steps. agentic_if set the same value as the new default,
so its line goes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(opencode_agent): count compaction passes toward OpenCode's step limit, as OpenCode does

reached_step_limit() took the last user message as the prompt and counted the assistant messages after it. An
automatic compaction adds user messages (the compaction marker, then a synthetic "Continue" text or a replay of the
prompt), so the count restarted after a compaction, and a prompt that reached the limit was not marked.

OpenCode 1.17.11's session loop (session/prompt.ts) counts passes: each build call, each compaction summary call,
and a pass that only starts a compaction after a finished call overflowed (session/compaction.ts saves its marker
without an overflow field). The counter is not reset by compaction. The check now skips the user messages that
compaction adds when it finds the prompt, and counts those passes.

Tests: five exports in OpenCode's message shapes, the overflow-pass and in-call compaction paths, a compaction with
no continuing message, and a new prompt after a compacted one. Four fail on the old count. The README says how the
limit is counted and when token capture allows it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(core): stop a lent sandbox whose seed is cancelled during file delivery, and keep a failed seed's stop for retry

Two cleanup gaps in LentSandboxes.lend():

- A seed cancelled while the new sandbox received its files left the sandbox running. AsyncSandbox.start() stops
  the sandbox when an upload fails, but that stop is not shielded, so it is cancelled with the request. lend() now
  runs start() inside its own failure path, whose shielded, bounded _stop() finishes the stop; after a stop that
  did finish, _stop() does nothing.
- When a failed seed's stop failed or timed out, the sandbox was dropped, so no close or shutdown could stop it.
  It is now kept apart from the lent sandboxes: get() never returns it, release() and release_all() retry its stop,
  and the session's next lend stops it before it starts another sandbox (a failed stop there fails the lend).

Tests: a seed cancelled during upload_file() with the real AsyncSandbox.start() and a provider close that crosses an
AnyIO checkpoint; a failed seed whose first stop fails or hangs, stopped later by release() or release_all(); a
repeated seed that stops the earlier sandbox first, and one that fails while that stop still fails. The seven new
tests fail without the fix. test_sandbox_lending.py and tests/unit_tests/sandbox: 2028 passed, 8 skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* docs(agent-server): list attachment in OpenCode's session settings, and when token capture allows the step limit

The harness guide's OpenCode row now matches the README: a session's opencode_config also accepts attachment (from
NVIDIA-NeMo#4922), and agent.build.steps works with token capture once the harness notes know OpenCode's step-limit message.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* refactor(agentic_mme): move the image tools from the agent to the resources server

The resources server serves the same 14 image tools to session harnesses (next commit), so the tools move to
resources_servers/agentic_mme/image_tools.py, unchanged. The Agentic-MME agent imports them from there. Both
components pin the same OpenCV build in their lock policy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* feat(agentic_mme): run Agentic-MME with several harnesses through agent sessions

The resources server now supports agent sessions and three new settings next to the Agentic-MME agent:
- server_tools.yaml: simple_agent with the 14 image tools served by the resources server, which return their new
  image in the tool reply (tool_output_images).
- opencode.yaml: OpenCode in a sandbox that the server lends at seed (LentSandboxes), with the task images as files;
  sandbox_no_internet.yaml closes its network to the model server.
- opencode_server_tools.yaml: OpenCode with the 14 image tools over MCP.

prepare.py writes the rows of every setting. score_step_limit_answer (default false) scores an answer at OpenCode's
step limit 0, as the Agentic-MME agent scores an episode that runs out of rounds; step_limit_reached shows the share
of such rollouts. The OpenCode settings set an episode deadline below the sandbox TTL, and a test keeps it there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* feat(agentic_mme_agent): run the Agentic-MME agent as an agent session

The agent now serves agent sessions under the Environment Server: one activation per session, an identical retry
joins it, and close cancels it. Under a session, a failed model call fails the response with its cause (the shared
agent outcome), and the Environment Server grades or retries it. On /run the behavior stays as on main: a context or
request-size refusal ends the episode unanswered, and any other failure raises PolicyRequestError into the failures
sidecar.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(agentic_mme): pass the schema and agent-session checks on main

Main now checks that every committed dataset row matches its schema and
that the list of agents with agent sessions matches the agent apps.

- Declare image_files in the agentic_mme task schema. The image file
  model moves from app.py to task_data.py so both use one definition.
- Add agentic_mme_agent to AGENT_SESSION_AGENT_TYPES.
- The OpenCode configs name the agentic_mme resources server on the
  agent block, so their example rows are checked against its schema
  (an agent with no resources_server reference must ship its own).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* feat(agentic_mme): set the lent sandbox's network from config

sandbox_network_access (inherit, model_only or model_and_tools) and
sandbox_model_server pass through to LentSandboxes; model_and_tools adds
this resources server as a tool server and needs expose_tools_over_mcp.

opencode.yaml now lends a model_only sandbox and runs the OpenCode copy
that the sandbox image holds; opencode_server_tools.yaml lends a
model_and_tools sandbox, so OpenCode reaches the model and this server's
/mcp and nothing else. sandbox_no_internet.yaml, which did this with a
hand-written allow list of one address, is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* feat(agentic_mme): declare image input in the OpenCode recipes

OpenCode passes an image that a tool returns to the model only when the model declares image input; otherwise it
sends an error text in its place. Since NVIDIA-NeMo#4922, opencode_agent declares it when the prompt has images or when
image_input is true. Agentic-MME prompts hold the task images, so it was declared already; image_input: true keeps it
declared for any row, as NVIDIA-NeMo#4922 asks of configs whose tools return images. Both recipes get it from opencode.yaml.

Tests: both recipes load with image_input true. agentic_mme tests: 151 passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* feat(agentic_mme): bake OpenCode's plugin dependencies into the sandbox image

opencode_agent always configures a plugin, so OpenCode 1.17.11 installs @opencode-ai/plugin from npm at each start
unless the dependencies are present. The lent sandbox reaches only the model server (and, with server tools, this
server), so each start waited about 70 s for that install to fail before the first model call.

The image now builds the dependency archive as visual_coding_opencode's does: from a copy of
benchmarks/agentic_if/opencode's lockfile with the recipe in benchmarks/agentic_if/README.md (Node 24.15.0 with
npm 11.12.1, then GNU tar 1.34 and GNU gzip 1.10). The build checks the archive against agentic_if's pin
(77b03eba...), and opencode.yaml sets sandbox_plugin_dependencies_path and _sha256; opencode_server_tools.yaml
inherits them.

Checked: the plugin-archive stage builds and its sha256sum -c passes. A test keeps the lockfile copy, the Dockerfile
and the pin in step. agentic_mme tests: 152 passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(agentic_mme): keep the OpenCode sandbox off every server but the ones it calls

The lent sandbox's egress rule opens every port of the policy model's host, and NeMo RL gives every server without
its own host that address. So sandbox code could call the judge (spending its API key), the agent's /run (which runs
OpenCode on the host), and the resources and Environment Servers (which start sandboxes and episodes).

opencode.yaml now sets host 127.0.0.1 on the judge, the agent, the resources server and the Environment Server. All
their callers run on the same host. opencode_server_tools.yaml sets the resources server's host back to null, because
OpenCode calls its /mcp route from the sandbox; it then takes the reachable address as before.

Tests: a parse with NeMo RL's default_host gives the node's address only to the policy model (and, for server tools,
the resources server). agentic_mme tests: 154 passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(agentic_mme): refuse cookie seeds when the server keeps episode state, harden the judge, and admit episodes at the agent's rate

The visual_coding_opencode review (NVIDIA-NeMo#5839) found these in code that Agentic-MME shares in shape:

- Seeds. The cookie arm has BeforeValidator(reject_partial_typed_seed), so a malformed typed seed gets 422. A server
  that lends a sandbox or serves the image tools refuses a cookie seed with 422 too: it would get neither, and an
  agent's own /run, which seeds that way, runs its harness on its own host.
- Judge. The verdict comes from every JSON object in the reply that has one, so a brace ahead of it no longer masks
  the row, and objects that disagree stay a judge failure. A reply with no choices is a judge failure. Judged rows
  are graded inside observe_llm_judge_grading with record_parsed_judge_verdict, so they carry a grading record.
  judge_model is removed: the judge's model server picks the model.
- Admission. opencode.yaml's Environment Server admits 32 episodes at a time (the agent's concurrency), because
  each seed starts a sandbox; the deadline stays 5400 s, below the sandbox's 7200 s TTL.
- Data. prepare.py also writes task_id at the row's top level, where `gym eval plan` reads it.
- README: a network rule opens every port of an allowed host (hence the 127.0.0.1 pins), blocks raw IPs only with
  dns+nft, and admission follows the agent's concurrency.

Tests: verdict parsing, empty choices, no model in the judge request, seed refusals with and without server tools,
the stateless server, admission and the top-level task_id. Ten new cases fail on the old code. 165 passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* test(agentic_mme): import the parser config from nemo_gym.config

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(agentic_mme): keep the head server on loopback in the OpenCode recipes

The lent sandbox's network rule opens every port of the policy model's host,
and a launcher's default_host also becomes the head server's address. The
head server returns the whole config, keys included, without authentication,
so sandbox code could read the credentials. opencode.yaml now sets
head_server.host 127.0.0.1, which opencode_server_tools.yaml inherits; the
policy model and, with server tools, the resources server keep the reachable
address. NeMo RL sets head_server in its own initial config, which wins over
the recipe, so under NeMo RL the head server stays on the node's address; the
README says so.

Tests: the launcher-host test checks the head server, and a new test checks it
for both recipes with and without absolute_ip_server_types.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(agentic_mme): grade only a context-limit refusal under agent sessions

On /run, the Agentic-MME agent scores a model call refused for its context or
request size as 0 and raises any other failed call into the failures sidecar.
Under an agent session it reported every refusal as model_request_error with
its status, and the Environment Server's default policy grades a 400, so a
serving limit (vLLM's per-prompt image limit) or an unsupported parameter
scored 0.

The agent now reports a context or request-size refusal as
model_context_limit, and configs/agentic_mme.yaml sets the Environment
Server's agent_outcome_policy: model_context_limit is graded, and 400, 413 and
422 fail ungraded. The policy applies to every harness of the benchmark:
OpenCode already reports a context overflow as model_context_limit, so it now
scores 0 there too; simple_agent reports a context limit as a plain 400, so in
server_tools.yaml that rollout fails ungraded. The benchmark README says so.

Tests: a session drives a crop and then a context-limit 400 and 413, an
image-limit 400, an unsupported-parameter 400, a 503 and a 401, and checks the
reported outcome, the kept tool work and the action under the benchmark's
policy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(agentic_mme): prepare each recipe's own file in the locked project

gym eval prepare requires prepare() to return the dataset's jsonl_fpath, but
prepare.py returns the atomic track's file, so the three new recipes failed
with ConfigError. prepare_server_tools.py, prepare_opencode.py and
prepare_opencode_server_tools.py run the shared conversion and return their
track's file, and each recipe points prepare_script at its own.

prepare.py also builds the server-tools rows from the image tools, which import
OpenCV, and the recipes declared no preparation dependencies. config.yaml now
sets prepare_project: resources_servers/agentic_mme in place of
prepare_dependencies: [pillow], and each recipe's benchmark dataset sets it.

Tests: for all four recipes, the preparer returns the dataset's jsonl_fpath and
the dataset sets prepare_project. Checked: gym eval prepare of all four recipes
on a one-task local release finishes in the locked project's environment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(agentic_mme): release state on retire, order tool calls with close, refuse unreadable images

- Retire. The server keeps its own sessions, so the inherited
  retire_session_state did nothing, and a retired attempt kept its workspace
  and lent sandbox. It now stops the sandbox and drops the workspace under the
  session lock, without close's fence; a failed stop keeps both for a retry.
- Tool calls. A call checked the fence before it waited on its own lock, which
  close did not take, so a call queued behind close changed the dropped
  workspace and returned success. A call now takes the session's lifecycle
  lock and checks the fence and the session under it. A client disconnect
  cancelled the await but not the worker thread, so the next call could run
  beside it; the await now runs in a shielded anyio cancel scope, so the lock
  is held until the worker finishes.
- Seed. A task image that exists but cannot be read raised a 500, which the
  Environment Server retries with the same input; it is now a 422.

Tests: retire with a failing first stop; close against a running and a queued
call; a call cancelled through an anyio cancel scope; an unreadable image. All
four fail on the old code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(agentic_mme): keep the tool trace and its counts under agent sessions

The default recipe runs the agent through agent sessions, and the session
path dropped the tool trace: the Environment Server sends verify only the
task data and the response, and the model's tool outputs leave out each
retrieval call's provider answer, leak-guard count and cache outcome. A
collected row therefore lost tool_trace, the counts and overthink.

The agent now puts the trace in response.metrics, which the model never
sees. Verify moves it into the result and derives the counts and
overthink from it, so /run and a session give the same fields, and the
row stores the trace once. /run takes them from verify instead of
computing them itself.

A test collects a rollout of the default recipe through collection, the
single-agent-turn Environment Server and the agent's session routes, with
a live search result, and checks the trace, its raw, contaminated and
cache keys, and the counts. It fails on the previous head.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(agentic_mme): mask a lost image session and record policy_error under sessions

- A tool call for a session this server does not hold (never seeded, or lost to
  a restart or a retired attempt) raises ResourcesSessionLostError (404,
  session_lost) instead of 409, which harnesses passed to the model as an
  ordinary tool error. The session middleware gives every request an ID, so the
  two cases look alike; this follows automationbench, enterpriseops_gym and
  gdpval.
- With serve_image_tools on, verify masks a session this server does not hold
  (lost_session_verification), as for a closed session.
- verify records a failed response (a context-limit refusal that the outcome
  policy grades) as failure_reason "policy_error" with the harness's message in
  policy_error, as the agent's /run does.
- serve_image_tools sets cv2.setNumThreads(1), as the agent does, since the
  tools run in to_thread workers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(agentic_mme): classify a failed model reply as simple_agent's session branch does

ServerClient.post returns a non-ok reply without raising, so the
ClientResponseError branch never ran and a confirmed policy timeout was
reported as model_request_error/500 without its failure report.

- The agent now calls raise_for_status on each model reply. A refusal is
  classified from the error: model_context_limit for a context or request-size
  refusal, model_policy_response_timeout when the model server's report shows
  every attempt timed out, model_request_error with the status for another 4xx
  or 5xx, and unknown for a 3xx (a redirect loop), which AgentOutcome cannot
  carry. The response keeps the failure report, merged with the model server's.
- PolicyCallError becomes PolicyCallFailure: it holds an AgentOutcome and the
  message, and derives infrastructure from the outcome. It stays local.
- Tests: a timed-out 500 keeps its cause and the model server's report; a
  default-recipe rollout collected through the Environment Server that ends on
  a context-limit refusal after one crop scores 0, is graded, counts the crop
  and records policy_error. The refused-reply fakes now raise as aiohttp does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* docs(agentic_mme): bound server-tools episodes and correct replay and head-server notes

- server_tools.yaml: the header says the track matches config.yaml only on
  rollouts without a context overflow (simple_agent reports one as a plain 400,
  which this benchmark fails ungraded) and asks for each track's failed-rollout
  count. The Environment Server admits 32 episodes at a time
  (max_concurrent_episodes, queue_timeout_seconds), which bounds the image
  workspaces on the resources server.
- READMEs: replay works only on the agent's own /run; repeatable runs use the
  shared cache with cache_write: false.
- Resources README: under NeMo RL, do not run opencode.yaml with real keys
  until the head server stops returning secrets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(agentic_mme): keep a context-limit refusal graded when the reply carries a report

The policy model server is a Gym server, so its 400 carries a failure report
that selects the refused model request (model_request_error). The Environment
Server fails a reply whose selected cause does not match its outcome
(model_context_limit), so the context-limit rule stopped grading once the agent
attached the report. The agent now keeps that report's events but selects no
cause for a context-limit refusal, and the outcome policy grades it.

The collected context-limit test now gives the refusal a model-server report;
it fails without this change. The timeout test checks that the Environment
Server rebuilds the timeout as the reply's selected cause, so its timeout rule
(retry by default) applies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* test(agentic_mme): drop the test that only fixes the OpenCode recipes' image_input

The review asked for fewer tests of config values. The deadline and admission tests stay, because each compares
settings in two blocks that gym env validate does not compare.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* chore(agentic_mme): regenerate the example rollouts through the agent session config

The old rows came from the relay to the agent's /run and named the old Environment Server instance. These come from
resources_servers/agentic_mme/configs/agentic_mme.yaml at a67d4e0: the agent's session routes under
single_agent_turn_legacy, instance agentic_mme_environment_server, 5 example rows, a hosted vision-language policy.
All 5 score 1 after one crop; the rows now carry evaluation_completed, step_limit_reached and failure_report.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

* fix(agentic_mme): report a model server queue timeout with its own kind

Main's NVIDIA-NeMo#5686 makes policy_timeout_failure return model_server_queue_timeout when every attempt waited in the
model server's queue, and simple_agent's session branch now reports the failure's own kind. The agent still
reported model_policy_response_timeout, which no longer matches the cause its report selects, so the Environment
Server would fail the reply instead of applying the queue timeout's rule (retry by default). The agent now reports
the timeout's own kind, as simple_agent does.

The timeout test covers a report without a queue reading, with an empty queue, and with requests waiting; the
queued case fails without this change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>

---------

Signed-off-by: Yi-Fu Wu <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:model Model servers, inference providers, and model adapters blocked Work cannot move forward until an external dependency is cleared bug Something isn't working sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants