Skip to content

fix(runtime): error when tool_calls finish has no tools - #824

Open
YIKUAIBANZI wants to merge 1 commit into
truefoundry:mainfrom
YIKUAIBANZI:fix/tool-calls-finish-without-calls
Open

YIKUAIBANZI wants to merge 1 commit into
truefoundry:mainfrom
YIKUAIBANZI:fix/tool-calls-finish-without-calls

Conversation

@YIKUAIBANZI

@YIKUAIBANZI YIKUAIBANZI commented Sep 21, 2026

Copy link
Copy Markdown

Summary

When an LLM response has finish_reason=tool_calls but the assembled assistant message has no tool_calls, the runtime currently treats the turn as a successful done. The model asked to call a tool, nothing is executed, and no error is emitted.

This change treats that case the same way as finish_reason=length: emit an error event and exit. For a sub-agent, the stored completion is error rather than done, so the parent does not treat the child as successful.

Fixes #447

Why

Observed on long multi-phase missions: a turn can end immediately after a tool.response while the last model.message still has finish_reason=tool_calls. The existing length path already refuses to finish as done; an empty tool-call payload is the same class of incomplete model output.

Tests

  • pnpm --filter @truefoundry/trueforge-core test -- tests/core/runtime/toolCallsFinishWithoutCalls.test.ts
    • root thread: AGENT_DONE status is error
    • sub-agent: context-append completion type is error, not done

Checklist

  • I have read the contributing guidelines
  • Tests added/updated where it makes sense
  • No hand-edits to generated code
  • Changeset included for @truefoundry/trueforge-core (patch)

Providers can emit finish_reason=tool_calls without a parsed tool-call
payload. Treat that as a terminal error, matching the length path, so
the turn does not silently complete.
@changeset-bot

changeset-bot Bot commented Sep 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 455e615

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

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.

[local-mode] turns intermittently terminate at finish_reason=tool_calls right after a tool.response

1 participant