Skip to content

Make agent multi-worker serving available without per-agent entrypoint boilerplate #3014

Open

Description

@ananthsub

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]
Loading

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 /run training 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.py serving must remain supported.

Acceptance criteria

  • Compatible agents can enable num_workers without module-specific app-import boilerplate.
  • Agent compatibility is explicit and startup fails with an actionable message for a known-incompatible configuration.
  • simple_agent runs 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

  1. Run the same deterministic rollout corpus with 1, 2, 4, and 8 agent workers.
  2. Test a lightweight synthetic model/resources pair to expose agent CPU limits, then a realistic model-bound setup.
  3. Record throughput, p50/p95/p99 /run latency, per-worker CPU/RSS, event-loop lag, model queue time, resources latency, and connector queue time.
  4. Verify result equivalence, cookie isolation, rollout IDs, token captures, and telemetry parentage across worker counts.
  5. Report the first downstream saturation point; do not attribute a plateau automatically to the agent.

Related work

  • #1439 removes agent loopback self-calls and must preserve the same cookie and rollout-context contracts.
  • #3008 exposes connector queueing that worker-count changes can create.
  • #3039 covers the distinct resources-worker serving problem.

Activity

  1. ananthsub commented on Nov 10, 2026

    @ananthsub
    ContributorAuthor

    Status update: every agent, resources and environment server now either runs with num_workers > 1 or refuses it at startup with a reason. Part of this is merged, and the rest is in two open pull requests.

    Merged

    Open

    • feat(server): run every server that can with several workers #4790 adds the module-level app to 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_agent without a resources_server, tool_simulation_agent with checkpointing, and the langgraph agents. It also makes the agents' local command line installs safe with several workers, keeps finance_sec_search within SEC.gov's rate limit, and adds a two-worker end-to-end test with real browsers.
    • feat(server): refuse several workers in servers that cannot share state #4885 makes every server that keeps state routing cannot reach refuse several workers through the same method, with the reason. A unit test reads every server entrypoint and fails when one has neither the module-level app nor a refusal.

    Acceptance criteria

    The benchmark plan has not been run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions