Skip to content

nes: speculative: allow reusing spec request more than once#311387

Open
ulugbekna wants to merge 1 commit intomainfrom
ulugbekna/nes-allow-reusing-more-than-once
Open

nes: speculative: allow reusing spec request more than once#311387
ulugbekna wants to merge 1 commit intomainfrom
ulugbekna/nes-allow-reusing-more-than-once

Conversation

@ulugbekna
Copy link
Copy Markdown
Contributor

Co-authored-by: Copilot copilot@github.com

Co-authored-by: Copilot <copilot@github.com>
Copilot AI review requested due to automatic review settings April 20, 2026 15:13
@ulugbekna ulugbekna self-assigned this Apr 20, 2026
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

Enables reusing a speculative NES request more than once by keeping the speculative pending request attached to SpeculativeRequestManager instead of detaching it on first reuse.

Changes:

  • Removed SpeculativeRequestManager.consumePending() (no longer clears _pending on consumption).
  • Stopped detaching the speculative pending request when NextEditProvider reuses it.
Show a summary per file
File Description
extensions/copilot/src/extension/inlineEdits/node/speculativeRequestManager.ts Removes the API used to detach (clear) the pending speculative request without cancelling it.
extensions/copilot/src/extension/inlineEdits/node/nextEditProvider.ts Keeps speculative pending requests attached when reused, allowing subsequent reuse attempts.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment on lines 553 to 556
// 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 {
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
// 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 {
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.
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.

3 participants