Skip to content

fix(sandbox): retry OpenSandbox file transfers that time out - #4702

Open
ffrujeri wants to merge 2 commits into
mainfrom
ffrujeri/opensandbox-retry-hung-file-transfers
Open

ffrujeri wants to merge 2 commits into
mainfrom
ffrujeri/opensandbox-retry-hung-file-transfers

Conversation

@ffrujeri

@ffrujeri ffrujeri commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What

OpenSandbox file uploads and downloads that get no response within connection.request_timeout_s now go through the provider's operation retry policy (operations.retries, backoff) instead of failing on the first TimeoutError.

A new predicate, _is_retryable_file_transfer_error, treats TimeoutError as retryable and otherwise falls back to _is_retryable_sdk_operation_error. Only _write_file and download_file use it. Rewriting the same bytes to the same path is idempotent, and a retried download truncates and restarts the local file, so retrying is safe. Uploads keep the per-attempt request_timeout_s deadline; streamed downloads still have no overall deadline, so for them this covers the SDK's per-read timeout. This follows the precedent of background command status and log polls, which already retry timeouts (#3993). Other operations keep treating a timeout as terminal.

Why

On HSG, OpenCode TB2.1 runs on main lost 52 of 267 rollouts (about 19.5%) to one error:

TimeoutError: Timed out during OpenSandbox write_file(/tmp/nemo-gym-opencode-sessions/<id>/process_supervisor.py) after 300s

The agent surfaced this as HTTP 500 / environment_server_failed.

The sandbox's own execd log shows the request arriving (http: POST /files/upload) and then nothing until the 300 s client timeout. A retry immediately afterwards succeeds and the harness launches normally. execd's HTTP server sets no timeouts, and the server proxy streams request bodies with no read deadline, so a stalled upload never produces an error response. The root cause of the stall is not identified yet. It reproduces from HSG and JHB, but not from a workstation: about 96 attempts from a workstation never hung, including a run at full concurrency (267 sandboxes, 8 concurrent activations). It also hits OpenCode only; Pi, Codex, Hermes, OpenClaw and Terminus had zero such timeouts. This PR makes the stall recoverable instead of fatal.

No issue filed; the investigation notes are summarized here.

Validation

  • pytest tests/unit_tests/test_opensandbox_provider.py: 156 passed. The new test_file_transfers_retry_unanswered_requests covers three cases:

    • an upload that is never answered once, then succeeds;
    • a streamed download whose read times out once, then succeeds;
    • an upload that is never answered on any attempt, which still raises the original TimeoutError after the configured retries.

    This test fails without the provider.py change.

  • ruff check, ruff format --check, and pre-commit run --files on the changed files: all clean.

  • Local fault injection: a reverse proxy in front of the real OpenSandbox endpoint swallowed the first supervisor upload.

    • On main, this reproduces the cluster error.
    • With this change, there is one Retrying OpenSandbox SDK operation warning, then staging completes and the uploaded file compiles.
    • When every attempt is swallowed, it fails after the retry budget, so it stays bounded.

Rollout evidence

  • Local: 16 real OpenCode TB2.1 rollouts against OpenSandbox with this change completed staging and launch.
  • HSG, OpenCode TB2.1 (Super GA, 267 rollouts, same configs as the failing main run, with only this change applied; job 8001464, W&B run): the job hit its 4-hour Slurm limit with 255 of 267 rollouts done. 79 supervisor uploads hung and were retried, every retry succeeded, and 0 rollouts failed (vs 52 of 267 on main). The scored mean reward was 0.518 (vs 0.512 on main).
  • HSG, OpenCode TB2.1 through the Harbor environment server with this change (job 8014654): 77 upload hangs were retried with no failures caused by them.
  • JHB, SWE-bench Pro (731 tasks, Nemotron Super, Harbor OpenCode, run without this change): 101 tasks went unscored after all 3 attempts hit TimeoutError: Timed out during OpenSandbox write_file(.../process_supervisor.py) after 300s. So the stall is not HSG-only; this is the same failure this PR retries.

Compatibility

No config or API changes. A stalled transfer now costs up to operations.retries + 1 attempts of request_timeout_s each (300 s by default) before failing, instead of one. Shortening the per-attempt timeout for file transfers is a possible follow-up.

@copy-pr-bot

copy-pr-bot Bot commented Oct 16, 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 20, 2026
Uploads and downloads that receive no response within request_timeout_s now go through the operation retry policy, like background command status and log polls (#3993). Rewriting the same bytes or rereading a file is idempotent, so a retry is safe. On HSG, OpenCode TB2.1 rollouts intermittently lose the process_supervisor.py upload: execd logs the request, then nothing answers until the 300 s timeout, and the rollout fails with HTTP 500.

Signed-off-by: Felipe Vieira Frujeri <[email protected]>
@ffrujeri
ffrujeri force-pushed the ffrujeri/opensandbox-retry-hung-file-transfers branch from e0aa1e7 to 8146f7d Compare October 27, 2026 04:15
@ffrujeri
ffrujeri marked this pull request as ready for review October 27, 2026 04:16
@ffrujeri

Copy link
Copy Markdown
Contributor Author

/ok to test 8146f7d

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 27, 2026 04:16
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 27, 2026

@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 concerns found.

Reviewed the provider changes, regression tests, and affected retry, staging, cleanup, and download paths. Timeout retries remain scoped to file transfers, retain configured attempt limits, and restart downloads by truncating the destination.

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.

@adil-a

adil-a commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

/ok to test 3a7edad

@copy-pr-bot

copy-pr-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

/ok to test 3a7edad

@adil-a, there was an error processing your request: E2

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

@adil-a

adil-a commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

/ok to test 3a7edad

@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/40556782812

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 27, 2026
@adil-a
adil-a added this pull request to the merge queue Oct 28, 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/40755660359

@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/40756041200

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 28, 2026

This branch was previously deployed

1 inactive deployment
public — 3a7edada Deployed Oct 27, 2026 by copy-pr-bot[bot] via release / finalize / notify #7630
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.

3 participants