Skip to content

fix(think): preserve regeneration branch context - #2038

Open
ben-reitz wants to merge 1 commit into
mainfrom
fix/think-regeneration-context
Open

fix(think): preserve regeneration branch context#2038
ben-reitz wants to merge 1 commit into
mainfrom
fix/think-regeneration-context

Conversation

@ben-reitz

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

Copy link
Copy Markdown
Contributor

Stacked on #2120.

Bug

Regeneration means “answer this user message again” while keeping the previous answer available. Think already stored the new answer as a sibling, but it generated that answer from the wrong history.

Stored conversation:

Earlier history → User message
                  └─ Old answer  ← active leaf

Expected model input: Earlier history → User message
Actual model input:   Earlier history → User message → Old answer → “Continue…”

The result looked like a new branch in storage, but the model had been asked to continue the old answer instead of producing an independent alternative.

Fix

Think now uses one server-validated branch point for both model input and output storage. For regeneration, model history ends at the selected user message, and the generated answer is stored beneath that same message.

Earlier history → User message
                  ├─ Old answer  ← preserved
                  └─ New answer  ← generated without seeing the old answer

The selected history also remains the inference source when lifecycle hooks or context compaction prepare the turn.

Testing

  • 87 client-tools tests
  • model-boundary regression verifies the prior assistant is absent from regenerated inference context
  • Session assertions verify the previous and regenerated assistants remain siblings

Fixes #2028

Stack

  1. fix(agents): keep session compactions branch-local #2120 — Session branch-local compaction
  2. This PR — Think regeneration context
  3. fix(think): preserve active transcript during repair #2121 — transcript repair ownership
  4. fix(think): preserve branches during recovery #2122 — branch-aware recovery
  5. fix(think): preserve regeneration branches after restart #2057 — restart durability

@changeset-bot

changeset-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fcda26e

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

This PR includes changesets to release 3 packages
Name Type
@cloudflare/think Patch
agents Patch
@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

@pkg-pr-new

pkg-pr-new Bot commented Aug 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 8659e64

@ben-reitz
ben-reitz marked this pull request as ready for review August 5, 2026 08:44
devin-ai-integration[bot]

This comment was marked as resolved.

@ben-reitz
ben-reitz marked this pull request as draft August 5, 2026 13:03
@ben-reitz
ben-reitz marked this pull request as ready for review August 6, 2026 11:04
@ben-reitz
ben-reitz force-pushed the fix/think-regeneration-context branch 4 times, most recently from 48e57e5 to 935bbb7 Compare August 13, 2026 10:21
@ben-reitz ben-reitz added the ready-for-review-and-merge PR is ready for review and/or merge label Aug 13, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@ben-reitz ben-reitz added wip still a work in progress and removed ready-for-review-and-merge PR is ready for review and/or merge labels Aug 14, 2026
@ben-reitz
ben-reitz force-pushed the fix/think-regeneration-context branch from ce64aca to 593c5c2 Compare August 17, 2026 09:23
@ben-reitz
ben-reitz changed the base branch from main to fix/session-branch-compaction August 17, 2026 09:25
@ben-reitz
ben-reitz force-pushed the fix/think-regeneration-context branch from 593c5c2 to 6228fd1 Compare August 17, 2026 09:42
@ben-reitz
ben-reitz force-pushed the fix/think-regeneration-context branch from 6228fd1 to 6783afe Compare August 18, 2026 08:49
@ben-reitz
ben-reitz force-pushed the fix/think-regeneration-context branch from 6783afe to 53734cb Compare August 18, 2026 09:17
Base automatically changed from fix/session-branch-compaction to main August 18, 2026 09:29
@ben-reitz
ben-reitz force-pushed the fix/think-regeneration-context branch from 53734cb to c5e0fc4 Compare August 18, 2026 09:29
devin-ai-integration[bot]

This comment was marked as resolved.

@ben-reitz
ben-reitz force-pushed the fix/think-regeneration-context branch from c5e0fc4 to 2ee21b6 Compare August 18, 2026 10:25
devin-ai-integration[bot]

This comment was marked as resolved.

@ben-reitz
ben-reitz force-pushed the fix/think-regeneration-context branch 3 times, most recently from dce349e to 8659e64 Compare August 18, 2026 13:17
@ben-reitz
ben-reitz force-pushed the fix/think-regeneration-context branch from 8659e64 to fcda26e Compare August 19, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wip still a work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Think regeneration includes the previous response in the model prompt

1 participant