Skip to content

refactor(core): move the failure modules from #5072 into their packages - #5536

Merged
ananthsub merged 1 commit into
mainfrom
ananthsub/group-failure-modules
Nov 3, 2026
Merged

ananthsub merged 1 commit into
mainfrom
ananthsub/group-failure-modules

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

#5072 added three modules at the top of nemo_gym/ and placed them in the import-linter contract beside core/ and utils/ rather than inside them. It also placed server_runtime/episode_types.py in the core layer, because client/, data/, sandbox/, trajectory/ and verification/ import its failure types, and all of those sit below server_runtime/. The contract held, but it no longer said which package owns these modules, and a reader of server_runtime/ could not tell that five lower packages depend on one of its files.

This PR moves each module into the package of its layer, so every layer of the contract is one package again:

Module New home Why
nemo_gym/exception_inspection.py nemo_gym/utils/exception_inspection.py It imports nothing from nemo_gym.
nemo_gym/typed_exceptions.py nemo_gym/core/typed_exceptions.py It was already in the core layer.
nemo_gym/failure_transport.py nemo_gym/core/failure_transport.py It was already in the core layer.
nemo_gym/server_runtime/episode_types.py nemo_gym/core/episode_types.py It imports only core/, and five packages below server_runtime/ import it.
flowchart BT
  utils["utils/<br/>exception_inspection"]
  core["core/<br/>episode_types, typed_exceptions,<br/>failure_transport, failure_kinds"]
  lower["client/, sandbox/, trajectory/,<br/>verification/, data/"]
  sr["server_runtime/"]
  upper["models/, agents/, rollouts/, eval/"]
  core --> utils
  lower --> core
  sr --> lower
  sr --> core
  upper --> sr
Loading

Arrows mean "imports". Nothing in the contract's ignore_imports list changes.

Imports follow the layout rule:

  • Code inside nemo_gym/ imports each name from the module that defines it.
  • Code outside it imports from nemo_gym.core and nemo_gym.utils.
  • The files feat(eval): report causal failures across service boundaries #5072 changed now import from the packages' public APIs instead of submodules. This makes the public API tests pass again; three of them fail on main today.
  • Names such as MaterializedTask and ModelFailureDetails, which servers imported from nemo_gym.server_runtime, now come from nemo_gym.core.
  • Servers also imported FailureBoundary, FailureReport, BaseEpisodeRequest, BaseEpisodeResponse and EpisodeFailure from nemo_gym.server_runtime.base_environment_server, which only re-imports them. They now import them from nemo_gym.core. The public API tests missed these, because those tests check only names the imported package exports, and the names resolve through the re-import. nemo_gym.server_runtime needs no new exports.

The tests #5072 added at the root of tests/unit_tests/ move into the folder of the package each one tests: agents/, core/, server_runtime/, client/, rollouts/, trajectory/, verification/, orchestration/ or eval/.

Compatibility

  • nemo_gym.episode_types shipped in 0.7.0. Its old-path entry now points at nemo_gym.core.episode_types, so the old import keeps working with a DeprecationWarning until 0.10.0, and its moved names still resolve.
  • The other old paths (nemo_gym.exception_inspection, nemo_gym.typed_exceptions, nemo_gym.failure_transport and nemo_gym.server_runtime.episode_types) never shipped in a release, so they get no old-path entries. NeMo RL does not import any of them.
  • The import snapshot that guards the failure API now records it under nemo_gym.core.typed_exceptions and nemo_gym.core.failure_transport. The test that keeps the failure API from being dropped by accident checks the new paths.

Validation

  • lint-imports: the layer contract is kept, with no new ignored imports.
  • A check that every name code outside the library imports from a public API resolves passes, as do the public API facade tests and the moved-path tests.
  • pytest tests/unit_tests -n 16 on this branch and on main in the same environment: this branch passes everything main passes, plus the three public API tests that fail on main. Two other tests that failed on main in that run (a committed-data schema check and an orchestration telemetry test) pass here. The remaining failures are the same on both, and come from this environment (local timing and missing optional packages).
  • The tests of every touched server that runs here pass, with the same results as on main. The servers covered are single_agent_turn, single_agent_turn_legacy, legacy_agent, swe_together, harbor, beam, genrm_compare, bird_sql, deepswe, swebench_pro, simple_agent, gdp_pdf_agent, codex_agent and kilocode_agent. The nemo_user_sim and miniswe_sandboxed_agent tests need optional packages that aren't installed here, and fail the same way on main; CI runs them.
  • pre-commit run on every touched file passes.

