Skip to content

Chat turns: a completed reply that ends in reasoning is kept; the reasoning is left out of the model request (F21) - #3487

Closed
mattzcarey wants to merge 7 commits into
slim/agent-runs-r3from
slim/inbox-f21-b
Closed

mattzcarey wants to merge 7 commits into
slim/agent-runs-r3from
slim/inbox-f21-b

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

A reply that ended with reasoning only (some models finish that way, finish: "stop") disappeared from the transcript at the next turn. The before-turn repair stripped trailing reasoning in storage and then deleted the message it had emptied. That was the missing assistant message in the deployed soak (F21). Matt's rule (b) replaces it: a reply that completed is kept as stored, and its trailing reasoning is left out of the model request only. A reply cut off while reasoning is still removed by recovery, as before.

  • Shared repair (before-turn.ts, repair-transcript.ts, chat-turns.ts): the before-turn repair no longer strips reasoning in storage (stripReasoning: false), so a reply that holds only reasoning is no longer "empty". requestMessages() builds the request view: each message without the reasoning it ends in, and without the messages that leaves empty. Replies that hold nothing at all are still removed.
  • Think builds its request from that view (settleBeforeTurn's returned messages).
  • AIChatAgent's this.messages is that view while onChatMessage builds its request, then the transcript again.
  • Unchanged: the recovery side (settleInterruptedReply, removeEmptyReplyToContinue, replyIsEmpty). A reply cut off in its reasoning, or one continueLastTurn() or a recovery would continue, is still removed and the question answered again.

Stacked on the switch group (#3298 + #3361 + #3475) and merges after it.

Cost

No extra statement. The repair writes less: it no longer rewrites or deletes a reply that ends in reasoning. Building the request view is one pass over the messages in memory.

How to probe

  1. packages/think: empty-reply.test.ts "keeps a completed reply that holds only reasoning when a new question comes". The reply is still stored, and the next model prompt has no assistant message. It fails with the switch's chat files (b2f743b).
  2. packages/ai-chat: chat-turn-races.test.ts. The reasoning-only reply is kept and no tab is sent a list without it, and getEndsInReasoningAtModelCallForTest() is empty, so the request is valid for Anthropic. The ai-chat suite passes 829/829. Chat unit tests pass 1472/1472 and chat-host 186/186.
  3. Deployed soak (verify): a turn whose model ends with reasoning only, then one more turn. The first reply is still in the transcript, and the second turn is answered.

Devin Review

@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 578ed54

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 4 packages
Name Type
agents Patch
@cloudflare/ai-chat Patch
@cloudflare/think Patch
@cloudflare/agent-think Patch

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 578ed54

@agent-think

agent-think Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🟢 agents import sizes: 1 entry point changed, no growth

Entry point Exports Largest gzip change Size now
🆕 agents/chat 1 new — 2.9 KiB
Changed exports (1)
Import Gzip change Size now
🆕 agents/chat#requestMessages — 2.9 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 f903bf45 → 578ed54b · workflow run · reported by agent-think[bot]

@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 3 potential issues.

Devin Review

Comment thread packages/agents/src/chat/chat-host.ts Resolved
Comment thread packages/ai-chat/src/index.ts Resolved
Comment thread .changeset/chat-turns.md Resolved
@mattzcarey
mattzcarey marked this pull request as draft November 27, 2026 16:11
@mattzcarey
mattzcarey marked this pull request as ready for review November 27, 2026 16:29
@mattzcarey
mattzcarey marked this pull request as draft November 27, 2026 16:51
@mattzcarey
mattzcarey marked this pull request as ready for review November 27, 2026 17:12
@mattzcarey
mattzcarey marked this pull request as draft November 27, 2026 17:14
…reasoning (a reply may complete that way); Think leaves that reasoning out of the model request only (F21)
…nscript, left out of the model request (F21)
…m messages without the reasoning a stored reply ends in; docs (client-tools-continuation, chat-turn-core D51/D57) and the changeset line
…ll.messages (the harness-backed Think's request too) and the stored list as .transcript; AIChatAgent gives its app the transcript, no swap
…soning-only reply as two tests, and that a reply cut off in its reasoning leaves none before the next question; client-tools checks the continuation's answer follows
…host) does not load the Lifecycle: the node chat tests import chat-turns -> chat-host again
@mattzcarey

Copy link
Copy Markdown
Member Author

Replaced by #3504, which carries this change with the rest of the switch (integrated and tested together).

@mattzcarey mattzcarey closed this Nov 28, 2026
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