Skip to content

feat(gym-v): add visual environments with optional context compaction - #5983

Merged
yfw merged 46 commits into
NVIDIA-NeMo:mainfrom
aroshanghias-nvd:gym-v-visual-environments
Nov 26, 2026
Merged

yfw merged 46 commits into
NVIDIA-NeMo:mainfrom
aroshanghias-nvd:gym-v-visual-environments

Conversation

@aroshanghias-nvd

@aroshanghias-nvd aroshanghias-nvd commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Add Gym-V resources and Responses API agent components for visual reset/action/step/verification episodes, with optional capture-backed context compaction. The default retains full history; the compaction overlay retains first-plus-latest-two reasoning/images while preserving actions and observation boundaries. It uses measured admission and the shared client/policy from #3368.

Context-management dependency #3368 is merged. This PR targets NVIDIA-NeMo/Gym main and incorporates upstream da75c436c3a17ba942a5b59ba31c0757727f59f5. Review the adapter-only diff. Both game adapters remain independent siblings; their common admission helper, core export and test helper are identical. No separate issue is needed for this scoped adapter integration.

The scope cleanup removes optional debug/transition plumbing and experiment-specific helpers while retaining the shared compaction client, capture identity, history boundaries, native reward and lifecycle protections. The November 20 refresh updates the four affected component locks to reflect upstream's optional Ray/E2B bounds. Resolved package versions, sources and simulator revisions are unchanged.

The adapter owns resource sessions, bounded cleanup and verification retries; infrastructure failures are masked, while legitimate model failures remain scored. Native accumulated reward remains the default; the qualification workload explicitly selects binary task success. Includes isolated component dependencies, deterministic smoke preparation, verifier fixtures, usage aggregation and rollout/capture identity propagation. Component-local pytest importlib mode and namespace-package discovery prevent provider/module shadowing during tests. No shared resources package marker or edits to existing Aviary components are needed.

Validation — November 20 refresh

Scope cleanup: the component-local discovery replacement passed 70 Gym-V resource tests plus 73 agent/workload tests, and 73 VisGym resource tests plus 89 agent/workload tests, with no skips. Both full pre-commit and resource lock checks passed. Aviary and the shared resources package layout match upstream main. Normal per-component CI discovers the local pytest configuration automatically; combined tests from the repository root should select --import-mode=importlib -o consider_namespace_packages=true. The public API checks below preceded this test-discovery-only cleanup.

  • Fresh locked Python 3.13.14 resource environment; 143 resource/agent/workload tests passed, including real provider reset/step and actual manifest verifier validation.
  • Reproduced two public-API contract failures in the shared test helper and component-setup test. Fixed five imports per adapter, with no gameplay runtime change. 1,118 public-API tests passed on each branch after the fix.
  • 35 affected compaction/HTTP/component-setup tests passed again per adapter after the import correction. These overlap the adapter suite; they are not additional unique cases.
  • Shared context-management suite: 70 passed against the merged parent/current main.
  • Both affected component policy checks and uv lock --check pass. Full repository pre-commit passes, including guardwords and layering. Both new commits are signed off. Root dependency files match upstream main.
  • No new live-model run for this refresh: adapter runtime source is unchanged. The November 10 live evidence below predates this refresh; no learner, all-family or new GPU qualification is claimed.
  • The PR remains full-scope under the current CI classifier because it includes core exports and shared test infrastructure. Full GitHub CI and its combined coverage gate remain unverified; maintainer CI authorization and reviewer approval are still required.

Rollouts

Representative real-model compaction smoke completed on November 10 (job 8838475, exit 0), using Super step_120, 8,192 output tokens, measured 51,200-token context and up to 20 calls. Measurement and generation both explicitly set truncate_history_thinking=false so the model template preserves selected reasoning.

  • Gym-V: 3 episodes, 33 successful captured calls. Both FrozenLake tasks succeeded; DoorKey reached the 20-call limit with a legitimate zero reward.
  • Across both concurrent arms: 5 episodes, 43 HTTP-200 calls, zero infrastructure masks. Every episode exercised image and reasoning omission. Actual staged-token decoding found all 99 selected reasoning occurrences and none of 147 omitted occurrences; image deltas, lineage/digests, finite log probabilities/media and summed usage all reconciled.
  • Two Gym-V action-text comparisons required only removing literal think delimiters from raw tokens to match parsed response text; no fuzzy matching or content loss. Live overflow rejection was not exercised; negative guards have local regression coverage.
  • These are serving/capture/compaction integration checks, not evidence of model quality, learner updates, training resume, every provider family, or typed-turn telemetry. Raw private model traces are not included in this PR.

Compatibility and benchmark impact

Experimental status and verified: false remain. Existing environments are not reconfigured. The legacy-agent relay remains the dispatch boundary; the agent does not claim typed-turn telemetry. The optional overlay uses 20 calls and 8,192/51,200 output/context limits without changing model sampling. Additional task families need their own audited success predicates and assets.

Gym-V is pinned to rohitrango/gym-v at 7ccf14ecb5241f37372dd530accf77f7e7ef5fc6, Apache-2.0. Provider dependencies/assets retain their own licenses; synthetic smoke inputs do not license them. Earlier full-history model smoke covered 25 scored records across five families; the compaction smoke above is narrower and does not establish a qualified 22-game benchmark.

