fix: handle sandbox create_if_not_exists races#148
Merged
mstolarzblaxelai merged 1 commit intoMay 26, 2026
Conversation
Contributor
There was a problem hiding this comment.
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
2 tasks
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.
create_if_not_existthrough sandbox and CodeInterpreter create paths.Note
Refactors
create_if_not_existsto thread acreate_if_not_existflag 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, andNON_REUSABLE_SANDBOX_STATUSESare extracted to eliminate duplication between async and sync paths.Written by Mendral for commit 6bfe6c8.