Repository navigation
fix(chat): one before-turn repair and one request context for AIChatAgent and Think - #2872
Open
mattzcarey wants to merge 1 commit into
Open
mattzcarey wants to merge 1 commit into
mattzcarey wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 7314bb0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 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 |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
Contributor
🔴 agents import sizes: 1 entry point over threshold
Changed exports (20)
How this worksEach runtime export is bundled on its own, minified, and gzipped. Changes smaller than 100 B, or smaller than 1% and 1 KiB, are ignored. Growth over 10% or 5 KiB is marked 🔴. This report is informational and does not fail CI. The workflow artifact contains every measurement. Compared |
mattzcarey
force-pushed
the
refactor/turn-core-repair
branch
from
November 17, 2026 18:36
2e778da to
eded472
Compare
mattzcarey
changed the base branch from
refactor/chat-turn-core
to
refactor/turn-core-rpc-agent-tool
November 17, 2026 18:36
mattzcarey
force-pushed
the
refactor/turn-core-repair
branch
from
November 17, 2026 23:06
eded472 to
2e02222
Compare
mattzcarey
force-pushed
the
refactor/turn-core-repair
branch
from
November 18, 2026 20:14
2e02222 to
76ab2b9
Compare
…reply rule for AIChatAgent and Think
mattzcarey
force-pushed
the
refactor/turn-core-repair
branch
from
November 19, 2026 21:48
1787434 to
7314bb0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Top of the turn-core stack, on #2874. It adds the last two shared pieces: what a turn settles in the transcript before it calls the model (
ChatTurns.settleBeforeTurn,agents/chat/before-turn.ts), and one owner for the stored client tools and body (ChatRequestContext,agents/chat/request-context.ts).AIChatAgentandThinksupply only where they store messages and those two values. These are D11 and D12 indesign/rfc-chat-turn-core.md.The two classes disagreed here, and each was wrong somewhere. Apps can observe all of this:
AIChatAgentkept them, and the provider rejected the next request withAI_MissingToolResultsError. A result that arrives later is ignored.repairInterruptedToolPartis called for those calls too. InAIChatAgentit only ever saw a dead server call. The default error text now says what is known: a client's tool "may still have run", an unanswered approval "did not run".SaveMessagesResulthas an optionalreason:"cleared","nothing-to-continue"or"awaiting-client".continueLastTurn()returns the last one, with an emptyrequestId, while the reply it continues still waits on a client. It calls no model and changes nothing. An auto-continuation in that state is dropped with the newchat:continuation:droppedreasonawaiting_client.Thinkstored it and a client drew an empty bubble. Tabs that drew the reasoning get the message list after the turn's terminal frame, so they drop it.AIChatAgentapp builds its request from the stored messages, and Anthropic rejects that shape.chat:transcript:repairednow carriesremovedMessages, each as it was stored, so an app can keep a copy.continueLastTurn(), or the recovery that would continue it. The last two then answer the question again.continueLastTurn()over such a reply used to be continued onmain.Think, a turn cut off afterstart-stepand before any content is now retried, where it used to store that marker and continue it.state: "done"), in both classes. It stayedstreamingafter a stop.AIChatAgent). It stored them before it decided to skip.AIChatAgentcontinuation no longer writes into a cut-off text part. It used to resume a text part that was stillstreaming: the continuation'stext-startwas withheld from clients and its text was appended to the old part. When the model reasoned first, that reasoning landed after the merged text, so a recovered reply read text, then reasoning, and ended in reasoning. Now the cut-off part is closed when the continuation starts (settleInterruptedPart, whichThinkalready did and which now lives in the core), and the continuation's reasoning and text are new parts after it. A tab seestext-startand a second text block where it used to see the first block grow. A plain-text continuation also opens its own part.clientToolsonly when it settles its call, and not across a clear. A late duplicate from another tab used to swap them. A continuation runs with the stored tools and body, read when its turn starts.AIChatAgentemitschat:transcript:repaired, before a turn and when recovery settles the reply it continues. The event has a new optionalremovedReasoningParts.Think: a request with noclientToolskey clears the stored tools, and a continuation whose repair throws is reported and settled.Validation:
ChatPendingandChatTurnsgained thirteen rules, each guard has a broken variant. The models are now checked with everystate, and I compared every case against TLC.chat-turn-races.test.ts,continue-last-turn.test.tsand Think'sclient-tools.test.ts,empty-reply.test.tsandterminal-frame-order.test.ts. The reasoning rule is tested against whatconvertToModelMessagesproduces.repair-transcript.ts,before-turn.tsandrequest-context.tsthat no test pinned. 26 mutants are now killed, seven guards that could not fire are deleted, and three survivors are equivalent.agentschat tests,ai-chatworkers, the fullthinksuite,pnpm run buildandpnpm run checkran on the rebased branch.Think's stall and error fixtures count chunks from the first content chunk, two abort tests stop after the first text chunk, and anAIChatAgentSSE fixture senttextDeltawhere the AI SDK readsdelta. Each had been storing a reply with no content.