-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: enhance conversation truncation logic to preserve dialog integr… #1687
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
Conversation
|
|
fixed #1485 |
src/core/sliding-window/index.ts
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.
Consider replacing direct calls to console.log with a structured logging mechanism (or a logger utility) to ensure consistent and configurable log output in production environments.
|
Thanks for the contribution! I think there's some interesting stuff in here that we should consider. @mrubens has the most context on the sliding window and context management. |
835cdce to
b1ca962
Compare
…ity and handle large message counts
b1ca962 to
002355f
Compare
|
I agree, this is interesting! I would like to set up a structure for these context management strategies though, ideally outside of Cline.ts (e.g. |
|
Hey @im47cn, Thank you for your contribution. You mentioned that this issue #1485 is solved on so we are closing this PR. We've now shifted to a clearer issue-first workflow to avoid this kind of situation going forward. Please create an issue first for any future contributions, as outlined there. |
Context
History message storage:
There are two core history stores in Cline.ts: apiConversationHistory and clineMessages
These histories grow over time and consume a lot of memory
Existing truncation mechanisms:
The MAX_HISTORY_MESSAGES = 150 constant is defined in sliding-window/index.ts
Long history detection and truncation logic in Cline.ts (lines 324-343 and 395-426)
But the strategy may not be aggressive enough or, in some cases, executed in a timely manner
Anti-shake delay problem:
Save history using anti-shake processing (300ms delay)
High frequency operations may cause the memory usage to increase until a crash occurs
Implementation
Lower the MAX_HISTORY_MESSAGES threshold to make truncation more aggressive
Improved truncation strategy of truncateConversation function
Optimized history saving mechanism in Cline.ts
Example Add memory usage monitoring logs
Screenshots
How to Test
Look test file
Get in Touch
dreambt@Discord
Important
Enhance conversation truncation logic in
Cline.tsandsliding-window/index.tsfor better memory management and dialog integrity, with added tests and logging.MAX_HISTORY_MESSAGESthreshold insliding-window/index.tsfor more aggressive truncation.truncateConversation()insliding-window/index.tsto retain first, last, and some middle messages.Cline.ts.saveApiConversationHistory()andsaveClineMessages()inCline.tsto include anti-shake logic and aggressive truncation.truncateConversationIfNeeded()insliding-window/index.tsto handle message count and token thresholds.truncateConversationIfNeeded()insliding-window.test.tsto verify truncation logic under different conditions.This description was created by
for 6556d0638bfcd5a14dd3423a249a49aaa77068b0. It will automatically update as commits are pushed.