fix(think): preserve regeneration branches after restart - #2057
Open
ben-reitz wants to merge 1 commit into
Open
Conversation
|
agents
@cloudflare/ai-chat
@cloudflare/codemode
create-think
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
ben-reitz
force-pushed
the
fix/think-regeneration-restart-recovery
branch
from
August 6, 2026 14:08
88b1368 to
7f0e51a
Compare
ben-reitz
force-pushed
the
fix/think-regeneration-restart-recovery
branch
from
August 7, 2026 07:24
7f0e51a to
7e46e91
Compare
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.
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"] endWhy 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.