Skip to content

fix(chat): make durable recovery unconditional - #2071

Open
ben-reitz wants to merge 3 commits into
mainfrom
fix/unconditional-chat-recovery
Open

fix(chat): make durable recovery unconditional#2071
ben-reitz wants to merge 3 commits into
mainfrom
fix/unconditional-chat-recovery

Conversation

@ben-reitz

@ben-reitz ben-reitz commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #2044.

Remove chatRecovery = false

This removes the option to disable durable chat recovery in AIChatAgent and Think. Every chat turn now runs in a recovery fiber. chatRecovery remains available for tuning recovery budgets and terminal behavior.

Previously compiled JavaScript that still supplies false receives the default recovery configuration.

Why the opt-out is unnecessary

The opt-out tied two separate concerns together: durable bookkeeping and automatic continuation. Users may need to prevent another model call, but the SDK still needs a durable record of the running turn.

Issue #2044 exposed one consequence of skipping that record. An agent-tool inspection handled by a fresh JavaScript instance could not see another instance's in-memory stream state. It could throw during inspection or mark a child as failed while that child was still running successfully.

Keeping the durable record for every turn removes that unsafe branch. Applications can still decline automatic continuation without giving up durable bookkeeping.

For existing false users

Remove the assignment. If recovery must not issue another model call, return { continue: false } from onChatRecovery() instead. Cancellation intent, side-effect completion, or spend limits should be stored durably and consulted by that hook; recovery budgets remain available as an additional bound.

Tests

A regression test runs an agent-tool child with the legacy false value, kills it during streaming, and verifies that recovery completes and the parent receives the real terminal result.

Suites: agents chat 514 · AI Chat workers 655 · Think workers 919 · agent-tool recovery E2E · pnpm run check.


Open in Devin Review

@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8b0cc15

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

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

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

View 2 additional findings in Devin Review.

Open in Devin Review

Comment thread docs/think/sub-agents.md
Instead of `chatRecovery = true`, assign an object to tune how long recovery is allowed to run and when it is given up on. A turn that keeps making forward progress survives unbounded interruption — duration is not a bound — as long as it stays under the `maxRecoveryWork` backstop. Recovery is only sealed by one of the limits below.
Assign a `chatRecovery` object to tune how long recovery is allowed to run and when it is given up on. A turn that keeps making forward progress survives unbounded interruption — duration is not a bound — as long as it stays under the `maxRecoveryWork` backstop. Recovery is only sealed by one of the limits below.

`chatRecovery = false` is no longer supported. If automatic continuation is unsafe, return `{ continue: false }` from `onChatRecovery()`. For cancellation that must survive hibernation, store cancellation intent durably and check it in that hook. See [Migrating from `chatRecovery = false`](../agents/chat-agents.md#migrating-from-chatrecovery--false) for side-effect and cost guidance.

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.

🟡 Recovery migration link in the Think sub-agent docs points to a section that does not exist

A new sentence in the Think sub-agents page links readers to a "Migrating from chatRecovery = false" section (../agents/chat-agents.md#migrating-from-chatrecovery--false at docs/think/sub-agents.md:440) that was never added, and it uses a relative path across package documentation directories instead of the absolute repository URL the docs conventions require.
Impact: Readers following the migration pointer land on the wrong place in the page, and the link style is inconsistent with the rest of the cross-package links.

Missing anchor and cross-directory link convention

The PR added the "Controlling automatic continuation" section to docs/agents/chat-agents.md:654, not a "Migrating from chatRecovery = false" heading, so the anchor #migrating-from-chatrecovery--false resolves to nothing.

docs/AGENTS.md states: "Link within a package directory using relative paths (./state.md); Link across package directories with an absolute repository URL." Other cross-package links in the same file follow that rule (e.g. docs/think/sub-agents.md:475 uses https://github.com/cloudflare/agents/blob/main/docs/agents/chat-agents.md#stream-recovery).

Suggested change
`chatRecovery = false` is no longer supported. If automatic continuation is unsafe, return `{ continue: false }` from `onChatRecovery()`. For cancellation that must survive hibernation, store cancellation intent durably and check it in that hook. See [Migrating from `chatRecovery = false`](../agents/chat-agents.md#migrating-from-chatrecovery--false) for side-effect and cost guidance.
`chatRecovery = false` is no longer supported. If automatic continuation is unsafe, return `{ continue: false }` from `onChatRecovery()`. For cancellation that must survive hibernation, store cancellation intent durably and check it in that hook. See [Controlling automatic continuation](https://github.com/cloudflare/agents/blob/main/docs/agents/chat-agents.md#controlling-automatic-continuation) for side-effect and cost guidance.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@pkg-pr-new

pkg-pr-new Bot commented Aug 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

create-think

npm i https://pkg.pr.new/create-think@2071

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 8b0cc15

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.

Think: inspectAgentToolRun throws when chatRecovery = false agent-tool child

1 participant