feat: add createIfNotExist query param support in SDK#272
feat: add createIfNotExist query param support in SDK#272devin-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 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 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:
|
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>
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 — 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 }); |
There was a problem hiding this comment.
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
| 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>
Summary
Adds
createIfNotExistquery parameter support to the TypeScript SDK's sandbox creation flow. WhencreateIfNotExist=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.Changes:
SandboxInstance.create()now accepts an optionalcreateIfNotExistboolean. Whentrue, it passes?createIfNotExist=trueas a query parameter tocreateSandbox, allowing the server to return an existing alive sandbox instead of a 409 error.SandboxInstance.createIfNotExists()passescreateIfNotExist: truetocreate()by default. All existing 409 handling logic is unchanged.CodeInterpreter.create()now accepts and forwards thecreateIfNotExistoption tosuper.create(). Previously,CodeInterpreter.createonly destructured{ safe }, silently discardingcreateIfNotExist.branchvariable (defaults tomain) somake sdk-controlplane/make sdk-sandboxcan regenerate clients from feature branches.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
setTimeoutdelay from the 409 handler — existing 409 handling was already correct and needs no modificationmainbranch (controlplane PR #3304 is now merged) instead of the feature branchDriveStateWritable→DriveStatereference in regeneratedtypes.gen.ts(codegen produced a reference to a non-existent writable variant)Review & Testing Checklist for Human
DriveStateWritablefix: The regeneratedtypes.gen.tsreferencedDriveStateWritablewhich doesn't exist — manually fixed toDriveState. 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.mainpulled in many new types and endpoints (image sharing, sandbox state, network domain filtering, workspace group mappings, etc.). Verify these are expected from the currentmainspec and acceptable to include in this PR.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
Note
Adds
createIfNotExistquery parameter support toSandboxInstance.create()andCodeInterpreter.create(), allowing the server to return an existing alive sandbox instead of a 409. FixesCodeInterpreter.create()which previously silently dropped the flag. Includes regenerated client types frommainadding image sharing endpoints,GithubRunnerConfig,JobVolume, sandbox state field, and other new types.Written by Mendral for commit 1a97a34.