Skip to content

Fix stale background compaction across model switches and /compact#317163

Merged
bhavyaus merged 1 commit into
mainfrom
dev/bhavyau/bg-summarizer-stale-state
May 23, 2026
Merged

Fix stale background compaction across model switches and /compact#317163
bhavyaus merged 1 commit into
mainfrom
dev/bhavyau/bg-summarizer-stale-state

Conversation

@bhavyaus
Copy link
Copy Markdown
Collaborator

@bhavyaus bhavyaus commented May 18, 2026

Fixes #316116.

AgentIntent._backgroundSummarizers is keyed only by sessionId, 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

  1. BackgroundSummarizer now records the endpointModel it was built for.
  2. AgentIntent.getOrCreateBackgroundSummarizer cancels & recreates the summarizer when the endpoint changes mid-session.
  3. handleSummarizeCommand (/compact) cancels any pending background summarizer once foreground compaction starts.
  4. Pre-render apply now gates on contextRatio >= 0.65 as defense-in-depth (covers context-size overrides). Below threshold the stale result is consumed-and-discarded.

Copilot AI review requested due to automatic review settings May 18, 2026 20:54
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 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 BackgroundSummarizer and recreate/cancel the summarizer when the endpoint changes for the same sessionId.
  • Cancel any pending background summarizer when /compact begins 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

Comment thread extensions/copilot/src/extension/intents/node/agentIntent.ts Outdated
Comment thread extensions/copilot/src/extension/prompts/node/agent/backgroundSummarizer.ts Outdated
Comment thread extensions/copilot/src/extension/intents/node/agentIntent.ts Outdated
@bhavyaus bhavyaus force-pushed the dev/bhavyau/bg-summarizer-stale-state branch from f8eb169 to 4471da1 Compare May 23, 2026 05:07
@bhavyaus bhavyaus marked this pull request as ready for review May 23, 2026 05:08
@bhavyaus bhavyaus force-pushed the dev/bhavyau/bg-summarizer-stale-state branch from 4471da1 to 42a3390 Compare May 23, 2026 05:11
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
@bhavyaus bhavyaus force-pushed the dev/bhavyau/bg-summarizer-stale-state branch from 42a3390 to ec2755a Compare May 23, 2026 05:12
@bhavyaus bhavyaus enabled auto-merge (squash) May 23, 2026 05:14
@bhavyaus bhavyaus requested a review from Copilot May 23, 2026 05:17
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.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Comment thread extensions/copilot/src/extension/intents/node/agentIntent.ts
@bhavyaus bhavyaus merged commit 15bd799 into main May 23, 2026
40 of 41 checks passed
@bhavyaus bhavyaus deleted the dev/bhavyau/bg-summarizer-stale-state branch May 23, 2026 15:27
@vs-code-engineering vs-code-engineering Bot added this to the 1.122.0 milestone May 23, 2026
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.

GitHub Copilot suddenly compacting at around 50% in v1.119.1

3 participants