fix: guard activeTabGroup access in copilot diffState (fixes #317055)#317062
Open
vs-code-engineering[bot] wants to merge 1 commit into
Open
fix: guard activeTabGroup access in copilot diffState (fixes #317055)#317062vs-code-engineering[bot] wants to merge 1 commit into
vs-code-engineering[bot] wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔧 Error Fix
Summary
The copilot extension's
DiffStateManager._updateContext()method throwsAssertion 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:
@DonJayamanneCulprit Commit
The
diffState.tsfile withsetupContextTrackingwas introduced in commit c1c606c by@DonJayamanne(Feb 27, 2026). The_updateContextmethod subscribes toonDidChangeTabsevents and accessesactiveTabGroupwithout 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 staleAffected Files
extensions/copilot/src/extension/chatSessions/copilotcli/vscode-node/diffState.tsactiveTabGroupunsafelysrc/vs/workbench/api/common/extHostEditorTabs.ts_activeGroupIdRepro Steps
onDidChangeTabsevent fires during a state transition where_activeGroupIdis temporarily inconsistent with the groups array_updateContext()accessesactiveTabGroupwhich throwsHow the Fix Works
Chosen approach (
extensions/copilot/src/extension/chatSessions/copilotcli/vscode-node/diffState.ts):Replaced the direct
vscode.window.tabGroups.activeTabGroupaccess (which internally callsassertReturnsDefined) withvscode.window.tabGroups.all.find(g => g.isActive). This returnsundefinedinstead of throwing when no active group is found. Added a guard clauseif (!activeTabGroup) returnto 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
activeTabGroupgetter to returnundefinedinstead of throwing was rejected because it would break the API contract for all consumers and mask other bugs.Recommended Owner
@DonJayamanne— author of thediffState.tsfile and thesetupContextTrackingmethod that introduced this code path.