Rollout evidence

N/A: this PR moves modules and rewrites imports. No behavior changes, and the unit suite covers the moved code.

Overlap with open PRs

The token capture rename (#5533) touches 17 of the same files, mostly import lines. The other rename PRs (#5526, #5528, #5531) share two to four files each, such as nemo_gym/_moved_paths.py and the import snapshot. Whichever lands second needs a small rebase.

Issue

Follow-up to the package reorganization tracked in #5166, for the modules #5072 added after it.

@copy-pr-bot

copy-pr-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@ananthsub
ananthsub marked this pull request as ready for review November 3, 2026 20:43
@ananthsub
ananthsub requested a review from a team as a code owner November 3, 2026 20:43
AdamRajfer
AdamRajfer previously approved these changes Nov 3, 2026
#5072 added three modules at the top of nemo_gym/ and listed them in the
import-linter contract beside core/ and utils/ instead of inside them. It
also listed server_runtime/episode_types.py in the core layer, because
client/, data/, sandbox/, trajectory/ and verification/ import its failure
types.

Each module now sits in the package of its layer:
- exception_inspection.py moves to utils/; it imports nothing from nemo_gym.
- typed_exceptions.py and failure_transport.py move to core/.
- server_runtime/episode_types.py moves to core/; it imports only core/.

Each layer of the contract is one package again. None of these paths
shipped in a release except nemo_gym.episode_types (0.7.0), whose old-path
entry now points at nemo_gym.core.episode_types. The import snapshot records
the failure API under its new paths.

Code outside the library imports these names from nemo_gym.core and
nemo_gym.utils. That includes the failure types that servers imported
through server_runtime.base_environment_server, which only re-imports them.
The files #5072 changed import from the packages' public APIs, so the public
API tests pass again. The tests #5072 added at the root of tests/unit_tests
move into the folder of the package they test.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ananthsub/group-failure-modules branch from a82cc46 to b02067c Compare November 3, 2026 20:59
@ananthsub
ananthsub merged commit 020edbd into main Nov 3, 2026
13 checks passed
@ananthsub
ananthsub deleted the ananthsub/group-failure-modules branch November 3, 2026 21:42
ananthsub added a commit that referenced this pull request Nov 3, 2026
AGENTS.md and the API reference page still said that failure_transport,
typed_exceptions and exception_inspection sit directly in nemo_gym/. #5536
moved the first two into core/ and the third into utils/. Drop that
paragraph and say what core/ and utils/ now hold instead.

Signed-off-by: Ananth Subramaniam <[email protected]>
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 3, 2026 22:44
ananthsub added a commit that referenced this pull request Nov 4, 2026
…lure records (#5564)

After #5536 moved episode_types.py into core/, the package held two modules
with overlapping names. episode.py held episode identity and the current
episode's context variables; episode_types.py held the episode wire
envelopes and the failure records. Episode types now have one home, and
each concern has its own module:

- core/episode_types.py: every episode data type, including EpisodeId and
  TaskId, which come back to the module that shipped them in 0.7.0.
- core/episode_context.py (new): the current episode, that is, the context
  variables, the rollout id rules and the verifier invocation id.
- core/failure_records.py (new): failure boundaries, failure events, the
  failure report and the episode failure envelope, beside failure_kinds.py
  and failure_transport.py.

core/episode.py is removed. It never shipped in a release, so it gets no
old-path entry. The old-path entries that pointed into it now point at the
new modules. nemo_gym.episode_types (0.7.0) keeps serving the failure names
that moved out of it until 0.10.0. nemo_gym.core serves the same public
names. The docs redirect for nemo_gym.episode_types now points at the
core/episode_types page instead of the server_runtime page that #5536
removed, and the core/episode page redirects to core/episode_types.

Follow-up to #5166.

Signed-off-by: Ananth Subramaniam <[email protected]>
katerynaCh pushed a commit to katerynaCh/Gym that referenced this pull request Nov 12, 2026
* feat(openhands): run OpenHands in task sandboxes through agent sessions

Add responses_api_agents/openhands_agent, a session-only adapter that runs
the OpenHands Software Agent SDK 1.59.0 headless inside the task sandbox
through SandboxSession. Seed installs a private runtime (a verified
standalone CPython 3.13.14 uploaded from the Agent Server, then the
hash-locked OpenHands packages from PyPI) and refuses seeds it cannot serve.
Every model call, including condenser summaries, goes to the
rollout-prefixed Model Server URL with an x-session-id header. OpenHands
state stays in a session directory outside the task repository and home.

Register openhands_agent as an agent-session type so its unbound config
gets no legacy relay.

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

* fix(openhands): clean terminal output and complete rollout evidence

The first real TB2.1 smoke on ws found three gaps:

- OpenHands 1.59.0's subprocess terminal left bash 5.1+ bracketed-paste
  codes (ESC[?2004h) in tool output. Point INPUTRC at a session file that
  includes the task's readline file and turns bracketed paste off.
- The condenser's summary call was referenced by the invocation, so the
  collector built a policy step from it (TE-9 steps.attempt_accounting).
  Reference it only from its compaction record.
- Sandbox and tool-call records had no sandbox_id (TE-6 sandbox.identity).

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

* test(openhands): build termination failures with harness_termination_failure

Main replaced HarnessTerminationError with the NgFailureEvent that
harness_termination_failure returns (NVIDIA-NeMo#5072, NVIDIA-NeMo#5536).

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

* fix(openhands): keep legacy relays away and list OpenHands in the harness docs

openhands_agent answers /run with 422, so the legacy environment-server
migration now skips it whatever its Resources binding, as it does for
Stirrup. The agent-server docs list it in both harness tables.

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

* docs(openhands): describe the install timing host generically

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

* build(openhands): lock the adapter environment with pyproject.toml and uv.lock

Main manages every component's dependencies with a pyproject.toml and a uv
lock that share the root uv policy. Replace requirements.txt with a
pyproject.toml copied from pi_agent's, declare openhands-sdk and
openhands-tools 1.59.0 so the Agent Server environment pins the versions the
sandbox runtime installs, and lock it with uv 0.13.7.

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

* refactor(openhands): build the sandbox runtime with SandboxPythonRuntime

Replace the adapter's own installer (a standalone CPython uploaded by the
Agent Server, then pip install from PyPI inside the sandbox) with Gym's
SandboxPythonRuntime, as stirrup_agent does. The Agent Server host builds
the runtime with uv at the versions its own environment pins, so the sandbox
needs no network. func-timeout, which openhands-tools pins and which ships
only an sdist, is given as a direct URL with its sha256 so the host builds
it. The runner keeps its openhands-gym name through a link beside python/.

Remove install_openhands_runtime.sh, sandbox_requirements.txt, the runtime
fingerprint and the cross-agent cached_download import; add tests for
runtime reuse, installation, the interpreter link, staging with a background
process, and collection.

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

* build(openhands): replace requirements.txt with a locked uv project

Main now requires each server to commit a pyproject.toml and uv.lock
(NVIDIA-NeMo#4837). The adapter uses the same dependencies as the other sandboxed
agents, so its project and lock match codex_agent's apart from the name.

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

* fix(openhands): grade rollout stops, bound owned sandboxes, and pin the chat API

- Grade a rollout stop that lands before launch, or before the runner records
  its first event, as an empty incomplete run instead of a retryable
  collection failure; a plain deadline without events still fails. Log an
  unreadable result.json.
- Give an agent-owned sandbox a finite default ttl_s and merge the provider's
  default_metadata, sandbox_config.metadata and gym-agent/session/rollout
  labels; refuse an invalid sandbox_provider or sandbox_config with a final
  422 instead of a 500.
- Default the runner's api_mode to chat, so OpenHands does not send gpt-5-style
  model names to /responses; llm_settings can still choose.
- Accept empty request metadata.
- Classify LiteLLM timeouts and connection errors as transport errors before
  the status codes LiteLLM attaches to them.
- Require model_server in the config instead of refusing each seed.
- README: three runner changes, capability level without harness
  conformance, concurrency and session_close_timeout_seconds, the relation to
  swe_agents' OpenHands mode, and condenser call ownership.
- Tests for each fix, plus ported coverage for close, disconnects, stops,
  tolerated tool errors, runner settings and the shipped config.

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

* fix(openhands): refuse unusable provider settings and workdirs at seed

An unknown provider name or malformed provider settings raised while the
provider was built, after the refusal guard, and a non-string workdir in
sandbox_config raised while its path was parsed. Both answered a retryable
500 for a configuration that cannot change. Build the provider inside the
guard and refuse a non-string workdir like an empty one, so both are final
422 refusals.

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

* fix(openhands): record tool results as the model read them

A recorded function_call_output held only the tool's raw output, while the
model read OpenHands' tool message: the output plus the exit-code and
working-directory lines, the no-output timeout notice, truncation, and
the wording of argument errors and rejections. In a TB2.1 smoke, 40 of 51
tool results differed from the captured tool message, 12 of them recorded
empty where the model read a notice.

The runner now records the text of each tool result's to_llm_message()
with the event, and the conversion uses it. The finish answer stays the
agent's own message.

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

* fix(openhands): type a deadline before any model reply

A run that reaches Gym's deadline before any model call returned is now a
failed response with ng_agent_outcome model_transport_error, which the
outcome policy retries by default, instead of a graded incomplete
response or an untyped HTTP 500 when no event was recorded. A rollout
stop and the deadline after a model reply stay graded.

A context-limit stop is incomplete without outcome metadata, since the
policy grades an incomplete response whatever it carries. The README
states the deadline rule, which failed endings are retried, and that an
owned sandbox's egress is open unless provider options restrict it.

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

* fix(openhands): record only observed error facts

A deadline before any model reply no longer stands for an LLMTimeoutError
with model_transport_error: nothing shows a model call was made, so the
response keeps the deadline (stop_reason timeout) with failure kind
unknown, which the outcome policy still retries by default.

The runner follows only explicit causes (raise ... from), so a local error
raised while a provider's HTTP 400 was being handled no longer takes that
status. It records each error's class, module and status, not its text,
which can hold a provider's response body; the traceback goes to the
runner's stderr, and the adapter logs its end when a run fails.

An OpenHands error class no longer stands for an HTTP status: without a
recorded status a model error is unknown instead of a made-up 400, 429 or
503.

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

* fix(openhands): preserve Unicode in JSONL events

Signed-off-by: yaoyu-33 <[email protected]>

* fix(openhands): preserve failure evidence and unknown usage

Signed-off-by: yaoyu-33 <[email protected]>

* feat(openhands): add network_access for agent-owned sandboxes

Like the other session harnesses, network_access (inherit, model_only,
model_and_tools) limits an agent-owned OpenSandbox sandbox's egress through
the shared restrict_sandbox_network. OpenHands keeps no tool grants, so both
restricted values open only the Model Server's host; the Agent Server uploads
the runtime, so setup needs no sandbox network. A borrowed sandbox keeps its
owner's network, so a session that borrows one refuses any other value than
inherit. An unenforceable setting (another provider, or an explicit
provider_options network_policy as well) is a final seed refusal, and the
provider is closed before any sandbox exists.

Merges main first for the shared helper.

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

* fix(openhands_agent): turn off OpenHands' own model retries

OpenHands SDK 1.59.0 retries a model call (num_retries: 5 in the shipped
config, 8-64 s apart) on LiteLLM's RateLimitError, Timeout, 5xx and
connection errors, and on any LiteLLM APIError with status 408, 409, 429
or 5xx. LiteLLM 1.105.7 itself does not retry (OpenHands passes
max_retries=0), but it maps any error whose text mentions a rate limit,
or reads "Request too large", to RateLimitError whatever the status. So
a 409, a 413 "Request too large" or a 400 mentioning a rate limit was
sent five times; checked against a stub server with the pinned SDK.

The adapter now always hands OpenHands num_retries: 0 and refuses the
retry settings in llm_settings, so each model call is sent once and the
Model Server's retries handle transient failures.

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

* test(agentic-if): isolate resume checks from concurrent source changes

Signed-off-by: yaoyu-33 <[email protected]>
(cherry picked from commit 9ba42b1)

* fix(ci): scope release rehearsal changelogs to PR changes

Signed-off-by: yaoyu-33 <[email protected]>

---------

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

This branch was previously deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants