Skip to content

feat(server): refuse several workers in servers that cannot share state - #4885

Draft
ananthsub wants to merge 4 commits into
mainfrom
ananthsub/multi-worker-refusals
Draft

ananthsub wants to merge 4 commits into
mainfrom
ananthsub/multi-worker-refusals

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

This is the last 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. #4884 added the refusal method, and #4790 gave every server that is safe with several workers its module-level app.

#5988, in parallel, gives the module-level app to the servers whose state session routing already reaches, including those that refused several workers or that main added without either. This change leaves them as they are on main. Merge #5988 first. On main, agentic_if, officeqa, vibench, webvoyager_judge, web_agent, droid_agent and openhands_agent have neither the module-level app nor a refusal method, so this change's repository-wide test fails on them until #5988 lands.

The servers below keep state that session routing cannot reach, or own a resource that one process must hold. Each now overrides multiple_workers_unsupported_reason(), and run_webserver refuses num_workers > 1 with that reason before uvicorn starts, and before a dry run returns.

Server Refuses Reason
aviary (all five entrypoints) always Environments are kept in memory by the env_id in the request body, and the aviary agent sends step, verify and close without the session cookie.
toolsandbox always Episodes are kept in memory by the env_id in the request body, and toolsandbox_agent sends step, close and verify without the session cookie.
critpt always verify calls are pooled in memory into batches submitted together; the batches, submission counters and API key rotation must be shared by every request.
speed_bench with metrics_source: prometheus The speculative decoding window starts from a metrics snapshot in memory, so each worker would measure from a different start.
osworld always Docker host capacity, startup cleanup of orphaned containers and the sessions.json state file are each owned by one process.
longmt_eval with compute_segale Each worker builds its own Ray GPU actor pool, so several workers multiply the GPU actors and can fail to schedule them.
wmt_translation with compute_comet The worker that serves an aggregation builds and keeps a Ray GPU actor pool for COMET, so an aggregation on another worker builds a second pool that can fail to schedule, and both write COMET's results to the same temporary file.
gdpval always A seed claims the persisted deliverables directory of its task and repeat in memory, keyed by the task ID and rollout ID in the request body, so sessions on different workers could write the same directory.
terminal_bench_4 always Seeds are deduplicated in memory by the client_session_id and rollout_id in the request body, which session routing does not route.
vlm_eval_kit always MMBench scoring waits in memory for every row of a group, keyed by the group in the request body, so a group split across workers never completes.
Legal Agent Bench Harbor bridge always Its entrypoint lives outside the harbor_agent directory, so the module path uvicorn workers import does not resolve.
voicebench always Legacy scoring draws every rule-scored row from one random stream shared by the whole server.
proof_judge with zero_reward_incorrect_groups It waits in memory for every rollout of a problem, keyed by the problem text.
genrm_compare with cohort verification (fixed_baseline or num_rollouts_per_prompt > 1) It collects a prompt's rollouts in memory.
ns_tools with the HTTP PythonTool Each worker starts a sidecar on the fixed python_tool_port.
visual_browser, webarena_browser always PyAutoGUI drives the one X display, and seed moves the session cookie to an identity that session routing does not follow, so later steps and /close can reach a worker without the browser.

speed_bench, longmt_eval, wmt_translation, proof_judge, genrm_compare and ns_tools get the module-level app too, because they are safe in their other configurations: speed_bench's default response metrics source scores each request on its own, longmt_eval without SEGALE builds no actors and keeps nothing between requests, and wmt_translation without COMET, as the IN22 profile runs it, keeps nothing between requests either. proof_judge's debug log takes a file lock around each append, as proof_genselect and proof_verification do since #4790, and still writes the record on a filesystem without file locks.

ns_tools now lists its tools in its lifespan, with await, instead of calling run_until_complete while it builds the server. A uvicorn worker imports the entrypoint from inside its running event loop, so without this every worker would fail at startup with "This event loop is already running" in every shipped config.

terminal_bench_4, osworld, genrm_compare, gdpval, voicebench, visual_browser and webarena_browser already refused several workers, in model_post_init, in a config validator or with num_workers: Literal[1]. Those checks now go through the method with the same conditions, so they all fail the same way and a dry run reports them.

run_webserver asks for the reason after it builds the server, and building a server runs model_post_init. gdpval, voicebench and speed_bench do setup there: installing LibreOffice, downloading NLTK data, or taking a metrics snapshot. So each also checks the refusal at the start of model_post_init, which keeps the fail-fast behavior their own checks had: a server with several workers fails on the worker count, not on that setup.

A unit test reads every server entrypoint without importing it: each server directory's app.py and each module a config names, anywhere in the repository. It fails when a server has neither the module-level app nor an override of the method, on its class or on a parent server class in the repository, and the message says which to add. A server whose override might return None, so that it refuses only in some configurations, needs the module-level app as well. Only a string literal or an f-string counts as a reason, so an override that returns a variable, a call or a conditional expression needs it too. A module-level app also fails the test when a config names the entrypoint by a path outside its server directory, which uvicorn cannot import. The scan skips dot directories, such as virtual environments, and caches. The only exemptions are the Gymnasium base class module and the local SEC search library, which configs name but which start no server. The resources server guide now mentions the test.

Issue

No separate issue: this follows #3905 and completes its multi-worker support for every resources, agent and environment server.

Validation

Run on this revision, on main at b4f6a0d:

Run on the previous revision, on main at 79e986f, after dropping the seven servers #5988 enables:

Run on an earlier revision, on main at 79e986f:

  • longmt_eval's tests in its own virtual environment, including a new one that it refuses several workers only with compute_segale. It fails on the previous revision, which refused in every configuration.
  • pytest -n 16 tests/unit_tests in a virtual environment synced with the extras the unit-test workflow installs. The files with failures fail the same way on main.
  • The repository-wide test passes. Its new fixture cases cover an override that can return None, overrides that return a conditional expression, a call or a variable, which fail on the previous revision, overrides that refuse in every configuration with a string literal or an f-string, and a module-level app in an entrypoint named from outside its server directory. With the module-level app removed from proof_judge or terminus_2_sandboxed_agent, whose refusals depend on their config, it now fails.
  • ns_tools' tests in its own virtual environment, including a new one that builds the server inside a running event loop, as a uvicorn worker does, and checks that the lifespan loads the tools. It fails on the previous revision with "This event loop is already running".
  • ns_tools started through gym env start with num_workers=2 and its DirectPythonTool config, on uvicorn 0.54 (its own lock) and 0.37. Both workers loaded their tools in their lifespan and stayed up, and stateful Python tool calls kept their state within each session, both through the public port and on each worker directly. The previous revision never became ready: both workers failed with "This event loop is already running" and uvicorn restarted them.
  • pre-commit run --files <changed files>.

Run on an earlier revision, rebased onto main at 7bceb31:

  • pytest -n 16 tests/unit_tests, with the same result, and the repository-wide test.

Run on an earlier revision, rebased with #4790 onto main at ada2efa:

  • 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). The files with failures fail the same way on main at the same commit.
  • The repository-wide test, which passes once feat(server): run every server that can with several workers #4790 gives the entrypoints main added since the last revision, chartography, copilot_agent and mini_swe_agent/sessions_app.py, the adapter, and this change moves vibench's check into the method.
  • vibench's refusal test.
  • pre-commit run --files <changed files>. CI's per-server run covers the server tests.

Run on an earlier revision, rebased with #4790 onto main at f49b582:

  • 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). Rerunning the files with failures on this branch and on main at the same commit gives the same failures on both; two tests that failed only under the parallel run pass on rerun.
  • The repository-wide test. After the rebase it failed on the four servers main added since the last revision, and it passes once feat(server): run every server that can with several workers #4790 gives three of them the adapter and this change makes officeqa refuse.
  • The tests of officeqa, partner_if and enterpriseops_gym, whose refusals this rebase touched, in the repository's virtual environment. gdpval's tests need packages that environment lacks, so CI's per-server run covers them.
  • pre-commit run --files <changed files>.

