Skip to content

fix(opensandbox): keep a finished command's exit status when it deleted its own output - #4871

Merged
cmunley1 merged 4 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/opensandbox-deleted-output-status
Oct 21, 2026
Merged

cmunley1 merged 4 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/opensandbox-deleted-output-status

Conversation

@gwarmstrong

@gwarmstrong gwarmstrong commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

With background_exec, execd keeps a command's output in a file under os.TempDir(), which is /tmp unless TMPDIR is set (command_common.go). A command that empties /tmp deletes 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's rdkit-ic-constraints verifier resets /tmp, /var/tmp and /dev/shm between 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_type stays unset, because callers treat any error_type as a failed command. Any other log-read failure still raises, and so would a reworded execd message.

Tradeoff: with error_type unset, a caller cannot tell "output lost" from "no output". A verifier that parses stdout and checks only error_type would score a run whose verifier cleaned /tmp as 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.
  • Earlier runs on an older 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. The terminal_bench_4 verifier writes its output to /logs/verifier/test-stdout.txt itself, 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.

…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]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:sandbox Sandbox providers, isolation, and sandbox runtime contracts bug Something isn't working labels Oct 21, 2026
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]>
@hemildesai

Copy link
Copy Markdown
Contributor

/review model=claude

@hemildesai hemildesai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Move the string check into a helper, for example _is_deleted_output_error(exc).
  2. Use the helper in the except block.
  3. Make the is_retryable predicate for this log read return False when the helper matches.

I could not confirm which status execd sends. The generated client accepts 400, 404, and 500 for this endpoint.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: same wording as DELETED_OUTPUT_NOTE. The log says "deleted by the command itself", but another process can delete the file too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@gwarmstrong
gwarmstrong marked this pull request as ready for review October 21, 2026 20:48
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 21, 2026
@NVIDIA-NeMo NVIDIA-NeMo deleted a comment from copy-pr-bot Bot Oct 21, 2026
@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test 3346cd2

@copy-pr-bot

copy-pr-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

/ok to test 3346cd2

@gwarmstrong, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@hemildesai

Copy link
Copy Markdown
Contributor

/ok to test 3346cd2

@copy-pr-bot

copy-pr-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

/ok to test 3346cd2

@hemildesai, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@cmunley1

Copy link
Copy Markdown
Contributor

/ok to test f6b9602

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 21, 2026 22:23
@cmunley1

Copy link
Copy Markdown
Contributor

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cmunley1
cmunley1 added this pull request to the merge queue Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/39692839918

Merged via the queue into NVIDIA-NeMo:main with commit 1a56bff Oct 21, 2026
52 of 58 checks passed
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Oct 22, 2026
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]>

This branch was previously deployed

1 inactive deployment
public — f6b96023 Deployed Oct 21, 2026 by copy-pr-bot[bot] via release / finalize / notify #6496
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:sandbox Sandbox providers, isolation, and sandbox runtime contracts bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants