Skip to content

Fix handleEndOfLifetime supersededBy tracking for inline completions#320143

Open
yavanosta wants to merge 1 commit into
microsoft:mainfrom
yavanosta:inline-completion-end-of-life-pid-fix
Open

Fix handleEndOfLifetime supersededBy tracking for inline completions#320143
yavanosta wants to merge 1 commit into
microsoft:mainfrom
yavanosta:inline-completion-end-of-life-pid-fix

Conversation

@yavanosta
Copy link
Copy Markdown
Contributor

Problem

When an inline completion item is superseded by a newer suggestion (e.g., from a subsequent completion request), the extension host provider's handleEndOfLifetime callback should receive the superseding completion item via reason.supersededBy. Instead, providers were receiving the old completion item itself (essentially being told the item superseded itself).

Root Cause

When the main thread processes handleEndOfLifetime in mainThreadLanguageFeatures.ts, it maps reason.supersededBy into an IPC reference { pid, idx }. Because individual IdentifiableInlineCompletion items only tracked idx and not pid, mapReason incorrectly fell back to using completions.pid:

mapReason(reason, i => ({ pid: completions.pid, idx: i.idx }))

Since completions.pid refers to the old completion list being disposed, it paired the old list's PID with the new item's index (0). When this arrived at the extension host, it resolved this._references.get(oldPid)?.items[0], incorrectly fetching the old item instead of the new one.

Solution

  1. Protocol Definition: Added pid: number to the IdentifiableInlineCompletion DTO interface in extHost.protocol.ts.
  2. Extension Host: Updated InlineCompletionAdapter.provideInlineCompletions in extHostLanguageFeatures.ts to include pid on every completion item DTO sent across the IPC bridge.
  3. Main Thread: Updated mapReason in mainThreadLanguageFeatures.ts to use i.pid instead of completions.pid.

Impact

This change is entirely scoped to the internal Core <-> Extension Host RPC boundary. The public vscode extension API remains 100% unchanged.

Copilot AI review requested due to automatic review settings June 5, 2026 17:07
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

Note

Copilot was unable to run its full agentic suite in this review.

Adds per-item pid tracking to inline completion items so end-of-lifetime events can reference the originating provider/id more precisely.

Changes:

  • Add pid to IdentifiableInlineCompletion to identify the originating provider/id per item.
  • Populate pid when converting inline completion items on the extension host side.
  • Update end-of-lifetime event mapping to forward pid from each reason item.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/vs/workbench/api/common/extHostLanguageFeatures.ts Includes pid on marshalled inline completion items sent to main thread.
src/vs/workbench/api/common/extHost.protocol.ts Extends the cross-thread inline completion item shape with pid.
src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts Adjusts end-of-lifetime event mapping to use per-item pid values.

Comment on lines 492 to 496
export interface IdentifiableInlineCompletion extends languages.InlineCompletion {
pid: number;
idx: number;
suggestionId: EditSuggestionId | undefined;
}

if (this._supportsHandleEvents) {
await this._proxy.$handleInlineCompletionEndOfLifetime(this.handle, completions.pid, item.idx, mapReason(reason, i => ({ pid: completions.pid, idx: i.idx })));
await this._proxy.$handleInlineCompletionEndOfLifetime(this.handle, completions.pid, item.idx, mapReason(reason, i => ({ pid: i.pid, idx: i.idx })));
}

export interface IdentifiableInlineCompletion extends languages.InlineCompletion {
pid: number;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants