Repository navigation
fix(chat): a stop drops the continuations that were waiting when it landed - #2881
Open
mattzcarey wants to merge 6 commits into
Open
mattzcarey wants to merge 6 commits into
mattzcarey wants to merge 6 commits into
Conversation
🦋 Changeset detectedLatest commit: 9dfa9c2 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 grew
Changed exports (2)
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-continuation-stop
branch
from
November 17, 2026 16:25
e77e94b to
3051352
Compare
mattzcarey
force-pushed
the
refactor/turn-core-continuation-stop
branch
from
November 17, 2026 22:05
3051352 to
79e5960
Compare
mattzcarey
force-pushed
the
refactor/turn-core-continuation-stop
branch
from
November 18, 2026 18:12
79e5960 to
5040ea4
Compare
…from a tab that waits drops the waiting continuations
…a redundant abort
mattzcarey
force-pushed
the
refactor/turn-core-continuation-stop
branch
from
November 19, 2026 17:20
5040ea4 to
9dfa9c2
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.
On top of #2876: stopping the turn that is running also drops the auto-continuations that were waiting when the stop landed. A tool result answered while the reply streamed, or one that arrived while a continuation ran before it was stopped, no longer starts the model again. The drop is one place in the turn core (
ChatTurns.cancel,stopAll,linkExternal), forAIChatAgentandThink.Both classes did the opposite, and agreed on it:
Apps can observe this:
abortRequest,abortAllRequests,Think.cancelAllChats, or thesignalpassed tosaveMessages,continueLastTurnorchat()(through refactor(chat): one path for turns the server starts #2870'srunServerTurn).STREAM_RESUME_NONE, andchat:continuation:droppedis emitted with reasonstopped.abortRequest.Think's WebSocket cancel now goes throughChatTurns.cancel, likecancelChat.abortAllRequestsandcancelAllChatsdrop every waiting continuation whether a turn is running or not: one in its coalesce window, one parked on an unanswered tool call, andThink's queued connection-less one.abortRequest(id)with no turn running drops the waiting continuation whenidis the request whose reply just ended.cf_agent_chat_request_cancelwithcontinuation: true, and the server stops the continuation that connection waits on. Before, the stop only ended the tab's local stream and the model ran anyway.abortAllRequestsalso stops a recovery attempt that is waiting to run, which a test now covers.chat:continuation:dropped,requestIdis the continuation's own id (nullfor a result dropped before it had one), and the newstoppedRequestIdnames the turn whose stop dropped it.Validation:
agentschat tests,ai-chatworkers and thethinksuite ran, withpnpm run check. Each case has a host test that failed before the change, except "a result that arrives after a continuation was stopped still continues", which pins a regression an earlier version of this PR had.ChatTurnsTLA+ model was changed first: ruleStopEndsContinuations, with a broken variant for each of the four ways a stop lands and for the second-stop and drop-at-settle mistakes. The stack's merged models pass all their cases.Read
ChatTurns.canceland#stopinpackages/agents/src/chat/chat-turns.tsfirst. Everything else follows from them.