-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: prevent context truncation when condensing is disabled (threshold=100%) #7812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -142,7 +142,7 @@ export async function truncateConversationIfNeeded({ | |||||||||
| } | ||||||||||
| // If no specific threshold is found for the profile, fall back to global setting | ||||||||||
|
|
||||||||||
| if (autoCondenseContext) { | ||||||||||
| if (autoCondenseContext && effectiveThreshold < 100) { | ||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a comment near the function signature or at the start of the function body documenting that a threshold of 100% has special meaning - it completely disables both condensing and truncation. This would make the API contract clearer for callers. |
||||||||||
| const contextPercent = (100 * prevContextTokens) / contextWindow | ||||||||||
| if (contextPercent >= effectiveThreshold || prevContextTokens > allowedTokens) { | ||||||||||
| // Attempt to intelligently condense the context | ||||||||||
|
|
@@ -166,7 +166,15 @@ export async function truncateConversationIfNeeded({ | |||||||||
| } | ||||||||||
|
|
||||||||||
| // Fall back to sliding window truncation if needed | ||||||||||
| // Exception: When context condensing is explicitly disabled (threshold = 100%), don't truncate | ||||||||||
|
||||||||||
| // Exception: When context condensing is explicitly disabled (threshold = 100%), don't truncate | |
| // Exception: When context condensing is explicitly disabled (threshold = 100%), don't truncate | |
| // This respects the user's explicit choice to maintain full conversation history, | |
| // even at the risk of hitting API token limits |
This would help future maintainers understand the design decision.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is using >= 100 intentional here? Since the issue specifically mentions setting the threshold to "100%" to disable condensing, would it be clearer to check for exactly 100? Values above 100% don't really make semantic sense in this context.
Consider:
| if (autoCondenseContext && effectiveThreshold >= 100) { | |
| if (autoCondenseContext && effectiveThreshold === 100) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test coverage for the main scenario! Would it be worth adding an edge case test for threshold values slightly above 100 (e.g., 101%) to ensure the
>= 100condition in the implementation handles these cases correctly? Even though such values shouldn't occur in practice, defensive testing could catch potential issues.