Skip to content

fix: guard activeTabGroup access in copilot diffState (fixes #317055)#317062

Open
vs-code-engineering[bot] wants to merge 1 commit into
mainfrom
fix/copilot-activeTabGroup-assertion-317055-b3677a1f81c05445
Open

fix: guard activeTabGroup access in copilot diffState (fixes #317055)#317062
vs-code-engineering[bot] wants to merge 1 commit into
mainfrom
fix/copilot-activeTabGroup-assertion-317055-b3677a1f81c05445

Conversation

@vs-code-engineering
Copy link
Copy Markdown
Contributor

🔧 Error Fix

Summary

The copilot extension's DiffStateManager._updateContext() method throws Assertion Failed: Argument is \undefined` or `null`.when accessingvscode.window.tabGroups.activeTabGroupduring tab operation events. TheactiveTabGroupgetter usesassertReturnsDefinedinternally, which throws when the internal_activeGroupId` doesn't match any group in the tab groups array — a transient state that can occur during tab close/move operations before the active group ID is reconciled.

Affects 640+ users across darwin and linux platforms.

Fixes #317055
Recommended reviewer: @DonJayamanne

Culprit Commit

The diffState.ts file with setupContextTracking was introduced in commit c1c606c by @DonJayamanne (Feb 27, 2026). The _updateContext method subscribes to onDidChangeTabs events and accesses activeTabGroup without guarding against the assertion. This is a new regression in copilot extension version 0.49.2026051504 vs baseline 0.48.1.

Code Flow

sequenceDiagram
    participant MT as MainThread
    participant EH as ExtHostEditorTabs
    participant EV as EventEmitter
    participant CP as CopilotDiffState

    MT->>EH: $acceptTabOperation(operation)
    EH->>EH: group.acceptTabOperation(operation)
    EH->>EV: _onDidChangeTabs.fire(event)
    EV->>CP: _updateContext()
    CP->>EH: tabGroups.activeTabGroup [getter]
    EH->>EH: assertReturnsDefined(find by _activeGroupId)
    Note over EH: THROWS when _activeGroupId is stale
Loading

Affected Files

File Role
extensions/copilot/src/extension/chatSessions/copilotcli/vscode-node/diffState.ts Extension code that accesses activeTabGroup unsafely
src/vs/workbench/api/common/extHostEditorTabs.ts Core API that throws assertion on stale _activeGroupId

Repro Steps

  1. Open VS Code with copilot extension active
  2. Have multiple tabs open in a tab group
  3. Rapidly close tabs or move tabs between groups
  4. The onDidChangeTabs event fires during a state transition where _activeGroupId is temporarily inconsistent with the groups array
  5. _updateContext() accesses activeTabGroup which throws

How the Fix Works

Chosen approach (extensions/copilot/src/extension/chatSessions/copilotcli/vscode-node/diffState.ts):

Replaced the direct vscode.window.tabGroups.activeTabGroup access (which internally calls assertReturnsDefined) with vscode.window.tabGroups.all.find(g => g.isActive). This returns undefined instead of throwing when no active group is found. Added a guard clause if (!activeTabGroup) return to bail out early. This fixes at the data producer — the extension code that creates the unsafe access pattern — rather than patching the core API's assertion.

Alternatives considered: Wrapping the access in try/catch was rejected because it hides the bug instead of fixing the data producer. Modifying the core activeTabGroup getter to return undefined instead of throwing was rejected because it would break the API contract for all consumers and mask other bugs.

Recommended Owner

@DonJayamanne — author of the diffState.ts file and the setupContextTracking method that introduced this code path.

Generated by errors-fix · ● 42.5M ·

The _updateContext method accessed vscode.window.tabGroups.activeTabGroup
directly, which throws an assertion error when the internal _activeGroupId
is out of sync during tab operation events. Use tabGroups.all.find() to
safely find the active group without triggering the assertion.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 18, 2026 16:25
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 encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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 encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@vs-code-engineering vs-code-engineering Bot marked this pull request as ready for review May 18, 2026 16:27
@vs-code-engineering vs-code-engineering Bot enabled auto-merge (squash) May 18, 2026 16:27
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.

[Regression] [Error] [GitHub.copilot-chat] unhandlederror-Assertion Failed: Argument is undefined or null.

2 participants