fix: defer sandbox cleanup until stream completes#5
Conversation
The `finally` block was calling `sandbox.stop()` immediately when `createAgentUIStreamResponse` returned, before the client consumed the stream. This killed the sandbox before any agent tool calls could execute, causing all bash commands to fail with "[Tool Error] Tool execution error". Now uses a TransformStream wrapper with `pipeTo().finally()` to ensure sandbox cleanup happens after streaming completes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ✨ 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 |
Summary
finallyblock in/api/agent/route.tscalledsandbox.stop()immediately whencreateAgentUIStreamResponsereturned the Response object — before the client started consuming the stream. This destroyed the Vercel Sandbox before the agent could execute any bash tool calls, causing every command to fail with[Tool Error] Tool execution error.finallyblock with aTransformStreamwrapper that pipes the response body through and callssandbox.stop()in the.finally()callback ofpipeTo(), ensuring cleanup happens only after the stream completes (or errors/disconnects).Test plan
agent "What is just-bash?"and verify bash commands execute successfullyagent "list the files"thenagent "show me the README")🤖 Generated with Claude Code