Skip to content

feat: add createIfNotExist query param support in SDK#272

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

feat: add createIfNotExist query param support in SDK#272
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 createIfNotExist query parameter support to the TypeScript SDK's sandbox creation flow. When createIfNotExist=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.

Changes:

  • SandboxInstance.create() now accepts an optional createIfNotExist boolean. When true, it passes ?createIfNotExist=true as a query parameter to createSandbox, allowing the server to return an existing alive sandbox instead of a 409 error.
  • SandboxInstance.createIfNotExists() passes createIfNotExist: true to create() by default. All existing 409 handling logic is unchanged.
  • CodeInterpreter.create() now accepts and forwards the createIfNotExist option to super.create(). Previously, CodeInterpreter.create only destructured { safe }, silently discarding createIfNotExist.
  • Makefile adds a branch variable (defaults to main) so make sdk-controlplane / make sdk-sandbox can regenerate clients from feature branches.
  • Regenerated client from main: Picks up latest OpenAPI spec including new image sharing endpoints, sandbox state field, network config changes, and other unrelated additions.

Updates since last revision

  • Removed the 2-second setTimeout delay from the 409 handler — 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
  • Fixed DriveStateWritableDriveState reference in regenerated types.gen.ts (codegen produced a reference to a non-existent writable variant)

Review & Testing Checklist for Human

  • DriveStateWritable fix: The regenerated types.gen.ts referenced DriveStateWritable which doesn't exist — manually fixed to DriveState. This suggests the Makefile's sed-based type renaming has a gap. Verify the fix is correct and consider patching the Makefile's sed rules to handle this case automatically.
  • Unrelated generated changes: Client regeneration from latest main pulled in many new types and endpoints (image sharing, sandbox state, network domain filtering, workspace group mappings, etc.). Verify these are expected from the current main spec and acceptable to include in this PR.
  • End-to-end verification: Test createIfNotExists() with a named sandbox: (1) first call creates, (2) second call returns existing sandbox via 200, (3) parallel creation race still correctly handles 409 and returns existing sandbox.

Notes

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


Open with Devin

Note

Adds createIfNotExist query parameter support to SandboxInstance.create() and CodeInterpreter.create(), allowing the server to return an existing alive sandbox instead of a 409. Fixes CodeInterpreter.create() which previously silently dropped the flag. Includes regenerated client types from main adding image sharing endpoints, GithubRunnerConfig, JobVolume, sandbox state field, and other new types.

Written by Mendral for commit 1a97a34.

drappier-charles and others added 2 commits March 21, 2026 21:01
…ane branch

- Add branch variable to Makefile for SDK regeneration from feature branches
- Regenerate controlplane client with createIfNotExist query parameter
- Update create() to accept createIfNotExist option
- Update createIfNotExists() to pass createIfNotExist=true and add 2s delay in 409 handler

ENG-2188

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The controlplane branch OpenAPI spec introduced Readable/Writable type
renames that break the SDK. The createIfNotExist query param already
exists in the main branch types, 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

devin-ai-integration[bot]

This comment was marked as resolved.

drappier-charles and others added 2 commits April 9, 2026 19:32
CodeInterpreter.create previously only accepted { safe?: boolean },
silently dropping the createIfNotExist flag when called via
CodeInterpreter.createIfNotExists. 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>
… 409 handling

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
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
mendral-app[bot]

This comment was marked as outdated.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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 — 1 issue in 1 file

The previous comment on the TERMINATED-sandbox branch was not addressed — the latest commit (1a97a34) changed create(sandbox) to create(sandbox, { createIfNotExist: true }), which is the opposite of the fix needed. A TERMINATED sandbox must be recreated without the flag so the server performs a fresh create rather than returning the terminated resource.

Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.

<assessment>
The previous comment on the TERMINATED-sandbox branch was **not addressed** — the latest commit (`1a97a34`) changed `create(sandbox)` to `create(sandbox, { createIfNotExist: true })`, which is the opposite of the fix needed. A TERMINATED sandbox must be recreated without the flag so the server performs a fresh create rather than returning the terminated resource.
</assessment>

<file name="@blaxel/core/src/sandbox/sandbox.ts">
<issue location="@blaxel/core/src/sandbox/sandbox.ts:295">
TERMINATED branch still passes `createIfNotExist: true`, causing the server to return the terminated sandbox instead of creating a fresh one. The flag must be omitted here.
</issue>
</file>

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

if (sandboxInstance.status === "TERMINATED") {
// Create a new sandbox - backend will handle cleanup of the terminated one
return await this.create(sandbox);
return await this.create(sandbox, { createIfNotExist: true });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

bug (P1): TERMINATED branch still passes createIfNotExist: true, causing the server to return the terminated sandbox instead of creating a fresh one. The flag must be omitted here.

Suggested change
Suggested change
return await this.create(sandbox, { createIfNotExist: true });
return await this.create(sandbox);
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At @blaxel/core/src/sandbox/sandbox.ts, line 295:

<issue>
TERMINATED branch still passes `createIfNotExist: true`, causing the server to return the terminated sandbox instead of creating a fresh one. The flag must be omitted here.
</issue>

@drappier-charles drappier-charles marked this pull request as ready for review April 13, 2026 19:58
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