-
-
Notifications
You must be signed in to change notification settings - Fork 547
Implement compaction with adjustable threshold and loading messages #2106
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
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c71e17861
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d50896b484
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8224ec7ab6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ffe851797e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c10b070d54
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
c10b070 to
79e5383
Compare
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 79e53830ca
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
79e5383 to
5b68559
Compare
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b68559d21
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9d62172a13
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8490870042
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
8490870 to
42b7e80
Compare
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9d7612b3c8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6863bfacb9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a358f1c71
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
1a358f1 to
b1ffb14
Compare
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b1ffb143ef
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b1ffb143ef
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
b1ffb14 to
881ace1
Compare
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 881ace1d85
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // Track paths from ALL messages for deduplication | ||
| for (const segment of l3Layer.segments || []) { | ||
| if (segment.metadata?.notePath) { | ||
| l2Paths.add(segment.metadata.notePath as string); | ||
| } |
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.
Track tag/folder note paths in L2 dedupe
The L2 dedupe set only collects segment.metadata.notePath (or compactedPaths), but tag/folder context is stored as a single L3 segment without notePath metadata (via appendTurnContextSegment). That means notes added via tags/folders in a previous turn are pulled into L2 (their <note_context> blocks are concatenated into l2Context), yet their paths are missing from l2Paths, so the same notes are reprocessed and appended to L3 again on later turns. This duplicates large note content and can prematurely trigger compaction/overflow. Consider storing per-note notePath metadata for tag/folder segments or parsing paths out of those segments when building l2Paths.
Useful? React with 👍 / 👎.
881ace1 to
31fc317
Compare
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 31fc31744d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
31fc317 to
015975a
Compare
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 015975af0f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const l3Layer = msg.contextEnvelope?.layers?.find((l) => l.id === "L3_TURN"); | ||
|
|
||
| if (l3Layer) { |
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.
Preserve L2 context for messages without envelopes
The new L2 builder only reads msg.contextEnvelope and skips messages without an envelope. Persisted chats only store the lightweight context metadata (see ChatPersistenceManager), so any loaded history will have contextEnvelope === undefined. That means continuing a saved chat drops all prior context from L2 and defeats deduplication/compaction for those messages. Users who resume a saved conversation will lose the “context library” from earlier turns. Consider rebuilding L2 from message.context when contextEnvelope is missing (or persisting envelopes).
Useful? React with 👍 / 👎.
015975a to
27330b8
Compare
- Add ContextCompactor class for map-reduce style context summarization - Implement auto-compact when context exceeds configurable threshold - Track note paths for tags/folders in L3 segment metadata for L2 deduplication - Add loadAndAddChatHistory for streamlined chat history loading - Store compacted paths in envelope metadata for multi-turn deduplication - Fix: Only track L3 context paths in compactedPaths (excludes L5 user message files) Co-Authored-By: Claude Opus 4.5 <[email protected]>
27330b8 to
7e63742
Compare
|
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7e63742ab2
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| private readonly BLOCK_TYPES = [ | ||
| "note_context", | ||
| "active_note", | ||
| "url_content", | ||
| "selected_text", |
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.
Compact web-selected text blocks too
Web selections are emitted as <web_selected_text> blocks (see processSelectedTextContexts), but the compactor only parses the BLOCK_TYPES list shown here. Because web_selected_text is missing, large web selections are never summarized, so auto-compaction can no-op when the oversized context is dominated by web-selected text. That leaves prompts above the threshold and defeats the overflow protection for that common case.
Useful? React with 👍 / 👎.
| for (let i = 0; i < previousUserMessages.length; i++) { | ||
| const msg = previousUserMessages[i]; | ||
| const l3Layer = msg.contextEnvelope?.layers?.find((l) => l.id === "L3_TURN"); | ||
|
|
||
| if (l3Layer) { |
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.
Rebuild L2 when envelopes are missing
This loop only consumes contextEnvelope to build L2. ChatPersistenceManager does not persist envelopes, so messages loaded from disk have no L3_TURN layer and are skipped here. After reopening a saved chat, the prior “context library” is silently lost and note paths won’t be deduped, so users can re-attach notes that were already present before the save. Consider falling back to message.context when contextEnvelope is absent, or persisting envelopes.
Useful? React with 👍 / 👎.
Auto-Compact Context Feature
Summary
Implements automatic context compaction using map-reduce summarization when context exceeds a configurable token threshold. This prevents context overflow errors and reduces token usage for large context windows.
Changes
New Files
src/core/ContextCompactor.ts- Singleton class that compresses large context using map-reduce patternsrc/types/compaction.ts- Type definitions forCompactionResultandParsedContextItemModified Files
src/core/ContextManager.ts- Integrated compaction, preserves compacted content across turnssrc/settings/model.ts- AddedautoCompactThresholdsettingsrc/constants.ts- Added default threshold (128k tokens) and "Compacting" loading messagesrc/settings/v2/components/ModelSettings.tsx- Added threshold slider in Models tabsrc/state/ChatUIState.ts- Thread loading message callbacksrc/core/ChatManager.ts- Thread loading message callbacksrc/components/Chat.tsx- Pass loading message callback to sendMessagesrc/core/ChatManager.test.ts- Added mocks and updated test assertionssrc/LLMProviders/chainRunner/utils/chatHistoryUtils.ts- AddedaddChatHistoryWithCompactionfor conversation history compactionsrc/LLMProviders/chainRunner/CopilotPlusChainRunner.ts- Uses compaction-aware chat historysrc/LLMProviders/chainRunner/AutonomousAgentChainRunner.ts- Uses compaction-aware chat historysrc/contextProcessor.ts- Removed verbose "Processing note" logsHow It Works
When context attached to a user message exceeds the threshold (in tokens), the compactor:
note_context,active_note,url_content, etc.) into discrete itemsMulti-Turn Compaction Preservation
Key improvement: Once context is compacted, it stays compacted across turns.
compactedPathsmetadatacompactedPaths)This is achieved by:
buildL2ContextFromPreviousTurnsreads stored L3 content from previous envelopessegment.metadata.compactedPathsfor deduplicationl2Pathsset to filter out files already in L2buildCompactedEnvelopestores original paths in metadata for future turnsConversation History Compaction
When total context (system + chat history + current message) exceeds the threshold, older conversation turns are automatically summarized:
Fail-safes
Configuration
Settings > Models > Auto-compact threshold
Higher values effectively disable compaction since context won't reach the threshold.
User Experience
[SUMMARIZED]prefix