fix: guard against null diagnostic code in Copilot CLI diagnosticsChanged (fixes #332348) - #332355
Open
VS Code PR Bot (vscodebot-pr) wants to merge 2 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
VS Code PR Bot (vscodebot-pr)
August 24, 2026 15:53
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents Copilot CLI diagnostic notifications from crashing when a diagnostic code is null.
Changes:
- Adds a null guard before reading
Diagnostic.code.value.
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…on tests Extracts a shared normalizeDiagnosticCode helper so both the diagnostics_changed push notification and the get_diagnostics tool guard against a null Diagnostic.code (typeof null === 'object'), and adds regression tests covering code: null. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Driver cycle recordederrors-fix-driver:cycle head:9f44f1b7812eb90ab160c177169f93cfa04f03bb |
Member
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.
Summary
The Copilot CLI diagnostics-changed notification crashes with
TypeError: Cannot read properties of null (reading 'value')when serializing a diagnostic whosecodeisnull.getDiagnosticsForUriusestypeof d.code === 'object' ? d.code.value : d.code, buttypeof null === 'object'istrue, so anullcode falls into the object branch and dereferencesnull.value. Language servers and extensions are free to setDiagnostic.codetonull, so this fires whenever such a diagnostic changes while a Copilot CLI session is active (50 users / 251 hits, new in extension 0.62.0).Fixes #332348
Recommended reviewer:
@alexweiningerCulprit Commit
ab48d553b302@alexweiningergetDiagnosticsForUriwith thetypeof d.code === 'object' ? d.code.value : d.codemapping at line 52. Becausetypeof null === 'object', anullcode is routed into the object branch and.valueis read offnull. The code shipped in extension 0.62.0, which is when the bucket first appeared.Code Flow
sequenceDiagram participant LS as Language Server / Extension participant API as vscode.languages.getDiagnostics participant Producer as getDiagnosticsForUri (map) participant CrashSite as d.code.value LS->>API: publishes Diagnostic with code = null API->>Producer: returns Diagnostic[] (code: null) Note over Producer: ⚠️ Root cause:<br/>typeof null === 'object' is true,<br/>so null enters the object branch Producer->>CrashSite: read d.code.value on null Note over CrashSite: TypeError: Cannot read<br/>properties of null (reading 'value')Affected Files
extensions/copilot/src/extension/chatSessions/copilotcli/vscode-node/tools/push/diagnosticsChanged.tscodemapping on line 52Repro Steps
Diagnostic.codeisnull(rather than a string, number, or{ value, target }object).getDiagnosticsForUrimaps the diagnostic and throwsTypeError: Cannot read properties of null (reading 'value').How the Fix Works
Chosen approach —
extensions/copilot/src/extension/chatSessions/copilotcli/vscode-node/tools/push/diagnosticsChanged.ts:52: tighten the type test totypeof d.code === 'object' && d.code !== nullso that anullcode falls through to the: d.codebranch and is emitted asnull, instead of being dereferenced. This is the correct location because thecodevalue crosses an external/untrusted boundary —vscode.languages.getDiagnosticsreturns data authored by arbitrary language servers and extensions, which the consumer cannot constrain — so the guard belongs at the point where the value is first narrowed and consumed. The fix is the standardtypeof x === 'object' && x !== nullidiom, preserves the existing behavior for real{ value, target }code objects and for string/number codes, and does not swallow or hide any error.Alternatives considered: wrapping the
.mapbody in try/catch was rejected because it would silence a legitimate serialization failure and hide it from telemetry rather than correctly serializing a valid (null) code.Recommended Owner
@alexweininger— authored the migration commit that introducedgetDiagnosticsForUri, is a VS Code team member with write access, and has landed commits tomicrosoft/vscodewithin the last 90 days.