Repository navigation
fix(chat): Keep earlier Turn request context out of compaction - #2301
Merged
Merged
Conversation
An in-turn compaction rebuilt runtime context from the newest <runtime-turn-context> block in history. When the current Turn had no block of its own, that was a follow-up block from an earlier Turn. Its disabled tools and plugin context came back as current facts, and the session context from the first Turn was lost. Pass the Turn start to active compaction. Keep the current Turn's runtime context, and from earlier Turns keep only the latest session context without its request sections, plus AGENTS.md instructions. Co-Authored-By: David Cramer <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
dcramer
approved these changes
Oct 28, 2026
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3454ca8. Configure here.
The compaction checkpoint kept the Turn start index from the old history. A resumed Turn could then compact again and strip this Turn's request context as if it came from an earlier Turn. Set the index to 0 before the checkpoint and restore it if the checkpoint fails.
Contributor
|
177 screenshot changes — 0 changed · 177 added · 0 removed |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

After an in-turn compaction, Junior refused to call
createEventAutomationin a Turn that a person started with a Slack message. In that Turn the tool was enabled. The model made no tool call. It said the tool was off for the Turn and asked the person to send the request again. The retry worked because no compaction ran.Root cause. An earlier Agent invocation Turn correctly had the event automation tools disabled, so its Turn context had a
<disabled-tools>block. The next Turn, started by a person, added no Turn context block. Active compaction rebuilds runtime context from the newest<runtime-turn-context>block in history (effectiveRuntimeContext). That block was the follow-up block from the earlier Turn. The replacement history put it first, ahead of the current instruction, as "These tools are disabled in this Turn". The production request after compaction had that exact block. It also had no session context (<runtime>,<context>, available skills), because the follow-up block replaced the first Turn's session block as the anchor. This started when #2148 put disabled tools in follow-up Turn context. Plugin context and Conversation notes also go stale this way.Fix. The agent now passes the current Turn start to
compactActiveContextIfNeeded. Compaction keeps all runtime context from the current Turn. From earlier Turns it keeps only the latest session context, without its request sections (plugin-context,conversation-notes,disabled-tools), and the visible AGENTS.md instructions. The section tag names moved toturn-context-tag.ts, so prompt assembly and compaction read the same names. The existing split host context test now has an earlier session Turn and a follow-up Turn that no person started. Onmainit fails because the session context is missing.Remaining risk.
compactContextForHandoffstill uses the old newest-block rule. A handoff in the middle of a Turn can probably keep stale request context too. I did not verify that, and this PR does not change handoff. When a resumed record has no Turn start, compaction uses the old rule.via David Cramer.
--
View Junior Session [Sentry]