Skip to content

Auto-continuation parks forever when an approval tool shares an assistant message with an already-settled tool #2185

Description

@abhagsain

What happens: within a single assistant turn the model calls one tool that resolves (toolA, ends output-available) and then, in a later step of the same turn, calls a needsApproval tool (toolB). Both parts serialize into the same assistant message. The user approves toolB. The continuation never fires — the turn stalls indefinitely. Any new user message unblocks it.

Root cause (confirmed): hasIncompleteToolBatch (agents chat) flags the leaf assistant message as an incomplete parallel batch because it holds both a settled tool result and a pending approval-requested part, so AutoContinuationController parks (the 0.9.0 "parks budget-free until the batch completes" behavior).

But the two tools are sequential — two step-start markers in one message, not a parallel fan-out — and at approval time the batch is actually complete (every non-approval part is settled), yet the approval resolution never re-arms the parked continuation.

Likely counterpart to #2171: that report is the over-firing side of this same machinery — _onStreamingTurnFinalized → rearmForBatch() firing a stale continuation after a stop finish. This is the under-firing side: the re-arm that should fire on approval-completion of an otherwise-settled leaf never does. Both live in the finalization/re-arm path and probably want fixing together.

Minimal repro: one turn that (1) calls a tool returning output, then (2) calls a needsApproval tool, so both land in the same assistant message; approve it. Contrast: when the needsApproval tool is the only tool in its message, the gate is false and approval continues immediately.

Expected: approving the last pending part of a leaf whose other parts are all settled should fire the continuation.

Versions: @cloudflare/ai-chat@0.9.0, agents@0.17.0, ai@6.0.213.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions