Skip to content

Chat: the chat module's host contract and turn definition (4.iii, slice 6, draft) - #3289

Merged
mattzcarey merged 15 commits into
mainfrom
slim/chat-fn-6
Nov 27, 2026
Merged

mattzcarey merged 15 commits into
mainfrom
slim/chat-fn-6

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

4.iii slice 6 (arch ruling "4.iii slices"): the chat module's host contract and its one turn definition, internal in agents/chat. Per arch it merges with its first caller (harness's H2, #3295, or the AIChatAgent move); 6a (ChatDeps built once per host) lands with that caller.

chat-host.ts has the RFC's contract as agreed with harness: ChatDeps (webSockets optional), ChatHost { respond, hooks, options }, ChatModelCall with step(name, fn) (the run's step.do), ChatHooks with repairInterruptedToolPart(part, { recovery }), ChatTurnInput and ChatTurnResult. Then chatTurnDefinition(deps, host, { name }), a framework task handler a host registers with tasks.register("__cf…", …) on its own lanes. A run:

  • reads the session's transcript, up to its question for a regenerate, builds the call and calls respond (a UI chunk stream, an AI SDK result, or a Response: an event stream or plain text);
  • writes each chunk (after transformChunk) to the run's stream and to the tabs, giving the reply an id when the model sent none;
  • stores the reply with the cutover: the stream settles and its rows go in the same transaction as the message and a run checkpoint, so a crash leaves the live stream or the stored reply, and a replay after it does not answer again;
  • after a reset, continues the reply the earlier attempt was cut off in. It rebuilds it from the stream (over the base reply a tool-answer turn extends), finishes cut text, settles cut-off server tools through repairInterruptedToolPart (a client tool call stays waiting), and calls respond with mode: "continue". options.recovery caps attempts and onRecovery may stop it or drop the partial;
  • treats a stall or a transient error as an interruption (TaskSettlement.retry after a backoff, stream left open; a transient in-band error isn't stored); on an overflow, calls onContextOverflow and asks once more with the shortened transcript;
  • on a stop (thrown, or the model closing its stream on the signal) keeps what it streamed, its cut-off server tools settled, and ends aborted; a chat clear keeps nothing.

22 tests on a minimal Durable Object (Tasks, Streams, Sessions) cover these. Not yet here: settling the stream of a run cancelled while it waits out its retry backoff (6f, with the lane's cancel path).

Cost: no hot path changes (nothing calls it in production yet).

@changeset-bot

changeset-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: bce274e

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 no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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 26, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: bce274e

@agent-think

agent-think Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

✅ agents import sizes: no significant changes (065c114a → bce274ec, workflow run)

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

…rn end to end (respond, stream, store), tested on a minimal DO
…n-band error is not stored; a stopped turn keeps what it streamed
…or plain text, continuation base, overflow history, pinned question, persist:false, cut parts settled)
… discards on, skip discarded chunks, a clear via Tasks keeps nothing, a recovered regenerate stays on its branch, settle a client tool cut mid-input, flag a continuation's first frame)
…an approved tool cut off by a reset is reported interrupted (rv-6 on #3295)
devin-ai-integration[bot]

This comment was marked as resolved.

…, and a call awaiting approval or a tool's progress output correctly; an approved client tool cut off by a reset still waits for its result (Devin)
@mattzcarey
mattzcarey merged commit 98d0d41 into main Nov 27, 2026
45 of 50 checks passed
@mattzcarey
mattzcarey deleted the slim/chat-fn-6 branch November 27, 2026 01:58
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