Skip to content

feat: route native tasks through environment servers - #3491

Closed
ananthsub wants to merge 4 commits into
ananthsub/episode-orchestration-08-hermes-sandbox-executionfrom
ananthsub/episode-orchestration-10-rollout-routing
Closed

ananthsub wants to merge 4 commits into
ananthsub/episode-orchestration-08-hermes-sandbox-executionfrom
ananthsub/episode-orchestration-10-rollout-routing

Conversation

@ananthsub

@ananthsub ananthsub commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds mixed compatibility and native taskset routing, then carries the selected Environment Server identity through persistence, retries, failures, and aggregation.

  • Materialized rows route from task_id.taskset through environment_server_routes and are posted as native episode requests.
  • Flat rows retain compatibility routing through the Environment Server fronting their agent.
  • Native success responses expose top-level reward and agent observations to existing collection logic.
  • Native failures go to the failure sidecar and preserve terminal/retry semantics.
  • Aggregation groups by _ng_environment_server, unwraps native verification responses, and rejects stale server stamps.
  • Shard globs exclude *_failures.jsonl sidecars.

This is the single-agent-turn collection flow; other Environment Server protocols may use different request and result shapes. Previous: #3715. Next: #3492.

No issue is linked because this is one layer of the existing Environment Server stack.

Validation

  • uv run pytest tests/unit_tests/test_rollout_collection.py tests/unit_tests/test_global_config.py tests/unit_tests/test_reward_profile.py tests/unit_tests/test_episode_types.py -q — 422 passed
  • uv run pytest tests/unit_tests/test_rollout_collection.py::TestExpandInputGlob -q — 9 passed

Rollouts

See the final integration PR for end-to-end rollout evidence.

Compatibility and benchmark impact

Flat-only batches retain existing behavior. Materialized rows require an explicit taskset route. Result artifacts gain the Environment Server stamp; native failures are no longer misclassified as zero-reward successes.

@ananthsub
ananthsub added this pull request to stack #3493 September 17, 2026 16:31
@copy-pr-bot

copy-pr-bot Bot commented Sep 17, 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 changed the title ananthsub/episode orchestration 10 rollout routing feat: route rollouts through episode processors Sep 17, 2026
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch from cb2c127 to 627e1c2 Compare September 17, 2026 20:17
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch 2 times, most recently from 0800040 to b0fd1f0 Compare September 18, 2026 00:55
@ananthsub ananthsub changed the title feat: route rollouts through episode processors feat: route rollouts through environment servers Sep 18, 2026
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch from b0fd1f0 to 4a168d2 Compare September 18, 2026 01:06
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch from 4a168d2 to 928e01b Compare September 18, 2026 01:32
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch from 928e01b to c2cc51d Compare September 18, 2026 20:44
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch from c2cc51d to 0b41dfb Compare September 18, 2026 21:36
@ananthsub
ananthsub removed this pull request from stack #3493 September 18, 2026 22:09
@ananthsub
ananthsub added this pull request to stack #3546 September 18, 2026 22:11
@ananthsub ananthsub changed the title feat: route rollouts through environment servers feat: route native tasks through environment servers Sep 18, 2026
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch from 0b41dfb to 7b349ad Compare September 18, 2026 22:22
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch from 7b349ad to 952a1a0 Compare September 18, 2026 22:27
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch 2 times, most recently from 4b3c7b8 to aa97910 Compare September 18, 2026 22:34
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch 2 times, most recently from 9b03b21 to a22e9d1 Compare September 22, 2026 16:47
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch from a22e9d1 to 30d46f8 Compare September 22, 2026 17:37
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch from 30d46f8 to 6a43738 Compare September 23, 2026 16:33
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch from 6a43738 to 041154b Compare September 23, 2026 16:36
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch from 041154b to 7842d93 Compare September 23, 2026 16:42
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch from 7842d93 to e44378e Compare September 23, 2026 16:49
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch from e44378e to 97b5362 Compare September 23, 2026 17:10
@ananthsub
ananthsub force-pushed the ananthsub/episode-orchestration-10-rollout-routing branch from 97b5362 to 934c327 Compare September 23, 2026 17:13
ananthsub and others added 4 commits September 28, 2026 07:47
…ts per row (#3576)

## What does this PR do?

Lets one rollout-collection batch mix native (materialized) tasksets and
compatibility-routed flat rows, with no new agent × resources pairing,
and keeps the chosen environment server's identity on every row through
shards, retries and results.

- A materialized task (`task_id.taskset` plus `task_input`) now routes
by `environment_server_routes` in **every** `environment_routing_mode`;
it is the native episode request and no agent-server `/run` accepts it.
- A flat row keeps following the mode: `agent` (default) resolves the
row's own environment server at dispatch, as today; `legacy` sends every
flat row to `environment_server_name`; `taskset` stays native-only and
rejects flat rows, so a native run cannot silently pick up legacy input.
- A materialized row whose taskset has no entry in
`environment_server_routes` fails at preprocessing with the missing
route named. (#3491 no longer has a `tasksets` config block, so routes
are the only declaration.)
- Two knobs that cannot apply to a materialized row now fail with the
fix named instead of a `KeyError`: `num_repeats_add_seed` (the seed
lives in the top-level prompt, which a materialized row keeps under
`task_input`).
- No config or YAML changes: routes point at existing environment-server
deployments, and flat rows reach the `legacy_agent` servers that #3490
generates in front of each existing pairing.

The `_ng_environment_server` stamp, written once at preprocessing,
already reaches the materialized input file, resume retries
(`_load_from_cache` re-reads the stamped rows) and result rows; this PR
does not change that path.

## Interaction flow

```mermaid
sequenceDiagram
    participant C as Rollout collector
    participant N as Native environment server, one per taskset route
    participant L as legacy_agent environment server, one per pairing
    participant A as Agent server

    Note over C: preprocess stamps _ng_environment_server once per row
    Note over C: materialized row routes by task_id.taskset, flat row follows the routing mode
    C->>N: POST /run with the episode request, episode_id plus task
    C->>L: POST /run with today's flat row
    L->>A: relay /run
    N-->>C: SingleAgentEpisodeResponse
    L-->>C: legacy result
```

## Stack position

Stacks on #3491 (part 12,
`ananthsub/episode-orchestration-10-rollout-routing`) and touches only
`nemo_gym/rollout_collection.py`, which #3492 does not modify. It can be
squashed into #3491 if preferred, since it changes the semantics of the
routing mode that PR introduces.

