Skip to content

fix(opensandbox): make exec resilient to execd bind race and dead backends - #2418

Merged
bxyu-nvidia merged 4 commits into
mainfrom
hemil/opensandbox-exec-resiliency
Aug 8, 2026
Merged

bxyu-nvidia merged 4 commits into
mainfrom
hemil/opensandbox-exec-resiliency

Conversation

@hemildesai

Copy link
Copy Markdown
Contributor

Summary

Makes OpenSandbox exec resilient to two failure modes that both surface as proxy 502s.

  1. execd bind race. Sandbox pods have no readiness probe, so the server can mark a sandbox Running and proxy exec requests before its exec daemon (execd) has bound its port. The proxy then returns 502 "could not connect to the backend" for a short window after a pod first reports Running (worse on cold images). The command never reached execd, so retrying it is safe even when command_retries=0 — the default, since agent commands are usually mutating and must not double-run.
  2. Dead backend. A container that OOM-kills mid-run leaves a live server record whose every request 502s forever, because sandbox pods never restart.

With command_retries=0, either mode currently fails the exec outright.

Changes

  • Add _submit_command, which retries only connect-class 502s under operations.retries (independent of command_retries) to cover the bind window.
  • Once that budget is exhausted, raise a typed SandboxBackendUnreachableError so a dead backend fails fast instead of retrying for hours.
  • Retry logging now carries operation + sandbox_id, so an absorbed create-probe retry is distinguishable from a failing agent exec.

No config change: command_retries stays 0, and the 502-retry lives in a separate budget so mutating commands are never double-run.

Testing

Two unit tests in tests/unit_tests/test_opensandbox_provider.py:

  • transient 502s are retried with command_retries=0 without the command double-running;
  • persistent 502s raise the typed backend-unreachable error.

🤖 Generated with Claude Code

…kends

OpenSandbox pods have no readiness probe, so the server can mark a sandbox
Running and proxy exec requests before its exec daemon (execd) has bound its
port. The proxy then returns a 502 "could not connect to the backend" for a
short window after a pod first reports Running (worse on cold images). Because
the command never reached execd, retrying is safe even when command_retries=0
(the default — agent commands are usually mutating and must not double-run).

A second, rarer mode: a container that OOM-kills mid-run leaves a live server
record whose every request 502s forever, since sandbox pods never restart.

Add `_submit_command`, which retries only connect-class 502s under
`operations.retries` (independent of `command_retries`) to cover the bind
window, then raises a typed `SandboxBackendUnreachableError` once the budget is
exhausted so a dead backend fails fast instead of retrying for hours. Retry
logging now carries the operation and sandbox_id to distinguish an absorbed
create-probe retry from a failing agent exec.

Tested: transient 502s are retried with command_retries=0 without the command
double-running; persistent 502s raise the typed backend-unreachable error.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Aug 7, 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.

hemildesai and others added 3 commits August 7, 2026 11:45
Trim to the essential why and drop the soft timing figure.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
The execd bind window is short, so reusing the per-operation backoff
(retry_max_delay_s defaults to 45s, tuned for slow creates) waited far too
long between retries (1, 2, 4, 8, 16s). Poll quickly with a small capped
backoff (0.25s doubling to a 2s cap) so the bind race is caught fast and a
dead backend is declared in a few seconds instead of ~30s.

Tests mock asyncio.sleep so the backoff no longer slows them, and drop the
now-irrelevant retry-delay config.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
Log args go one-per-line under the magic-trailing-comma rule.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
@hemildesai

Copy link
Copy Markdown
Contributor Author

/claude review

@claude

claude Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

SHIP — well-scoped 502-retry fix; correct, tested, no reliability concerns.

The design cleanly separates the two failure modes: real command failures still honor command_retries=0 (no double-run), while proxy-connect 502s — where the command never reached execd — get retried under the operations.retries budget and then fail fast with a typed SandboxBackendUnreachableError instead of hanging on a dead backend. Non-502 exceptions and TimeoutError re-raise immediately (_submit_command, provider.py:795-797), the inner _await_sdk_operation is called with the caller's retries so budgets don't multiply, and the backoff is capped with the existing hard-cap wait_for as a backstop. Both new paths have unit coverage.

NOTE (author's call): the whole safety of retrying under command_retries=0 rests on the documented premise that "a proxy 502 is a TCP-connect failure ⇒ the command never started" (_submit_command docstring, provider.py:778-784). If this proxy can ever return 502 after forwarding the request (upstream started the command, then the connection dropped), a retry would double-run a command in a stateful sandbox — the exact case command_retries=0 exists to prevent. This reads as deliberate infra knowledge about the OpenSandbox proxy; just flagging that the correctness guarantee is only as strong as that 502 semantics assumption. No change requested.

@hemildesai
hemildesai marked this pull request as ready for review August 7, 2026 21:39
@bxyu-nvidia
bxyu-nvidia merged commit ce3be4e into main Aug 8, 2026
18 checks passed
@bxyu-nvidia
bxyu-nvidia deleted the hemil/opensandbox-exec-resiliency branch August 8, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants