Fix stale background compaction across model switches and /compact#317163
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a lifecycle bug in Copilot’s background conversation compaction where a completed background summary could be applied on a later turn even after the user switched models or ran /compact, leading to unexpected “Compacted conversation” notices with ample context headroom.
Changes:
- Track the endpoint identity on
BackgroundSummarizerand recreate/cancel the summarizer when the endpoint changes for the samesessionId. - Cancel any pending background summarizer when
/compactbegins foreground compaction. - Add a pre-render “apply” guard (
contextRatio >= applyMinRatio) that discards completed background results when they’re no longer warranted, plus telemetry for the new discard outcome.
Show a summary per file
| File | Description |
|---|---|
| extensions/copilot/src/extension/prompts/node/agent/backgroundSummarizer.ts | Adds applyMinRatio threshold and records the endpoint model on BackgroundSummarizer. |
| extensions/copilot/src/extension/intents/node/agentIntent.ts | Cancels/recreates background summarizers across endpoint changes; cancels on /compact; gates/discards pre-render apply and adds telemetry outcome. |
| extensions/copilot/src/extension/intents/node/test/agentSummarizeCommand.spec.ts | Adds tests for /compact cancellation, endpoint-switch cancellation, and same-endpoint reuse. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 3
f8eb169 to
4471da1
Compare
4471da1 to
42a3390
Compare
The `_backgroundSummarizers` map on `AgentIntent` is keyed only by sessionId, so a summary kicked off against one model's prefix could be applied unconditionally on the next render — even after the user switched to a model with a larger context window or ran `/compact`. The user saw a 'Compacted conversation' notice on a turn with plenty of headroom, with content summarized against the old model's history. * `BackgroundSummarizer` now records the `endpointModel` it was built for. * `AgentIntent.getOrCreateBackgroundSummarizer` cancels and recreates the summarizer if the endpoint identity changed since last call. * `handleSummarizeCommand` (`/compact`) cancels any pending background summarizer once we commit to foreground compaction. * Pre-render apply now gates on `contextRatio >= applyMinRatio` (0.65) as defense-in-depth — covers context-size overrides and any path that slips past the endpoint check. Stale completed results are consumed-and-discarded so a fresh kick-off can replace them. Telemetry gains a `discardedBelowApplyMinRatio` outcome. Refs #316116
42a3390 to
ec2755a
Compare
dmitrivMS
approved these changes
May 23, 2026
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.
Fixes #316116.
AgentIntent._backgroundSummarizersis keyed only bysessionId, so a completed background summary kicked off against one model's prefix was applied unconditionally on the next render — even after the user switched models (typically to a bigger window) or ran/compact. Result: surprising "Compacted conversation" notice on a turn with plenty of headroom.The floor logic from #315444 composes correctly across switches; the bug is in state lifecycle.
Fix
BackgroundSummarizernow records theendpointModelit was built for.AgentIntent.getOrCreateBackgroundSummarizercancels & recreates the summarizer when the endpoint changes mid-session.handleSummarizeCommand(/compact) cancels any pending background summarizer once foreground compaction starts.contextRatio >= 0.65as defense-in-depth (covers context-size overrides). Below threshold the stale result is consumed-and-discarded.