Skip to content

fix(agents): keep session compactions branch-local - #2120

Merged
ben-reitz merged 1 commit into
mainfrom
fix/session-branch-compaction
Aug 18, 2026
Merged

fix(agents): keep session compactions branch-local#2120
ben-reitz merged 1 commit into
mainfrom
fix/session-branch-compaction

Conversation

@ben-reitz

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

Copy link
Copy Markdown
Contributor

Problem

Session compaction overlays* were selected globally before the provider checked whether their endpoint belonged to the requested conversation branch. A newer sibling-branch compaction could therefore hide a valid compaction for the branch being read.

SQLite compactions were also ordered only by CURRENT_TIMESTAMP, whose one-second resolution made the winning overlay nondeterministic when multiple compactions were created together.

  • called an overlay because it's a summary of a single thread of messages through the tree. Those messages are still stored - the compaction is just an 'overlay' over the top of them.

Fix

  • validate each compaction endpoint against the requested root-to-leaf path before selecting it
  • select the latest valid branch-local overlay in both Agent and Postgres session providers
  • order SQLite compactions by created_at, rowid for deterministic ties
  • preserve iterative compaction on the same branch without allowing sibling branches to interfere

Testing

  • 170 Session/provider tests
  • includes sibling-branch and same-timestamp regressions for both providers

Stack

This PR was getting too big so I've stacked a bunch of related fixes into separate PRs:

  1. This PR — Session branch-local compaction
  2. fix(think): preserve regeneration branch context #2038 — 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 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0028a20

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

This PR includes changesets to release 2 packages
Name Type
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

@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 2 additional findings.

Open in Devin Review

@pkg-pr-new

pkg-pr-new Bot commented Aug 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 0028a20

@ben-reitz
ben-reitz force-pushed the fix/session-branch-compaction branch 2 times, most recently from 92f8508 to 967bf6d Compare August 18, 2026 08:49
@ben-reitz
ben-reitz force-pushed the fix/session-branch-compaction branch from 967bf6d to 0028a20 Compare August 18, 2026 09:17
@ben-reitz
ben-reitz merged commit b038440 into main Aug 18, 2026
15 checks passed
@ben-reitz
ben-reitz deleted the fix/session-branch-compaction branch August 18, 2026 09:29
@github-actions github-actions Bot mentioned this pull request Aug 18, 2026
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