feat(sandbox): add idempotent retry for sandbox creation and connection - #472
Merged
Conversation
- Add idempotency key auto-generation (uuid4) with Idempotency-Key header - Add _retryCall method wrapping create/connect with configurable max_retries - Retry on 408/5xx server errors and network errors (timeout, connection refused, etc.) - Configurable via SandboxClient(max_retries=N) or SANDBOX_RETRY_MAX env var - Add Sandbox.create(idempotency_key=...) optional parameter - Add integration test for Git clone timeout retry scenario - Add sandbox_idempotency_retry example - Add SANDBOX_RETRY_MAX to .env.example
There was a problem hiding this comment.
Review summary
Found two issues that prevent the advertised retry behavior from being reliably delivered and verified. Changed Python files compile successfully. The full pytest suite could not run in this workspace because requests and pytest are not installed.
…rrors - Add exponential backoff with jitter (500ms → 10s) between retries - Integration test: re-raise non-retryable 4xx errors instead of logging
- _is_retryable now checks SandboxError messages when status_code is 0 (wrapped network errors like timeouts, connection refused) - Extract _is_retryable_message for reuse
…integration test - Add 'failed to resolve' DNS pattern to retryable message matching - Integration test: raise on all 4xx/5xx except 408 instead of only 4xx
miclle
reviewed
Jul 29, 2026
miclle
reviewed
Jul 29, 2026
miclle
reviewed
Jul 29, 2026
…and add unit tests _normalize_max_retries validates max_retries as non-negative integer. _is_retryable inspects err.cause via ConnectionError/Timeout instead of string matching. SandboxError carries cause from the underlying request exception. Add 6 unit tests for retry/validation. Use GIT_REPO_URL.
miclle
reviewed
Jul 29, 2026
miclle
reviewed
Jul 29, 2026
…otency example Sandbox.create now passes max_retries to SandboxClient internally. Example verifies idempotency with dual creation and proper cleanup. Remove test_create_retry_with_git_clone integration test.
miclle
approved these changes
Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Idempotency-Keyheader for Create_retryCallmethod wrapping Create and Connect, retries on 408/5xx server errors and network errorsmaxRetriesviaSandboxClient(max_retries=N)orSANDBOX_RETRY_MAXenv var (default 5)Sandbox.create(idempotency_key=...)optional parameterexamples/sandbox_idempotency_retry.py