feat: add double-buffer context management#4858
Open
marklubin wants to merge 1 commit intoAider-AI:mainfrom
Open
feat: add double-buffer context management#4858marklubin wants to merge 1 commit intoAider-AI:mainfrom
marklubin wants to merge 1 commit intoAider-AI:mainfrom
Conversation
Implements a two-phase compaction strategy that checkpoints at 60% of max_chat_history_tokens and swaps at 85%, producing higher-quality summaries by running summarization while the model still has full attention rather than at the capacity cliff. New files: - aider/double_buffer.py: DoubleBufferManager with background checkpoint via threading, phase tracking, swap logic - tests/basic/test_double_buffer.py: 18 tests covering transitions, thresholds, error handling Modified files: - aider/coders/base_coder.py: opt-in integration via summarize_start() delegation to _double_buffer_check() when enabled - aider/args.py: --double-buffer, --checkpoint-threshold, --swap-threshold CLI flags The feature is opt-in (--double-buffer flag) and the existing summarization flow is completely unchanged when not enabled. Algorithm: https://marklubin.me/posts/hopping-context-windows/
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.
Summary
Adds opt-in double-buffer context management that produces higher-quality chat history summaries by checkpointing early (at 60% of
max_chat_history_tokens) while the model still has full attention, rather than waiting until the history is too big and attention is degraded.How it works:
ChatSummary.summarize()on a snapshot ofdone_messagesThe feature is opt-in via
--double-bufferand the existing summarization flow is completely unchanged when not enabled.New files:
aider/double_buffer.py:DoubleBufferManagerwith background checkpoint via threading,Phaseenumtests/basic/test_double_buffer.py: 18 tests (phase transitions, thresholds, error handling)Modified files:
aider/coders/base_coder.py:summarize_start()delegates to_double_buffer_check()when--double-bufferis enabledaider/args.py:--double-buffer,--checkpoint-threshold(default 0.60),--swap-threshold(default 0.85)Design:
ChatSummaryfor summarization (no new LLM calls)summarizer_threadpattern inbase_coder.pyAlgorithm description: https://marklubin.me/posts/hopping-context-windows/
Test plan
pytest tests/basic/test_double_buffer.py -v)black --line-length 100 --previewcleanisort --profile blackcleanflake8clean (no warnings)--double-buffer --verboseon a long session and observe checkpoint/swap log messages