Repository navigation
fix(opensandbox): make exec resilient to execd bind race and dead backends - #2418
Conversation
…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]>
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]>
|
/claude review |
|
SHIP — well-scoped 502-retry fix; correct, tested, no reliability concerns. The design cleanly separates the two failure modes: real command failures still honor NOTE (author's call): the whole safety of retrying under |
Summary
Makes OpenSandbox
execresilient to two failure modes that both surface as proxy502s.Runningand proxy exec requests before its exec daemon (execd) has bound its port. The proxy then returns502 "could not connect to the backend"for a short window after a pod first reportsRunning(worse on cold images). The command never reachedexecd, so retrying it is safe even whencommand_retries=0— the default, since agent commands are usually mutating and must not double-run.502s forever, because sandbox pods never restart.With
command_retries=0, either mode currently fails the exec outright.Changes
_submit_command, which retries only connect-class502s underoperations.retries(independent ofcommand_retries) to cover the bind window.SandboxBackendUnreachableErrorso a dead backend fails fast instead of retrying for hours.operation+sandbox_id, so an absorbed create-probe retry is distinguishable from a failing agent exec.No config change:
command_retriesstays0, and the502-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:502s are retried withcommand_retries=0without the command double-running;502s raise the typed backend-unreachable error.🤖 Generated with Claude Code