Skip to content

fix: report continuation turns that fail before streaming (#2381) - #2393

Merged
threepointone merged 3 commits into
fix/2382-approved-tool-repairfrom
fix/2381-continuation-prestream-errors
Sep 28, 2026
Merged

threepointone merged 3 commits into
fix/2382-approved-tool-repairfrom
fix/2381-continuation-prestream-errors

Conversation

@threepointone

@threepointone threepointone commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2381. Stacked on #2392.

Problem

When an auto-continuation (after a tool approval or a client tool result) or a connection-less continuation threw before streaming, for example from beforeTurn or onChatMessage, the failure was only logged. Clients got no error frame, onChatResponse never fired, and no terminal status was recorded. The conversation looked like it was still waiting.

Change

A continuation that fails before streaming is now reported like any other failed turn:

  • an error cf_agent_use_chat_response frame with continuation: true
  • onChatResponse with status: "error" and continuation: true, for the assistant message the continuation would have extended
  • a recorded terminal status, so a client that reconnects learns the turn failed

Think also calls onChatError(error, { stage: "turn", continuation: true }) and emits chat:request:failed. continuation is a new optional field on ChatErrorContext.

Aborts and Durable Object resets are not reported, since their own paths handle them. Failures after streaming starts are unchanged: _streamResult and _reply already report those. Per the decision on the issue, this only reports the failure. The approval part itself is settled by #2392 on the next new turn.

Tests

  • Think: an approval continuation that fails in beforeTurn (WebSocket), and a connection-less continuation after approveExecution (no socket). Both check that the failure is reported exactly once.
  • ai-chat: a tool-result auto-continuation that fails in onChatMessage.
  • All three fail without the fix.

@threepointone
threepointone added this pull request to stack #2395 September 28, 2026 10:50
@changeset-bot

changeset-bot Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 11f484c

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

This PR includes changesets to release 3 packages
Name Type
@cloudflare/think Patch
@cloudflare/ai-chat Patch
@cloudflare/agent-think 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

@agent-think

agent-think Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

✅ agents import sizes: no significant changes (a2287c61 → 11f484cc, workflow run)

@threepointone
threepointone force-pushed the fix/2381-continuation-prestream-errors branch from 9747261 to c1da263 Compare September 28, 2026 10:57
@threepointone
threepointone marked this pull request as ready for review September 28, 2026 10:57
@pkg-pr-new

pkg-pr-new Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@2393

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@2393

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@2393

hono-agents

npm i https://pkg.pr.new/hono-agents@2393

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@2393

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@2393

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@2393

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@2393

commit: 11f484c

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

Devin Review found 2 potential issues.

Devin Review

Comment thread packages/ai-chat/src/index.ts Outdated
Comment thread packages/think/src/think.ts Outdated
Comment on lines +18705 to +18712
this._broadcastChat({
type: MSG_CHAT_RESPONSE,
id: requestId,
body: errorMessage,
done: true,
error: true,
continuation: true
});

@devin-ai-integration devin-ai-integration Bot Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Replayed continuation errors lack the continuation flag

Live continuation failures carry continuation: true, but terminal replay reconstructs error frames without it. Check whether reconnecting chat clients need that flag to associate the error with the pending continuation.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@threepointone
threepointone force-pushed the fix/2381-continuation-prestream-errors branch from c1da263 to 452db97 Compare September 28, 2026 11:36
devin-ai-integration[bot]

This comment was marked as resolved.

threepointone and others added 3 commits September 28, 2026 12:48
When an auto-continuation or a connection-less continuation throws before
it streams (for example from beforeTurn or onChatMessage), report it like a
failed turn: an error frame for the continuation, onChatResponse with
status "error", and a recorded terminal status. Think also calls
onChatError with stage "turn" and continuation: true, and emits
chat:request:failed.

Co-authored-by: Cursor <cursoragent@cursor.com>
Addresses review on #2393: _reply now signals when it takes over reporting
(onStreamStart), and takes the body reader before starting the resumable
stream, so an unreadable body fails before anything was sent and is
reported by the continuation.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ok; release the reader on stream setup failure

Co-authored-by: Cursor <cursoragent@cursor.com>
@threepointone
threepointone force-pushed the fix/2381-continuation-prestream-errors branch from 452db97 to 11f484c Compare September 28, 2026 11:58
@threepointone
threepointone merged commit a7d0e02 into main Sep 28, 2026
10 of 16 checks passed
@threepointone
threepointone deleted the fix/2381-continuation-prestream-errors branch September 28, 2026 12:29
@github-actions github-actions Bot mentioned this pull request Oct 2, 2026
tombeckenham added a commit to tombeckenham/agents-tom that referenced this pull request Oct 7, 2026
…ry for transient reader errors

Ports upstream cloudflare#2194, cloudflare#2190, cloudflare#2223, cloudflare#2360, cloudflare#2385 and cloudflare#2393 to AGUIChatAgent.

- Recovery attempts are __cf_internal_chat_recovery Task runs dispatched to the model handoff; a root agent's chat turn is a Task run (facets stay on fibers). The origin-ids scope moves into the dispatch wrapper.
- The progress marker is derived from the stream log; a settled TOOL_CALL_RESULT is flushed as it lands.
- A platform-transient reader error routes into bounded recovery like a stall: onChatRecovery is consulted with the live turn's stash data, persist:false drops the partial, a blank new turn is retried, and a running attempt that reschedules leaves the incident to its successor.
- A cancel during backoff cancels the queued recovery.
- An auto-continuation that fails before streaming sends an error frame and reaches onChatResponse.

The agui test worker follows the Tasks transport and the derived marker.
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.

Think: an auto-continuation that fails before streaming is only logged — no onChatError, no response hook, no terminal status

1 participant