Skip to content

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

Merged
ben-reitz merged 6 commits into
mainfrom
fix/unconditional-chat-recovery
Aug 19, 2026
Merged

fix(chat): make durable recovery unconditional#2071
ben-reitz merged 6 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 (but will get a type error).

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.

If any users are currently using this option, they'll get a typescript failure which should be enough for their clanker to figure out the issue

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: b196b94

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[bot]

This comment was marked as resolved.

@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

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: b196b94

@ben-reitz ben-reitz added the ready-for-review-and-merge PR is ready for review and/or merge label Aug 12, 2026
@ben-reitz
ben-reitz merged commit 9620b58 into main Aug 19, 2026
15 checks passed
@ben-reitz
ben-reitz deleted the fix/unconditional-chat-recovery branch August 19, 2026 14:12
@github-actions github-actions Bot mentioned this pull request Aug 19, 2026
brandhaug added a commit to brandhaug/b2b-saas-starter that referenced this pull request Sep 3, 2026
## Dependency Updates

| Package | From | To | Type |
| --- | --- | --- | --- |
| `agents` | 0.21.0 | 0.22.0 | minor |

## Release Notes

<details>
<summary><b>agents</b> (0.21.0 → 0.22.0)</summary>

### Minor Changes

- [#2071](cloudflare/agents#2071)
[`9620b58`](cloudflare/agents@9620b58)
Thanks [@ben-reitz](https://github.com/ben-reitz)! - Make durable chat
recovery unconditional for `AIChatAgent` and `Think`.

Every chat turn now runs in a recovery fiber, including WebSocket,
programmatic, retry, and continuation paths. `chatRecovery` accepts
`true` or a configuration object; `false` is no longer supported.
Previously compiled JavaScript that still supplies `false` safely
receives the default recovery configuration.

To keep durable bookkeeping while preventing automatic inference after
an interruption, return `{ continue: false }` from `onChatRecovery()`.
Use durable cancellation, side-effect, or spend state in that hook and
tune `chatRecovery` budgets when retries must be bounded.

- [#2133](cloudflare/agents#2133)
[`d536067`](cloudflare/agents@d536067)
Thanks [@mattzcarey](https://github.com/mattzcarey)! - Vendor the
required PartyServer runtime into `agents/lifecycle` and add a reusable
Durable Object lifecycle for startup, request interception, alarms, and
WebSockets. `Agent` now directly extends Cloudflare's `DurableObject`
and composes the same lifecycle used by standalone objects; standalone
hosts use the explicit `Lifecycle.install(this)` factory (or the
expanded `new ...` plus `installHandlers()` form). Both Agent subclasses
and standalone hosts use the existing `routeAgentRequest()` API and
`/agents` URL prefix; the lifecycle entry point does not introduce a
second public router.

Lifecycle WebSockets always use Cloudflare's Hibernation API; the
`static options.hibernate` switch and in-memory connection mode are
removed. Named Durable Objects use native `ctx.id.name`, while a
read-only `__ps_name` fallback migrates objects created by older
releases without writing new compatibil

…[full
notes](https://github.com/cloudflare/agents/releases/tag/agents%400.22.0)

</details>

---
*This PR was auto-generated by
[catalog-update-action](https://github.com/brandhaug/catalog-update-action).*

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review-and-merge PR is ready for review and/or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants