Fixes #397: Abort sandbox exec on turn cancellation - #407
Fixes #397: Abort sandbox exec on turn cancellation#407rohanmalhotracodes wants to merge 7 commits into
Conversation
🦋 Changeset detectedLatest commit: b476ce4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
|
Thanks for your contribution. Can you attach a video that showcases
Please add a before-and-after video by changing the branch in between. |
|
Please also confirm that you have covered all Acceptance Criteria present on #397 Feel free to copy them into this PR description. |
Before Screen.Recording.2026-08-24.at.5.33.37.PM.movAfter Screen.Recording.2026-08-24.at.5.45.34.PM.mov |
There was a problem hiding this comment.
The video you uploaded is not very satisfactory.
For instance - From the video it is not very clear that next turn can be created after the cancellation or not(using the same sandbox, or code mode works etc)
You should test the acceptance criteria mention in the Issue
|
Added coverage for the
I also reran |
|
Just a note: #409 also adds signal to download method |
|
Before Screen.Recording.2026-08-25.at.1.03.35.PM.movAfter Screen.Recording.2026-08-25.at.1.07.47.PM.movScreen.Recording.2026-08-25.at.1.08.14.PM.mov |
|
Thanks for the heads-up. I kept this PR scoped to #397 and only pass the turn abort signal through the sandbox |
|
sorry to bother here can I get more issues assigned please I cannot see help wanted issues as the newer issues have not yet been approved @govindavashishtha @debajyoti-truefoundry, I have got the chat deletion issue merged so I do have time to work on more |
|
Checkout these. For such communication you can join discord - https://github.com/truefoundry/trueforge#talk-to-us |
|
This looks good. |
Summary
Fixes #397
Fixes sandbox turn cancellation so an in-flight sandbox
execcan stop promptly when the turn is cancelled, instead of waiting for the command timeout.sanity check added a video
Screen.Recording.2026-08-22.at.8.07.24.PM.mov
Changes
AbortSignalintoSandboxOptionsandSandboxExecParams.execpath, not init, skills, mkdir, uploads, downloads, or general tool execution.sandbox.stop(timeout, true)and avoid recovery/retry of the cancelled command./execfetch when the turn signal aborts.killExecTreepath without deleting the sandbox root.@truefoundry/trueforge-coreand@truefoundry/trueforge.How was this tested?
git diff --checkpnpm --filter @truefoundry/trueforge-core test -- sandboxBridgeTimeout tfyLayoutpnpm --filter @truefoundry/trueforge-core typecheckpnpm --filter @truefoundry/trueforge typecheckpnpm --filter @truefoundry/trueforge testChecklist
pnpm build,pnpm test,pnpm typecheck,pnpm lint:ci, andpnpm format:checkpass locallypackages/trueforge-sdk,.github/fern/openapi/openapi.json,docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge.env.exampleupdated if configuration or behavior changedAcceptance Critera
Client cancel during a long sandbox exec ends the turn without a wait for the full exec timeout. This applies to Daytona and Local.
After a Daytona cancel, executeWithSandboxRecovery must not start the sandbox and run the same cancelled command again on DaytonaError.
After a Daytona / Local stop, the next turn can reuse existingSandboxId. The sandbox starts. The filesystem is available. Any commands run successfully.
After a Daytona / Local stop, Code Mode works in the next turn.
After a Daytona / Local stop during Code Mode MCP use, the next turn recovers on-disk state without a hard failure.
If the mcp_client tools cache {server}.tools.json is corrupt or truncated, the client deletes it and refetches over NATS.
freezeTurn with reason cancelled-for-next-turn does not change.
Note
Medium Risk
Changes cancellation and teardown paths across Daytona, TFY, and local sandbox exec; incorrect signal scoping or recovery logic could leave sandboxes stuck or retry cancelled commands.
Overview
Fixes #397 by wiring the turn
AbortSignalfrom turn creation intoSandboxandSandboxExecParams, so cancelling a turn can stop a long-running sandboxexecinstead of waiting for the full command timeout.The signal is passed only on the agent-facing
exectool path (including retry after recreate); sandbox init, skill setup, uploads, and downloads do not receive it. Providers returnSANDBOX_EXEC_ABORTEDwhen cancellation wins.Daytona registers an abort handler that force-stops the sandbox (
stop(..., true)), clears the cached SDK handle, and skipsexecuteWithSandboxRecoveryretry when the signal is aborted. TFY links the turn signal to the/execfetch and maps turn-drivenAbortErrorto the aborted result (distinct from timeout). Local kills the supervised process tree viakillExecTreewithout removing the sandbox root, soexistingSandboxIdstays usable on the next turn.onSignalAbortnow returns a disposer;isSignalAbortedis exported. Tests cover signal scoping, TFY fetch abort, Daytona no-recovery-on-abort, and local smoke abort behavior.Reviewed by Cursor Bugbot for commit b476ce4. Bugbot is set up for automated code reviews on this repo. Configure here.