feat: add createIfNotExist query param support in SDK#120
feat: add createIfNotExist query param support in SDK#120devin-ai-integration[bot] wants to merge 6 commits into
Conversation
…ane branch - Add branch variable to Makefile for SDK regeneration from feature branches - Regenerate controlplane client with createIfNotExist query parameter - Update async create() and create_if_not_exists() to pass create_if_not_exist - Update sync create() and create_if_not_exists() with same changes - Add asyncio.sleep(2) / time.sleep(2) delay in 409 handler for race condition ENG-2188 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The controlplane branch OpenAPI spec introduced unrelated model changes (sso_domain, group_workspace_mapping, etc) that should not be in this PR. The create_if_not_exist query param already exists in the main branch client, so no client regeneration is needed. ENG-2188 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Both async CodeInterpreter.create and sync SyncCodeInterpreter.create previously only accepted safe parameter, silently dropping create_if_not_exist when called via create_if_not_exists. The server never received the query parameter, falling back to 409 + unnecessary 2s delay. ENG-2188 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… 409 handling Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Needs attention
Two bugs in the 409 fallback path. First, e.code in [409, \"SANDBOX_ALREADY_EXISTS\"] — e.code is typed str | None, so the integer 409 can never match; the check is effectively just e.code == \"SANDBOX_ALREADY_EXISTS\" (pre-existing, but worth fixing). Second, in the TERMINATED re-create path (sandbox/default/sandbox.py:463, sandbox/sync/sandbox.py:395), the new cls.create(sandbox, create_if_not_exist=True) call can itself receive a 409 (race: another process already recreated the sandbox), which escapes uncaught from create_if_not_exists() — wrap it in a try/except that falls back to cls.get(name) on 409.
Tag @mendral-app with feedback or questions. View session
|
Update: Superseded by #148. |
Summary
Adds
create_if_not_existquery parameter support to the Python SDK's sandbox creation flow. Whencreate_if_not_exist=Trueis passed, the controlplane returns an existing alive sandbox (200) instead of creating a new one, reducing unnecessary 409 conflicts. Existing 409 handling is preserved unchanged for parallel-creation race conditions.Key changes:
branchvariable (?= main) sosdk-sandboxandsdk-controlplanetargets can regenerate clients from feature branches viamake sdk-controlplane branch=<branch>SandboxInstance.create()and syncSyncSandboxInstance.create(): Accept newcreate_if_not_exist: bool = Falseparameter, forwarded to the generatedcreate_sandbox()client callcreate_if_not_exists()(both async and sync): Now passescreate_if_not_exist=Truetocreate()callsCodeInterpreter.create()/SyncCodeInterpreter.create(): Forward the newcreate_if_not_existparameter through toSandboxInstance.create()Updates since last revision
asyncio.sleep(2)/time.sleep(2)delays from the 409 handler — the existing 409 handling was already correct and needs no modificationmainbranch (controlplane PR #3304 is now merged) instead of the feature branchPart of ENG-2188. Depends on controlplane PR #3304 (already merged).
Review & Testing Checklist for Human
mainpulled in new image sharing endpoints (list_image_shares.py,share_image.py,unshare_image.py),sandbox_state.py,share_image_body.py, and minor whitespace changes across many models. These are not related to createIfNotExist but are a side effect of regenerating against the latest spec. Verify this is acceptable to include in this PR.create_if_not_exists()with a named sandbox to confirm: (1) first call creates, (2) second call returns existing sandbox via 200 without hitting 409, (3) parallel creation race still correctly handles 409 and returns existing sandbox.Notes
create_sandboxclient function already had thecreate_if_not_existquery parameter on main, so no client regeneration was needed for this feature specifically — the regeneration just picks up the latest spec.Link to Devin session: https://app.devin.ai/sessions/c6b33927f20443edaa3e9e14b9f74f63
Requested by: @drappier-charles
Note
Adds
create_if_not_existquery parameter support to sandbox creation, forwarding it throughSandboxInstance.create()andSyncSandboxInstance.create()to the controlplane API. When the server still returns 409 (race condition),create_if_not_exists()falls back to fetching the existing sandbox. Also includes regenerated client files with new image-sharing endpoints and model additions.Written by Mendral for commit 81f0eaf.