Repository navigation
Description
Parent workstream
#3000 — Performance workstream: agent servers
Slowdown path
flowchart LR
A[Concurrent rollouts] --> B[One agent worker event loop]
B --> C[Ingress validation and JSON work serialize]
C --> D[Requests wait before model and tool calls]
Current behavior
Gym's shared runner already has a multi-worker branch. When num_workers > 1, it reconstructs an import path from the configured entrypoint and asks Uvicorn to import <module>:app in each worker (server_utils.py lines 972–1007). The configuration surface is generic and available to all run servers (config_types.py lines 593–605).
Each imported module must nevertheless create app under Gym's worker-entrypoint sentinel. tau2 carries that extra branch (tau2/app.py lines 553–556); simple_agent only handles direct execution and therefore cannot be imported as a multi-worker Uvicorn app without adding per-file boilerplate (simple_agent/app.py lines 368–369).
Centralize app construction/import serving so compatible agent modules can opt into num_workers without repeating an elif is_nemo_gym_fastapi_entrypoint(...) block. Add an explicit compatibility contract for agents that hold process-local mutable state or initialize non-fork-safe dependencies.
Impact and provenance
Measured
The investigation measured a separate synthetic agent fan-out knee near four agent processes behind one shared model producer. That experiment does not establish the gain from Uvicorn num_workers, and the shared producer eventually became the bottleneck.
Expected
Multi-worker gains are therefore a hypothesis. Expected benefit is parallel JSON, validation, middleware, and agent-side CPU capacity for agents whose rollouts are process-independent. Gains may be small for model-bound workloads and may stop once model, resources, connection-pool, or driver capacity becomes limiting.
Implementation constraints
- Preserve signed session cookies, rollout IDs and context propagation, token capture, telemetry, aggregate-metrics behavior, and the
/runtraining record. - Do not mark an agent compatible only because
run()is async. Process-local caches, background tasks, native clients, and mutable module state must be audited. - Aggregate aiohttp connector limits are divided across workers; enabling workers must not silently create an undersized per-process pool.
- Startup and shutdown hooks must execute exactly once per worker where appropriate.
- Existing direct
python app.pyserving must remain supported.
Acceptance criteria
- Compatible agents can enable
num_workerswithout module-specific app-import boilerplate. - Agent compatibility is explicit and startup fails with an actionable message for a known-incompatible configuration.
-
simple_agentruns correctly with at least 2 workers through the centralized path. - Cookie/session correlation, rollout context, telemetry, token capture, and aggregation are tested across workers.
- Worker crashes and graceful shutdown do not leave the parent reporting a healthy server.
- Effective per-worker connection-pool limits are visible or validated.
- Scaffolded/new agents get the centralized behavior by default.
Benchmark plan
- Run the same deterministic rollout corpus with 1, 2, 4, and 8 agent workers.
- Test a lightweight synthetic model/resources pair to expose agent CPU limits, then a realistic model-bound setup.
- Record throughput, p50/p95/p99
/runlatency, per-worker CPU/RSS, event-loop lag, model queue time, resources latency, and connector queue time. - Verify result equivalence, cookie isolation, rollout IDs, token captures, and telemetry parentage across worker counts.
- Report the first downstream saturation point; do not attribute a plateau automatically to the agent.
Related work
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDev Todo
Activity
ananthsub commentedon Nov 10, 2026
Status update: every agent, resources and environment server now either runs with
num_workers > 1or refuses it at startup with a reason. Part of this is merged, and the rest is in two open pull requests.Merged
simple_agentand the math-with-judge server.resources_session_id) and agent sessions (byagent_session_id). A request without a session can name a worker inx-ng-session-owner, assimple_agent's call to its own/v1/responsesdoes with checkpointing.multiple_workers_unsupported_reason().run_webserverrefusesnum_workers > 1with " needs num_workers=1: " before uvicorn starts, and before a dry run returns. It also addednemo_gym.utils.install_lock, so the workers' first calls share one local tool install, and made the environment scaffold generate the module-levelapp.__mp_main__copy of the entrypoint.owned_session_routing) before the release.Open
appto every server that is safe with several workers, including those that refused them before although routing reaches all of their state:interactive_browser,swebench_pro,terminal_bench_2_1,harbor_oracle_agent,browsecomp_agent,miniswe_sandboxed_agentwithout aresources_server,tool_simulation_agentwith checkpointing, and the langgraph agents. It also makes the agents' local command line installs safe with several workers, keepsfinance_sec_searchwithin SEC.gov's rate limit, and adds a two-worker end-to-end test with real browsers.appnor a refusal.Acceptance criteria
num_workerswithout per-module boilerplate: partly met. Each entrypoint still ends with theis_nemo_gym_fastapi_entrypointbranch, but the scaffold generates it, and feat(server): refuse several workers in servers that cannot share state #4885's test fails when a server has neither that branch nor a refusal. That way a missing adapter is caught before merge, where before it surfaced as workers exiting at startup.simple_agentwith at least two workers: met by allow multiple workers for math with judge and simple agent #3892 and fix(server): route a session's requests to the worker that holds it #3905, whose end-to-end tests runsimple_agentwith several workers.The benchmark plan has not been run.