Skip to content

A queued message is stored when its turn starts, so each turn answers its own message - #2928

Open
mattzcarey wants to merge 11 commits into
refactor/turn-core-rfcfrom
refactor/turn-core-queue-order
Open

mattzcarey wants to merge 11 commits into
refactor/turn-core-rfcfrom
refactor/turn-core-queue-order

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

A message sent while a turn runs is now stored when its own turn starts, not when it arrives, in both AIChatAgent and Think. Each turn answers its own message and the transcript reads U1, A1, U2, A2. Tabs still see the waiting message at once: message lists end with it and name it in a new queuedMessageIds field, and useAgentChat draws it after the streaming reply.

Before, a queued message was stored at acceptance, so the transcript read U1, U2, A1 and the queued turn's model request ended in the first reply. On deployed Workers with gpt-oss-120b the queued "Say the word apple." got a second reply of "apple" in 5 of 40 runs before this change and 200 of 200 after it, live and after an isolate reset, under queue, latest, merge and debounce. What apps can observe:

  • this.messages (and the messages onChatMessage builds from, and Think's model context) gains a waiting message only when its turn starts. The running turn and its recovery never see it.
  • Under queue the stored order is U1, A1, U2, A2. A superseded (latest, merge, debounce) or stopped waiting message is stored at its place in the queue with no reply. A clear while it waits means it is never stored.
  • CF_AGENT_CHAT_MESSAGES frames can carry queuedMessageIds, and a tab that connects while something waits is sent that list. /get-messages still returns stored messages only.
  • A message waiting at a rollback to a release without admission records is lost. It lives on the record, and the old release does not read records.

The waiting message lives on the request's admission record from #2918 (cf_agents_chat_admissions, new columns, plus a _messages table for large messages). That record also replaces the recovery-leaf and snapshot special cases. RFC rows D101 to D108 and the queueing docs are updated. A TLA+ spec (ChatOrder.tla, checked with everystate) covers resets, stops and clears at every step.

Validated with the agents chat, ai-chat workers and React, and Think suites, plus pnpm run build and pnpm run check. New tests fail before the change, including real isolate resets with ctx.abort(). I also ran a deployed probe (tc-order) and checked two and three browser tabs against tc-order-client.


Devin Review

@changeset-bot

changeset-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 724b087

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

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

@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 724b087

@agent-think

agent-think Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🔴 agents import sizes: 1 entry point over threshold

Entry point Exports Largest gzip change Size now
🔴 agents/chat 3 resized up to +581 B (+18.34%) 3.7 KiB
Changed exports (3)
Import Gzip change Size now
🔴 agents/chat#createChatAdmissionStore +581 B (+18.34%) 3.7 KiB
🟡 agents/chat#ChatTurns +535 B (+4.66%) 11.7 KiB
🟡 agents/chat#ChatAdmissions +263 B (+7.94%) 3.5 KiB
How this works

Each 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 4047c4af → 724b0873 · workflow run · reported by agent-think[bot]

devin-ai-integration[bot]

This comment was marked as resolved.

…e records on whole characters, keep queued messages to their chat and setMessages

@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.

Devin Review found 0 new potential issues.

Devin Review

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.

1 participant