AGE-2264: Reset in-flight work when a turn starts with a user message. - #875
Conversation
Cancel child threads and close open parent tool calls before appending the new user text. Persist child completion so a finished child's send_to_parent is kept, skip public thread.done for cancelled children, and treat parented AGENT_DONE as thread identity plus SubAgentCompletion. Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: ce85a9c 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 |
The wire-schema change belongs with the follow-up that publishes it, so this branch should not cut a minor release on its own. Co-authored-by: Cursor <cursoragent@cursor.com>
…copies. Split persist vs public thread.done, yield child AGENT_DONE from the stored completion, and assert a completion-only createTurn append does not add messages. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…ads. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ce85a9c. Configure here.
| if (messages.length === 0 && !this.isAwaitingUserInput()) { | ||
| return; | ||
| } | ||
| this.throwIfAlreadyComplete(); |
There was a problem hiding this comment.
Complete HITL children reject empty send
Medium Severity
cancel() marks a child complete but leaves pending approvals and client-side calls open, so isAwaitingUserInput() stays true. The new empty-batch no-op then skips, and throwIfAlreadyComplete() still fires. Resume or approval fan-out of [] after a user-message reset can fail createTurn when a leftover cancelled child was waiting on HITL.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit ce85a9c. Configure here.


Cancel child threads and close open parent tool calls before appending the new user text. Persist child completion so a finished child's send_to_parent is kept, skip public thread.done for cancelled children, and treat parented AGENT_DONE as thread identity plus SubAgentCompletion.
Summary
Closes #
Changes
How was this tested?
Checklist
pnpm build,pnpm test,pnpm typecheck,pnpm lint:ci, andpnpm format:checkpass locallypackages/trueforge-sdk,python/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 changedNote
Medium Risk
Changes core orchestration, turn persistence, and client-visible thread lifecycle events when users interrupt parallel sub-agents or pending tool calls.
Overview
When a turn begins with a user message, the orchestrator now cancels in-flight child threads, closes open tool calls on the main thread (using each child’s
send_to_parentwhen already finished, otherwise a standard cancel reason), and routes the new text only to the root thread—replacing the previous hard error that blocked user input while sub-agents were running.Cancelled children are modeled with a
cancelledSubAgentCompletion, persisted on turn snapshots viaTurnContextAppend.completion, and suppressed from publicthread.done(only done/error remain on the wire). Completed threads with a precomputed completion no-op on emptysend()so resume/approval fan-out does not breakcreateTurn.OpenAPI/SDK types drop
BaseThreadDoneEventin favor of a flatThreadDoneEventschema (generated TS/Python updated).Reviewed by Cursor Bugbot for commit ce85a9c. Bugbot is set up for automated code reviews on this repo. Configure here.