Repository navigation
Conversation
|
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. |
9e4901b to
9bed8e0
Compare
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]>
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE — one RISK: enabling several workers exposes a cleanup path that can return success without releasing the retained sandbox.
I reviewed all 23 changed files and traced the affected session-routing, worker startup, cleanup and Harbor configuration contracts. The finding below consolidates the same ownership defect in OfficeQA, ViBench and Agentic IF.
This was a static review; I didn't execute tests or rollouts. The PR reports real multi-worker smokes for Partner IF mock tools and Terminus 2, but not the other adapters.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
| super().model_post_init(context) | ||
| if self.config.num_workers not in (None, 1): | ||
| raise ValueError("OfficeQA process-local sandboxes require num_workers=1") | ||
| self._sessions: dict[str, _DocumentSession] = {} |
There was a problem hiding this comment.
RISK — Keep routing ownership while retained session state needs cleanup
With num_workers: 2, let worker A receive a seed whose sandbox start and cleanup both fail. OfficeQA retains the session so a later close can retry cleanup. ViBench and Agentic IF retain failed setup similarly.
These custom maps aren't included in the inherited session_release_pending() callback, which checks only the base class's verification records. Consequently, routing expires ownership after the failed seed's retry window, despite A still holding resources. After expiry and the ownership sweep, a cookieless close arriving on B sees an empty map, fences the ID and returns 200 without retrying A's cleanup. The retained sandbox then survives until shutdown or the provider TTL; a reseed on B can also allocate another session under the same ID. Removing the worker refusal makes this failure newly reachable. The PR acknowledges this edge, but the successful close still misreports cleanup.
Could these three adapters expose their retained state through the existing callback before enabling several workers? The invariant is that routing must not release an ID while its holder retains session state that close needs. A small suggested addition to both OfficeQAResourcesServer and VibenchResourcesServer is:
def session_release_pending(self, session_id: str) -> bool:
return session_id in self._sessions or super().session_release_pending(session_id)For AgenticIFResourcesServer, use its episode map:
def session_release_pending(self, session_id: str) -> bool:
return session_id in self._episodes or super().session_release_pending(session_id)These suggestions use the callback already passed to routing by owned_session_routing(). Map membership also covers OfficeQA's retained session when serialization fails after ready=True; checking only not ready would miss that case. Verify the suggested code before adopting it.
Preserve identical successful-seed replay, conflicting episode rejection, retryable failed closes and the normal close fence. A successful close must remove the retained entry and allow ownership to expire after the retry window; a failed seed that retains nothing must still expire normally. Keep ViBench's artifact_dir multi-worker refusal and its one-worker relay behavior.
Proposed acceptance checks, not executed: for each adapter, use two routed app instances sharing an ownership directory and a controlled clock. Inject setup and cleanup failures on A, advance beyond a short retry window and sweep ownership, then close through B. The close must reach A, retry cleanup and remove A's retained entry before returning 200; reseeding before cleanup must not allocate on B. Repeat OfficeQA with serialization failure after startup. After successful cleanup, check ownership expiry, 409 for conflicting closes and late seeds within the fence window, and normal expiry for a failed seed with no retained state. Retain the cleanup assertions in OfficeQA's failed-start/release test, ViBench's failed-setup test and Agentic IF's failed-release test, plus ViBench's relay worker-count assertions.
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]>
… workers enterpriseops_gym, officeqa, vibench, agentic_if, partner_if's mock-tools and SWE servers, and terminus_2_sandboxed_agent refused num_workers > 1 because their sessions live in process memory. Each of them keys that state by a session that session routing follows: the resources servers by resources_session_id, which is also the cookie's session_id, and Terminus 2's episode sessions by agent_session_id. Seeds, retried seeds, closes and late seeds all reach the worker that saw the session first, and each resources server fences a closed session for the close retry window, which routing's ownership outlasts. None of them binds a fixed host port or shares a temporary path between workers. So these servers drop their refusals. officeqa, vibench and agentic_if gain the module-level app that each uvicorn worker serves; the others already had it. Harbor task preparation no longer pins Terminus 2 to one worker, so its generated instance keeps the shipped template's workers. ViBench still refuses several workers when artifact_dir configures the legacy relay path: vibench_agent's seed opens a routed session that the agent never closes, so a relay episode that fails before a successful verify would leave a worker owning that session until the server exits. agentic_if's max_concurrent_grades and partner_if's judge_max_concurrency are now documented as per-worker limits; the judge's model server bounds its own load. The tests that checked each refusal now check that the server accepts several workers, and officeqa, vibench and agentic_if test that a worker imports their module-level app. The READMEs and the Harbor guide no longer say these servers need one worker. Signed-off-by: Ananth Subramaniam <[email protected]>
Servers that main added since this branch's first commit either refused num_workers > 1 or had no module-level app, so with several workers each uvicorn worker failed at import. Session routing reaches all of their per-episode state: - webvoyager_judge keeps no state, and web_agent keeps an episode's state only inside its /run. Both gain the module-level app. - droid_agent and openhands_agent keep each agent session in the base agent-session records, which routing follows by agent_session_id, and run their harness inside the session's sandbox. They gain the module-level app, and their configs drop the num_workers: 1 pin. - crewai_agent drops its num_workers check for the same reason, and its config and README drop the pin. - chartography drops its refusal. Its lent sandboxes are keyed by resources_session_id, and verify stops the sandbox before grading. - gdp_pdf's sandbox server and visual_coding_opencode drop their refusals, and visual_coding_opencode gains the module-level app. Both keep a lent sandbox from seed until close, past a verify that has no close-follows header. They now report that sandbox through session_release_pending, so routing keeps the session on the worker that holds it until the close stops the sandbox. Without that, the close could reach another worker after the close retry window, and the sandbox would run until its TTL. The agents' concurrency limits are documented as per-worker limits. The tests that checked each refusal now check that the server accepts several workers. New tests import each new entrypoint the way a uvicorn worker does, and check that gdp_pdf and visual_coding_opencode keep ownership until a successful close. Signed-off-by: Ananth Subramaniam <[email protected]>
9bed8e0 to
909d9c5
Compare
athitten
left a comment
There was a problem hiding this comment.
No blocking issues from my side. I checked the routing claim with real two-worker starts (gdp_pdf sandbox, officeqa, webvoyager_judge, visual_coding_opencode, droid, openhands, crewai, and terminus_2 with 4 workers). All served, exited cleanly and printed the startup report once. A 64-session two-worker run of partner_if mock tools kept every session on its seeding worker (seed, tool, verify and close all 200; late calls 409). The 14 component suites pass on the head and on main + this PR.
- Question: the overrides also change checkpoint tracking at any worker count.
session_ended_byreadssession_release_pending(_checkpoint/resources.py#L292-L306), so a verified but unclosed gdp_pdf or visual_coding_opencode session now stays tracked until close. I checked with one worker: tracked with the PR, untracked with the base hook. That is harmless for these restart-only servers, but the base docstring (base_resources_server.py#L710-L715) no longer describes what the overrides return, and #6061 says the hook keeps its meaning. Is this intended? A line in the docstring would help. - Optional: use one rule for state kept past
/verify. partner_if mock tools, officeqa, agentic_if and enterpriseops also keep per-session resources after/verifyuntil close, without this override. No shipped caller sends them a/verifywithout close-follows, so it is not reachable today, but mock tools and enterpriseops stay uncovered after #6061. Either add the same two-line override (suites pass: partner_if 500, officeqa 87, agentic_if 928, enterpriseops 71), or drop the defensive overrides and document that callers must send close-follows. The Fern section "State With Several Workers" could mention this hook for server authors. - Optional:
test_uvicorn_workers_import_a_module_level_appis copied 8 times, and it passes whenappis built from the wrong class (app = SimpleResourcesServer.run_webserver()in officeqa). A shared helper withmonkeypatch.setattr(SimpleServer, "run_webserver", classmethod(lambda cls: cls))andassert module["app"] is module["OfficeQAResourcesServer"]catches that. - PR body: the sentence that #4885's contract test passes with this PR is out of date. On today's main it fails for deepcad and video_caption, which landed after this PR's base and are not this PR's to fix.
- Heads-up: rebasing #5981 onto this PR would bring back the agentic_if refusal (
multiple_workers_unsupported_reason()). - Merge conflict: only the import block of
crewai_agent/tests/test_app.py. Keep bothBaseRunRequestandrefuse_unsupported_num_workers.
| def session_release_pending(self, session_id: str) -> bool: | ||
| # verify leaves the lent sandbox running until close, so with several workers the close must still reach | ||
| # the worker that holds it. | ||
| return session_id in self._sessions or super().session_release_pending(session_id) |
There was a problem hiding this comment.
Non-blocking: this override (and gdp_pdf's at sandbox_app.py#L166-L169) misses the sandbox a failed seed leaves behind.
With several workers:
- A seed's sandbox start fails and its stop also fails.
LentSandboxeskeeps the sandbox in_failed_seed_sandboxesfor a later close (sandbox_lending.py#L135-L147). - The failed seed never sets
_sessions[id](gdp_pdf deletes_seeds[id]), sosession_release_pendingreturns False and routing holds ownership only for the 300 s retry window. - A close after the window lands on another worker. That worker fences the ID and answers 200, while the first worker keeps the sandbox until shutdown or TTL.
Repro: two in-process workers with real routing over Unix sockets, the local provider and a 0.5 s window. The late close got 200 on worker B, and worker A still held the sandbox after 1 stop attempt. With the fix below, the close was forwarded to A, the stop was retried, and the sandbox was released. gdp_pdf behaves the same. No shipped caller closes that late, so the impact is low. But these two servers are not in the "Known edge" list, and #6061 won't cover them.
Suggested fix. I ran it on this branch: gdp_pdf 131 passed, visual_coding_opencode 59, chartography 75, test_sandbox_lending.py 22.
# nemo_gym/server_runtime/sandbox_lending.py, LentSandboxes
def holds(self, resources_session_id: str) -> bool:
"""Whether a sandbox of the session, lent or left by a failed seed, still waits for a stop."""
return resources_session_id in self._sandboxes or resources_session_id in self._failed_seed_sandboxes
# resources_servers/visual_coding_opencode/app.py
def session_release_pending(self, session_id: str) -> bool:
lent = self._lent_sandboxes
return (
session_id in self._sessions
or (lent is not None and lent.holds(session_id))
or super().session_release_pending(session_id)
)gdp_pdf: session_id in self._seeds or self._sandboxes.holds(session_id) or super().session_release_pending(session_id).
Test: in test_sandbox_of_a_failed_seed_is_stopped_later, add assert server.session_release_pending("session") after the failed seed. It fails at this head and passes with the fix.
| # Its shipped template leaves `resources_server.name` unset for benchmark composition; | ||
| # here the environment server drives it, so the generated instance declares none (and is not a composition source). | ||
| "terminus_2_sandboxed_agent": {"num_workers": 1, "resources_server": None}, | ||
| # It keeps the template's workers: session routing sends each episode session's requests to the worker that holds it. | ||
| "terminus_2_sandboxed_agent": {"resources_server": None}, |
There was a problem hiding this comment.
Non-blocking question: Harbor's Terminus 2 now runs the template's 4 workers. Was this measured at Harbor concurrency?
Measured on the real entrypoint with the shipped template fields:
- 1 worker: 1 process, 361 MB unique memory, serving after 3.0 s.
- 4 workers: 5 processes, 1,464 MB, serving after 6.5 s.
That is about +1.1 GB and +3.5 s per run. A request forwarded to another worker adds about 0.5 ms at p50.
Connections are split too. Each worker gets global_aiohttp_connector_limit_per_host // workers = 1024 / 4 = 256 connections to the model server (connection_pool.py#L99-L102), and a session stays on the worker that accepted its seed's connection. Without uvicorn_reuse_port, the busiest of 4 workers held 41-56% of the sessions (8 runs, 64-256 sessions, keep-alive client). So model calls start queuing at about 460-620 concurrent episodes instead of 1024 with one worker. The PR's own Harbor samples show the same skew (droid 134/22, openhands 157/34).
Options:
- Keep
"num_workers": 1here until a run shows 4 workers help (test_harbor_tasks.pypasses with it). - Set
uvicorn_reuse_port: trueon the generated instance (Linux only). - Say in the Harbor guide that the per-host limit is split across workers.
This change could also be its own PR.
Lets fifteen servers run with several uvicorn workers. Each one keeps its session state in memory, keyed by a session ID that session routing (#3905) follows, so a second worker loses nothing. This PR runs in parallel with #4885, which makes the remaining servers refuse several workers through
multiple_workers_unsupported_reason(). The two PRs change different files.Merge this PR before #4885, or together with it. #4885 adds a contract test that every server entrypoint either serves a module-level
appor refuses several workers throughmultiple_workers_unsupported_reason(). Onmain,agentic_if,officeqa,vibench,webvoyager_judge,web_agent,droid_agentandopenhands_agenthave neither, so #4885 alone fails that test. This PR gives each of them the module-levelapp.What changed
Session routing sends each session's requests to the worker that holds it. So a server whose per-session state is keyed by a session ID that routing follows does not need to refuse several workers. This PR has two commits.
The first lifts seven servers that raised in
model_post_initwhennum_workers > 1:enterpriseops_gymresources_session_id, which is also the cookie'ssession_idpartner_ifmock tools (mock_tools_app.py)resources_session_idand the cookiepartner_ifSWE (swe_app.py)scale_swe, which already runs with several workersresources_session_idand the cookieofficeqaresources_session_idand the cookievibenchresources_session_idand the cookieagentic_ifresources_session_idand the cookieterminus_2_sandboxed_agentagent_session_idThe second covers eight servers that
mainadded or changed since. Each one either refused several workers or had no module-levelapp, so with several workers each uvicorn worker failed at import:webvoyager_judgeappweb_agent/runappdroid_agentagent_session_idapp; config dropsnum_workers: 1openhands_agentagent_session_idapp; config dropsnum_workers: 1crewai_agentagent_session_idnum_workers: 1chartographyverifystops the sandbox before gradingresources_session_idand the cookiegdp_pdf(sandbox_app.py)resources_session_idand the cookiesession_release_pendingoverride; config dropsnum_workers: 1visual_coding_opencoderesources_session_idand the cookiesession_release_pendingoverride; module-levelappFor each server I also checked the following:
resources_session_idoragent_session_id, so they reach the worker that saw the ID first. Each resources server records a closed session inResourcesSessionFences, built from the samesession_close_retry_window_secondsthat routing uses. Routing's window starts after the close reply, so a late seed reaches the worker that holds the fence and gets a 409. The agents inherit the same behavior from the base agent-session records./verify, so the session stays on its worker until the close.gdp_pdfandvisual_coding_opencodekeep the lent sandbox after/verifyand stop it on/close_session. A/verifywithout the close-follows header ends routing's ownership one retry window later, so a close after that could reach another worker. That worker would fence the ID and answer 200 while the sandbox kept running until its TTL. Both servers now return True fromsession_release_pendingwhile they hold the session's sandbox, which keeps routing's ownership until a successful close. fix(routing): keep a resources session's owner while the server keeps its state #6061 addskeeps_session_statefor the same purpose but does not touch these two servers. Moving their overrides tokeeps_session_stateis a follow-up once both PRs land.enterpriseops_gymdownloads its seed archive to a temporary file and moves it into place, so two workers that download at once each publish a complete file.agentic_ifwrites its evidence under a directory per run.droid_agentcaches the Droid package on the host. A download writes a uniquely named file and moves it into place, so two workers that download at once each publish a complete file. The agents run their harness, and create its working directories, inside the session's sandbox.resources_serveris unset, which is the episode-session mode. Those sessions are agent sessions, which routing follows byagent_session_id.miniswe_sandboxed_agentandharbor_oracle_agentalready accept several workers in this mode. The legacy/runpath keeps its sandbox in one worker for the length of one request, so it was never affected.Other changes:
nemo_gym/data/tasks/harbor/prepare.py) no longer pinsterminus_2_sandboxed_agentto one worker. The generated instance keeps the shipped template'snum_workers: 4, so a Harbor run with Terminus 2 now starts four agent workers. The table of keys Gym sets in the Harbor guide now matches the code. Itsminiswe_sandboxed_agentrow has been out of date since feat(server): run every server that can with several workers #4790 and is removed too.agentic_if'smax_concurrent_grades,partner_if'sjudge_max_concurrency, and theconcurrencyofcrewai_agent,droid_agentandopenhands_agentare documented as per-worker limits, as feat(server): run every server that can with several workers #4790 did for other limits. With several workers, the server as a whole allows up tonum_workerstimes as many.app, a new test imports the entrypoint the way a uvicorn worker does and gets itsapp. Forgdp_pdfandvisual_coding_opencode, a new test checks that the session's ownership lasts through verify and a failed close, and ends with a successful close.Not in this PR:
visual_browserandwebarena_browserdrive one X display and keep in-process site locks, andmisalignment_monitorserves endpoints that carry no routed ID. They keep refusing several workers, and #4885 moves the browser servers' refusal into an override. Thenum_workers: 1lines in thegoose_agent,kimi_code_agent,cline_agentandsimple_strands_agentsandboxed configs are unchanged.Kept refusals
ViBench still refuses several workers when
artifact_diris set, which configures the legacy relay path (configs/vibench_legacy_agent.yaml).vibench_agent's seed carries noresources_session_id, so routing mints one, and the successful seed opens that session on its worker./close_session. A relay episode that fails before a successful/verifywould therefore leave its worker owning that session until the server exits.The override returns
Nonewhenartifact_diris unset, so the episode-session config (configs/vibench.yaml) runs with several workers.Known edge
officeqa,vibench,agentic_ifandchartographykeep a session's state after a failed seed whose teardown also failed, so that a later close can retry the teardown.#6061 addresses this in session routing, by keeping ownership while the server still holds state for the session.
#6061 also changes
agentic_if/app.py,officeqa/app.py,vibench/app.pyand their tests. Whichever of the two PRs lands second rebases onto the other.Issue
None. #4885's description lists these servers as this PR's scope, so no separate issue is needed.
Validation
enterpriseops_gym,officeqa,vibench,agentic_if,partner_if,gdp_pdf,visual_coding_opencode,chartography,webvoyager_judge,terminus_2_sandboxed_agent,crewai_agent,droid_agent,openhands_agentandweb_agent.main's version of the server.main(b4f6a0d449) merged with feat(server): refuse several workers in servers that cannot share state #4885 (c0c8e8130b) and this PR.pre-commit runon the changed files passes.Rollout evidence
All runs were local, on one workstation, with Docker sandboxes.
partner_ifmock tools with two workers. It needs no sandbox provider.gym env startwithresources_servers/partner_if/configs/mock_tools.yaml,++partner_if_mock_tools.resources_servers.partner_if.num_workers=2, andnvidia/openai/eccn-gpt-oss-20bas the policy model. Thengym eval run --no-serveondata/mock_tools_example.jsonl, with 8 repeats at a concurrency of 16. All 16 rollouts went throughpartner_if_mock_tools_environment_server. All 16 scored reward 1, none was masked, and the run recorded no failures.The lending servers with two workers, over HTTP on real Docker sandboxes. For
visual_coding_opencode,chartographyandgdp_pdfI started the server's entrypoint with two workers, the Docker sandbox provider, and a 3 s close retry window. I drove 12 concurrent sessions through each. Each session ran a seed that lends a container, a retried seed, a verify with the session cookie and no close-follows header, a wait past the retry window, a cookieless close, a retried close, and a late seed.gdp_pdfran on a Docker--internalnetwork, as its isolation check requires.visual_coding_opencode'ssession_release_pendingoverride and reran. 8 of 12 sessions' closes reached the other worker, and 8 containers were still running before shutdown.chartographyreal rollouts with two workers.gym env startwithconfigs/chartography.yaml,configs/judge_model_openai.yamland++chartography.resources_servers.chartography.num_workers=2, withus/azure/openai/gpt-4o-minias the policy and the judge. Thengym eval run --no-serveondata/example.jsonl, with 4 repeats at a concurrency of 20. All 20 rollouts completed throughchartography_environment_server: 3 scored reward 1 and 17 scored 0, none was masked, and the run recorded no failures. The owner files showed both workers holding sessions (17 and 3).The agents on Harbor with two workers.
gym eval run terminal_bench_2_1 --sandbox dockerwithnvidia/openai/eccn-gpt-oss-20bas the policy model, onfix-git,log-summary-date-rangesandgit-multibranch, with 2 repeats at a concurrency of 6. The generated agent instance was set tonum_workers: 2.droid_agentopenhands_agentcrewai_agent(--allow-unsupported-pairing)terminus_2_sandboxed_agent(4 workers, 4 repeats at a concurrency of 12)failedbecause the model returned no content (EmptyLLMResponseError).harbor:trajectory_export_failed), which rejectsNeMoGymResponseMcpCallitems. A rerun with one worker gave the same result, so it does not depend on the number of workers. fix(trajectory): export MCP calls the model endpoint returns to ATIF #6060 fixes that export.Startup with two workers.
webvoyager_judgeandweb_agentstarted with two workers, and each worker served requests. A fullweb_agentepisode needs the browser resources server and an X display. That server keeps refusing several workers, andweb_agentkeeps an episode's state only inside its/run.Compatibility
There is no change for deployments that keep one worker. A config that sets
num_workersabove 1 for these servers used to fail at startup, except a ViBench config that setsartifact_dir. It now starts. Thedroid_agent,openhands_agent,crewai_agentandgdp_pdfconfigs dropnum_workers: 1, which was already the default, so they still start one worker. A Harbor run that usesterminus_2_sandboxed_agentnow starts its template'snum_workers: 4agent workers instead of one. Setting that instance'snum_workersback to 1 restores the old behavior.