Skip to content

feat(middleware/context-compression): Add history tracking and resolution - #6270

Draft
ssbushi wants to merge 1 commit into
sb/context-compression-3-summarizefrom
sb/context-compression-4-history
Draft

feat(middleware/context-compression): Add history tracking and resolution#6270
ssbushi wants to merge 1 commit into
sb/context-compression-3-summarizefrom
sb/context-compression-4-history

Conversation

@ssbushi

@ssbushi ssbushi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions github-actions Bot added docs Improvements or additions to documentation js labels Sep 2, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a non-destructive session history feature to the context compression middleware, preserving original uncompressed messages in the request and response while storing the compressed history in message metadata. It also adds a helper function resolveCompressedHistory to extract active messages, along with corresponding tests and documentation updates. Feedback is provided regarding a potential edge case in Array.prototype.slice where a negative index could be passed if compressedMessages.length is less than tailCount.

Comment on lines +977 to +983
const compressedPrefix =
tailCount > 0
? compressedMessages.slice(
0,
compressedMessages.length - tailCount
)
: compressedMessages;

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.

medium

If compressedMessages.length is less than tailCount (which can occur in edge cases such as summarization failures or custom middleware modifications), compressedMessages.length - tailCount will be negative. In JavaScript, passing a negative index as the second argument to Array.prototype.slice slices from the end of the array rather than returning an empty array, which would result in an incorrect compressedPrefix. Using Math.max(0, compressedMessages.length - tailCount) ensures it safely defaults to 0 and returns an empty array.

Suggested change
const compressedPrefix =
tailCount > 0
? compressedMessages.slice(
0,
compressedMessages.length - tailCount
)
: compressedMessages;
const compressedPrefix =
tailCount > 0
? compressedMessages.slice(
0,
Math.max(0, compressedMessages.length - tailCount)
)
: compressedMessages;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation js

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant