Skip to content

fix: handle sandbox create_if_not_exists races#148

Merged
mstolarzblaxelai merged 1 commit into
mainfrom
mstolarz/eng-2188-python-sdk-create-if-not-exist
May 26, 2026
Merged

fix: handle sandbox create_if_not_exists races#148
mstolarzblaxelai merged 1 commit into
mainfrom
mstolarz/eng-2188-python-sdk-create-if-not-exist

Conversation

@mstolarzblaxelai
Copy link
Copy Markdown
Contributor

@mstolarzblaxelai mstolarzblaxelai commented May 26, 2026


Note

Refactors create_if_not_exists to thread a create_if_not_exist flag through to the server-side API, then adds a bounded 3-attempt retry loop to handle races where a sandbox is found in a non-reusable state (TERMINATED, FAILED, etc.) between the 409 response and the next create attempt. Shared helpers _is_sandbox_conflict, _sandbox_name, and NON_REUSABLE_SANDBOX_STATUSES are extracted to eliminate duplication between async and sync paths.

Written by Mendral for commit 6bfe6c8.

Copy link
Copy Markdown
Contributor

@mendral-app mendral-app Bot left a comment

Choose a reason for hiding this comment

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

LGTM

Logic is correct: the loop correctly handles the create→409→get→non-reusable→retry cycle, and the 3-attempt ceiling prevents infinite loops. No security, data-loss, or correctness issues found. The only non-critical gap is the absence of any backoff between retry attempts — under sustained contention (e.g., a slow backend deletion), all 3 attempts may fire within milliseconds and exhaust before the terminal sandbox is cleaned up, but this is a reliability trade-off rather than a correctness bug.

Tag @mendral-app with feedback or questions. View session

@mstolarzblaxelai mstolarzblaxelai marked this pull request as ready for review May 26, 2026 23:24
@mstolarzblaxelai mstolarzblaxelai merged commit 3607ab6 into main May 26, 2026
19 checks passed
@mstolarzblaxelai mstolarzblaxelai deleted the mstolarz/eng-2188-python-sdk-create-if-not-exist branch May 26, 2026 23:27
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.

1 participant