Skip to content

refactor(env): share dependency-failure classification across environment servers - #4945

Merged
yaoyu-33 merged 12 commits into
NVIDIA-NeMo:mainfrom
yaoyu-33:refactor/share-dependency-failure-classification
Oct 23, 2026
Merged

yaoyu-33 merged 12 commits into
NVIDIA-NeMo:mainfrom
yaoyu-33:refactor/share-dependency-failure-classification

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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, and nemo_user_sim.

Three helpers in nemo_gym.base_environment_server provide 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 with format_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_code derives 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 main at e0811535f9c7d99152f4e4a03e333ed79204f442 through a merge commit, preserving the existing branch history. The resolution uses the upstream rename from describe_dependency_error to format_exception_with_response_body and 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.

InvalidURL also inherits from ValueError. UserSim now excludes non-HTTP ClientError instances 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 used python -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 loaded pytest_asyncio.plugin.

Scope Result
tests/unit_tests/test_environment_server.py, test_server_utils.py, environment_servers/single_agent_turn/tests, environment_servers/harbor/tests 631 passed, 9 failed
tests/unit_tests/test_checkpoint_agent.py, test_checkpoint_environment.py, test_environment_scaffold.py 120 passed
tests/unit_tests/test_harness_conformance_ci.py 53 passed
environment_servers/nemo_user_sim/tests 33 passed
pre-commit run --all-files Passed

The nine Harbor failures all reproduce on unchanged base e0811535f with 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 plus test_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 InvalidURL and InvalidUrlRedirectClientError, 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.

yaoyu-33 and others added 10 commits October 19, 2026 16:32
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]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 22, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test ac44d30

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:env-infra Shared environment framework, lifecycle, registry, scaffolding, and validation feature New capabilities, enhancements, or enablement work labels Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@yaoyu-33
yaoyu-33 marked this pull request as ready for review October 23, 2026 17:06
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 23, 2026

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

LGTM, approved. Thanks for also fixing the URL error.

@yaoyu-33
yaoyu-33 enabled auto-merge October 23, 2026 17:41
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test b3585ff

@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

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.

@yaoyu-33
yaoyu-33 added this pull request to the merge queue Oct 23, 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/39999820960

Merged via the queue into NVIDIA-NeMo:main with commit 925371c Oct 23, 2026
55 of 58 checks passed
@yaoyu-33
yaoyu-33 deleted the refactor/share-dependency-failure-classification branch October 23, 2026 18:30

This branch was previously deployed

1 inactive deployment
public — b3585ff2 Deployed Oct 23, 2026 by copy-pr-bot[bot] via release / finalize / notify #6891
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants