Skip to content

feat(server): run every server that can with several workers - #4790

Merged
ananthsub merged 1 commit into
mainfrom
ananthsub/multi-worker-server-adapters
Nov 11, 2026
Merged

ananthsub merged 1 commit into
mainfrom
ananthsub/multi-worker-server-adapters

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

This is the second 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, now merged, added the refusal method and the shared install lock, and #4885 adds the refusals.

With num_workers > 1, each uvicorn worker imports the server's entrypoint and serves its module-level app. Most servers had no such app, so every worker exited at startup and uvicorn stopped the server. Every server that is safe with several workers now ends its entrypoint with it:

if __name__ == "__main__":
    MyServer.run_webserver()
elif is_nemo_gym_fastapi_entrypoint(__file__):
    app = MyServer.run_webserver()  # noqa: F401
flowchart TD
    A["A config sets num_workers > 1"] --> B{"Where does the server keep state between requests?"}
    B -->|"in a session that routing follows, an external store, read-only data, or nowhere"| C["Entrypoint ends with the module-level app (this change)"]
    B -->|"anywhere else"| D["run_webserver refuses with the reason (#4885)"]
    C --> E["uvicorn starts the workers, and each serves app"]
    D --> F["The server fails at startup, before uvicorn starts"]
Loading

For langgraph_agent the adapter goes in its four entrypoint modules, and for langchain_deepagents_agent in reasoning_search_agent.py. The langgraph configs and environment pairings no longer pin num_workers: 1. #5681, now merged, keeps uvicorn's __mp_main__ copy of the entrypoint from building a second server in each worker.

Servers that no longer refuse several workers

