Repository navigation
fix: protectedContext floors compaction tail on long-superseded messages - #469
Closed
Satya Arjunan (satya-arjunan) wants to merge 1 commit into
Closed
Satya Arjunan (satya-arjunan) wants to merge 1 commit into
Satya Arjunan (satya-arjunan) wants to merge 1 commit into
Conversation
protectedContext scanned forward from the start of the whole transcript for the first unanswered user message, instead of walking backward from the current turn as its own doc comment describes. A user message that's immediately superseded by a retry/resend (the retry gets answered, the original never does) satisfies that scan forever, so selectTail's protectedStart floor pins tailStartId to it permanently, no matter how much later work is fully resolved. Walk backward from the current turn instead, stopping at the first already-answered or already-compacted user message. Adds a regression test in message-v2.test.ts using real Identifier.ascending ids.
|
Satya Arjunan (@satya-arjunan) is attempting to deploy a commit to the InkVell Team on Vercel. A member of the Team first needs to authorize it. |
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.
Fixes #470
Problem
protectedContextinbackend/cli/src/session/compaction.tsis documented as returning "the transcript span that still belongs to the active, unanswered turn," but the implementation scans forward from the start of the whole transcript for the first unanswered user message, not backward from the current turn. A common real pattern breaks this: a user message immediately superseded by a retry/resend (the retry gets answered, the original never does, sinceansweredis keyed byparentID). That original message satisfies the scan forever, soselectTail'sprotectedStartfloor (if (protectedStart > 0) cut = Math.min(cut, protectedStart)) permanently pinstailStartIdto it — no matter how much later work has been fully, properly resolved.Found this via a real session where every subsequent compaction kept flooring
tailStartIdat an old, superseded message well past 100k+ tokens of genuine follow-up work, even after raising the model's context window.Fix
Scope the scan to the contiguous unanswered span ending at the current turn: walk backward from
currentand stop at the first user message that's already terminally answered or already compacted. This matches the function's own doc comment and still protects a run of genuinely-pending retries ending at the current turn — it just no longer reaches back to unrelated, long-resolved history.Verification
message-v2.test.ts(session.compaction.selectTail — protectedContext floor (regression)) that builds a realistic history with realIdentifier.ascending("message")ids: 3 earlier answered turns, an orphaned original request + its answered retry, then 8 further fully-answered work turns. Fails onmain(tailStartIdresolves to the orphaned message); passes with this fix.bun run typecheck— clean.bunx prettier --checkon both changed files — clean.bun testacrossbackend/cli: 470 pass / 3 fail, same 3 pre-existing unrelated failures as onmain(a stale MCP tool-description string assertion, unrelated to this change) — confirmed by running the full suite againstmainbefore this fix (469 pass / 4 fail there, the 4th being the bug this PR fixes).See #470 for the full root-cause writeup and real-session evidence.