Repository navigation
fix(agent): enforce monotonic deadlines on the event loop's clock - #6324
Conversation
Signed-off-by: Chris Wing <[email protected]>
|
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. |
|
/ok to test bed436d |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP
LGTM. No concerns found. I inspected all eight changed files and traced the affected deadline producers, timeout handling, and session cleanup paths. The converted call sites use monotonic deadlines, and the added regressions exercise the event-loop clock offset.
Static review only. I did not run tests or rollouts.
Note: formal approval is not available for this request, so this review is posted as a comment only.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
…line Signed-off-by: Chris Wing <[email protected]> # Conflicts: # nemo_gym/agents/utils/sandbox_session.py # nemo_gym/utils/__init__.py # responses_api_agents/opencode_agent/app.py
…ent bench Activation.slot() waited until its deadline on the event loop's clock while OpenCode passed it a time.monotonic() deadline, so under uvloop on macOS the slot wait expired at once. It now uses monotonic_timeout. legal_agent_bench_native computed its deadline from loop.time() and passed it to SandboxSession.execute, which expects a time.monotonic() deadline. It now uses time.monotonic() throughout. Signed-off-by: Chris Wing <[email protected]>
Move the miniswe monotonic_timeout import into the import block, state in the checkpointable harness guide that Activation.slot takes a time.monotonic() deadline, and describe the uvloop clock by its observed behavior. Signed-off-by: Chris Wing <[email protected]>
Add tests that run the swe_together collection deadline, the miniswe setup deadlines and the OpenCode slot and preparation deadlines on an event loop whose clock runs ahead of time.monotonic(); each fails if its call site goes back to asyncio.timeout_at. Share the clock-ahead loop through tests/helpers, drop the test that only exercised asyncio.timeout_at, and state in SandboxSession.execute that its deadline is a time.monotonic() time. Signed-off-by: Chris Wing <[email protected]>
…s on a fast-running loop clock The clock test now lets the activation wait yield and asserts that staging started, so it fails when either deadline is read on the event loop clock. The shared helper cleans up its loop the way asyncio.run does. Signed-off-by: Chris Wing <[email protected]>
|
/ok to test cf83ea1 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/46035394024 |
Main fixed the macOS clock mismatch itself (#6324): a SandboxSession or checkpoint-slot deadline is now a time.monotonic() time, enforced with monotonic_timeout. This branch had fixed the same bug the other way, with deadlines on the event loop's clock, and the two cannot be mixed: a loop-clock deadline handed to main's execute would expire at once under uvloop on macOS again. So this branch's clock changes are dropped in favour of main's, in sandbox_session, OpenCode, Pi, Codex, OpenClaw and mini-SWE, together with their loop-clock tests; mini-SWE keeps its setup-timeout warning. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Adil Asif <[email protected]>
What changed and why
Deadlines built as
time.monotonic() + timeoutwere passed toasyncio.timeout_at, which compares them withloop.time(). Under uvloop (which uvicorn picks automatically when installed),loop.time()also counts time the machine slept, so on macOS it can run days ahead oftime.monotonic(). On the machine where this was found the gap was about 927,750 s, so every such deadline was already in the past and expired at once. Ahello_worldOpenCode rollout with a Docker sandbox failed every time with aTimeoutErrorabout 6 s in, insideSandboxSession.execute. Linux CI does not catch it because the two clocks agree there.This PR adds
nemo_gym.utils.deadlines.monotonic_timeout(deadline), which turns a monotonic deadline into a remaining duration forasyncio.timeout, and uses it at every site that passed a monotonic deadline totimeout_at:nemo_gym/agents/utils/sandbox_session.py(execute)responses_api_agents/opencode_agent/app.py(activation preparation and the session response)responses_api_agents/miniswe_sandboxed_agent/app.py(agent setup, two sites)environment_servers/swe_together/app.py(turn collection)nemo_gym/server_runtime/_checkpoint/agent.py(Activation.slot): its only caller, OpenCode, passes a monotonic deadline, butslottreated it as loop time.responses_api_agents/legal_agent_bench_native/app.py: built its deadline fromloop.time()and passed it toSandboxSession.execute, which expects a monotonic one. It now usesmonotonic()throughout.Deadlines stay monotonic everywhere else, since they are used in arithmetic with
monotonic(). Sites that build and consume their deadline onloop.time()alone (opencode_agent/sandbox.py,terminal_bench_4/verifier.py) are unchanged. TheSandboxSession.executeandActivation.slotdocstrings andcheckpointable-harness.mdxnow say the deadline is atime.monotonic()time. The helper is exported fromnemo_gym.utilsfor servers.Issue
None filed. The bug was found and root-caused during a local smoke run, and this PR is the complete fix, so a separate issue would only duplicate this description.
Validation
tests/helpers/event_loop_clock.py(new): an event loop whose clock runs 10^6 s ahead oftime.monotonic(), as uvloop's does on macOS.tests/unit_tests/utils/test_deadlines.py(new): on that loop,monotonic_timeoutdoes not fire a future deadline early, fires a past one, fires a near one after its remaining time, and never expires forNone.pytest tests/unit_tests/utils tests/unit_tests/agents tests/unit_tests/test_*.py: all pass except threetest_outcome_policy.py::test_upload_evidence_roundtrips_in_reports_and_process_projectioncases, which fail the same way on unmodifiedmain.responses_api_agents/opencode_agent/tests: pass apart from intermittent failures intest_sandbox_sessions.py/test_opencode2_session.pythat also occur on unmodifiedmainand pass when rerun alone.responses_api_agents/miniswe_sandboxed_agent/tests(in a venv with the server's dependencies): 108 passed, 1 skipped.test_server.pywas not collected because of a local venv dependency issue (pathspecimport viaterminal_bench_4), unrelated to this change.environment_servers/swe_together/tests: 282 passed.tests/unit_tests/server_runtime/test_checkpoint_agent.pyandresponses_api_agents/legal_agent_bench_native/tests: pass.pre-commit run --files <changed files>andlint-imports: passed.Rollout evidence
macOS (Apple silicon), Docker via Colima, uvloop 0.21.0 installed in the OpenCode agent venv:
With this fix the rollout reached the model and scored reward 1.0 with 0 failures. Without the fix, the same command on unmodified
main(71c58dc6a3), same machine and same uvloop, dropped the rollout from the score: the agent returned 500 withTimeoutErrorraised fromasyncio.timeout_at(deadline)inSandboxSession.execute(sandbox_session.py:231), before the model was reached.Compatibility
No behavior change where
loop.time()equalstime.monotonic()(the default asyncio loop, and uvloop on Linux). One new public helper,nemo_gym.utils.monotonic_timeout.Activation.slot(semaphore, deadline=...)now takes atime.monotonic()deadline instead of an event loop time; a checkpointable harness that passedloop.time()there must passmonotonic()instead. No config, data or benchmark result changes.