Skip to content

Commit 05d42a2

Browse files
bhavyausCopilot
andauthored
Fix double compaction on first-turn budget exceeded (#308949)
* Fix double compaction on first-turn budget exceeded When the first render of a turn throws BudgetExceededError and the background summarizer is Idle, we fall back to a synchronous foreground 'full' summarization via renderWithSummarization. That path did not set the 'summary applied this iteration' flag, so the post-render gate (>= 80% + Idle) would also kick off a background 'inline' compaction in the same buildPrompt call — producing both summarizeConversationHistory-full and summarizeConversationHistory-inline. - Set the flag on both foreground fallback call sites so the post-render gate correctly short-circuits. - Rename 'summaryAppliedThisIteration' to 'didSummarizeThisIteration' to better reflect that it covers any summarization work (pre-render bg apply, budget-exceeded bg apply, or foreground fallback). * Update extensions/copilot/src/extension/intents/node/agentIntent.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 78e6db3 commit 05d42a2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

extensions/copilot/src/extension/intents/node/agentIntent.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,10 @@ export class AgentIntentInvocation extends EditCodeIntentInvocation implements I
465465
? (this._lastRenderTokenCount + toolTokens) / baseBudget
466466
: 0;
467467

468-
// Track whether we applied a summary in this iteration so we don't
469-
// immediately re-trigger background compaction in the post-render check.
470-
let summaryAppliedThisIteration = false;
468+
// Track whether this iteration already performed compaction-related work
469+
// (including applying a summary or using a foreground fallback path) so
470+
// we don't immediately re-trigger background compaction in the post-render check.
471+
let didSummarizeThisIteration = false;
471472

472473
// If a previous background pass completed, apply its summary now.
473474
if (summarizationEnabled && backgroundSummarizer?.state === BackgroundSummarizationState.Completed) {
@@ -478,7 +479,7 @@ export class AgentIntentInvocation extends EditCodeIntentInvocation implements I
478479
this._applySummaryToRounds(bgResult, promptContext);
479480
this._persistSummaryOnTurn(bgResult, promptContext, this._lastRenderTokenCount);
480481
this._sendBackgroundCompactionTelemetry('preRender', 'applied', contextRatio, promptContext);
481-
summaryAppliedThisIteration = true;
482+
didSummarizeThisIteration = true;
482483
} else {
483484
this.logService.warn(`[ConversationHistorySummarizer] background compaction state was Completed but consumeAndReset returned no result`);
484485
this._sendBackgroundCompactionTelemetry('preRender', 'noResult', contextRatio, promptContext);
@@ -611,7 +612,7 @@ export class AgentIntentInvocation extends EditCodeIntentInvocation implements I
611612
this._applySummaryToRounds(bgResult, promptContext);
612613
this._persistSummaryOnTurn(bgResult, promptContext, contextLengthBefore);
613614
this._sendBackgroundCompactionTelemetry(budgetExceededTrigger, 'applied', contextRatio, promptContext);
614-
summaryAppliedThisIteration = true;
615+
didSummarizeThisIteration = true;
615616
// Re-render with the compacted history
616617
const renderer = PromptRenderer.create(this.instantiationService, endpoint, this.prompt, { ...props, promptContext });
617618
result = await renderer.render(progress, token);
@@ -621,9 +622,11 @@ export class AgentIntentInvocation extends EditCodeIntentInvocation implements I
621622
this._recordBackgroundCompactionFailure(promptContext, budgetExceededTrigger);
622623
// Background compaction failed — fall back to synchronous summarization
623624
result = await renderWithSummarization(`budget exceeded(${e.message}), background compaction failed`);
625+
didSummarizeThisIteration = true;
624626
}
625627
} else {
626628
result = await renderWithSummarization(`budget exceeded(${e.message})`);
629+
didSummarizeThisIteration = true;
627630
}
628631
} else {
629632
throw e;
@@ -656,7 +659,7 @@ export class AgentIntentInvocation extends EditCodeIntentInvocation implements I
656659
}
657660

658661
// Post-render: kick off background compaction at ≥ 80% if idle.
659-
if (summarizationEnabled && backgroundSummarizer && !summaryAppliedThisIteration) {
662+
if (summarizationEnabled && backgroundSummarizer && !didSummarizeThisIteration) {
660663
const postRenderRatio = baseBudget > 0
661664
? (result.tokenCount + toolTokens) / baseBudget
662665
: 0;

0 commit comments

Comments
 (0)