Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,6 @@ export class NextEditProvider extends Disposable implements INextEditProvider<Ne
// Nice! No need to make another request, we can reuse the result from a pending request.
if (speculativeRequest) {
logger.trace(`reusing speculative pending request (opportunityId=${speculativeRequest.opportunityId}, headerRequestId=${speculativeRequest.headerRequestId})`);
// Detach the speculative — caller is consuming it now.
this._specManager.consumePending();
} else {
Comment on lines 553 to 556
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

This change enables reusing a speculative pending request multiple times, but there’s no test exercising the new behavior (e.g. multiple getNextEdit calls in the same post-edit state should still reuse the same speculative request and not create an additional provider call). Please add/extend a Vitest case in nextEditProviderSpeculative.spec.ts to cover reusing the same speculative request more than once.

Copilot uses AI. Check for mistakes.
Comment on lines 553 to 556
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

By no longer clearing _specManager.pending when a speculative request is reused, the pending entry (including postEditContent and trajectory strings) can now live much longer. Since onActiveDocumentChanged is currently not invoked (it’s commented out in the constructor), this pending state may stick around even after the document diverges, increasing retained memory per accepted suggestion. Consider adding an explicit cleanup strategy (e.g. clear pending after N reuses / after the request completes, or re-enable a safe divergence signal) to avoid holding large document snapshots unnecessarily.

Copilot uses AI. Check for mistakes.
logger.trace(`reusing in-flight pending request (opportunityId=${requestToReuse.opportunityId}, headerRequestId=${requestToReuse.headerRequestId})`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ export class SpeculativeRequestManager extends Disposable {
this._pending = req;
}

/** Detaches the pending speculative without cancelling — caller is consuming it. */
consumePending(): void {
this._pending = null;
}

schedule(s: ScheduledSpeculativeRequest): void {
this._scheduled = s;
}
Expand Down
Loading