Skip to content

fix(compaction): Keep earlier Turns' answers out of the Turn after a history replacement - #3695

Closed
sentry-junior[bot] wants to merge 2 commits into
mainfrom
fix/swap-turn-start
Closed

sentry-junior[bot] wants to merge 2 commits into
mainfrom
fix/swap-turn-start

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3687.

Before: A prepared-summary swap keeps every message after its mark, so the replacement can hold reply or noReply results from earlier Turns. After any replacement, the Turn start was set to 0. A gated Turn then counted an earlier answer as its own: a resumed slice returned without calling the model, and the Turn ended with the earlier answer.

After: After a replacement, only the current Turn's messages count toward its answer, also after a pause and resume.

  • compactWithPreparedSummary returns turnStartMessageIndex, the index of the current Turn's first message in the replacement. When the Turn starts after the mark, that is the same kept message as before the swap. Otherwise it is 0, because before the kept messages the replacement has only user messages, the summary, and system state. A blocking summary still uses 0.
  • The Turn cursor stores the Turn start as the seq of the message before it, and found the index again by counting seqs <= that seq. After a swap the seqs are out of order: kept messages keep their source seq, and the summary, runtime context, and folded system message get the seq of the swap. So the count put the start too early, on the earlier answer. Now the cursor finds the position of that seq, and counts only when the seq is not in the history.
  • In a resumed slice, turnStartIndex() read the saved record's Turn start before the live one. After a replacement in that slice, the saved index points into the old history. It now uses the Turn start that the replacement set.

Open question: this keeps the Turn boundary as an index into history that each replacement must remap (see #2567). An explicit Turn boundary could replace these fixes.

via @dcramer.

--

View Session [Sentry]

…ter a summary swap

A prepared-summary swap keeps every message after its mark, so the
replacement can hold reply or noReply results of earlier Turns. The swap
now returns where the current Turn starts inside the replacement, and the
Turn cursor maps the saved Turn-start seq back by position, because swapped
history has out-of-order seqs.

Fixes #3687

Co-Authored-By: David Cramer <[email protected]>
@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 18, 2026 4:55pm UTC

Request Review

… a resumed slice

A resumed slice read the Turn answer from the saved Turn start. After a
replacement in that slice, the saved index points into the old history.

Co-Authored-By: David Cramer <[email protected]>
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

11 screenshot changes — 11 changed · 0 added · 0 removed

Review screenshots in Frameshift

Automation Run Details · Desktop
Automation Run Details · Desktop
Changed
Automation Skill Editor · Desktop
Automation Skill Editor · Desktop
Changed
Automation Skill Editor · Mobile
Automation Skill Editor · Mobile
Changed
Automations Runs Filters · Desktop
Automations Runs Filters · Desktop
Changed
Conversation Attachment Zoom · Desktop
Conversation Attachment Zoom · Desktop
Changed
Conversation Attachment Zoom · Mobile
Conversation Attachment Zoom · Mobile
Changed
Show 5 more changed screenshots
Conversation Question · Desktop
Conversation Question · Desktop
Changed
Conversation Question Light · Desktop
Conversation Question Light · Desktop
Changed
Inbox Snooze · Desktop
Inbox Snooze · Desktop
Changed
Person Profile · Desktop
Person Profile · Desktop
Changed
System Cache Tokens · Desktop
System Cache Tokens · Desktop
Changed

@sentry-junior sentry-junior Bot changed the title fix(compaction): Keep earlier Turns' answers before the Turn start after a summary swap fix(compaction): Keep earlier Turns' answers out of the Turn after a history replacement Nov 18, 2026
@sentry-junior

sentry-junior Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Replaced by #3705, which decides Turn membership by event seq instead of fixing the Turn start index. Closing this one.

@sentry-junior sentry-junior Bot closed this Nov 18, 2026

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 08781cf7 Deployed Nov 18, 2026 by vercel[bot]
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.

Summary swap makes a gated Turn reuse an old answer

1 participant