The adapter is extracted from existing NVIDIA-NeMo/Gym work at 22742c13589b610d6af81a87949916b7f682b62f, Apache-2.0, under resources_servers/gym_v and responses_api_agents/gymv_agent. It is not copied from the external simulator implementation; that implementation remains an isolated dependency. No NeMo-RL code is included.

Checklist

  • Read the contributing guidelines; scope and dependencies described above.
  • Local tests completed; prior live-model evidence and current validation limits recorded; repository CI remains pending.
  • Documentation, compatibility requirements and benchmark limits recorded.
  • Full pre-commit passed; new source headers and DCO sign-offs checked.

For contributor CI, a qualified maintainer must authorize the current head with /ok to test 3ce0e4853920dccbecdd083e6459078dc8a1ee50. No trust-gate comment is part of this refresh.

aroshanghias-nvd and others added 30 commits October 6, 2026 12:50
Let training frameworks own capture roots and continuation decisions using request replay evidence and committed coordinates. Preserve completion identity, buffered Responses capture, explicit retry controls, and exact measurement through the ordinary vLLM server.

Keep the existing compaction agent and model intact in this infrastructure layer. The native agent migration is a separate stacked change.

Validation: 618 core/model cases and 56 retained legacy agent/model cases passed on Mac CPU across the documented runs. Combined-head GPU smoke evidence is recorded separately.

Co-authored-by: alexandery <[email protected]>
Signed-off-by: Ali Roshan Ghias <[email protected]>
Preserve concurrent framework capture alongside upstream rollout timing, outbound telemetry, tool-call attribution, and canonical finish reasons. Keep retry suppression effective with metrics and tracing enabled.

Validation: 2,475 affected Gym CPU tests and 184 paired RL compatibility tests passed; two optional custom OpenCode exporter cases skipped. Full pre-commit passed. Fern check passed with the unauthenticated redirect check skipped.
Signed-off-by: Ali Roshan Ghias <[email protected]>
Normalize string input as a user message before capture matching and measurement. Verify unchanged history continues while omitted or changed initial questions start new roots.

Validation: 840 affected Gym CPU tests, three HTTP prefix checks using the actual RL input decision, and pre-commit checks passed.
Signed-off-by: Ali Roshan Ghias <[email protected]>
Move semantic history, policies and the context client into the reusable context_management package. Return ordinary accepted rollout history from simple_agent_with_compaction and use the ordinary vLLM capture server.

Preserve shared termination semantics and remove the replaced legacy compaction session/model with its paired ASR configuration entry. Context management stays optional for external harnesses.

The combined source tree exactly matches the qualified Gym PR head cf90856; no dependency or lockfile changes.

Signed-off-by: Ali Roshan Ghias <[email protected]>
Merge main while preserving rollout dispatch tracing. Validate Responses
conversion before intent registration, shield cancellation failure writes,
reuse connection-safe replay controls, and root ambiguous source candidates
without selecting a parent.

Validated with 2,279 Gym CPU cases, four paired Gym/RL selection and
reconstruction cases, and pre-commit --all-files.

Signed-off-by: Ali Roshan Ghias <[email protected]>
Replace removed _retry arguments in context measurement, generation, and resources calls. Exercise the real ServerClient retry stack against aiohttp's accepted arguments, preserving safe connection retries and refusing ambiguous resends.

Signed-off-by: Ali Roshan Ghias <[email protected]>
Merge Gym main at 4945282. Retain upstream output-budget classification in both backend routes and source-history worker-acknowledged refusal handling.

Signed-off-by: Ali Roshan Ghias <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work blocked Work cannot move forward until an external dependency is cleared labels Nov 16, 2026
Integrate the validated source tree while retaining the published PR history.

Signed-off-by: Ali Roshan Ghias <[email protected]>
Integrate the validated source tree while retaining the published PR history.

Signed-off-by: Ali Roshan Ghias <[email protected]>

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

Verdict: HOLD. This is not ready to merge yet, but each of the two blockers has a small, tested fix.

The two blockers are the plain 409s that turn the required core test red (resources_servers/gym_v/app.py:169) and the capture key that drops NeMo RL's rollout ID (responses_api_agents/gymv_agent/app.py:436-446). Please also fix the four risks before merge. Each one is small and has a tested fix:

The notes can follow.

The agent's own session path is careful: an abort, a cancellation or a failed /verify call closes the session and discards its reward. The five shipped success predicates match each game's real win condition.

Process: the PR merges with main without a conflict, and all commits have a DCO sign-off. In CI only the early jobs ran (lint, locks, DCO, copyright, secrets), and they pass. The unit and server tests wait for a maintainer's /ok to test on the current head 9549d4236434382014a56013488637727c38d2a4. The PR description names an older SHA, 3ce0e4853920dccbecdd083e6459078dc8a1ee50. The core job will be red until the 409 change lands. Locally, pre-commit run --all-files on main merged with this PR passes every hook, and scripts/component_locks.py passes.