Run on an earlier revision, on main at 390c954:

  • The repository-wide test fails on the parent commit, naming exactly the servers this change makes refuse, and passes here.
  • Each changed server's own tests, in the server's own virtual environment (the one gym env test creates): aviary, toolsandbox, critpt, speed_bench, longmt_eval, wmt_translation, osworld, gdpval, terminal_bench_4, vlm_eval_kit, voicebench, enterpriseops_gym, partner_if, terminus_2_sandboxed_agent, agentic_if, legal_agent_bench, proof_judge, genrm_compare and ns_tools. They include a refusal test for each server whose refusal depends on its config, and one for vlm_eval_kit. wmt_translation's venv needs its current requirements, which add the IN22 normalizer.
  • NEMO_GYM_MULTIWORKER_E2E=1 pytest tests/e2e/session_routing.

Rollout evidence

The only startup change is ns_tools' tool listing, and the two-worker ns_tools run under Validation exercises it: tools load in each worker and serve stateful Python calls. Model rollouts are N/A: no verifier or agent logic changes; the rest is a startup check and a debug log lock.

Compatibility

  • A config that sets num_workers > 1 on a refusing server now fails at startup with the reason, instead of failing in its own way or starting and misbehaving.
  • genrm_compare in its stateless mode (rollout_cohort with num_rollouts_per_prompt == 1), speed_bench with its default response metrics source, longmt_eval without SEGALE, wmt_translation without COMET, and proof_judge and ns_tools in their other configurations accept num_workers > 1.
  • gdpval refuses num_workers > 1 both at the start of model_post_init and in run_webserver, as described above.
  • WebResourcesServerConfig no longer rejects num_workers > 1 when it is built. visual_browser and webarena_browser refuse it in run_webserver, so the error now names the server and a dry run reports it.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer labels Oct 21, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 21, 2026 21:58
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

class GDPValResourcesServer(SimpleResourcesServer):
config: GDPValResourcesServerConfig

def multiple_workers_unsupported_reason(self) -> Optional[str]:

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.

Non-blocking: could we keep the refusal before dependency setup? With num_workers=2, GDPVal now calls ensure_libreoffice() before the shared guard; VoiceBench's IFEval path similarly calls _ensure_nltk(). This can install dependencies unnecessarily or mask the worker-count error with a setup failure. Calling the shared guard early in these constructors would preserve the previous fail-fast behavior.

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.

Fixed. gdpval, voicebench, the partner_if mock tools and speed_bench now call refuse_unsupported_num_workers(self) at the start of model_post_init, before LibreOffice, the NLTK data, the tool backend or the startup metrics snapshot. run_webserver still checks it once the server is built, so nothing else changes.

The other refusing servers build only in-memory objects or read small files in model_post_init, so their worker-count error already comes first.

The gdpval and voicebench tests now fail if LibreOffice or the NLTK data is set up before the refusal, and both fail without the early check.

@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 26, 2026
@ananthsub
ananthsub force-pushed the ananthsub/multi-worker-refusals branch from ad4850b to d9751c1 Compare October 27, 2026 16:27
@ananthsub
ananthsub force-pushed the ananthsub/multi-worker-server-adapters branch from 0f694d1 to 8be02af Compare October 27, 2026 16:27
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 27, 2026 16:28
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 6, 2026 22:06
@ananthsub
ananthsub force-pushed the ananthsub/multi-worker-server-adapters branch from 676aded to 19153c6 Compare November 9, 2026 23:06
@ananthsub
ananthsub force-pushed the ananthsub/multi-worker-refusals branch from 0ca5d40 to fd2049b Compare November 9, 2026 23:06
@ananthsub
ananthsub force-pushed the ananthsub/multi-worker-server-adapters branch from 19153c6 to 8b1d47e Compare November 9, 2026 23:44
@ananthsub
ananthsub force-pushed the ananthsub/multi-worker-refusals branch from fd2049b to 1d40152 Compare November 9, 2026 23:44
@ananthsub
ananthsub force-pushed the ananthsub/multi-worker-server-adapters branch from 8b1d47e to 476bc54 Compare November 10, 2026 20:04
@ananthsub
ananthsub force-pushed the ananthsub/multi-worker-refusals branch from 1d40152 to d35232b Compare November 10, 2026 20:04
cmunley1
cmunley1 previously approved these changes Nov 13, 2026
Some servers keep state that session routing cannot reach, or own a resource
that one process must hold, so they cannot run with several workers. They
now override multiple_workers_unsupported_reason(), and run_webserver
refuses num_workers > 1 with that reason before uvicorn starts:

