Repository navigation
fix(core): close shared aiohttp clients on their owner loop - #4823
Merged
JeffPengCoder merged 3 commits intoOct 28, 2026
Merged
JeffPengCoder merged 3 commits into
JeffPengCoder merged 3 commits into
Conversation
The process-wide data client and the reserved control client were closed at exit with asyncio.run(), i.e. on a new event loop rather than the loop that created them. Record the owner loop and close both clients there: schedule the close when called from the owner loop, hand it to the owner loop when that loop runs in another thread, and run it to completion otherwise. close_global_aiohttp_client() offers the same close to async callers. Clients also stop dialing wildcard bind addresses: a server bound to 0.0.0.0 or :: is reached at 127.0.0.1 or [::1]. A proxy-aware HTTP client can otherwise send a request for 0.0.0.0 to an external proxy instead of the local server. Split from NVIDIA-NeMo#3591. Signed-off-by: Jeff Peng <[email protected]>
JeffPengCoder
added a commit
to JeffPengCoder/Gym
that referenced
this pull request
Oct 21, 2026
…#4822 and NVIDIA-NeMo#4823 The sandbox-provider changes (Docker create reconciliation, E2B service endpoints and transport fallback, OpenSandbox endpoint compatibility, the e2b>=2.46.0 range) now live in NVIDIA-NeMo#4822, and the owner-loop close of the shared aiohttp clients with wildcard-host handling lives in NVIDIA-NeMo#4823. Restore those 16 files to this branch's main base so each change is reviewed in exactly one PR. Nothing else in this PR uses them; it keeps the component runtime policy, rollout identity and the vLLM transport-log context. Signed-off-by: Jeff Peng <[email protected]>
zyzhou5
pushed a commit
to zyzhou5/Gym
that referenced
this pull request
Oct 21, 2026
…VIDIA-NeMo#3591) * fix(core): isolate runtime, sandbox and model transport contracts Extract shared support from JeffPengCoder/Gym 360b0df. Include E2B endpoint/transport and vLLM model changes; retain upstream GymAiohttpTransport while preserving the no-config Ray worker fallback. Keep OSWorld tasks, agents and resources out of this PR. Signed-off-by: Jeff Peng <[email protected]> * fix(e2b): align SDK installation guidance with gateway requirements Signed-off-by: Jeff Peng <[email protected]> * fix(cli): keep site-packages off server import paths in wheel installs In a wheel install the built-in servers live in the parent interpreter's site-packages, so dir_path.parent.parent is that site-packages. Passing it as project_root put it first on each server's PYTHONPATH and NEMO_GYM_EXTRA_ROOTS, ahead of the server venv's own pinned dependencies. Apply the source-checkout guard the verifier runner already uses, and test both layouts; the wheel-install case fails without the guard. Signed-off-by: Jeff Peng <[email protected]> * fix(rollout): keep index-derived capture ids and gate dispatch logging Rows without a caller-supplied _ng_rollout_id no longer receive a random rollout-<uuid4>. The capture key stays main's {task}-{rollout}, so a resumed attempt decodes to the same rollout as attempt 0 and existing capture files keep their names. A caller-supplied id is still forwarded unchanged. Rows are no longer mutated, so the per-dispatch deep copy is removed as well. The per-dispatch summary is printed only when request debugging is enabled, like the reverification summary. The summary drops the NeMo-RL purpose and trajectory-identity fields and adds only the core _ng_rollout_id. Signed-off-by: Jeff Peng <[email protected]> * fix(vllm): drop the per-request purpose marker The marker printed on every chat-completion request and ran before sampling overrides and capture/prefix preparation, so it could report temperature and top_p values the engine never received. The opt-in transport log (NEMO_GYM_VLLM_TRANSPORT_LOG) already records the final request body together with the rollout context headers. A test now checks that the log holds the post-override values and that nothing is printed per request. Signed-off-by: Jeff Peng <[email protected]> * chore(agent): drop the legacy compaction session change Publishing the final policy decision only after guard admission changes nothing observable today: a guard rejection raises before build_response, the only place the decision is published. NVIDIA-NeMo#3368 deletes this session, and its replacement client checks guards before generation and acknowledges history only after accepting a response, so the invariant belongs there. Restore session.py and its test to main's versions; this also removes the only conflict with NVIDIA-NeMo#3368. Signed-off-by: Jeff Peng <[email protected]> * chore(core): leave provider and HTTP lifecycle changes to NVIDIA-NeMo#4822 and NVIDIA-NeMo#4823 The sandbox-provider changes (Docker create reconciliation, E2B service endpoints and transport fallback, OpenSandbox endpoint compatibility, the e2b>=2.46.0 range) now live in NVIDIA-NeMo#4822, and the owner-loop close of the shared aiohttp clients with wildcard-host handling lives in NVIDIA-NeMo#4823. Restore those 16 files to this branch's main base so each change is reviewed in exactly one PR. Nothing else in this PR uses them; it keeps the component runtime policy, rollout identity and the vLLM transport-log context. Signed-off-by: Jeff Peng <[email protected]> * fix(core): keep server venvs on the parent Python and fail loudly on pin conflicts - A server's .python-version now selects its interpreter only when it excludes the parent's Python. A request that admits it (such as >=3.13.14,<3.14, 3.13 or [email protected]) builds the venv with the parent's exact version, because Ray rejects processes on different patch releases. Variant and pre-release requests (3.13+freethreaded, 3.13.14+debug, 3.13.14rc1) and requests for other implementations are passed to uv unchanged. Like uv, the first non-comment line is the request. - Only the parent's constraints (the Ray pin) are passed as uv overrides, through process substitution like the existing -c flag. head_server_deps such as openai stay ordinary requirements, so a server pin that conflicts with them fails setup instead of being replaced silently. - Drop the environment-identity file: nothing read it, so it could not detect a stale venv, and its tests passed whatever it contained. - Replace the vacuous vllm_model marker-file test with one that checks the real policy, and document per-server .python-version/uv.toml and NEMO_GYM_ALLOWED_COMPONENT_ROOTS. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]> --------- Signed-off-by: Jeff Peng <[email protected]> Signed-off-by: yaoyu-33 <[email protected]> Co-authored-by: Onur Yilmaz <[email protected]> Co-authored-by: yaoyu-33 <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Oct 22, 2026
This was referenced Oct 22, 2026
This was referenced Oct 27, 2026
yfw
approved these changes
Oct 28, 2026
Contributor
|
/ok to test 18d7d51 |
JeffPengCoder
enabled auto-merge
October 28, 2026 02:15
Collaborator
Author
|
/ok to test 9b3af48 |
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/40640889128 |
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This splits the HTTP-lifecycle changes out of #3591, as suggested in its review.
Owner-loop close. At exit, the process-wide data client and the reserved control client (feat(checkpoint): add the participant control plane, episode steps, and coordination #3882) were closed with
asyncio.run(), on a new event loop rather than the loop that created them. The owner loop is now recorded when the data client is created, and both clients are closed there:close_global_aiohttp_client()gives async callers the same close.Wildcard bind addresses. Gym clients now dial a server bound to
0.0.0.0or::at127.0.0.1or[::1]. Otherwise a proxy-aware HTTP client can send a request for0.0.0.0to an external proxy instead of the local server.There is no separate issue: this is a split of #3591, and #3591 drops these hunks once this lands.
Validation
On macOS ARM64 with Python 3.13.14 and the
devandsandboxdependencies (aiohttp 3.14.4, yarl 1.25.1, FastAPI 0.135.2):tests/unit_tests/test_server_utils.py: 197 passed. Four tests are new: closing on an idle owner loop, closing from the owner loop without blocking it, closing the control client with the data client, and dialing wildcard bind hosts through loopback.968e069c5: 10,889 passed here against 10,884 on main; the 4 new tests all pass. The remaining 27 failures are identical on main and are specific to this macOS machine.pre-commit runon the changed files: passed.Rollouts
N/A. No environment or agent behavior changes. This code was also part of #3591's head in the October 20 OSWorld reproduction (361 tasks, no degradation).
Compatibility and benchmark impact
close_global_aiohttp_client(). Benchmark impact: none.Checklist
pre-commit run --all-files) (so CI lint/format checks pass).git commit -s) (so the DCO check passes).