fix(ai-sandbox-boxd): clean up cancelled sandbox startup - #1607
Conversation
🦋 Changeset detectedLatest commit: be602cd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughBoxdProvider now checks for cancellation after machine readiness and workspace creation. If either check detects cancellation, the provider deletes the machine and rethrows the abort reason. Unit and end-to-end tests cover cancellation during creation and snapshot restoration. ChangesBoxd startup cancellation cleanup
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to This change makes cancelled Boxd startup delete the new machine instead of returning a running handle. No merge-blocking risk was identified. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 3 systems. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thanks for the PR, @Tyagiquamar! 🙌 @AlemTuzlak will take a look. Automated pre-review checks
Automated triage — a human review follows. |
…the fix Keep one unit test for each abort check and one E2E case against the built package. State in the docs that the delete is best effort.
tombeckenham
left a comment
There was a problem hiding this comment.
Thank you for this.
|
View your CI Pipeline Execution ↗ for commit be602cd
☁️ Nx Cloud last updated this comment at |
@tanstack/ai
@tanstack/ai-acp
@tanstack/ai-angular
@tanstack/ai-anthropic
@tanstack/ai-bedrock
@tanstack/ai-byteplus
@tanstack/ai-claude-code
@tanstack/ai-client
@tanstack/ai-cloudflare
@tanstack/ai-code-mode
@tanstack/ai-code-mode-snippets
@tanstack/ai-codex
@tanstack/ai-cohere
@tanstack/ai-compaction
@tanstack/ai-devtools-core
@tanstack/ai-durable-stream
@tanstack/ai-elevenlabs
@tanstack/ai-event-client
@tanstack/ai-fal
@tanstack/ai-gemini
@tanstack/ai-grok
@tanstack/ai-grok-build
@tanstack/ai-groq
@tanstack/ai-isolate-cloudflare
@tanstack/ai-isolate-daytona
@tanstack/ai-isolate-node
@tanstack/ai-isolate-quickjs
@tanstack/ai-isolate-quickjs-bun
@tanstack/ai-llmgateway
@tanstack/ai-lovable
@tanstack/ai-mcp
@tanstack/ai-memory
@tanstack/ai-mistral
@tanstack/ai-octane
@tanstack/ai-ollama
@tanstack/ai-ollaya
@tanstack/ai-openai
@tanstack/ai-opencode
@tanstack/ai-openrouter
@tanstack/ai-perplexity
@tanstack/ai-persistence
@tanstack/ai-preact
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-reactor
@tanstack/ai-remix
@tanstack/ai-sandbox
@tanstack/ai-sandbox-blaxel
@tanstack/ai-sandbox-boxd
@tanstack/ai-sandbox-cloudflare
@tanstack/ai-sandbox-daytona
@tanstack/ai-sandbox-docker
@tanstack/ai-sandbox-e2b
@tanstack/ai-sandbox-local-process
@tanstack/ai-sandbox-sprites
@tanstack/ai-sandbox-upstash-box
@tanstack/ai-sandbox-vercel
@tanstack/ai-skills
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-typesafe
@tanstack/ai-utils
@tanstack/ai-vercel-gateway
@tanstack/ai-vertex
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/ai-worldlabs
@tanstack/openai-base
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
@tanstack/svelte-ai-devtools
commit: |
If you abort Boxd
createor snapshot restore during startup, the provider returned a handle and left the new machine running. This PR checks the abort signal after each startup call. An abort now deletes the new machine and rejects with the abort reason.🎯 Changes
adopt()inpackages/ai-sandbox-boxd/src/provider.tschecks the abort signal after the readiness wait and after the workspacemkdir.docs/sandbox/providers.mddescribes the cancellation behavior.✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.docs/for this change, or this change is not user-facing.pnpm changeset), or this PR does not change a published package.The full
test:prsuite did not run locally. The Testing section lists the focused commands that ran.🚀 Release Impact
Root cause
Issue. A caller aborts
createorrestoreSnapshotwhile the new machine becomes ready, or while the provider makes the workspace directory. The call resolves with a handle, and the machine continues to run.Cause.
adopt()checked the abort signal only beforewaitUntilReady. It did not check afterwaitUntilReadyor after themkdirexec.ensure()in@tanstack/ai-sandboxdoes not check the signal aftercreatereturns.Fix.
adopt()checks the signal after each of the two calls. An abort goes to the existing cleanup path, which tries to delete the machine and throws the abort reason again.Possible alternatives
return handle. This is one line less and stops the same leak. This PR uses two checks, so an abort during readiness does not run amkdiron a machine that the provider then deletes.ensure()afterprovider.create. This change would cover each provider. It is a larger change in a different package, so this PR does not include it.waitUntilReadyand the one-shot exec do not accept an abort signal, so this is not possible today.Testing
Commands run
A reviewer-written repro test on pinned main
d31e4ebb9and on PR head3d8cb4094. The repro abortscreateduring readiness, then duringmkdir.On head
be602cd89, frompackages/ai-sandbox-boxd:pnpm exec vitest runpassed (65 passed, 8 skipped).pnpm run test:typesandpnpm run test:oxlintpassed.On head
be602cd89: Playwright ran onlysandbox-boxd-startup-cancellation.spec.tswith a minimal config, afternx run @tanstack/ai-sandbox-boxd:build. 1 passed.With each of the two new checks removed in turn, one unit test failed.
Not run:
pnpm test:prand the full E2E suite. CI runs them.Manual test
main, add a test that aborts the signal inside a mockedmachines.waitUntilReady. Then callboxdSandbox({ apiKey: 'k' }).create({ signal }). The call resolves with a handle.pnpm exec vitest run tests/provider.test.ts -t "cancellation during adoption"frompackages/ai-sandbox-boxd. Both tests pass.pnpm run build:all, thenpnpm --filter @tanstack/ai-e2e test:e2e -- --grep "boxd create cleans up". The spec passes.How this PR makes testing easy
packages/ai-sandbox-boxd/tests/provider.test.ts: two tests, one for each new check.testing/e2e/tests/sandbox-boxd-startup-cancellation.spec.ts: one case against the built package.The SDK machine calls are stubs. No test starts a live Boxd machine.
Risk / rollback
Risk is low. Two signal checks are added to the startup of new and restored machines. The delete is best effort: if the delete call fails, the machine continues to run and the provider does not log it. This behavior is the same as on
main. To undo, revert this PR.Summary by CodeRabbit
Bug Fixes
Documentation