Skip to content

Sessions: the annotation carry walk jumps over older overlays - #3107

Merged
mattzcarey merged 1 commit into
mainfrom
slim/sessions-carry
Nov 24, 2026
Merged

mattzcarey merged 1 commit into
mainfrom
slim/sessions-carry

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

When addCompaction or compact() stores an overlay in a session that has annotations, it looks for the newest annotation of each kind among what the overlay hides, to carry onto it. That walk went row by row from the overlay's end down to where the history continues, including every row already under an older overlay. The gate measured the second compaction of a 100,000-row session at 600,158 rows read with an annotation present, against 200,211 without. With #2773, every Think session with a context block has an annotation.

Now the walk steps the way reads do. At a row where an older overlay applies (the newest one ending there with a known continuation), it takes that overlay's summary, which already carries the newest annotation of what it hid, and jumps to the overlay's continuation. seq falls along an ancestor chain, so the walk stops at the first row at or below the new overlay's continuation, even when a jump passes it.

The doc comment on internal_annotations also now says that an annotation an overlay carried stays on the overlay after the rows it came from are deleted, since the summary was written with them (the gate's note on #3061).

Cost. Each step of the walk is one overlay probe and one message lookup: it carries the parent id in the walk's row, so it doesn't read the current row again. Measured in the Workers pool on a 15,000-row session with one annotation, before (#3061) / after:

Compaction Rows read before After
first, m1..m10000 (no older overlay) 60,013 60,014
second, m1..m15000 over the first 90,010 50,020

On a deployment at 100,000 rows, rv-5 measured the nested compaction at 25% fewer rows. An earlier version of this PR looked up two rows per step and made the first compaction 17% dearer (352k against 302k). The rest of each count is the compaction's own checks, about 2 rows per stored row with or without annotations. The gate, deployed at 100,000 rows: the second compact() with an annotation reads 200,263 rows, against 600,167 before (200,267 on main with #2773's real context records, at the root and in a facet). A first overlay over raw rows still reads about 6 rows per hidden row when the session has an annotation; there is no older overlay to jump over there.

Tests ran: annotations.test.ts "carries past an older overlay by its summary, not row by row" (90,010 rows before, under 60,000 here, and the first compaction under 61,000; the value is carried even after the annotated row is deleted), the sessions suite (183), and check.

How to probe: on a deployment, seed a session with 100,000 rows and annotate one of them, then compact it twice with ranges that overlap, the second wider. Compare rows read by the second compaction against #3061, then check which annotation the second overlay carries.

@changeset-bot

changeset-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b2dd931

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

Base automatically changed from slim/sessions-annotations to main November 24, 2026 11:07
@pkg-pr-new

pkg-pr-new Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: b2dd931

@mattzcarey
mattzcarey marked this pull request as ready for review November 24, 2026 11:42
@agent-think

agent-think Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

🟡 agents import sizes: 1 entry point grew

Entry point Exports Largest gzip change Size now
🟡 agents/sessions 1 resized +258 B (+1.64%) 15.7 KiB
Changed exports (1)
Import Gzip change Size now
🟡 agents/sessions#Sessions +258 B (+1.64%) 15.7 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 9be3183e → b2dd931e · workflow run · reported by agent-think[bot]

@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 packages/agents/src/sessions/core.ts Resolved
@mattzcarey
mattzcarey merged commit 82cabb7 into main Nov 24, 2026
28 checks passed
@mattzcarey
mattzcarey deleted the slim/sessions-carry branch November 24, 2026 12:02
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