Skip to content

feat(server): let servers refuse several workers and share local installs - #4884

Merged
marcromeyn merged 1 commit into
mainfrom
ananthsub/multi-worker-core
Oct 27, 2026
Merged

marcromeyn merged 1 commit into
mainfrom
ananthsub/multi-worker-core

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

This is the first of three changes that let every resources, agent and environment server either run with num_workers > 1 or 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_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, and 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. run_webserver raises ValueError("<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_lock lets the workers of one server share a local tool install, so the first calls in several workers do not download, unpack or npm install into 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.
  • The environment scaffold (gym env init) ends the generated resources server and agent entrypoints with the module-level app, so a new server supports several workers from the start. The scaffold tests check both.

Docs

  • The resources server guide's section on several workers shows the entrypoint ending, describes the refusal method and that a dry run reports it, and says that concurrency limits such as judge semaphores apply per worker.
  • The agent server page says the same for agents.
  • The tutorials' complete entrypoints (single-step, multi-step, stateful, MCP and the workplace assistant implementation) and the add-benchmark skill's server pattern end with the module-level 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_tests in 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.
  • The run_webserver refusal tests, including the one showing that a dry run with num_workers=2 on 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 None by default, and nothing uses the install lock until #4790.

Compatibility

None for existing servers. Servers generated by gym env init after this change end with the module-level app.

@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 21, 2026 21:58
@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:core Shared APIs, servers, telemetry, health, and registries feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer labels Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
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]>

@yaoyu-33 yaoyu-33 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.

LGTM. Reviewed the shared worker refusal, install locking, and scaffold changes; 19 focused tests passed locally. No blocking issues found.

@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 26, 2026
@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 26, 2026
@marcromeyn
marcromeyn added this pull request to the merge queue Oct 27, 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/40512654150

Merged via the queue into main with commit dc64d67 Oct 27, 2026
56 of 59 checks passed

This branch was previously deployed

1 inactive deployment
public — e02e2fd0 Deployed Oct 26, 2026 by copy-pr-bot[bot] via release / finalize / notify #7283
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 feature New capabilities, enhancements, or enablement work 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.

4 participants