Repository navigation
refactor(env): share dependency-failure classification across environment servers - #4945
Conversation
Add AgentSeedRejectedError, an HTTPException (422) that is also a ValueError. Seeds an agent cannot serve (num_workers > 1, unsupported sandbox or grants) used to raise plain ValueError, which became a 500 that single_agent_turn retried as transient. Use it in the base num_workers guard, simple_agent and hermes_agent, and add check_agent_seed_rejected. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…ilure AgentSeedRejectedError promises that a refused seed fails the episode once with the agent's message, but single_agent_turn and nemo_user_sim built failure_reason from str(ClientResponseError), which names only the status, reason phrase, and URL. The agent's detail stayed on response_content. Add nemo_gym.server_utils.describe_dependency_error, which appends the bounded response body for an HTTP error, and use it for single_agent_turn's agent seed failure and nemo_user_sim's episode failures. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…rn failures Resources servers now refuse unfixable seeds and closes with 422 or 409 and a reason in the body (NVIDIA-NeMo#4679), but single_agent_turn built failure_reason from str(ClientResponseError) for every stage except the agent seed, so the reason was lost. Use describe_dependency_error for the resources seed, agent turn, agent close and verify failures too. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…d verify failures describe_dependency_error is used at every single_agent_turn stage, but only the two seed stages had a test, so reverting the agent turn, agent close or verify call site to str(error) passed. Add one parametrized test that sends a 4xx with a body at each of those stages and checks the detail reaches failure_reason. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…sal to 422 - nemo_user_sim: participant agent-turn failures are wrapped in _ParticipantActivationError, whose message dropped the refusing server's reason; build it with describe_dependency_error. - An agent that does not implement episode sessions refuses its seed with AgentSeedRejectedError (final 422) instead of a NotImplementedError 500 that was retried. - check_agent_seed_rejected requires 422 with a string detail, so a missing route (404), a conflict (409) or a request-validation 422 no longer passes. - Tests pin each simple_agent and hermes refusal to 422 over HTTP, and the openclaw/opencode num_workers refusal to its detail. - Docs: the _seed_agent_session_state docstring and the agent-server page tell hook authors to raise AgentSeedRejectedError. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Merge origin/main while preserving the PR runtime changes. Keep the guide reorganization from NVIDIA-NeMo#4713 and move AgentSeedRejectedError guidance into the harness integration contract, replacing the obsolete Hermes 500 caveat. Validation: 251 focused core tests and 154 SimpleAgent/episode lifecycle tests passed; pre-commit run --all-files passed; Fern check passed (redirect checks skipped because local Fern authentication is unavailable). All 16 non-documentation PR diffs are unchanged by the merge. No model rollout was run for this documentation-only conflict resolution. Signed-off-by: yaoyu-33 <[email protected]>
main routes each agent session to the worker that seeded it (NVIDIA-NeMo#3905), so the base seed no longer refuses agents with num_workers > 1. Drop this branch's conversion of that guard to AgentSeedRejectedError and its tests; take main's multi-worker seed tests for simple_agent, codex, openclaw and opencode. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Resolve the test_agent_sessions.py conflict by keeping both sides: main's NVIDIA-NeMo#3729 close-response trajectory tests and this branch's seed-refusal tests. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…atus guidance - Harbor builds failure_reason with describe_dependency_error for its seed, agent seed, agent turn and agent close failures, so an agent's 422 refusal reason reaches the episode failure there too. New Harbor tests carry the reason only in ClientResponseError.response_content. - seed_agent_session logs each AgentSeedRejectedError refusal once, since a handled 422 never reaches the exception middleware that used to log the ValueError. - The _seed_agent_session_state docstring and the harness guide say an HTTPException keeps its explicit status; only other, unexpected exceptions answer 500. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…ment servers single_agent_turn, nemo_user_sim and harbor each carried their own copy of _is_retryable_dependency_error (retry 408, 425, 429 and 5xx; every other 4xx is final) and their own describe+classify step when a call to another server fails. Move the rule into nemo_gym.base_environment_server: - is_retryable_dependency_status / is_retryable_dependency_error hold the one definition of the retried statuses and transient transport errors. - dependency_failure describes the error with describe_dependency_error, classifies it, and builds the protocol's failure model. The three servers now raise dependency_failure at every dependency failure site with the same stage, terminal value and failure_reason text. AgentOutcomePolicyConfig.by_status_code derives its default retry rows from the same rule. nemo_user_sim keeps its participant-activation handling (404 and 409 also retry, and never score the assistant) on top of the shared rule. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test ac44d30 |
…name Signed-off-by: yaoyu-33 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
weijiac0619
left a comment
There was a problem hiding this comment.
LGTM, approved. Thanks for also fixing the URL error.
|
/ok to test b3585ff |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP
LGTM — no reliability concerns.
Reviewed all seven changed files and traced affected failure paths through cleanup, scoring, response contracts, and rollout collection. The shared helper preserves terminal overrides and diagnostic fields. UserSim’s classification guard keeps dependency URL failures unscored while retaining malformed-assistant-response scoring.
Validation was limited to source and regression-test inspection; no tests were executed in this read-only review.
Note: formal approval is not available for this request, so this review is posted as a comment only.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/39999820960 |
What changed and why
Follow-up to #4680 and the request for a shared helper. This consolidates dependency-failure formatting, classification, and construction across
single_agent_turn,harbor, andnemo_user_sim.Three helpers in
nemo_gym.base_environment_serverprovide the shared behavior:is_retryable_dependency_status: retry 408, 425, 429, and server-error statuses, preserving the existing rule.is_retryable_dependency_error: classify HTTP errors by status; retry connection, payload, and timeout errors; treat other errors as final.dependency_failure: format the dependency's reason withformat_exception_with_response_body, bound it to 2,000 characters, classify it, and construct the protocol's failure model.The environment call sites preserve their stages, reason prefixes, explicit terminal overrides, partial responses, observations, and trajectories. The default
AgentOutcomePolicyConfig.by_status_codederives its existing retry rows from the shared rule. UserSim retains its additional retryable/unscorable participant-activation statuses, 404 and 409.Base and conflict resolution
#4680 has merged. This branch now includes
mainate0811535f9c7d99152f4e4a03e333ed79204f442through a merge commit, preserving the existing branch history. The resolution uses the upstream rename fromdescribe_dependency_errortoformat_exception_with_response_bodyand keeps one copy of each refusal regression test.Compatibility and review correction
UserSim previously retried every non-HTTP
aiohttp.ClientError. It now follows the other environments: non-response client errors outside the connection/payload families, such as invalid or non-HTTP URLs, are final if they reach the episode failure boundary.InvalidURLalso inherits fromValueError. UserSim now excludes non-HTTPClientErrorinstances from assistant-error scoring, so a final dependency URL error cannot be attributed to the assistant merely through that inheritance. Genuine malformed assistant responses and the existing scorable HTTP statuses retain their behavior.This is a defensive correction at the failure boundary. The normal internal transport currently retries malformed URL errors until the activation timeout; the added tests inject the real exception types at the episode boundary and do not claim a production network reproduction. Shared transport retries are unchanged.
Validation
Final head:
b3585ff2ccebfa95512064e9f8cea7148e3a80fe.Tests ran on macOS with Python 3.13.14 and aiohttp 3.14.5. UserSim tests used the repository-pinned UserSim source
a5f676bf6dc5a73914c8a0860f97c10dd2c214ee. The launcher usedpython -S, explicit dependency paths, and module-path assertions to bind imports to the reviewed checkout. Pytest options were--import-mode=importlib -o addopts= -o log_cli=false -q; UserSim explicitly loadedpytest_asyncio.plugin.tests/unit_tests/test_environment_server.py,test_server_utils.py,environment_servers/single_agent_turn/tests,environment_servers/harbor/teststests/unit_tests/test_checkpoint_agent.py,test_checkpoint_environment.py,test_environment_scaffold.pytests/unit_tests/test_harness_conformance_ci.pyenvironment_servers/nemo_user_sim/testspre-commit run --all-filesThe nine Harbor failures all reproduce on unchanged base
e0811535fwith the same supported aiohttp version: one macOS compose/tmp-path assertion and eight verifier filesystem/shell cases. The base comparison ran the failing compose case plustest_verifier_filesystem.py: 13 passed, the same nine failed.The four new invalid-URL regression cases failed before the guard and passed after it. They cover both
InvalidURLandInvalidUrlRedirectClientError, asserting final episode failure and no verification while preserving the transient connection-error case. Existing malformed-response zero-reward tests still pass.Claude Code ran a team review with independent contract and bug/test reviewers, a challenger, and a fresh final-delta reviewer. Independent Codex review and challenge also checked the final correction. No remaining actionable finding was identified. Reviewer source inspection is separate from the test execution above.
Rollout evidence
N/A for model inference: this refactor preserves successful episode and scoring behavior; the intentional change and defensive correction concern dependency-error classification. Those paths are exercised with real exception classes at the episode boundary and require no model output. No paid model rollout or full benchmark was run.