Skip to content

docs(architecture): describe Environment Server episode orchestration - #4711

Merged
yaoyu-33 merged 3 commits into
mainfrom
yaoyu-33/docs-architecture-environment-server
Oct 20, 2026
Merged

yaoyu-33 merged 3 commits into
mainfrom
yaoyu-33/docs-architecture-environment-server

Conversation

@yaoyu-33

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

Copy link
Copy Markdown
Contributor

What does this PR do?

Describe the Environment Server on the architecture page. The page still shows the agent calling seed_session and verify itself; with a native Environment Server, such as single_agent_turn, it orders those calls.

  • Add an "Episode orchestration" row to the component table.
  • Describe an episode under a native Environment Server in four steps (seed, agent loop, close and verify, clean up) with a sequence diagram.
  • Add an Environment Server section under Server Types.
  • Describe the legacy_agent relay, which most shipped configurations still use: the agent runs the whole episode itself, including seed_session and verify.
  • Add a sandbox-ownership note: the Resources Server creates and destroys the task sandbox, and under a native Environment Server the agent borrows it.
  • Note that sandbox execution and file transfer use the sandbox provider's transport, not Gym HTTP calls.

This is the architecture-only part of draft #3917, split out so the concept change can be reviewed on its own. It is the bottom of a three-PR stack:

  1. this PR;
  2. the harness guide, a new page that is unchanged from docs(agent): add harness onboarding and upgrade guide #3917;
  3. the agent-server page restructure.

Tracks GYM-1011.

Validation

October 20 main sync (f648c4987fb7313ef0ef7579da3f7aa8db311a7f)

Synchronized the stack with main 1266a119a7606124f7f6c367a78d9b2e191eddf6 using signed-off merge commits. Main already contains the mini-SWE dependency/runtime isolation fixes in #4733 and #4735 for the required shard-2 failure observed on #4711. The approved documentation is byte-for-byte unchanged from the preceding source commit, and the diff against the updated stack base remains documentation-only.

Validation on this synchronized tree:

  • Source-bound tests/unit_tests/test_fern_docs_links.py: 24 passed, 21 subtests passed.
  • npm run check in fern/: 0 errors, 1 warning.
  • pre-commit run --all-files: all applicable hooks passed.
  • git diff --check: passed; no runtime changes relative to the updated base.
  • Model rollouts: N/A for this documentation-only diff. No new upstream-runtime or model-smoke validation is claimed.
  • Fresh CICD run 39475739719 on this exact source: required Nemo_CICD_Test, Lint and DCO all passed. Fern check and docs preview passed. The actual classifier reports docs_only=true, so core/server tests were legitimately skipped. Optional conformance jobs have failures; this is required-check readiness, not an overall workflow-success claim.

Final diff e0a18be3d:

  • pre-commit run --all-files: all applicable hooks passed.
  • python -m pytest tests/unit_tests/test_fern_docs_links.py: 24 passed.
  • fern check --warnings with a cached Fern CLI: 0 errors, 1 warning (redirect validation is skipped without Fern authentication).
  • The Mermaid CLI rendered the sequence diagram without errors.

Review fixes (efc52a63f) scope the episode steps, the table row, the Environment Server section, and the sandbox note to native Environment Servers, and add the legacy_agent paragraph. After them:

  • python -m pytest tests/unit_tests/test_fern_docs_links.py: 24 passed.
  • pre-commit run --files fern/versions/latest/pages/about/architecture.mdx: passed.
  • Not rerun: fern check and the Mermaid render (the diagram is unchanged).

Not done: a full-page Fern preview.

Rollouts

N/A: documentation only; no runtime behavior changed.

Compatibility and benchmark impact

None. Compared with the architecture changes in #3917, the sandbox-ownership note no longer links to the harness guide, which lands in the next PR.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification.
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass).
  • New source files include the required Apache-2.0 SPDX header (N/A: no source files).
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

🤖 Generated with Claude Code

Add the Environment Server to the architecture page: a table row, an
episode lifecycle (seed, agent loop, close and verify, clean up) with a
sequence diagram, a server-type section, a sandbox-ownership note and a
sandbox-transport note. Split from #3917 so the concept change can be
reviewed on its own; the harness guide and agent-server pages follow.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 17, 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
yaoyu-33 added this pull request to stack #4714 October 17, 2026 15:49
@yaoyu-33 yaoyu-33 changed the title yaoyu 33/docs architecture environment server docs(architecture): describe Environment Server episode orchestration Oct 17, 2026
@yaoyu-33 yaoyu-33 added docs Documentation-only updates or documentation debt area:docs Generic documentation without another dominant domain labels Oct 17, 2026

