Repository navigation
fix(opensandbox): keep a finished command's exit status when it deleted its own output - #4871
Conversation
…ed its own output execd keeps background-command output under /tmp/opensandbox-execd. A command that empties /tmp (terminal-bench-science's rdkit-ic-constraints verifier resets /tmp, /var/tmp and /dev/shm between worker calls) deletes that file, so the post-completion log read failed with "error open combined output file ... no such file or directory" and the trial was reported as an infrastructure error. The status read has already returned the exit code, so keep it and report no output for that one error; any other log-read failure still raises. Signed-off-by: gwarmstrong <[email protected]>
When a finished background command deleted its own output file, the result now carries a stderr note that the output is gone and the exit status was kept, so a caller that needed the output sees why it is empty. error_type stays unset because callers treat any error_type as a failed command. The comment cites where execd keeps the output (os.TempDir()) and the message this matches. A reworded execd message still raises, as before. Signed-off-by: gwarmstrong <[email protected]>
|
/review model=claude |
hemildesai
left a comment
There was a problem hiding this comment.
The fix is narrow and correct. It keeps the exit code only for the deleted-output error, and all other errors still raise. I ran tests/unit_tests/test_opensandbox_provider.py on this head in a fresh venv: 129 passed.
I have one main request (no retries for this error) and some small notes. See the inline comments.
| sandbox_id=handle.sandbox_id, | ||
| timeout_s=poll_timeout_s, | ||
| retries=self._operations.retries, | ||
| is_retryable=_command_read_is_retryable, |
There was a problem hiding this comment.
The provider retries this error before the fallback runs.
If execd sends the missing-file error as HTTP 500, the SDK raises SandboxApiException(status_code=500). 500 is in RETRYABLE_HTTP_STATUS_CODES, so _command_read_is_retryable returns True. With the default operations.retries=3, the provider reads the deleted file 3 more times. Each attempt adds backoff time, a retry warning, and an SDK logger.error with a traceback.
Suggested fix:
- Move the string check into a helper, for example
_is_deleted_output_error(exc). - Use the helper in the
exceptblock. - Make the
is_retryablepredicate for this log read returnFalsewhen the helper matches.
I could not confirm which status execd sends. The generated client accepts 400, 404, and 500 for this endpoint.
There was a problem hiding this comment.
Good catch, fixed in 3346cd2. The string check is now _is_deleted_output_error(). The except block uses it, and so does the log read's is_retryable predicate, which returns False for it. A deleted file is read once; other 500s keep their retries.
| status_error = getattr(status, "error", None) | ||
| stderr = status_error or None | ||
| if output_deleted: | ||
| stderr = f"{stderr}\n{DELETED_OUTPUT_NOTE}" if stderr else DELETED_OUTPUT_NOTE |
There was a problem hiding this comment.
A design note. No change is necessary in this PR.
With error_type=None, a caller cannot tell "output lost" from "no output". Some verifiers parse stdout and check only error_type first, for example swebench_pro/verification.py. If such a script cleans /tmp, the rollout gets a reward of 0 and is not marked inconclusive. AGENTS.md asks us to keep infrastructure failures separate from task failures.
The risk is low today, because TB4 and Harbor read a reward file. Please add one sentence about this tradeoff to the PR body. A follow-up can run execd with TMPDIR outside the scratch directories of the task.
Also: if exit_code is None and the status has no error, the code below returns return_code=0. That fallback is older than this PR. But with the output deleted, the result says "success" with no evidence.
There was a problem hiding this comment.
Agreed. I added the tradeoff to the PR body: a caller can't tell "output lost" from "no output", the risk is low while verifiers read a reward file, and the stderr note says what happened. The sandbox-side fix is execd with its own TMPDIR. On the return_code=0 fallback: this PR now keeps the exit status only when execd returned one. With the output deleted and no exit code, the original error still raises, so that path can't report a success without evidence. I left the older fallback itself unchanged.
| ATTRIBUTION_KEY_PREFIX_RE = re.compile(r"(?=.{1,253}$)[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*") | ||
| # Returned as stderr when a finished background command deleted its own output file, | ||
| # so a caller that needed the output sees why it is empty. | ||
| DELETED_OUTPUT_NOTE = ( |
There was a problem hiding this comment.
Nit: this note (and the LOGGER.warning below) says that the command deleted its own output. A different process can also delete the file. For example, a concurrent exec in the same sandbox that cleans /tmp deletes the output files of all running commands.
Suggested text: "The output file was deleted, for example by a command that cleaned the temporary directory."
There was a problem hiding this comment.
Done in 3346cd2, using your wording: "the output file was deleted, for example by a command that cleaned the temporary directory."
| if "combined output file" not in message or "no such file or directory" not in message: | ||
| raise | ||
| LOGGER.warning( | ||
| "OpenSandbox command output was deleted by the command itself; keeping its exit status %r. " |
There was a problem hiding this comment.
Nit: same wording as DELETED_OUTPUT_NOTE. The log says "deleted by the command itself", but another process can delete the file too.
There was a problem hiding this comment.
Done, same commit: "OpenSandbox command output file was deleted; keeping the command's exit status ...".
| return SimpleNamespace(running=False, exit_code=3, error=status_error) | ||
|
|
||
| async def get_background_command_logs(self, execution_id: str) -> Any: | ||
| raise RuntimeError(log_error) |
There was a problem hiding this comment.
Nit: this fake raises a plain RuntimeError, and the test sets retries=0. So the test does not cover the retry path from my other comment.
I checked the SDK. handle_api_error builds "Get command logs failed: {parsed.message}", so the message text here matches the real error. Consider a fake exception with status_code=500 and retries > 0. Then assert that the log read runs only once.
There was a problem hiding this comment.
Done. The fake now raises SandboxApiException(..., status_code=500) with retries: 2. It asserts the deleted output is read once and other 500s are read 3 times. A case without an exit code checks that the error still raises. With the old predicate, 4 of the 6 cases fail.
Review follow-up. execd reports a deleted output file as an HTTP 500, which the log read treated as retryable, so the provider reread a file that cannot come back, with backoff, a retry warning and an SDK traceback each time. The check is now a helper that also disables retries for that error. The exit status is kept only when execd returned one; without it there is no evidence of how the command ended, so the error still raises. The note and the warning no longer say the command deleted its own output, since another command in the sandbox can clean the temporary directory too. The test raises the SDK's SandboxApiException with status 500 and retries enabled, and checks that the deleted output is read once while other 500s keep their retries. Signed-off-by: gwarmstrong <[email protected]>
|
/ok to test 3346cd2 |
@gwarmstrong, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
|
/ok to test 3346cd2 |
@hemildesai, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
|
/ok to test f6b9602 |
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP — LGTM, no material reliability concerns found.
The provider fallback requires a known exit code, avoids retrying deleted-output reads, preserves status diagnostics, and leaves unrelated log failures raising. The earlier retry and missing-exit-code concerns are addressed in the current source and regression tests.
Both changed files and the directly affected retry, result, and verifier paths were reviewed. Static review only; tests were not executed.
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.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/39692839918 |
Brings in NVIDIA-NeMo#4871, which keeps rdkit-ic-constraints from being reported as an infrastructure error on OpenSandbox, before the full oracle rerun. Signed-off-by: gwarmstrong <[email protected]>
What does this PR do?
With
background_exec, execd keeps a command's output in a file underos.TempDir(), which is/tmpunlessTMPDIRis set (command_common.go). A command that empties/tmpdeletes that file, so the provider's log read after the command finished fails with "error open combined output file ... no such file or directory", and the trial is reported as an infrastructure error even though the status read already returned the exit code. Terminal-Bench-Science'srdkit-ic-constraintsverifier resets/tmp,/var/tmpand/dev/shmbetween worker calls, so without this every one of its trials is an infrastructure error on OpenSandbox.The provider now keeps the exit code for that one error, returns no stdout, and puts a note in stderr saying the output file was deleted, so a caller that needed the output sees why it is empty. It reads the deleted file once instead of retrying (execd reports it as an HTTP 500, which is otherwise retryable), and keeps the exit status only when execd returned one.
error_typestays unset, because callers treat anyerror_typeas a failed command. Any other log-read failure still raises, and so would a reworded execd message.Tradeoff: with
error_typeunset, a caller cannot tell "output lost" from "no output". A verifier that parses stdout and checks onlyerror_typewould score a run whose verifier cleaned/tmpas 0 instead of inconclusive. The risk is low today, since Terminal-Bench 4 and Harbor-style verifiers read a reward file, and the stderr note says what happened. The root fix is on the sandbox side: run execd with a temporary directory outside the task's scratch directories, which would make this fallback unnecessary.No issue: found in Terminal-Bench-Science runs; the repro is above.
Validation
tests/unit_tests/test_opensandbox_provider.py: 131 passed. The new cases raise the SDK's 500 with retries on, with and without a status error, and check that a deleted output file is read once, that other 500s keep their retries, and that a deleted output without an exit code still raises.main, on OpenSandbox:rdkit-ic-constraints's reference solution passed 35/35 checks with this change (it was an infrastructure error without it), within a 70-task reference-solution run that passed 70/70. Theterminal_bench_4verifier writes its output to/logs/verifier/test-stdout.txtitself, so nothing it reads is lost.Rollouts
N/A (provider error handling).
Compatibility and benchmark impact
No settings change. A command whose output file disappeared now returns its exit status, no stdout and an explanatory stderr note, instead of raising.