-
Notifications
You must be signed in to change notification settings - Fork 14
π€ refactor: move compaction logic to backend #670
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: compact-messages-queue-system
Are you sure you want to change the base?
π€ refactor: move compaction logic to backend #670
Conversation
b186d47 to
7d2df23
Compare
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".
7d2df23 to
2b2b2fc
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.
βΉοΈ 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 |
eeafe28 to
1eda7a1
Compare
Move history compaction handling from WorkspaceStore to agentSession to centralize server-side operations. Backend changes: - Added handleCompactionCompletion() to detect and handle compaction stream-end events - Added handleCompactionAbort() to handle Ctrl+A (accept early with [truncated]) and Ctrl+C (cancel) flows - Added performCompaction() to atomically replace chat history with summary message - Added processedCompactionRequestIds Set to dedupe repeated compaction events - Implemented abandonPartial flag flow from IPC through to StreamAbortEvent - Extract truncated message content from history instead of partialService - Wrap compaction handlers in try-catch to ensure stream events always forwarded - Made performCompaction return Result type for proper error handling Frontend changes: - Removed compaction handlers from WorkspaceStore - Simplified cancelCompaction() to just call interruptStream with abandonPartial flag - Fixed Ctrl+A keybind to pass abandonPartial: false for early accept Shared changes: - Updated StreamAbortEvent to include abandonPartial flag - historyService.clearHistory() now returns deleted sequence numbers - Created calculateCumulativeUsage() utility to extract and sum usage from messages - aiService respects abandonPartial flag - skips committing when true
1eda7a1 to
4560627
Compare
Move compaction handling from agentSession to dedicated CompactionHandler class. Changes: - Created src/node/services/compactionHandler.ts with CompactionHandler class - Extracted handleAbort, handleCompletion, and performCompaction methods - Updated agentSession.ts to delegate to CompactionHandler - Moved frontend compaction handler to browser utils - Reduced agentSession.ts from 764 to 589 lines Benefits: - Better separation of concerns - Easier to test compaction logic independently - Cleaner session orchestration code _Generated with `mux`_
|
|
||
| // Wait for first stream to complete | ||
| const collector1 = createEventCollector(env.sentEvents, workspaceId); | ||
| await collector1.waitForEvent("stream-end", 30000); |
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.
This was flaking on Thomas' PRs too, so I've bumped the timeout
ibetitsmike
left a comment
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.
lgtm but I'd add some testing
Generated with
muxStack
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)
handleCompactionCompletion()- detects compaction stream-end, extracts summary from event.parts, performs history replacementhandleCompactionAbort()- handles Ctrl+A (accept early with[truncated]) and Ctrl+C (cancel) flowsperformCompaction()- atomically replaces chat history with summary message including cumulative usageabandonPartialflag flow from IPC through to StreamAbortEventFrontend (WorkspaceStore.ts)
handleCompactionCompletion()andhandleCompactionAbort()methodsperformCompaction()methodprocessedCompactionRequestIdsSetcancelCompaction()- just callsinterruptStreamwithabandonPartial: trueabandonPartial: falsefor early acceptShared
StreamAbortEventto includeabandonPartial?: booleanhistoryService.clearHistory()now returns deleted sequence numberscalculateCumulativeUsage()utility indisplayUsage.tsto extract and sum usage from messagesTesting
/compactcompletes successfully[truncated]