Skip to content

feat: add createIfNotExist query param support in SDK#120

Closed
devin-ai-integration[bot] wants to merge 6 commits into
mainfrom
cdrappier/devin-ENG-2188-create-if-not-exist
Closed

feat: add createIfNotExist query param support in SDK#120
devin-ai-integration[bot] wants to merge 6 commits into
mainfrom
cdrappier/devin-ENG-2188-create-if-not-exist

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot commented Mar 21, 2026

Summary

Adds create_if_not_exist query parameter support to the Python SDK's sandbox creation flow. When create_if_not_exist=True is 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:

  • Makefile: Added branch variable (?= main) so sdk-sandbox and sdk-controlplane targets can regenerate clients from feature branches via make sdk-controlplane branch=<branch>
  • Async SandboxInstance.create() and sync SyncSandboxInstance.create(): Accept new create_if_not_exist: bool = False parameter, forwarded to the generated create_sandbox() client call
  • create_if_not_exists() (both async and sync): Now passes create_if_not_exist=True to create() calls
  • CodeInterpreter.create() / SyncCodeInterpreter.create(): Forward the new create_if_not_exist parameter through to SandboxInstance.create()
  • Regenerated client from main: Picks up latest OpenAPI spec (includes new image sharing endpoints, sandbox state model — unrelated to this feature)

Updates since last revision

  • Removed asyncio.sleep(2) / time.sleep(2) delays from the 409 handler — the existing 409 handling was already correct and needs no modification
  • Regenerated client from main branch (controlplane PR #3304 is now merged) instead of the feature branch
  • Simplified overall approach: just pass the query parameter, keep all existing behavior

Part of ENG-2188. Depends on controlplane PR #3304 (already merged).

Review & Testing Checklist for Human

  • Unrelated generated files in diff: Client regeneration from latest main pulled 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.
  • End-to-end verification: Test 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

  • The generated create_sandbox client function already had the create_if_not_exist query parameter on main, so no client regeneration was needed for this feature specifically — the regeneration just picks up the latest spec.
  • No sleep/delay was added to the 409 handler; the existing fallback logic (get existing sandbox, check if TERMINATED, re-create or return) is unchanged.

Link to Devin session: https://app.devin.ai/sessions/c6b33927f20443edaa3e9e14b9f74f63
Requested by: @drappier-charles


Open with Devin

Note

Adds create_if_not_exist query parameter support to sandbox creation, forwarding it through SandboxInstance.create() and SyncSandboxInstance.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.

drappier-charles and others added 2 commits March 21, 2026 21:00
…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-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

drappier-charles and others added 2 commits April 9, 2026 19:33
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>
Copy link
Copy Markdown
Contributor Author

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

drappier-charles and others added 2 commits April 13, 2026 19:39
… 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>
@devin-ai-integration devin-ai-integration Bot changed the title feat: createIfNotExist server-side optimization + SDK updates feat: add createIfNotExist query param support in SDK Apr 13, 2026
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.

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

@drappier-charles drappier-charles marked this pull request as ready for review April 13, 2026 19:58
@mstolarzblaxelai
Copy link
Copy Markdown
Contributor

Update: Superseded by #148.

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.

2 participants