Skip to content

H2: ThinkHarness's runs are the chat module's turn definition - #3295

Merged
mattzcarey merged 6 commits into
mainfrom
slim/harness-h2
Nov 27, 2026
Merged

mattzcarey merged 6 commits into
mainfrom
slim/harness-h2

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

ThinkHarness's runs are now the chat module's turn definition (chatTurnDefinition from #3289), registered under both of the harness's definitions and run on its per-session lanes. The first attempt places the operation and records the placement in the run's checkpoint, in the same transaction as the transcript write. Every attempt then calls the definition, and its respond is the harness's model-and-tools loop. That loop is one model call per step, with the context prepared and beforeTurn run each time. Every server tool runs as a durable step of the run, and approvals are requested in the stream. The definition owns the turn's stream, the store-and-cutover, recovery of an interrupted attempt (continue mode, the budget, onRecovery), the stall watchdog and the context-overflow retry. So the harness's own versions of these are deleted: #steps, #callModel, #recoverModel, #interrupted, #abandon, the per-call stream ids and the segment packing, and the backoffMs option. Slice (a)'s thinkResponder is deleted too; its single streamText loop couldn't run the per-step hooks. The shipped read-only tools (the workspace's read, ls, grep and find, fetch_url, and the skills' activate and read-resource tools) are marked recovery: "rerun". ThinkChat keeps its own protocol dispatch for now: the chat functions in #3298 start runs under the request id with a ChatTurnInput, and the harness's runs carry its own input and ids.

This is H2 of THINK-HARNESS.md: one implementation of a chat turn, with the harness as its first caller (#3289 merges together with this PR). Think's queued-submission behaviour is kept, per the overnight Q2 ruling: a queued turn's question enters the transcript when its turn starts, and a cancelled queued submission never appears. A server tool cut off by a reset is reported to the model as interrupted unless the tool is marked recovery: "rerun". That now includes a call whose input had streamed but which hadn't started. Open runs from the release (the harness store's operations, carried into runs with a turn checkpoint) are placed from that progress: what their model call had streamed is kept, the tool calls they had started are reported as interrupted, and the reply is continued.

Validated with the harness-think suite (132 of 132, with the released-row and default-table stream tests unchanged) a new upgrade test (a released version's running turn, carried forward and continued in a sub-agent) and a test of the shipped tools' recovery marks. The Think compat scoreboard matches the base at 290 passing. The one loss was a tool output with its own toJSON, fixed by journaling tool results as JSON. Cost per prompt at ab48c9c (statements / rows written, harness-think meter): hello 87/25, a one-tool turn 103/31, two tools 113/35. Against main's harness: hello 71/20, and 33 and 37 rows written for the tool turns. Against the release's Think turn (PERF-BUDGET think/turn-short, 87/30 on perf's workerd meter, a different probe): at or below. The text-turn increase over main comes from the definition writing each chunk to the stream as it arrives (the harness used to pack ten into one segment) and from its reply checkpoint. Batching those writes belongs in the definition and is asked of limits. The release's ThinkHarness (the harness-store version) has no perf scenario; perf is asked to add one. #3298's submitTurn reads each message a tab sends (getMessage per message) to keep only new or changed ones; this PR doesn't call submitTurn (ThinkHarness places a turn's messages itself, and ThinkChat keeps its own dispatch until H2c), so it adds no such read. The harness's own placement already reads one getMessage per message a client sends, to refuse rewriting a stored id, as on main. H2c, the first caller of submitTurn through ThinkChat, will state that cost against today's per-request cost.

@changeset-bot

changeset-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7fd8a21

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 2 packages
Name Type
agents Minor
@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 26, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 7fd8a21

@agent-think

agent-think Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🔴 agents import sizes: 2 entry points over threshold

Entry point Exports Largest gzip change Size now
🔴 agents/harness/think 2 resized up to +1.7 KiB (+41.39%) 5.6 KiB
🔴 agents/chat 170 resized up to +417 B (+15.03%) 3.1 KiB
Changed exports (172)
Import Gzip change Size now
🔴 agents/harness/think#ThinkChat +1.7 KiB (+41.39%) 5.6 KiB
🔴 agents/chat#handleRecoveryAttemptError +417 B (+15.03%) 3.1 KiB
🔴 agents/chat#AGENT_TOOL_STREAM_PROGRESS_BUMP_THROTTLE_MS +415 B (+18.48%) 2.6 KiB
🔴 agents/chat#CHAT_STREAM_PROGRESS_CREDIT_THROTTLE_MS +415 B (+18.48%) 2.6 KiB
🔴 agents/chat#currentTurnCheckpoint +414 B (+18.34%) 2.6 KiB
🔴 agents/chat#runAppStart +414 B (+18.34%) 2.6 KiB
🔴 agents/chat#chunkMustBeStoredNow +414 B (+18.32%) 2.6 KiB
🔴 agents/chat#takeAtFirstContent +414 B (+17.83%) 2.7 KiB
🔴 agents/chat#sweepStaleChatRecoveryIncidents +414 B (+17.38%) 2.7 KiB
🔴 agents/chat#CHAT_RECOVERING_FLAG_TTL_MS +413 B (+18.42%) 2.6 KiB
🔴 agents/chat#CHAT_RECOVERY_ALARM_DEBOUNCE_MS +413 B (+18.42%) 2.6 KiB
🔴 agents/chat#DEFAULT_CHAT_RECOVERY_NO_PROGRESS_TIMEOUT_MS +413 B (+18.42%) 2.6 KiB
🔴 agents/chat#CHAT_RECOVERY_STABLE_RETRY_DELAY_SECONDS +413 B (+18.39%) 2.6 KiB
🔴 agents/chat#DEFAULT_CHAT_RECOVERY_MAX_INTERRUPTED_ATTEMPTS +413 B (+18.39%) 2.6 KiB
🔴 agents/chat#DEFAULT_CHAT_RECOVERY_MAX_WORK +413 B (+18.39%) 2.6 KiB
🔴 agents/chat#DEFAULT_CHAT_RECOVERY_STABLE_TIMEOUT_MS +413 B (+18.39%) 2.6 KiB
🔴 agents/chat#CHAT_RECOVERING_KEY +413 B (+18.33%) 2.6 KiB
🔴 agents/chat#CHAT_RECOVERY_CANCELLED_REASON +413 B (+18.33%) 2.6 KiB
🔴 agents/chat#CHAT_RECOVERY_PROGRESS_KEY +413 B (+18.29%) 2.6 KiB
🔴 agents/chat#CHAT_LAST_TERMINAL_KEY +413 B (+18.27%) 2.6 KiB
🔴 agents/chat#CHAT_RECOVERY_INCIDENT_KEY_PREFIX +413 B (+18.27%) 2.6 KiB
🔴 agents/chat#CHAT_RECOVERY_CONTINUED_REASON +413 B (+18.26%) 2.6 KiB
🔴 agents/chat#readChatRecoveryProgress +413 B (+18.15%) 2.6 KiB
🔴 agents/chat#cutOffReplyToSettle +413 B (+17.94%) 2.7 KiB
🔴 agents/chat#streamErrorText +413 B (+17.87%) 2.7 KiB
🔴 agents/chat#chatRecoveryBackoffSeconds +413 B (+17.1%) 2.8 KiB
🔴 agents/chat#runChatRecoveryExhaustion +413 B (+16.53%) 2.8 KiB
🔴 agents/chat#settleReplyBeforeRecovery +413 B (+11.2%) 4 KiB
🔴 agents/chat#aiSdkRecoveryCodec +412 B (+18.38%) 2.6 KiB
🔴 agents/chat#CHAT_RECOVERY_INCIDENT_TTL_MS +412 B (+18.38%) 2.6 KiB
🔴 agents/chat#partialHasSettledToolResults +412 B (+18.37%) 2.6 KiB
🔴 agents/chat#DEFAULT_CHAT_RECOVERY_MAX_ATTEMPTS +412 B (+18.34%) 2.6 KiB
🔴 agents/chat#pendingChatTerminal +412 B (+18.08%) 2.6 KiB
🔴 agents/chat#chunkCarriesContent +412 B (+17.98%) 2.6 KiB
🔴 agents/chat#bumpChatRecoveryProgress +412 B (+17.96%) 2.6 KiB
🔴 agents/chat#shouldCreditStreamProgress +412 B (+17.92%) 2.6 KiB
🔴 agents/chat#recordChatTerminal +412 B (+17.84%) 2.7 KiB
🔴 agents/chat#uiMessageStreamSource +412 B (+17.4%) 2.7 KiB
🔴 agents/chat#scheduleRecoveredTurn +412 B (+16.69%) 2.8 KiB
🔴 agents/chat#CHAT_RECOVERY_TASK_NAME +411 B (+18.19%) 2.6 KiB
🔴 agents/chat#DEFAULT_CHAT_RECOVERY_TERMINAL_MESSAGE +411 B (+17.92%) 2.6 KiB
🔴 agents/chat#clearChatTerminal +411 B (+17.88%) 2.6 KiB
🔴 agents/chat#buildChatRecoveringFrame +411 B (+17.73%) 2.7 KiB
🔴 agents/chat#chatRecoveryProgressReader +411 B (+17.56%) 2.7 KiB
🔴 agents/chat#listActiveChatRecoveryIncidents +411 B (+17.49%) 2.7 KiB
🔴 agents/chat#classifyAgentToolChildRecovery +411 B (+17.33%) 2.7 KiB
🔴 agents/chat#turnSignal +410 B (+17.97%) 2.6 KiB
🔴 agents/chat#setChatRecovering +410 B (+17.19%) 2.7 KiB
🔴 agents/chat#sendIfOpen +408 B (+17.53%) 2.7 KiB
🔴 agents/chat#responseSource +408 B (+15.18%) 3 KiB

…and 122 more exports in the workflow artifact.

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 98d0d41d → 7fd8a21a · workflow run · reported by agent-think[bot]

@mattzcarey
mattzcarey force-pushed the slim/harness-h2 branch 2 times, most recently from 968e1eb to b6e23dd Compare November 26, 2026 23:06
@mattzcarey
mattzcarey force-pushed the slim/harness-h2 branch 2 times, most recently from 1760665 to 2989b09 Compare November 26, 2026 23:21
@mattzcarey mattzcarey changed the title H2: ThinkHarness's step loop as the chat module's respond H2: ThinkHarness's runs are the chat module's turn definition Nov 27, 2026
@mattzcarey
mattzcarey marked this pull request as ready for review November 27, 2026 00:24
devin-ai-integration[bot]

This comment was marked as resolved.

mattzcarey added a commit that referenced this pull request Nov 27, 2026
…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.

devin-ai-integration[bot]

This comment was marked as resolved.

mattzcarey added a commit that referenced this pull request Nov 27, 2026
…ce 6, draft) (#3289)

* WIP 4.iii slice 6: the chat module's host contract (ChatDeps, ChatHost, ChatModelCall with step, ChatHooks)

* WIP 4.iii slice 6: chatTurnDefinition(deps, host, { name }) runs a turn end to end (respond, stream, store), tested on a minimal DO

* WIP 4.iii slice 6: a later attempt continues the reply the earlier one was cut off in; cut-off tools are settled

* WIP 4.iii slice 6: the reply is stored and its stream settled and dropped in one transaction (cutover)

* WIP 4.iii slice 6: a tool-answer turn continues the reply that asked for the tool

* WIP 4.iii slice 6: recovery budget, onRecovery, the stall watchdog and context overflow in the turn definition

* WIP 4.iii slice 6: the turn definition sends every chunk and the end to the tabs

* WIP 4.iii slice 6: respond may return a Response (event stream or plain text)

* Chat: a replay after the cutover does not answer again; a transient in-band error is not stored; a stopped turn keeps what it streamed

* Chat: review fixes in the turn definition (stop on clean close, ids for plain text, continuation base, overflow history, pinned question, persist:false, cut parts settled)

* Chat: a turn's input may name its session; a regenerated reply is a new branch under its question

* Test: the regenerate branch test does not depend on the fixture's reply id

* Chat: Devin fixes on the turn definition (keep a tool answer recovery 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)

* Chat: the stall watchdog times only the model, not a tool that runs; an approved tool cut off by a reset is reported interrupted (rv-6 on #3295)

* Chat: the stall watchdog counts an approved continued call as running, 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)
Base automatically changed from slim/chat-fn-6 to main November 27, 2026 01:58
…he harness's model-and-tools loop as its respond
…llel results stream at once, the stall watchdog watches the model only, an overflow after progress continues, a failed call keeps what it streamed, a failed regeneration stays on its branch, onRecovery gets the partial; the facet upgrade test takes the released path)
… tool result survives a sibling failing the turn, a tool's hooks see its step's attempt; the changeset names the rerun mark)
…or a tool safe to rerun; the rerun test checks both hooks' attempt

@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 1 new potential issue.

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