@yaoyu-33 yaoyu-33 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Team review of #4711 (docs only: about/architecture.mdx).

The native single_agent_turn flow on this page matches the code step for step: endpoint order, activation, close before verify, cleanup on failure, sandbox ownership for SWE-bench Pro and Terminal Bench 2.1, and the provider transports. Links and the new #environment-server anchor that #4712 and #4713 rely on resolve, the Mermaid diagram renders, and test_fern_docs_links.py and fern check pass.

The inline comments cover one issue: the page now presents the native Environment Server flow as the only one, while the legacy_agent relay is still the default path. The agent-owned flow is still described in system-design.mdx and resources-server-apis.mdx, but it is gone from this overview page, which tutorials link to for the full architecture.

Process

  • CI has not run yet; copy-pr-bot is waiting for /ok to test <sha>.
  • Two checklist boxes are unchecked: "read the contributing guidelines" and "the change is focused".

Not in this PR's scope: the unchanged "Retry logic with exponential backoff (3 attempts)" bullet (L106) is inaccurate for calls between Gym servers (fixed 0.5 s delay; ServerClient calls retry without the 3-attempt cap, server_utils.py L765-782). AGENTS.md repeats the claim, so it fits a separate small PR.

Reviewed by 4 agents (core-library expert, bug finder, test agent, devil's advocate) plus a stack-wide comment reviewer.

Generated by Claude Code

E->>R: close_session
```

The Agent Server does not decide when to verify. The Environment Server orders the calls, so a different agent or a different benchmark can be swapped in through configuration, with no pair-specific launcher. The built-in `single_agent_turn` Environment Server runs one agent turn against one Resources Server. Other interaction patterns, such as a simulated user, define their own Environment Server.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

architecture.mdx:68

[DOC] RISK. The new steps (L37-42) and this paragraph read as if every episode runs this way. Most shipped configurations still run through the legacy_agent Environment Server (about 515 YAML files, against 6 that use single_agent_turn or single_agent_turn_legacy), and Gym generates that relay for any agent that no Environment Server names (global_config.py#L1150-L1157). On that path the agent's own /run calls seed_session and verify (simple_agent/app.py#L811-L813, #L909), and calls /close_session only when checkpointing is on (#L944-L946). Tutorials such as single-step-environment.mdx send readers here for the full architecture, so could we scope this paragraph to native Environment Servers and keep a short description of the relay path? The same scoping is suggested at L37, L74, and L25.

Suggested change
The Agent Server does not decide when to verify. The Environment Server orders the calls, so a different agent or a different benchmark can be swapped in through configuration, with no pair-specific launcher. The built-in `single_agent_turn` Environment Server runs one agent turn against one Resources Server. Other interaction patterns, such as a simulated user, define their own Environment Server.
With a native Environment Server, the Agent Server does not decide when to verify. The Environment Server orders the calls, so a different agent or a different benchmark can be swapped in through configuration, with no pair-specific launcher. The built-in `single_agent_turn` Environment Server runs one agent turn against one Resources Server. Other interaction patterns, such as a simulated user, define their own Environment Server.
Most shipped configurations still use the `legacy_agent` Environment Server, which Gym also generates by default for any agent that no Environment Server names. It relays `/run` to the agent, and the agent runs the whole episode itself, including any `seed_session` and `verify` calls. Cleanup then depends on the agent, so Resources Servers on this path usually release per-task state in `verify()` (see [Session Cleanup](/main/environment-tutorials/resources-server-apis#session-cleanup)). For that request flow, see [System Design](/main/infrastructure/engineering-notes/system-design).

│ → text, tool calls, │ │ my_tool(): execute action │
│ or code │ │ verify(): evaluate → reward │
└───────────────────────────┘ └────────────────────────────────────┘
Each task attempt is an *episode*. An Environment Server runs it in order, and the resulting trajectory is called a *rollout*:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

architecture.mdx:37

[DOC] RISK (same finding as L68). Scope the ordered steps to native Environment Servers, since legacy_agent relays /run and the agent orders the calls itself (legacy_agent/app.py#L110-L122).

Suggested change
Each task attempt is an *episode*. An Environment Server runs it in order, and the resulting trajectory is called a *rollout*:
Each task attempt is an *episode*. Rollout collection sends every episode to an Environment Server. A native Environment Server, such as `single_agent_turn`, runs it in this order, and the resulting trajectory is called a *rollout*:


### Environment Server

Orchestrates one episode: it seeds the Resources Server and Agent Server sessions, activates the agent, closes the agent session, verifies, and cleans up, including on failure. It binds an agent and a resources server by reference and exposes a `/run` endpoint that rollout collection submits tasks to. It does not implement tools, agent logic, or scoring.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

architecture.mdx:74

[DOC] RISK (same finding as L68). Only native Environment Servers bind an agent and a Resources Server and run the cleanup context. legacy_agent binds only agent_server (legacy_agent/app.py#L57-L62) and routes /run straight to its relay, bypassing run_request and its cleanup (#L88-L92, base_environment_server.py#L238-L249).

Suggested change
Orchestrates one episode: it seeds the Resources Server and Agent Server sessions, activates the agent, closes the agent session, verifies, and cleans up, including on failure. It binds an agent and a resources server by reference and exposes a `/run` endpoint that rollout collection submits tasks to. It does not implement tools, agent logic, or scoring.
Is the entry point for each episode: rollout collection submits tasks to its `/run` endpoint. A native Environment Server, such as `single_agent_turn`, binds an agent and a Resources Server by reference and orchestrates the episode: it seeds the Resources Server and Agent Server sessions, activates the agent, closes the agent session, verifies, and cleans up, including on failure. The `legacy_agent` Environment Server binds only an agent and relays `/run` to it, so that agent runs the episode. An Environment Server does not implement tools, agent logic, or scoring.

| Agent Harness | FastAPI Agent Server |
| Verifier + State | FastAPI Resources Server |
| Model | FastAPI Model Server or managed by your own agent harness |
| Episode orchestration | FastAPI Environment Server, which binds an agent and a Resources Server and runs one episode |

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

architecture.mdx:25

[DOC] RISK (same finding as L68). The table row has the same scope; this wording mirrors new-environment.mdx.

Suggested change
| Episode orchestration | FastAPI Environment Server, which binds an agent and a Resources Server and runs one episode |
| Episode orchestration | FastAPI Environment Server, the entry point for each episode. A native one binds an agent and a Resources Server and runs the episode; `legacy_agent` relays it to an agent that runs it |

@yaoyu-33
yaoyu-33 marked this pull request as ready for review October 19, 2026 16:31
… Servers

Most shipped configurations still run through the legacy_agent relay, where
the agent seeds and verifies itself. Scope the ordered steps, the component
table row, the Environment Server section, and the sandbox-ownership note to
native Environment Servers, describe the legacy_agent path, and stop saying
that agent harnesses orchestrate rollouts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33 yaoyu-33 added area:core Shared APIs, servers, telemetry, health, and registries complexity:low Localized change in one scope with a small, straightforward review surface needs-review PR is ready for code review and waiting on a reviewer and removed area:docs Generic documentation without another dominant domain labels Oct 19, 2026
@ffrujeri

Copy link
Copy Markdown
Contributor

Looks good to me overall. One question before approving, about the Communication section:

The unchanged bullet "Retry logic with exponential backoff (3 attempts)" doesn't match _request_with_retries in nemo_gym/server_utils.py. The delay is a fixed 0.5 s, not a backoff, and calls between Gym servers (ServerClient) have no 3-attempt cap. This PR doesn't introduce the problem, and I see #4754 fixes it. Should that one land first, or is it fine to merge this as-is and leave the fix to #4754?

Either order works, but both PRs touch neighbouring lines in architecture.mdx (this one rewrites "Servers communicate…" right above the retry bullet that #4754 replaces), so whichever merges second may need a quick rebase.

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

Approving. The retry-bullet question above is non-blocking; it can be handled in #4754.

@yaoyu-33 yaoyu-33 added ready-to-merge PR is approved, current, and waiting for final CI or merge and removed needs-review PR is ready for code review and waiting on a reviewer labels Oct 20, 2026
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test efc52a6

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 20, 2026 17:12
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test f648c49

@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/39487822094

Merged via the queue into main with commit 59eab16 Oct 20, 2026
40 of 45 checks passed
@yaoyu-33
yaoyu-33 deleted the yaoyu-33/docs-architecture-environment-server branch October 20, 2026 20:09

This branch was previously deployed

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

Labels

area:core Shared APIs, servers, telemetry, health, and registries complexity:low Localized change in one scope with a small, straightforward review surface docs Documentation-only updates or documentation debt ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants