Skip to content

fix(sessions): share the change-feed mirror between hosts (#2205) - #2404

Merged
threepointone merged 1 commit into
fix/2217-tool-result-cleanupfrom
fix/2205-session-mirror
Sep 28, 2026
Merged

threepointone merged 1 commit into
fix/2217-tool-result-cleanupfrom
fix/2205-session-mirror

Conversation

@threepointone

@threepointone threepointone commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2205.

Problem

AIChatAgent and Think each carried their own copy of the reduction that keeps an in-memory transcript in step with the Sessions change feed. That covers upserting on append and update, filtering on delete, and emptying on clear. The two copies had already drifted in small ways.

Fix

A new session.mirror({ get, set, transform?, intercept?, onApplied? }) applies the shared reduction for one session:

  • get() is read on every event, so a host that reassigns its array is followed rather than shadowed.
  • intercept lets a host handle an event itself. onApplied reports each write together with the entry it replaced.

AIChatAgent uses the plain form. Think keeps its own behavior exactly through the hooks: branch appends resync, imports mark the cache stale, compaction resyncs and refreshes the prompt, and linear appends still drive growth accounting and media-eviction bookkeeping.

Tests

  • New mirror tests in tests/sessions/capability.test.ts cover the reduction, reassignment, the onApplied log, intercept, other sessions, and unsubscribe.
  • The full Think (1196) and AIChat (806) suites pass unchanged.

@changeset-bot

changeset-bot Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0cb19a6

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 Patch
@cloudflare/think 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

@threepointone
threepointone added this pull request to stack #2407 September 28, 2026 14:47
@threepointone
threepointone marked this pull request as ready for review September 28, 2026 14:50

@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 found 1 potential issue.

Devin Review

Comment thread docs/agents/sessions.md
@threepointone
threepointone force-pushed the fix/2205-session-mirror branch from 4941ace to 21ca00e Compare September 28, 2026 15:46
@agent-think

agent-think Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🔴 agents import sizes: 1 entry point over threshold

Entry point Exports Largest gzip change Size now
🔴 agents/sessions 2 resized up to +249 B (+11.86%) 2.3 KiB
Changed exports (2)
Import Gzip change Size now
🔴 agents/sessions#Session +249 B (+11.86%) 2.3 KiB
🟡 agents/sessions#Sessions +220 B (+2.22%) 9.9 KiB
How this works

Each runtime export is bundled on its own, minified, and gzipped. Changes smaller than 100 B, or smaller than 1% and 1 KiB, are ignored. Growth over 10% or 5 KiB is marked 🔴. This report is informational and does not fail CI. The workflow artifact contains every measurement.

Compared 5fba64a1 → 0cb19a64 · workflow run · reported by agent-think[bot]

Adds session.mirror(), the one reduction AIChatAgent and Think each
carried a copy of. Think keeps its branch, compaction and prompt-refresh
handling through the intercept and onApplied hooks.

Co-authored-by: Cursor <cursoragent@cursor.com>
@threepointone
threepointone force-pushed the fix/2205-session-mirror branch from 21ca00e to 0cb19a6 Compare September 28, 2026 16:54
@pkg-pr-new

pkg-pr-new Bot commented Sep 28, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 0cb19a6

@threepointone
threepointone merged commit 9d125c8 into main Sep 28, 2026
18 of 31 checks passed
@threepointone
threepointone deleted the fix/2205-session-mirror branch September 28, 2026 18:04
@github-actions github-actions Bot mentioned this pull request Oct 2, 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.

sessions: the change-feed cache mirror is duplicated in every host

1 participant