These servers refused several workers, or main gave them a one-worker pin, although session routing (#3905) reaches all of their state:

Server Where its state lives How routing reaches it
interactive_browser, swebench_pro, terminal_bench_2_1 Keyed by the session cookie or by resources_session_id An environment server's cookieless seed and close are routed by resources_session_id
harbor_oracle_agent, browsecomp_agent Agent sessions Routed by agent_session_id
miniswe_sandboxed_agent without a resources_server Agent sessions Routed by agent_session_id. With a resources_server, its own /run replays a retried run from process memory, so it still refuses
tool_simulation_agent with checkpointing The episode its own /run holds Its call to its own /v1/responses now names this worker in x-ng-session-owner, as simple_agent's does

A seed or close from an environment server carries no cookie, so the worker that accepts it looks up the session's owner and forwards the request there:

sequenceDiagram
    participant E as Environment server
    participant A as Worker A
    participant B as Worker B, holds the browser
    E->>A: seed or close for resources_session_id s, no cookie
    A->>A: the owner file for s names worker B
    A->>B: forward over B's private socket
    B->>B: act on the browser for s
    B-->>A: reply
    A-->>E: reply, unchanged
Loading

tool_simulation_agent's own /run path calls the server's /v1/responses to activate the episode. Without the header, that call could reach another worker and restart the rollout there:

sequenceDiagram
    participant C as Caller
    participant A as Worker A, runs the episode
    participant B as Worker B
    C->>A: POST /run
    A->>B: POST /v1/responses, x-ng-session-owner names A
    Note over B: the shared listener handed the call to B
    B->>A: forward to the worker the header names
    A-->>C: the rollout continues on A
Loading

agentic_mme, agentic_mme_agent and big_finance, which main added since the last revision, get the adapter too. big_finance keeps each session's as-of date by the session cookie and writes its SEC cache files atomically. The two Agentic MME servers' concurrency limits are per worker, and agentic_mme_agent's retrieval cache is files written atomically under one root, which several processes can already share.

chartography, copilot_agent and mini_swe_agent's new sessions_app.py, which main added since then, get the adapter as well. chartography's verify reads only its request, and its judge limit is per worker. copilot_agent keeps its state in agent sessions, installs the CLI inside the task sandbox rather than on the host, and limits Copilot invocations per worker. sessions_app.py serves mini_swe_agent's agent sessions without Ray. Those sessions keep their state in agent sessions and install mini-SWE inside the task sandbox, so mini_swe_agent/app.py keeps its adapter after main moved it onto agent sessions.

An opt-in end-to-end test (NEMO_GYM_MULTIWORKER_E2E=1) runs interactive_browser with two workers and real headless browsers, and CI now builds that server's environment and Chromium so the test runs there:

  • The first seeds go through each worker's private socket in turn, so both workers hold browsers. A shared TCP listener may hand every connection to one worker, and on the previous push CI reached only one.
  • Every later request goes over TCP without the cookie: a retried seed succeeds, a seed for another episode answers 409, the close removes the browser, and a seed after the close answers 409 and opens nothing.
  • Without routing by resources_session_id, an earlier revision of fix(server): route a session's requests to the worker that holds it #3905 failed this test: closes left browsers open, and later seeds opened new ones.

swebench_pro and terminal_bench_2_1 need real sandboxes for the same check, so their coverage is the unit tests plus the shared routing.

Closed sessions and their owner

A worker owns a resources_session_id until session_close_retry_window_seconds after its close. Within that window, a delayed seed or retried close reaches the worker that remembers the close.

  • nemo_user_sim keeps a closed session's tombstone for session_ttl_seconds, 1980 seconds by default. A closed session now keeps its owner for the longer of the two settings, so a delayed seed reaches the worker that holds the tombstone and is refused there. The override uses main's new name, owned_session_routing.
  • interactive_browser, swebench_pro and example_single_tool_call keep closes in ResourcesSessionFences for the same window, and terminal_bench_2_1 forgets a close after it. Each gives a late seed the same answer on every worker.

Local installs shared by several workers

The Claude Code, Codex, CVDP, Kilo Code, OpenClaw, OpenCode and Pi agents install their command line tools on first local use, into one shared directory per agent. With several workers, the first calls raced and a partial tree could be reused later. Each install now runs under nemo_gym.utils.install_lock:

flowchart TD
    A["A worker's first local call"] --> L["Take the install lock beside the install directory"]
    L --> R{"Does the record name this version, and does its binary exist?"}
    R -->|"yes"| U["Reuse the install another worker finished"]
    R -->|"no"| I["Install into an empty directory"]
    I --> M["Mark the tree complete once every file is in place"]
    M --> W["Write the record, naming the version"]
    U --> X["Release the lock"]
    W --> X
Loading
  • A record from before this change names no version, so each agent installs once more after upgrading, and, when the tool is not already on PATH, a pin bump installs the new version instead of reusing the old install. Claude Code, Codex, Kilo Code and Pi still run a tool found on PATH first, as on main.
  • The local Node.js toolchain and the CVDP runtime are reused only when their completion marker exists, so an interrupted install is redone. OpenClaw's removal of an outdated toolchain runs under the same lock.
  • On a filesystem without file locks, such as NFS without lockd or Lustre mounted with noflock, or in a read-only package directory, the install logs a warning and runs unlocked, as it did before. A record that cannot be written logs a warning too, and a later process installs again.
  • A worker waits for another's install with no timeout. A hung install already hung the worker that ran it, and a timeout would let a waiter install into a directory the holder may still be writing.
  • interactive_browser counts Chromium as installed only once Playwright writes INSTALLATION_COMPLETE.
  • iheval fetches its IFEval corpus in the main process, before the workers start.
  • Cline and AnyTerminal install in the main process before the workers start, so they need no lock. A comment at each install states that ordering.

Other changes for servers that run with several workers

Server Change
finance_sec_search Each worker admits requests_per_second // num_workers requests a second, so the server stays within SEC.gov's rate limit. It refuses more workers than requests_per_second.
legal_agent_bench Rebuilds its runtime task tree only in the main process, instead of in every worker through one backup path.
proof_genselect, proof_verification, competitive_coding_challenges The debug log takes a file lock around each append, and still writes the record on a filesystem without file locks, such as NFS without lockd or Lustre mounted with noflock.
tavily_search, browsecomp_advanced_harness Each worker writes session_id_metrics.<main pid>.<worker pid>.json at exit, and plot_session_id_metrics.py reads one run's files together.
finance_agent_v2, finance_sec_search Configure their logging in the workers too.
opencode_search, indian_banking, competitive_coding_challenges, agentic_mme, agentic_mme_agent Comments say which caches, counters, concurrency limits and memory are per worker. competitive_coding_challenges loads about 27 GB per worker for the full test set.
swe_pivot Its verifier test's nemo_gym stub now includes nemo_gym.utils, which the adapter imports.
math_with_code The session worker moves to its own module, and the forkserver preloads that module instead of the server module, so it no longer builds a second server in each worker.
code_gen sandbox_app.py, the entrypoint without Ray, gets its own adapter.
Docs The browsecomp_agent and Terminal-Bench 2.1 READMEs, the harness guide and the add-harness skill no longer say agent sessions need one worker.

Issue

No separate issue: this follows #3905.

Validation

Run on this revision, rebased onto main at 65dd99e:

  • 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.
  • test_multiple_workers_contract.py failed after the rebases on chartography, copilot_agent and mini_swe_agent/sessions_app.py, and passes with their adapters and feat(server): refuse several workers in servers that cannot share state #4885 on top.
  • The unit tests of chartography, copilot_agent, the install lock and the langgraph pairings, whose num_workers assertion moved to a new file on main.
  • New tests for the second review: the install lock and its record in a read-only directory, which fails on the previous revision with PermissionError, and two CVDP agents building the sandbox runtime archive at once, which builds twice with a lock that does nothing.
  • math_with_code's tests, and a check that its forkserver preloads only the main script and the session worker's module.
  • pre-commit run --files <changed files>. CI's per-server run covers the server tests.

Run on the previous revision, rebased 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.
  • test_multiple_workers_contract.py, which reads every server entrypoint, passes with feat(server): refuse several workers in servers that cannot share state #4885 on top.
  • The tests of the servers this rebase touched, in the repository's virtual environment: agentic_mme, agentic_mme_agent (with its image packages added), agentic_turn_simulation, bbq, gdp_pdf, terminal_bench_2_1, harbor_oracle_agent, tool_simulation_agent, swe_pivot and nemo_user_sim; nemo_user_sim's failures fail the same way on main. gym env test for big_finance and finance_sec_search; the test of finance_sec_search's refusal fails on the previous message, which did not name the limit. swebench and langgraph_agent need packages that environment lacks, so CI's per-server run covers them.
  • NEMO_GYM_MULTIWORKER_E2E=1 pytest tests/e2e/session_routing/test_typed_sessions_e2e.py, the two-worker interactive_browser case.
  • The install lock's tests, including a new one in which flock fails with ENOLCK: both locks must still run the install and warn. It fails on the previous revision.
  • pre-commit run --files <changed files>.

Run on earlier revisions, rebased onto main at 390c954:

  • New tests for the review fixes, each checked to fail without its fix: a version-pinned install record meeting a new pin, tool_simulation_agent's owner header, a half-unpacked Chromium build, and refusals no longer raised by swebench_pro, harbor_oracle_agent and browsecomp_agent.
  • The install race tests (two worker processes making their first local call together) and the interrupted install tests pass. On an earlier revision they failed on the agents' installers without this change.
  • gym env test for the resources servers this change touches beyond the adapter, each in its own environment: interactive_browser, tavily_search, browsecomp_advanced_harness, iheval, code_gen, xstest, competitive_coding_challenges, proof_genselect, proof_verification, swebench_pro, opencode_search, indian_banking and reasoning_gym. The touched agents' tests ran in the repository's virtual environment: tool_simulation_agent, harbor_oracle_agent and the Claude Code, Codex, Kilo Code, OpenCode and OpenClaw installers pass; Pi's pinned-runtime tests fail the same way on main, because they run the host's Pi. langgraph_agent needs packages that environment lacks, so CI's per-server run covers it.
  • NEMO_GYM_MULTIWORKER_E2E=1 pytest tests/e2e/session_routing, which runs fix(server): route a session's requests to the worker that holds it #3905's routing cases and the two-worker interactive_browser case, and the same with NEMO_GYM_MULTIWORKER_STRESS=1 for the stress cases.

Rollout evidence

N/A for model rollouts: no verifier or agent logic changes, and the behavior changes are startup, install and file handling, which the tests above cover. On this revision, the end-to-end tests start real servers with two workers and drive sessions through them. On an earlier revision, as evidence that the adapter serves, gym env start ran these servers with num_workers=2: resources servers arc_agi, mcqa, wordle, xlam_fc, grl_sokoban, structured_outputs and nemo_user_sim; agents gymnasium_agent, non_executing_simple_agent, tool_simulation_agent and langgraph_agent (ReWOO); and the nemo_user_sim environment server. Each started two uvicorn worker processes under its parent, answered GET /health with 200 on repeated requests, and the resources servers answered POST /seed_session with 200.

Compatibility

  • Servers with the adapter accept num_workers > 1, including interactive_browser, swebench_pro, terminal_bench_2_1, harbor_oracle_agent, browsecomp_agent, and miniswe_sandboxed_agent without a resources_server, which refused it before.
  • finance_sec_search refuses more workers than requests_per_second, and its refusal names that limit.
  • A closed nemo_user_sim session keeps its owner as long as its tombstone, session_ttl_seconds, when that is longer than session_close_retry_window_seconds.
  • Concurrency limits such as judge semaphores stay per worker, so a server with several workers allows num_workers times the configured limit.
  • tool_simulation_agent with checkpointing accepts several workers.
  • The langgraph configs and environment pairings no longer set num_workers: 1.
  • The CLI agents install once more after upgrading, because their old install records name no version.
  • Per-worker session metrics files are named session_id_metrics.<main pid>.<worker pid>.json.
  • iheval looks up NLTK's punkt data at startup, and downloads it if it is missing, even with one worker. Before, its first verify call did that. On a host without the data or network access, startup waits for the failed download, which does not stop it.
  • A crashed worker's swebench_pro sandboxes stay open until the provider's TTL, as a crashed single-worker server's do. The shipped config sets ttl_s: 18000, so keep ttl_s set when overriding it.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

@ananthsub
ananthsub force-pushed the ananthsub/fix-session-worker-routing branch from 43c289e to 8b6e4a6 Compare October 20, 2026 20:55
@ananthsub
ananthsub requested a review from a team as a code owner October 20, 2026 20:55
@ananthsub
ananthsub force-pushed the ananthsub/fix-session-worker-routing branch from 8b6e4a6 to bbe9e7a Compare October 20, 2026 22:18
@ananthsub
ananthsub marked this pull request as draft October 20, 2026 23:20
@ananthsub
ananthsub force-pushed the ananthsub/multi-worker-server-adapters branch from 19ca169 to 7a970aa Compare October 20, 2026 23:20
@copy-pr-bot

copy-pr-bot Bot commented Oct 20, 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.

@ananthsub
ananthsub force-pushed the ananthsub/fix-session-worker-routing branch from bbe9e7a to 939644b Compare October 20, 2026 23:39
@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:core Shared APIs, servers, telemetry, health, and registries feature New capabilities, enhancements, or enablement work labels Oct 21, 2026
@ananthsub
ananthsub force-pushed the ananthsub/fix-session-worker-routing branch from 939644b to c46fd97 Compare October 21, 2026 12:57
Base automatically changed from ananthsub/fix-session-worker-routing to main October 21, 2026 13:18
@ananthsub
ananthsub force-pushed the ananthsub/multi-worker-server-adapters branch from 7a970aa to 0fff412 Compare October 21, 2026 13:23
@ananthsub
ananthsub force-pushed the ananthsub/multi-worker-server-adapters branch from 0fff412 to e54313a Compare October 21, 2026 21:57
@ananthsub ananthsub changed the title feat(server): run every server with several workers or refuse them feat(server): run every server that can with several workers Oct 21, 2026
@ananthsub
ananthsub changed the base branch from main to ananthsub/multi-worker-core October 21, 2026 21:57

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

Reviewed at 8b1d47e, looking at three things: reuse of the existing multi-worker support, retries, and cleanup.

Summary: the design is sound. The PR reuses the session routing from #3905, the same routing simple_agent relies on, and adds no new routing code. Retries and normal shutdown hold up. One regression is worth fixing before merge, and the crash path has gaps worth stating.

1. Reuse of simple_agent's multi-worker support: yes

  • Most of the diff is the module-level app adapter, which simple_agent already has. Requests are still routed by SessionRoutingMiddleware (private Unix sockets plus owner files), and nothing under nemo_gym/server_runtime changes.
  • tool_simulation_agent's x-ng-session-owner header on its own /v1/responses call matches what simple_agent/app.py already does. 👍

2. Retries

Working as intended:

  • A retried seed or close is forwarded to the worker that owns the session. The owner remembers the close for the close retry window, so every worker answers a late seed the same way. The two-worker interactive_browser e2e test covers this.
  • A retried /run on simple_agent or tool_simulation_agent with checkpointing claims the episode from the coordinator, so any worker can take it. Keeping the refusal for miniswe_sandboxed_agent with a resources_server, which replays from process memory, is right.
  • A failed install releases the lock, and the next call deletes the partial tree before installing again. The version in the install record makes a pin change reinstall.

Should fix: install_lock has no fallback for filesystems without file locks. install_lock.py:42 and :57 call fcntl.flock bare, so on Lustre mounted with noflock, or NFS without lockd, they raise OSError.

  • The PR already handles this case for the log appends in competitive_coding_challenges and proof_genselect (except OSError: pass), but not here.
  • This PR wraps every first local install in the lock even with num_workers=1: the Claude Code, Codex, Kilo Code and OpenClaw installers, and CVDP's deps build. The lock files sit beside the install, inside the repository checkout (e.g. setup_claude_code.py:36), which on a cluster is often on Lustre.
  • So a single-worker first install that works on main can fail after this PR.
  • Suggestion: catch OSError other than BlockingIOError in both functions, log a warning and continue without the lock, as the log appends do. Add a test that patches flock to raise OSError(ENOLCK).

Nit: waiting for the lock has no time limit. If one worker's npm install hangs, every other worker blocks on its first local call indefinitely. The event loops stay responsive (to_thread / polling), so this isn't a blocker. A time limit with a clear error, or a comment on the trade-off, would help.

3. Cleanup

Working as intended:

  • On normal shutdown each worker runs its own lifespan. swebench_pro and terminal_bench_2_1 stop their sandboxes, each worker closes its private socket and forwarding clients, the background sweep releases owner files of ended sessions, and the runtime dir is removed at exit.
  • Install leftovers are deleted before a reinstall.

Gaps worth stating in the PR's Compatibility section:

  • A crashed worker (OOM, kill) leaks its sandboxes until the provider TTL. In swebench_pro, ttl_s comes from sandbox_config and is optional (app.py:447), so without it they never expire. More workers means more processes that can die: competitive_coding_challenges alone is about 27 GB per worker. Consider giving ttl_s a default when num_workers > 1, or at least documenting it. The dead worker's sessions answer 410, which is the right signal.
  • interactive_browser has no shutdown hook. Remote CDP browsers (the lexmount provider) outlive a worker that exits. This predates the PR, but several workers make it more likely.
  • Minor: the per-worker tavily_search metrics files (session_id_metrics.<ppid>.<pid>.json) build up across runs with nothing removing them. They're gitignored, so this is low priority.

Removing num_workers: 1 from configs

This is fine: the default is None, which still runs one worker. A short line in the langgraph README on how to raise it would help users who relied on the pin as a signal, e.g. ++<instance>.<server type>.<implementation>.num_workers=N.

@ananthsub

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Changes, now in bc2440ef33:

  • install_lock without file locks: fixed. Both install_lock and async_install_lock now catch an OSError from flock, log a warning naming the lock path, and run the install without the lock, as on main. In the async loop, BlockingIOError is still handled first, so a held lock still means waiting. A new test makes flock raise OSError(ENOLCK) and checks that both functions run the block and warn. It fails on the previous head.
  • No time limit on the wait: the module docstring now explains this. A hung install already hangs the worker running it, and a timeout would let a waiter install into the directory the holder may still be writing.
  • Sandboxes of a crashed worker: added to Compatibility. They stay open until the provider's TTL, as they do when a single worker crashes. The shipped swebench_pro.yaml sets ttl_s: 18000, so they expire unless a config removes it. I left the default unchanged.
  • langgraph README: it now shows how to raise the worker count, with ++reasoning_gym_langgraph_agent.responses_api_agents.langgraph_agent.num_workers=4.

Not changed in this PR:

  • interactive_browser shutdown hook: agreed that remote CDP browsers can outlive a worker. As you noted, this predates the PR, so it belongs in a separate follow-up.
  • tavily_search metrics files: these are debug output, gitignored, and one file per worker per run, so I left them as they are.

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

Re-reviewed at bc2440ef33. Thanks for the quick turnaround on the last round.

Merge conflict first: GitHub now reports the branch as conflicting with main, on responses_api_agents/mini_swe_agent/app.py (8 commits landed since dff64b2041). Could you merge or rebase onto main? Please also check that any servers added there get the adapter or a refusal. With the conflict resolved, I'm happy to approve: nothing below blocks merge.

Previous round, verified at this head:

  • install_lock and async_install_lock fall back on an OSError from flock and warn. The async loop still handles BlockingIOError first, and the ENOLCK test covers both functions (nemo_gym/utils/install_lock.py:52-80, tests/unit_tests/utils/test_install_lock.py:111).
  • The module docstring explains why the wait has no timeout. The crashed-worker note is in Compatibility, and swebench_pro.yaml does ship ttl_s: 18000.
  • The langgraph README override path matches the reasoning_gym_langgraph_agent instance.
  • The bot's three threads hold at this head:
    • finance_sec_search gives each worker requests_per_second // num_workers and refuses more workers than requests_per_second.
    • nemo_user_sim keeps a closed session's owner for the longer of the two windows.
    • miniswe_sandboxed_agent with a resources_server still refuses several workers.
  • Agreed on deferring the interactive_browser shutdown hook. A linked follow-up issue would be nice.

Also checked, no change needed:

  • All 196 added adapters run the same class as their __main__ branch, and each imports the helper.
  • Every installer's sync lock runs in asyncio.to_thread.
  • The main-process-only steps in legal_agent_bench and iheval run before run_webserver marks the process as a worker.
  • Playwright 1.62.0 writes INSTALLATION_COMPLETE after unpacking.
  • Unit tests for the touched agents, installers, swebench_pro, terminal_bench_2_1, interactive_browser, legal_agent_bench and the proof servers pass locally. CI is green.

Inline comments: all NOTEs. They cover:

  • one stray server build in math_with_code's forkserver;
  • the install lock on a read-only package directory;
  • vibench getting the adapter while it still refuses several workers;
  • code_gen/sandbox_app.py;
  • leftover "one worker" docs;
  • an e2e filter that never matches;
  • public-API imports;
  • one untested lock path.

PR description:

  • "A pin bump installs the new version instead of running the old one" holds only when the CLI is not already on PATH. Claude Code, Codex, Kilo Code and Pi return on shutil.which before reading the record (responses_api_agents/claude_code_agent/setup_claude_code.py:72), the same as on main. Could you narrow that sentence?
  • The adapter-or-refusal contract test lives in #4885, and this PR already drifted from it once (chartography, copilot_agent). Landing #4885 right after this one would keep new servers honest.

Comment thread resources_servers/math_with_code/app.py Resolved
Comment thread nemo_gym/utils/install_lock.py Resolved
Comment thread resources_servers/vibench/app.py Resolved
Comment thread resources_servers/code_gen/app.py Resolved
Comment thread responses_api_agents/cvdp_agent/app.py Resolved
yaoyu-33
yaoyu-33 previously approved these changes Nov 10, 2026

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

Approving at b0d000696a. The rebase onto main resolves the mini_swe_agent conflict, and the range-diff from bc2440ef33 is only that resolution plus the adapter on mini_swe_agent/sessions_app.py, whose state lives in agent sessions that routing follows. The NOTEs from the previous review are non-blocking and fine as follow-ups. Please land #4885 soon after, so its contract test covers new servers.

With num_workers > 1, each uvicorn worker imports the server's entrypoint
and serves its module-level app. Most resources, agent and environment
servers had no such app, so every worker exited at startup and uvicorn
stopped the server. Every server that is safe with several workers now ends
its entrypoint with it. For langgraph_agent that is its four entrypoint
modules, and for langchain_deepagents_agent it is reasoning_search_agent.py.
The langgraph configs and environment pairings no longer pin one worker.

interactive_browser, swebench_pro and terminal_bench_2_1 no longer refuse
several workers. Their per-session state is keyed by the session cookie or
by resources_session_id, and session routing sends an environment server's
cookieless seed and close by resources_session_id to the worker that holds
the session. An opt-in end-to-end test runs interactive_browser with two
workers and real browsers. It seeds through each worker's private socket in
turn, so both workers hold browsers whichever worker the TCP listener picks,
and checks that a cookieless retried seed, a conflicting seed, a close and a
late seed each act on the worker that holds the browser.
miniswe_sandboxed_agent drops its num_workers: Literal[1] for episode
sessions, which are routed by agent_session_id, and refuses several workers
when a resources_server enables its own /run path, which replays a retried
run from process memory keyed by the cookie's session_id and the rollout ID;
and harbor_oracle_agent drops its own num_workers check, because its
sessions are agent sessions, which routing follows. browsecomp_agent drops
the num_workers: Literal[1] main gave it with its sandboxed session
harness, for the same reason. The CI job for the
routing tests now builds interactive_browser's environment and Chromium,
so its two-worker test runs there instead of skipping.

tool_simulation_agent's own /run path calls its /v1/responses, which
activates the episode this worker holds. The call now names this worker
in x-ng-session-owner, as simple_agent's does, so with several workers it
returns here instead of restarting the rollout on another worker.

nemo_user_sim keeps a closed session's tombstone for session_ttl_seconds,
1980 seconds by default, while a closed session keeps its owner only
session_close_retry_window_seconds after the close. It now keeps its owner
for the longer of the two, so with several workers a delayed seed still
reaches the worker that holds the tombstone and is refused there.
interactive_browser, swebench_pro and example_single_tool_call already keep
closed sessions in ResourcesSessionFences, which forgets a close when the
session's owner expires.

The Claude Code, Codex, CVDP, Kilo Code, OpenClaw, OpenCode and Pi agents
install their command line tools on first local use, into one shared
directory per agent, so the first calls in several workers raced. Each
install now runs under nemo_gym.utils.install_lock beside the install
directory, and checks inside the lock for an install another worker
finished. The record names the version it installed and is reused only for
that version, so a changed pin reinstalls instead of running the old tool.
The Node.js toolchain and the CVDP runtime are reused only when a marker
written last says the install finished, so an interrupted install is redone
from an empty directory. Cline and AnyTerminal install before uvicorn starts
the workers, and a comment at each install states that ordering.
interactive_browser counts Chromium as installed only once Playwright marks
the install complete, and iheval fetches its IFEval corpus in the main
process before the workers start.

Other servers that are safe with several workers needed a change:

- finance_sec_search divides requests_per_second among the workers, so the
  server as a whole stays within SEC.gov's rate limit, and refuses more
  workers than requests_per_second, where a worker's share would round to
  zero;
- legal_agent_bench rebuilds its runtime task tree only in the main process,
  which runs setup_webserver before uvicorn starts the workers;
- the proof_genselect, proof_verification and competitive_coding_challenges
  debug logs take a file lock around each append, and still write the
  record on a filesystem without file locks;
- tavily_search and browsecomp_advanced_harness write one session metrics
  file per worker at exit, named by the main process and the worker, and
  the plot script reads one run's files;
- finance_agent_v2 and finance_sec_search configure their logging in the
  workers too;
- opencode_search, indian_banking, competitive_coding_challenges,
  agentic_mme and agentic_mme_agent say which caches, counters, concurrency
  limits and memory are per worker.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub

Copy link
Copy Markdown
Contributor Author

Thanks for the second pass. Rebased onto 65dd99e969, and every note is addressed, in 9b5a812a20:

This branch had an error being deployed

1 failed deployment
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 sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants