Skip to content

feat: Implement auto compression feature for chat context#250

Open
ethanyhou wants to merge 8 commits into
mainfrom
ethan/auto-compress
Open

feat: Implement auto compression feature for chat context#250
ethanyhou wants to merge 8 commits into
mainfrom
ethan/auto-compress

Conversation

@ethanyhou
Copy link
Copy Markdown
Contributor

@ethanyhou ethanyhou commented May 21, 2026

Demo:

Recording.2026-05-21.165012.mp4

The status context aligns with VSCode:
image

Copilot AI review requested due to automatic review settings May 21, 2026 08:53
@jdneo
Copy link
Copy Markdown
Member

jdneo commented May 21, 2026

Any consideration to expose a preference to disable auto compact?

I prefer to always enable it, enable it simply give users more value and advantages.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an Auto Compress chat setting and end-to-end UI wiring for automatic conversation compression, including preference propagation to the language server and a “Compacting conversation...” status indicator in the chat view when compression notifications arrive.

Changes:

  • Adds a new Auto Compress preference (default enabled) and propagates it to Copilot agent settings.
  • Introduces LSP notification handling for $/copilot/compressionStarted / $/copilot/compressionCompleted, showing/hiding a spinner banner and refreshing context-size UI.
  • Improves streaming UX by eagerly rendering trailing partial lines (without waiting for a newline) in chat turns.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/messages.properties Adds localized strings for the Auto Compress preference UI.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/Messages.java Exposes new preference strings via NLS.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/LanguageServerSettingManager.java Sends autoCompress setting to the language server and reacts to preference changes.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/CopilotPreferenceInitializer.java Defaults Auto Compress to enabled.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/ChatPreferencesPage.java Adds the Auto Compress checkbox + description to the Chat preferences page.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/i18n/messages.properties Adds “Compacting conversation...” user-facing string.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/i18n/Messages.java Exposes the new compaction status string via NLS.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/CopilotTurnWidget.java Adds compacting status UI (spinner + text) to the latest Copilot turn.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/ChatView.java Subscribes to compression events and updates turn UI + context size on completion; ensures cancel clears compaction UI.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/ChatContentViewer.java Adds a helper to safely fetch the latest Copilot turn widget.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/BaseTurnWidget.java Eagerly renders trailing partial lines for better streaming visibility.
com.microsoft.copilot.eclipse.swtbot.test/test-plans/context-compress/context-compress.md Adds a manual test plan for Auto Context Compression UX.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/CopilotAgentSettings.java Adds autoCompress to agent settings serialization + equality/hash.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/CompressionStartedParams.java Adds protocol type for compression-start notification.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/CompressionCompletedParams.java Adds protocol type for compression-complete notification (with optional context info).
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageClient.java Handles new compression notifications and forwards them via event broker.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/events/CopilotEventConstants.java Defines new event topics for compression started/completed.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/Constants.java Adds the autoCompress preference key constant.

@iloveeclipse
Copy link
Copy Markdown

Any consideration to expose a preference to disable auto compact?

I prefer to always enable it, enable it simply give users more value and advantages.

We have errors reported by customers due the context "overflow" with Claude models, having this feature enabled by default would probably help to avoid the errors. What would be the point in not enabling it by default? Just the fear that the feature doesn't work properly or are there some use cases where it would harm if enabled?

If there is no use case for disabling the auto compression, I would hide the preference or just don't provide one at all.

@ethanyhou
Copy link
Copy Markdown
Contributor Author

Any consideration to expose a preference to disable auto compact?

I prefer to always enable it, enable it simply give users more value and advantages.

@jdneo Removed as we aligned.

@ethanyhou
Copy link
Copy Markdown
Contributor Author

Hi @iloveeclipse,

Thanks for the input. Agreed and it was removed. Compression will always be enabled.

* Shows the compacting status on the latest Copilot turn after flushing any buffered reply text.
*/
public void showCompactingStatusOnLatestCopilotTurn() {
CopilotTurnWidget turn = getLatestCopilotTurn();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latestCopilotTurn is member, which can directly access, I don't see the benefit introduce getLatestCopilotTurn(), and this is why I propose to move logics into ChatContentViewer in #250 (comment)

*/
public void showCompactingStatusOnLatestCopilotTurn() {
CopilotTurnWidget turn = getLatestCopilotTurn();
if (turn == null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If using latestCopilotTurn directly, check dispose status here.

// Flush any buffered reply text from the previous round so it is rendered
// above the compacting spinner; otherwise it would be concatenated with
// the next round's reply and produce a single garbled line.
turn.notifyTurnEnd();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm considering to rename notifyTurnEnd(). It's a little bit confused now since compression can happen in the middle of the turn. How about flushMessageBuffer()

Comment on lines +408 to +412
if (flushBufferedReply) {
// Flush any buffered reply text before hiding the compacting banner; callers that
// cancel a turn may not receive a later end progress event to do this for them.
turn.notifyTurnEnd();
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it simpler, hideCompactingStatusOnLatestCopilotTurn will always flush the buffer (which should have very tiny load because the buffer should be empty at this stage. If the buffer is not empty at this stage for some unknown reason, this can be a guard)

That way, boolean flushBufferedReply can be removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants