Repository navigation
fix(opensandbox): time out background commands at Gym's own deadline - #5925
AdamRajfer merged 2 commits into
Conversation
execd reports the kill at a command's timeout only as a signal death (exit -1, "signal: killed"), and since NVIDIA-NeMo#5127 the provider no longer infers a timeout from that. With operations.background_exec a command that runs out its time therefore never comes back as a timeout. A harness that treats an unexplained -1 as an unknown outcome (opencode_sandboxed_agent since NVIDIA-NeMo#5859) reruns it as an environment fault instead of verifying it. Background exec now enforces timeout_s itself, as the session path already does: it records provider_command_timeout, interrupts a command still running at the deadline and returns 124 with error_type="timeout". execd's timer moves command_timeout_headroom_s / 2 later and only stops a command whose interrupt was refused; a refused interrupt keeps the reported exit. Signed-off-by: Adam Rajfer <[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 37f1266 |
mpatel31415
left a comment
There was a problem hiding this comment.
SHIP WITH CARE — one reproduced reliability issue below to resolve before approval. The explicit Gym-owned timeout approach is consistent with #5127 and #5859.
Validation: all 295 tests in tests/unit_tests/sandbox/test_opensandbox_provider.py pass locally. I also compared the status-outage scenario against the parent implementation and checked the SDK 0.1.15 / execd 1.1.0 interrupt contract.
Before approval, please attach the live OpenSandbox timeout smoke evidence discussed in Slack, including retained partial output, confirmed process termination, and the intended OpenCode timeout reaching verification. CI core shard 2 currently fails in the unchanged test_only_detached_services_survive_harness_group_termination[False-grace]; this needs a clean rerun or documented baseline diagnosis.
Non-blocking timing note: Gym's command deadline starts after submission returns, while execd starts its timer at launch. A submission reply delayed longer than half the headroom can still let the backstop win and preserve -1/unknown (reproduced with timeout=0.1s, headroom=0.2s, submit latency=0.15s). Please consider anchoring the deadline before submission or documenting this remaining limit.
…dline When status reads failed after the command deadline, the past deadline stayed in the sleep limits and zeroed the polling and backoff delay until the status recovery window ran out. Only a future deadline now shortens the sleep. Adds a regression test for a status outage that spans the deadline. Signed-off-by: Adam Rajfer <[email protected]>
|
/ok to test 200a23c |
|
Live check on a real OpenSandbox deployment at
An OpenCode rollout smoke with the verifier, 2 tasks with a 300 s agent budget, is queued. I'll add its row outcomes here when it ends. |
|
OpenCode rollout smoke at |
mpatel31415
left a comment
There was a problem hiding this comment.
SHIP — LGTM.
Reviewed 200a23c. The status-polling regression is fixed, and the regression test fails against the previous implementation and passes with the fix.
Validation: all 296 provider tests pass locally; CI passes after rerunning the unchanged checkpoint-worker timing tests, which also passed locally. Live timeout and early-exit checks confirm retained partial output and process cleanup. The rollout smoke reached verification without infrastructure retries.
No remaining blocking findings.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42814235326 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE — one timeout-bound regression and the required rollout evidence remain; there’s also a documentation correction below.
I reviewed all three changed files and traced the timeout result into OpenCode’s capture and verification paths. The historical busy-poll issue is fixed: expired command deadlines no longer constrain retry sleeps, while polling cadence and Retry-After handling remain active.
RISK — Complete the representative OpenCode timeout smoke
The supplied live check establishes partial-output retention and process termination for sleep, but its comment explicitly leaves the model-driven OpenCode smoke queued. The intended timeout → capture → verifier path therefore still lacks the representative rollout evidence required by AGENTS.md and the review rubric.
Could you finish that smoke against this head and attach the model, task IDs, effective configuration, and row/log outcomes? Include a budget-exhausted agent that returns 124/timeout, retains a usable export, and reaches verification without being retried as provider_command_outcome_unknown, plus a normally completed control. Preserve the existing capture guard and configured grading policy: missing capture and genuinely unknown outcomes must not become gradable merely to complete the smoke. No production-code change is requested for this evidence gap.
Validation was static; I couldn’t execute tests or inspect the external SDK implementation. One delegated report wasn’t available, so I inspected its documentation and consumer scope directly.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
| seen_running = True | ||
| if command_deadline is not None and not timed_out and loop.time() >= command_deadline: | ||
| timed_out = await self._interrupt_at_deadline( | ||
| handle, execution_id, timeout_s=command_timeout_s, request_timeout_s=status_timeout_s |
There was a problem hiding this comment.
RISK — Bound the interrupt by the remaining client wait.
Could you apply the overall deadline to this new request? Status reads already honor that bound, but the interrupt receives the full status_timeout_s.
Source-derived trigger, not executed: set timeout_s=0.1, command_timeout_headroom_s=0.2, and status_poll_timeout_s=1; keep status Running and make interrupt() take 0.3 seconds. The interrupt starts around 0.1 seconds and returns around 0.4 seconds, beyond the overall client deadline of roughly 0.3 seconds. Only then does the next loop raise provider_command_outcome_unknown. A stalled interrupt can overrun that deadline by almost an entire status-request budget.
In _exec_background, replace this call’s arguments with:
handle,
execution_id,
timeout_s=command_timeout_s,
request_timeout_s=(
min(status_timeout_s, max(0.0, deadline - loop.time()))
if deadline is not None
else status_timeout_s
),This preserves the invariant that interruption cannot extend the existing client wait. Keep the single attempt and preserve uncertainty when its acknowledgement times out; a request timeout does not prove remote termination.
Proposed regression: use a Running fake whose interrupt() waits on an unset event. Assert cancellation at the remaining client deadline, a final provider_command_outcome_unknown failure, one submission, and one interrupt attempt. Retain the existing deadline-test assertions: prompt acceptance returns 124/timeout with partial output, early completion causes no interrupt, and refusal preserves -1 with error_type=None. Please verify the suggested code before adopting it.
| | Other string | Wrap the command with `su -s /bin/sh -c ... <user>`. | | ||
|
|
||
| Commands with a reported exit status return `SandboxExecResult`. A missing or contradictory final outcome raises `NgFailureEvent` with `provider_command_outcome_unknown`. A signal death near the configured deadline does not establish that the command timer fired, so its reported exit code is preserved. For session commands, Gym observes its own deadline directly: it records `provider_command_timeout`, performs cleanup and returns the existing timeout result. A client request timeout instead reports `provider_io_timeout`; it does not establish that the remote command stopped. | ||
| Commands with a reported exit status return `SandboxExecResult`. A missing or contradictory final outcome raises `NgFailureEvent` with `provider_command_outcome_unknown`. A signal death near the configured deadline does not establish that the command timer fired, so its reported exit code is preserved. Gym observes its own deadline directly. For session commands it records `provider_command_timeout`, performs cleanup and returns the existing timeout result. For background commands (`operations.background_exec: true`) it records `provider_command_timeout`, interrupts a command still running at the deadline and returns code `124` with `error_type="timeout"`; execd's own timer is set `command_timeout_headroom_s / 2` later and only stops a command whose interrupt was refused. A client request timeout instead reports `provider_io_timeout`; it does not establish that the remote command stopped. |
There was a problem hiding this comment.
NOTE — Suggest qualifying the timeout guarantee.
This says a background command still running at the deadline returns 124/timeout, and execd’s backstop acts only after a refused interrupt. The implementation is narrower: it interrupts only after a successful Running status read, and any interrupt exception leaves the reported outcome unchanged. A status outage can prevent any interrupt attempt, while subsequent status/log failures can still raise instead of returning a timeout. Operators shouldn’t rely on the unconditional wording when interpreting retries.
Replace only the background-command sentence with wording such as:
For background commands (
operations.background_exec: true), Gym recordsprovider_command_timeoutand makes one interrupt attempt when a successful status read still reports Running at its deadline. An acknowledged interrupt enables the124result witherror_type="timeout", subject to successful completion and output handling. execd’s timeout is set totimeout_s + command_timeout_headroom_s / 2as a backstop. Without an acknowledged interrupt, Gym preserves the reported outcome or raises the existing provider failure.
Preserve the neighboring session-timeout explanation and the distinction between a command timeout, a signal exit, and a client I/O timeout. Static acceptance: check the wording against the accepted-interrupt, refused-interrupt, and status-outage branches; none should promise 124 without an acknowledged interrupt. No runtime test is needed for this wording change.
0a264a3
What
With
operations.background_exec: true, OpenSandbox background commands now time out at Gym's own deadline. Gym recordsprovider_command_timeout, interrupts a command still running attimeout_s, and returns124witherror_type="timeout". This is what the session path already does.Why
execd reports the kill at a command's timeout only as a signal death (
-1,signal: killed). Since #5127 the provider has deliberately not inferred a timeout from that. So in background mode a command that runs out its time never comes back as a timeout. Since #5859,opencode_sandboxed_agenttreats an unexplained-1asprovider_command_outcome_unknown. An agent that uses its whole budget is therefore rerun as an environment fault instead of going to the verifier. We saw this on an OpenCode SWE task: three attempts, each ended at exactly the 3 h agent budget with the model still working.This change does not bring back elapsed-time inference. The timeout result is returned only when Gym itself interrupted the command at its own deadline and execd accepted the interrupt. execd's timer moves
command_timeout_headroom_s / 2later and stays as a backstop. If the interrupt is refused, for example because the command finished just before it, the reported exit is kept.Tests
-1.tests/unit_tests/sandboxandresponses_api_agents/opencode_sandboxed_agent/testspass locally. The exceptions are twotest_script_help_runs_by_direct_pathtests and thetest_openshell_provider.pycollection, which fail the same way on main in my environment.