Repository navigation
feat(server): let servers refuse several workers and share local installs - #4884
Merged
Merged
Conversation
This was referenced Oct 21, 2026
Contributor
…alls With num_workers > 1, run_webserver hands uvicorn the import string <entrypoint module>:app, and each worker imports the entrypoint and serves its module-level app. A server that cannot run in several processes had no standard way to say so: some refused in model_post_init or a config validator, others started and misbehaved. SimpleServer gains multiple_workers_unsupported_reason(), which returns None by default. A server that cannot run with several workers overrides it and returns why, and run_webserver raises "<name> needs num_workers=1: <reason>" before uvicorn starts, and before a dry run returns, so a dry run reports it too. It is a method rather than a class attribute, so a server can decide from its config. nemo_gym.install_lock lets the workers of one server share a local tool install. It provides a file lock across processes (fcntl.flock), an asyncio variant that polls instead of blocking the event loop, and a record of where a finished install put its tool, written atomically so a waiting worker never sees a partial record. The environment scaffold now ends the generated resources server and agent entrypoints with the module-level app, and the scaffold tests check it. The resources server guide and the agent server page describe running several workers, the refusal method, and that concurrency limits such as judge semaphores apply per worker. The tutorials' complete entrypoints and the add-benchmark skill's server pattern end with the module-level app too. Signed-off-by: Ananth Subramaniam <[email protected]>
ananthsub
force-pushed
the
ananthsub/multi-worker-core
branch
from
October 26, 2026 12:55
e85360e to
e02e2fd
Compare
yaoyu-33
approved these changes
Oct 26, 2026
yaoyu-33
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Reviewed the shared worker refusal, install locking, and scaffold changes; 19 focused tests passed locally. No blocking issues found.
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/40512654150 |
7 tasks
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 changed and why
This is the first of three changes that let every resources, agent and environment server either run with
num_workers > 1or refuse it at startup with a reason. It follows #3905, which routes each session's requests to the worker that holds the session. This change adds the shared pieces and the docs; the servers change in the next two pull requests (#4790, then #4885). Nothing here changes how an existing server behaves.With
num_workers > 1,run_webserverhands uvicorn the import string<entrypoint module>:app, and each worker imports the entrypoint and serves its module-levelapp. A server that cannot run in several processes had no standard way to say so: some refused inmodel_post_initor a config validator, and others started and misbehaved.SimpleServergainsmultiple_workers_unsupported_reason(), which returnsNoneby default. A server that cannot run with several workers overrides it and returns why.run_webserverraisesValueError("<name> needs num_workers=1: <reason>")before uvicorn starts, and before the dry-run return, so a dry run reports the misconfiguration too. It is a method rather than a class attribute, so a server can decide from its config.nemo_gym.install_locklets the workers of one server share a local tool install, so the first calls in several workers do not download, unpack ornpm installinto the same directory at once. It provides a file lock across processes (fcntl.flock), an asyncio variant that polls instead of blocking the event loop, and a record of where a finished install put its tool, replaced atomically so a waiting worker never sees a partial record.gym env init) ends the generated resources server and agent entrypoints with the module-levelapp, so a new server supports several workers from the start. The scaffold tests check both.Docs
app.Issue
No separate issue: this follows #3905 and starts its multi-worker support for every resources, agent and environment server.
Validation
pytest -n 16 tests/unit_testsin a virtual environment synced with the extras the unit-test workflow installs (uv sync --extra dev --extra ray --extra sandbox --extra openshell --extra mlflow --extra wandb): no failures.run_webserverrefusal tests, including the one showing that a dry run withnum_workers=2on a refusing server raises, fail without this change and pass here. The install lock tests cover the lock across processes, a cancelled asynchronous waiter, and the install record. The scaffold tests fail on the scaffold without this change.pre-commit run --files <changed files>.Rollout evidence
N/A: no server changes behavior in this pull request. The method returns
Noneby default, and nothing uses the install lock until #4790.Compatibility
None for existing servers. Servers generated by
gym env initafter this change end with the module-levelapp.