Skip to content

fix: Propagate turn abort to in-flight tool calls and sandbox exec - #835

Open
bhaveshpatel640 wants to merge 1 commit into
mainfrom
AGE-2252
Open

bhaveshpatel640 wants to merge 1 commit into
mainfrom
AGE-2252

Conversation

@bhaveshpatel640

@bhaveshpatel640 bhaveshpatel640 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Summary

fix: Propagate turn abort to in-flight tool calls and sandbox exec

Closes AGE-2252

Changes

How was this tested?

Checklist

  • I have read the contributing guidelines
  • pnpm build, pnpm test, pnpm typecheck, pnpm lint:ci, and pnpm format:check pass locally
  • Tests added/updated where it makes sense
  • No hand-edits to generated code (packages/trueforge-sdk, python/trueforge_sdk, .github/fern/openapi/openapi.json, docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge
  • Docs / .env.example updated if configuration or behavior changed

Note

Medium Risk
Changes agent turn lifecycle and sandbox/process teardown on cancel; behavior is scoped to cancellation but touches core tool execution and both sandbox providers.

Overview
When a user cancels a turn, in-flight work now stops instead of running until timeout. An optional AbortSignal is threaded from AgentThread.execute through executeToolCalls and IToolSet.callTool (including local tools and ToolSet wrappers).

Sandbox exec forwards the same signal into provider exec calls (init, git credentials, and the agent command). TFY merges the turn signal with the client timeout via AbortSignal.any and surfaces Cancelled; the local SRT supervisor kills the sandbox process tree on abort and reports Cancelled.

After tools finish under abort, the thread skips tool-response processors, still records tool results where applicable, and exits the turn without continuing the agent loop. Unit tests cover executeToolCalls signal passthrough and TFY exec cancellation.

Reviewed by Cursor Bugbot for commit 3aa6e42. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Sep 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3aa6e42

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@truefoundry/trueforge-core Patch
@truefoundry/trueforge Patch

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit dd68970. Configure here.

cancelled = true;
killExecTree(child);
};
signal?.addEventListener('abort', onAbort, { once: true });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Abort can miss spawned sandbox process

Medium Severity

Local sandbox cancel can miss the child. The abort listener is attached only after wrapWithSandboxArgv, spawn, and optional stdin writes, and an already-aborted signal does not invoke a new abort listener. Cancel during that window leaves the process running until the exec timeout.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit dd68970. Configure here.

if (signal?.aborted) {
return 'exit';
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cancel drops completed sub-agent tools

Medium Severity

When the turn signal is aborted after executeToolCalls, stepToolResponse persists regular tool results and then returns exit before yielding createThreadEvents. A completed create-sub-agent call in that batch never creates the child thread and never gets a matching tool result, so the stored turn context can contain an unmatched tool_call.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit dd68970. Configure here.

This branch has not been deployed

No deployments
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