Follow-up (separate PR): aggregate metrics grouped by
`_ng_environment_server` instead of `agent_ref.name`, and native
`failure` replies written to the failures sidecar, so identity also
persists through `gym eval aggregate` and retries of native episodes.

## Validation

- `pytest tests/unit_tests/test_rollout_collection.py
tests/unit_tests/test_global_config.py -q` → 383 passed.
- Adversarial review (four lenses, two independent refuters per finding,
each reproduced against the code): the two surviving findings
attributable to this PR are fixed in the second commit.
- New tests in `TestEnvironmentServerRouting`: a mixed batch dispatches
the native row to its taskset's route as an episode request and the flat
row to the server fronting its agent as today's flat body; a
materialized row without a route fails before dispatch; `legacy` mode
stamps flat rows with `environment_server_name` and materialized rows by
taskset, then dispatches both through `run_examples` against a
`legacy_agent` server that binds no resources server;
`num_repeats_add_seed` on a materialized row fails before dispatch;
`taskset` mode still rejects flat rows.
- `ruff check` and `ruff format --check` pass.

## Compatibility and benchmark impact

Default behavior for flat-only batches is unchanged. Materialized rows
in `agent` mode previously had no route and could not be dispatched;
they now require `environment_server_routes`, which is what `taskset`
mode already required.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Adil Asif <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…tive failures, retries and aggregation

A native environment-server reply (`BaseEpisodeResponse`) is projected when the
collector persists it: a handled `failure` becomes a failures-sidecar row with
`_ng_failure_class=environment_server_failed`, `_ng_failure_terminal` from the
reply, and the row's `_ng_environment_server` stamp, so resume retries a
non-terminal failure on the same server and never a terminal one; a `result`
keeps the native record and gains the top-level `reward` and mask flag that
progress accounting and the health check read.

`/aggregate_metrics` is grouped by the environment server stamped on each row,
falling back to the server that fronts the row's agent as before, and native
records are unwrapped to their `result.verification` before scoring. Each entry
in `_aggregate_metrics.json` now names its `_ng_environment_server` beside the
`agent_ref` label, and `gym eval aggregate` inherits the grouping because result
rows carry the stamp across shards.

A run that configures `environment_server_routes` sets up the environment-server
client even in the default routing mode, so stamped rows resolve against the
merged config.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
…agent observations, keep aggregate labels distinct

Projection of a BaseEpisodeResponse now happens only for rows the collector
dispatched as native episode requests, and the shape check requires object
identities, so a legacy verify reply that echoes identity fields is never
turned into a sidecar row. A non-object `failure` fails with the episode
named instead of an AttributeError outside the dispatch guard.

A native result lifts `result.agent_observations` to `ng_agent_observations`,
as the legacy adapter does, so trajectory capture and the health check see
the agent's evidence. Collector-stamped `ng_perf` travels with the unwrapped
record into `/aggregate_metrics`.

Aggregation labels: two environment servers bound to one agent (a native
server and its legacy_agent twin) produced duplicate `agent_ref` entries,
which `gym eval compare` rejects; the second is now labelled by its own
name. A stamped server missing from the aggregate-time config fails naming
the server and the available ones instead of an omegaconf KeyError.

The end-to-end resume test no longer installs a global-config fallback, so it
fails if a run with routes does not set up the environment-server client.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
@ananthsub

Copy link
Copy Markdown
Contributor Author

Closing to recreate the remaining Environment Server work as one correctly ordered GitHub Stack. Branch commits are preserved; a replacement PR will follow.

This branch was successfully deployed

No deployments
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