- aviary and toolsandbox keep environments in memory by the env_id in the
  request body, and their agents send step, verify and close without the
  session cookie;
- critpt pools verify calls in memory into batches submitted together;
- osworld owns the Docker host capacity, startup cleanup and its state file;
- longmt_eval builds a Ray GPU actor pool per worker;
- gdpval claims deliverable directories in memory by task and rollout ID;
- terminal_bench_4 deduplicates seeds by the client_session_id and
  rollout_id in the request body;
- vlm_eval_kit waits in memory for every row of an MMBench group;
- voicebench's legacy scoring draws every rule-scored row from one random
  stream shared by the whole server;
- enterpriseops_gym sessions and the partner_if mock-tool episodes are
  process-local, agentic_if sessions hold their sandbox connections in one
  process, and the officeqa document sandboxes and partner_if SWE actor
  sandboxes live in the server's memory;
- the Legal Agent Bench Harbor bridge has an entrypoint outside its server
  directory, which uvicorn workers cannot import.

speed_bench, wmt_translation, proof_judge, genrm_compare, ns_tools and
terminus_2_sandboxed_agent refuse only in the configurations that need one
process, and get the module-level app otherwise: speed_bench with the
Prometheus metrics source, which measures from a snapshot in memory;
wmt_translation with COMET, which builds a Ray GPU actor pool per worker;
proof_judge with zero_reward_incorrect_groups; genrm_compare with cohort
verification; ns_tools with the HTTP PythonTool sidecar on a fixed port; and
terminus_2_sandboxed_agent without a resources server, which serves only
process-local episode sessions. proof_judge's debug log also takes a file
lock around each append, and still writes the record on a filesystem without
file locks. The checks that did this job in model_post_init, in config
validators and as num_workers: Literal[1], including those main added to
voicebench, enterpriseops_gym, agentic_if, officeqa, the partner_if mock
tools and SWE server and terminus_2_sandboxed_agent, become the method with
the same conditions.
gdpval, voicebench, the partner_if mock tools and speed_bench check the
refusal at the start of model_post_init as well, before they install
dependencies, load their backend or take a metrics snapshot, so a
misconfigured server fails on the worker count rather than on that setup.

A unit test reads every server entrypoint without importing it, including
the entrypoints configs name outside app.py, and fails when a server has
neither the module-level app nor a refusal. It fails on the parent commit.

Signed-off-by: Ananth Subramaniam <[email protected]>
…ation

An override that returns a variable, a call or a conditional expression
might return None, so the contract test now asks for the module-level
app unless every return is a string literal or an f-string.

Signed-off-by: Ananth Subramaniam <[email protected]>
The seven servers whose state session routing already reaches get the module-level app in #5988,
which lands in parallel. Refusing them here first and lifting the refusals there would churn the same files.

Signed-off-by: Ananth Subramaniam <[email protected]>
… sees

visual_browser and webarena_browser, which main added, refused several
workers in a WebResourcesServerConfig validator. The contract test reads
only refusal methods on server classes, so it reported both servers as
having neither the module-level app nor a refusal, and a dry run did not
report the refusal. Each server now overrides
multiple_workers_unsupported_reason() with the reason, and the validator
check is gone. Constructing the config with several workers no longer
fails; run_webserver refuses it instead.

The coverage test no longer expects
langchain_deepagents_agent/reasoning_search_agent.py, which no config
names since that agent's configs moved to app.py.

Signed-off-by: Ananth Subramaniam <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

This branch had an error being deployed

1 failed (outdated) deployment
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 feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants