Skip to content

AGE-2264: Reset in-flight work when a turn starts with a user message. - #875

Merged
chiragjn merged 19 commits into
mainfrom
turn-can-start
Oct 1, 2026
Merged

chiragjn merged 19 commits into
mainfrom
turn-can-start

Conversation

@debajyoti-truefoundry

@debajyoti-truefoundry debajyoti-truefoundry commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

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

  • 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 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_parent when 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 cancelled SubAgentCompletion, persisted on turn snapshots via TurnContextAppend.completion, and suppressed from public thread.done (only done/error remain on the wire). Completed threads with a precomputed completion no-op on empty send() so resume/approval fan-out does not break createTurn.

OpenAPI/SDK types drop BaseThreadDoneEvent in favor of a flat ThreadDoneEvent schema (generated TS/Python updated).

Reviewed by Cursor Bugbot for commit ce85a9c. Bugbot is set up for automated code reviews on this repo. 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.

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ce85a9c

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 Minor
@truefoundry/trueforge Minor

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>

@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.

Stale Bugbot comment from a previous run.

Comment thread packages/trueforge-core/src/core/runtime/AgentThread.ts Outdated
…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>

@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.

Stale Bugbot comment from a previous run.

Comment thread packages/trueforge-core/src/core/runtime/AgentThread.ts Outdated
Comment thread packages/trueforge-core/src/core/runtime/AgentThread.types.ts
Comment thread packages/trueforge-core/src/core/runtime/AgentThread.types.ts Outdated
Comment thread packages/trueforge-core/src/core/runtime/AgentThread.types.ts
Comment thread packages/trueforge-core/src/core/runtime/AgentThreadOrchestrator.ts Outdated
Comment thread packages/trueforge-core/src/core/runtime/AgentThreadOrchestrator.ts
Comment thread packages/trueforge-core/src/core/runtime/AgentThreadOrchestrator.ts
Comment thread packages/trueforge-core/src/core/runtime/AgentThreadOrchestrator.ts
Comment thread packages/trueforge-core/src/core/runtime/AgentThread.types.ts Outdated
Comment thread packages/trueforge-core/src/core/runtime/AgentThread.ts

@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.

Stale Bugbot comment from a previous run.

Comment thread packages/trueforge-core/src/core/runtime/AgentThread.ts
@chiragjn
chiragjn enabled auto-merge (squash) October 1, 2026 09:16
@chiragjn
chiragjn merged commit 88024b6 into main Oct 1, 2026
16 checks passed
@chiragjn
chiragjn deleted the turn-can-start branch October 1, 2026 09:17

@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 1 potential issue.

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 ce85a9c. Configure here.

if (messages.length === 0 && !this.isAwaitingUserInput()) {
return;
}
this.throwIfAlreadyComplete();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ce85a9c. Configure here.

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.

2 participants