Shared files: the PR adds one core export, NeMoGymMessageForTraining, which is additive and not used by NeMo RL. It also adds two files in shared places, responses_api_agents/visual_context.py and tests/helpers/visual_context_contract.py, and only this agent uses them. With the file move (responses_api_agents/visual_context.py:1) and the union removal (resources_servers/gym_v/schemas.py:45-60), the PR touches no shared file. #5984 has byte-identical copies of all three files, so the same changes apply there.

A faster path, if you want one: move the compaction overlay to a follow-up PR. That takes five comments out of this PR: environments/gym_v/config.yaml:42, responses_api_agents/visual_context.py:51, responses_api_agents/gymv_agent/app.py:163, responses_api_agents/visual_context.py:1 and responses_api_agents/gymv_agent/README.md:12-16. This is a choice, not a requirement. The capture-key fix still applies to the full-history path.

Rollout evidence: the November 10 run covered only the compaction overlay, and it predates main's capture changes. After the fixes, one run of environments/gym_v/config.yaml on the five example rows at the new head will show the default path.

Generated by Claude Code

Comment thread resources_servers/gym_v/app.py Resolved
Comment thread responses_api_agents/gymv_agent/app.py Resolved
Comment thread responses_api_agents/gymv_agent/app.py Resolved
Comment thread resources_servers/gym_v/app.py Resolved
Comment thread environments/gym_v/config.yaml Resolved
Comment thread resources_servers/gym_v/app.py Resolved
Comment thread resources_servers/gym_v/app.py Resolved
Comment thread environments/gym_v/config.yaml Resolved
@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Nov 24, 2026
@aroshanghias-nvd

Copy link
Copy Markdown
Contributor Author

@yfw, pushed the review fixes in 304f3b1 and 4eb7dc1; the current head is 4eb7dc1af65c665ffc24fad4d8dee926cccc57cc. I replied to all 18 inline threads with the corresponding changes or scope decision.

The fixes cover the conflict exception contract, capture owner/sampling/skip propagation, model-infrastructure failure handling, all seven MiniGrid invalid-action wrappers, overlay instance naming, source-history admission, call/token caps, caller instructions and nested boxed actions. Helpers now live with their component, the copied core union/export is removed, and failed typed construction remains retryable through the existing framework fence.

Validation on the pushed source: 76 resource tests and 116 agent/HTTP/workload/core-session checks passed, plus full pre-commit. The new failed-construction regression reproduced the old behavior before the fix.

Live E2E validation is still incomplete. At the latest job check, the full-history smoke reached model readiness but failed in the test launcher's directory creation before any rollout; the compaction learner was still queued. No new live rollout, optimizer-update or checkpoint/resume pass is claimed. The earlier November 10 rollout evidence does not validate these new changes.

The optional migration to another harness remains outside this PR. I have left the review threads open for your verification.

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

All 18 review comments are fixed at 4cbf92d, and the threads are resolved. Before approval, please add one real rollout at the current head.

The fixes change what the agent does. A failed model call now ends the episode without a score. The model also gets only the row's instructions as its system prompt. The November 10 run covered only the compaction overlay, and it came before these changes.

Please run environments/gym_v/config.yaml without the overlay on the five rows in environments/gym_v/data/example.jsonl. In the Rollouts section, please give the model, the reward and task_success for each row, and what the agent and the verifier did. If the launcher's directory error stops the job again, please post the error here.

Generated by Claude Code

@aroshanghias-nvd

Copy link
Copy Markdown
Contributor Author

Tested the current head 4cbf92d using environments/gym_v/config.yaml directly, with the five original example rows and token budgets, full history, and no compaction overlay.

Model: Super step_120 (NemotronH_Omni_Reasoning_V3), thinking enabled, served on one four-GPU node.

Example Reward Task success
FrozenLake 0 false
GameOfLife 0 false
DoorKey 0 false
GridComponent 1 true
TreeEvenPartitioning 0 false

All five episodes completed verification without infrastructure masking. All 80 model calls returned HTTP 200; 37 reached their output-token limit.

For a concrete successful episode, GridComponent returned \boxed{1}, and verification reported reward 1 and task success. DoorKey completed 50 calls without solving the task; its retained history reached 39 images.

The initial serving configuration allowed only 21 images, which blocked longer histories. Raising the server-side allowance to 65 fixed that without changing agent behavior or shortening episodes.

These are inference/verification results. The separate latest-commit RL test remains queued.

Model serving used temperature 1/top_p 1 to match the NeMo-RL endpoint’s sampling profile; the example rows request temperature 0.7. Agent/resource defaults were preserved.

@yfw

yfw commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

/ok to test 4cbf92d

@yfw
yfw enabled auto-merge November 26, 2026 00:13
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 26, 2026 00:13
@yfw
yfw added this pull request to the merge queue Nov 26, 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/45728891133

Merged via the queue into NVIDIA-NeMo:main with commit e597c96 Nov 26, 2026
69 of 71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers benchmark-onboarding Self-contained benchmark onboarding blocked Work cannot move forward until an external dependency is cleared feature New capabilities, enhancements, or enablement work risk:high Autobot PR risk: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants