fix(openai-history): keepTail:0 in mixed Responses collapse protected every message - #154
Merged
teamchong merged 1 commit intoJul 27, 2026
Conversation
… every message planResponsesMixedCollapse computed the protected tail as messageIndices.slice(-Math.max(0, Math.floor(keepTail))). When keepTail is 0 that is slice(-0), which returns the WHOLE array, so "protect zero trailing messages" instead protected every message and blocked all history collapse (reason: no_closed_prefix, nothing imaged). keepTail:0 is a legal host override (nonNegativeInt accepts 0 via gptHistory.keepTail). Guard keepTail===0 explicitly so it protects nothing; the latest user turn is still protected separately via latestUserIndex. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
In
planResponsesMixedCollapse(src/core/openai-history.ts), the protected trailing messages are computed as:When
keepTailis0, that expression isslice(-0).Array.prototype.slice(-0)treats-0as0and returns the entire array — so "protect zero trailing messages" instead protects every message. Every old turn then becomes a hard barrier, no history collapses, and the planner returnsreason: 'no_closed_prefix'with nothing imaged (the exact inverse of the intent).keepTail: 0is a legal, reachable config: it flows throughnonNegativeInt(historyIn?.keepTail, …)(which accepts0) from a host'sgptHistory.keepTailoverride. The shipped Sol profile useskeepTail: 1, so this is a latent correctness bug on an override path, not a default-path failure.Fix
Guard
keepTail === 0explicitly so it protects nothing; the latest user turn is still protected separately vialatestUserIndex.Added a regression test (verified it fails on the old code, passes on the fix). Full suite green except 3 pre-existing Windows-only file-permission failures in
node-security.test.ts(unrelated; fail on a clean tree here too).typecheckclean.Generated with Claude Code