-
Notifications
You must be signed in to change notification settings - Fork 15
🤖 feat: add auto-compaction with progressive warnings #683
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
base: main
Are you sure you want to change the base?
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.
ℹ️ 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.
ℹ️ 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 |
## Stack 1. #685 1. #683 1. #670 1. #650 ⬅ This PR (base) ## Problem Compact continue messages were handled by a frontend hook that watched workspace states and manually sent continue messages after compaction. This was complex, had potential race conditions, and poor separation of concerns. Relates to #651. ## Solution Use the existing message queue system: - Backend queues continue message when compaction starts - Queue auto-sends when stream ends (existing behavior) - Clear queue on error paths **Benefits:** Simpler (-134 lines), more reliable, better UX (continue message visible in queue). _Generated with `mux`_
e72e057 to
f93f212
Compare
_Generated with `mux`_ ## Stack 1. #685 1. #683 1. #670 ⬅ This PR 1. #650 (base) ## Summary Moves history compaction handling from WorkspaceStore (frontend) to agentSession (backend) to centralize server-side operations and fix race conditions. Relates to #651. ## Changes ### Backend (agentSession.ts) - Added `handleCompactionCompletion()` - detects compaction stream-end, extracts summary from event.parts, performs history replacement - Added `handleCompactionAbort()` - handles Ctrl+A (accept early with `[truncated]`) and Ctrl+C (cancel) flows - Added `performCompaction()` - atomically replaces chat history with summary message including cumulative usage - Implemented `abandonPartial` flag flow from IPC through to StreamAbortEvent - Extracts truncated message content from history instead of partialService ### Frontend (WorkspaceStore.ts) - Removed `handleCompactionCompletion()` and `handleCompactionAbort()` methods - Removed `performCompaction()` method - Removed `processedCompactionRequestIds` Set - Simplified `cancelCompaction()` - just calls `interruptStream` with `abandonPartial: true` - Fixed Ctrl+A keybind to pass `abandonPartial: false` for early accept ### Shared - Updated `StreamAbortEvent` to include `abandonPartial?: boolean` - `historyService.clearHistory()` now returns deleted sequence numbers - Created `calculateCumulativeUsage()` utility in `displayUsage.ts` to extract and sum usage from messages ## Testing - [x] Manual: `/compact` completes successfully - [x] Manual: Ctrl+A during compaction accepts early with `[truncated]` - [x] Manual: Ctrl+C during compaction cancels and enters edit mode - [x] Verify cumulative usage preserved across multiple compactions
2438689 to
087e85f
Compare
|
@codex review |
|
@codex review |
|
@codex review |
|
@codex review |
Stack
Summary
Adds automatic context compaction that triggers at 70% usage, with progressive countdown warnings starting at 60%.
Relates to #651.
Key Changes
Auto-Compaction:
Progressive Warnings:
Implementation:
shouldAutoCompact()utility centralizes threshold logic with configurable constants{ shouldShowWarning, usagePercentage, thresholdPercentage }ContinueMessagetype now includes optionalimagePartsTechnical Details
Usage Calculation:
The auto-compaction check uses the most recent usage entry from
usageHistoryto calculate the current context size. This matches the percentage displayed in the UI token meter and correctly handles post-compaction scenarios:This prevents the infinite loop where post-compaction workspaces would continuously re-compact because historical usage tokens were being included in the threshold check.
Future Work
Future PRs will add user settings to configure auto-compaction (enable/disable, custom threshold).
Generated with
mux