Repository navigation
harness-backed Think: Think's chatRecovery honoured through the turn definition's recovery budget (A-4) - #3447
Merged
Merged
Conversation
|
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
mattzcarey
force-pushed
the
slim/harness-score-recovery-4
branch
from
November 27, 2026 09:52
54d8cf6 to
c69bf58
Compare
Contributor
|
✅ agents import sizes: no significant changes ( |
mattzcarey
marked this pull request as ready for review
November 27, 2026 10:15
mattzcarey
force-pushed
the
slim/harness-score-recovery-4
branch
from
November 27, 2026 10:21
c69bf58 to
3e9670e
Compare
mattzcarey
force-pushed
the
slim/harness-score-recovery-4
branch
from
November 27, 2026 10:37
cebcb93 to
97a04ff
Compare
mattzcarey
changed the base branch from
slim/turn-task-recovery-budget
to
main
November 27, 2026 11:04
…definition's recovery budget
…tream ids as onChatRecovery
…are the operation id, whatever form the definition gives them
…hausted see one incident id
mattzcarey
force-pushed
the
slim/harness-score-recovery-4
branch
from
November 27, 2026 11:08
97a04ff to
b5e991a
Compare
mattzcarey
force-pushed
the
slim/harness-score-recovery-4
branch
from
November 27, 2026 11:17
efa2b1c to
8603860
Compare
mattzcarey
added a commit
that referenced
this pull request
Nov 27, 2026
…and also wakes on Tasks' events (#3471)
mattzcarey
added a commit
that referenced
this pull request
Nov 27, 2026
…o main as one commit AIChatAgent runs its turns on chatTurnDefinition and chatDispatch, and its old engine is deleted. Rebased onto the rebased #3298 from f87cd85 plus verify's FIX: main merged in (#3389, #3444, #3447, #3435, #3423 resolved in chat-host.ts with turn-task's notes), F27, the stop in a retry backoff ending the turn once, a throwing onChatRecovery given up with recovery_error, and turn-task's 25baf34.
mattzcarey
added a commit
that referenced
this pull request
Nov 27, 2026
…o main as one commit AIChatAgent runs its turns on chatTurnDefinition and chatDispatch, and its old engine is deleted. Rebased onto the rebased #3298 from f87cd85 plus verify's FIX: main merged in (#3389, #3444, #3447, #3435, #3423 resolved in chat-host.ts with turn-task's notes), F27, the stop in a retry backoff ending the turn once, a throwing onChatRecovery given up with recovery_error, and turn-task's 25baf34.
mattzcarey
added a commit
that referenced
this pull request
Nov 27, 2026
…o main as one commit AIChatAgent runs its turns on chatTurnDefinition and chatDispatch, and its old engine is deleted. Rebased onto the rebased #3298 from f87cd85 plus verify's FIX: main merged in (#3389, #3444, #3447, #3435, #3423 resolved in chat-host.ts with turn-task's notes), F27, the stop in a retry backoff ending the turn once, a throwing onChatRecovery given up with recovery_error, and turn-task's 25baf34.
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.
The harness-backed Think now hands Think's released
chatRecoveryconfig to the turn definition's recovery budget (#3444), so its fields are honoured as on Think:maxAttempts,terminalMessage,onExhausted,shouldKeepRecovering, and the transient and retry-after bounds. The harness carries the config through an@internalrecovery.chatRecoveryoption. The shell passeschatRecoveryas it is, and only translates the ids inonExhausted/shouldKeepRecoveringcontexts from the run id to the operation id an app knows.This is arch's A-4 ruling: one implementation in the turn definition, and the shell maps onto it and does nothing else. It merges together with #3444, behind verify's gate.
Validated against std's give-up successors (#3437, merged locally): "gives up through onExhausted with max_attempts_exceeded once the attempts are spent" and "ends recovery with recovery_aborted when shouldKeepRecovering says no" fail on the harness config before this change and pass with it. The class config passes 14/14. Two other successors in that file still fail on the shell, for other slices: stash's
recoveryData, andcreatedAtfrom A-3 (#3429), which isn't in this base.Included: #3444 chat: the turn definition applies the released chatRecovery budget
The chat turn definition (
chat/chat-host.ts) gets the one implementation of the recovery budget: a turn found cut off is judged by the host's releasedchatRecoveryoptions, where it counted three attempts by the run's attempt number. This is the chat-module part of the AIChatAgent switch's recovery work, taken out of that stack so the harness-backed Think can map Think'sChatRecoveryConfigonto it now.What changed
ChatOptions.recoverytakes the released config object (plusstallTimeoutMs). In the definition:evaluateChatRecoveryIncident) decides, with what it counted kept in one checkpoint of the run (chat:incident) and progress measured as the chunks the turn has streamed. So: ten attempts by default, and an attempt that streamed more starts the count again; the no-progress window; the work budget; the interrupted attempts;shouldKeepRecovering.terminalMessageas its error, andonExhaustedis told the reason (max_attempts_exceeded,no_progress_timeout,work_budget_exceeded,interrupted_attempts_exceeded,recovery_aborted). A recovery the app declines (onRecovery→continue: false) ends with the failure that led to it when there was one.onRecovery's attempt is the incident's: 1 on the first recovery, as released.chat:failed). The wait before the next attempt honours the provider's retry-after, up to the cap. Recovery attempts that keep failing that way are bounded bymaxAttemptshowever fast they come.harness.ts(small): the harness passedmaxAttempts + 1and reportedattempt - 1to make the old count look like Think's; both adjustments are gone, since the definition now counts as Think does. An operation whose recovery gave up still ends with the reasoninterrupted: the harness asks the definition (chatRecoveryGaveUp(step),@internal) and no longer matches an error text. A model call's error carries the provider's error as itscause, which is where the retry-after is read.Also, from review:
shouldKeepRecoveringis told the work in units;Not here (they need
ChatDeps.emit, which is on the switch's branch): thechat:recovery:*andchat:stream:stalledevents.Tests
chat-turn-definition.test.ts(59 pass):Also run: the harness's own suite (149 pass) and Think's
chat-recovery-public.test.tson the harness config (5 of 5; three of them fail without the twoharness.tslines).Behaviour change for
ThinkHarnessThinkHarnessis a released experimental export (agents/harness/think, agents 0.34), and it runs on this definition. Withrecoveryunset it counted ten interruptions and had no other bound. It now has thechatRecoverydefaults:recovery.maxAttempts(default 10)So an operation can now be given up where 0.34 kept going (no progress, five resets in a row) and kept going where 0.34 stopped (more than ten interruptions that each made progress). There is a line for it in
.changeset/chat-recovery.md. The harness-backed Think built on it is not released.Cost
Measured by the reviewer on a deployed minimal Durable Object running the definition, main against this head, in SQL statements counted in the object (three runs each, identical):
The one extra statement is the
chat:incidentcheckpoint write. A transient failure writes one more checkpoint (chat:failed).How to probe
On a harness-backed Think agent with
chatRecovery = { maxAttempts: 2, terminalMessage: "…", onExhausted }and a model that stalls on every call: the turn ends with the terminal message after the first attempt and two recoveries, andonExhaustedis called once withmax_attempts_exceeded. With a model that streams a little more on each attempt before the object is reset, the turn is still recovered on its fourth reset.