Skip to content

fix(think): preserve regeneration branches after restart - #2057

Open
ben-reitz wants to merge 1 commit into
fix/think-regeneration-contextfrom
fix/think-regeneration-restart-recovery
Open

fix(think): preserve regeneration branches after restart#2057
ben-reitz wants to merge 1 commit into
fix/think-regeneration-contextfrom
fix/think-regeneration-restart-recovery

Conversation

@ben-reitz

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

Copy link
Copy Markdown
Contributor

Stacked on #2038.

What users see

The parent PR fixes regenerated answers using the wrong conversation branch. One restart case remained: if the server's Durable Object restarted while a regenerated answer was streaming, the recovered text could be saved beneath the original answer instead of beside it.

flowchart TB
  subgraph after["After"]
    AU["User message"] --> AO["Original answer"]
    AU --> AR["Recovered regeneration"]
  end

  subgraph before["Before"]
    BU["User message"] --> BO["Original answer"]
    BO --> BR["Recovered regeneration"]
  end
Loading

Why it happens

The streamed text survives a restart because it is stored in SQLite. The message it belongs beside did not: that link only lived in memory. After a restart, Think still had the words, but had forgotten where to put them.

The fix

Resumable streams now save that optional parent link with their existing metadata. When Think rebuilds an interrupted answer, it reads the link back and restores the answer to the right branch.

Existing rows keep the old fallback behavior. Conversations that do not branch also keep using the existing schema until they actually need this field.

Tests

A new WebSocket test disables automatic chat recovery, forces a Durable Object restart, acknowledges the resumed stream, and checks that the recovered answer is a sibling of the original. Migration tests cover both old databases and ordinary linear streams.

Suites: think 925 · agents workers 1746 · agents chat 514 · ai-chat workers 655 · pnpm run check.


Open in Devin Review

@changeset-bot

changeset-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7e46e91

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

@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: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@pkg-pr-new

pkg-pr-new Bot commented Aug 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

create-think

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 7e46e91

@ben-reitz
ben-reitz force-pushed the fix/think-regeneration-restart-recovery branch from 88b1368 to 7f0e51a Compare August 6, 2026 14:08
@ben-reitz
ben-reitz force-pushed the fix/think-regeneration-restart-recovery branch from 7f0e51a to 7e46e91 Compare August 7, 2026 07:24
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