You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Copilot CLI diagnostics-changed notification crashes with TypeError: Cannot read properties of null (reading 'value') when serializing a diagnostic whose code is null. getDiagnosticsForUri uses typeof d.code === 'object' ? d.code.value : d.code, but typeof null === 'object' is true, so a null code falls into the object branch and dereferences null.value. Language servers and extensions are free to set Diagnostic.code to null, 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).
This commit introduced getDiagnosticsForUri with the typeof d.code === 'object' ? d.code.value : d.code mapping at line 52. Because typeof null === 'object', a null code is routed into the object branch and .value is read off null. 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')
Crash site and root cause — the code mapping on line 52
Repro Steps
Open a Copilot CLI chat session so the diagnostics-changed notification is registered.
Trigger a diagnostic from a language server/extension whose Diagnostic.code is null (rather than a string, number, or { value, target } object).
When the diagnostics change fires, getDiagnosticsForUri maps the diagnostic and throws TypeError: 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 to typeof d.code === 'object' && d.code !== null so that a null code falls through to the : d.code branch and is emitted as null, instead of being dereferenced. This is the correct location because the code value crosses an external/untrusted boundary — vscode.languages.getDiagnostics returns 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 standard typeof x === 'object' && x !== null idiom, 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 .map body 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 introduced getDiagnosticsForUri, is a VS Code team member with write access, and has landed commits to microsoft/vscode within the last 90 days.
Original error: ERR_API: [2026-08-24T15:50:52.676Z] create pull request in microsoft/vscode failed (attempt 1)
Original error: Validation Failed: {"resource":"PullRequest","code":"custom","field":"fork_collab","message":"fork_collab Fork collab can't be granted by someone without permission"} - https://docs.github.com/rest/pulls/pulls#create-a-pull-request
Retryable: false
Suggestion: This error cannot be resolved by retrying. Please check the error details and fix the underlying issue.
To create the pull request manually:
gh pr create --title "fix: guard against null diagnostic code in Copilot CLI diagnosticsChanged (fixes #332348)" --base main --head vscodebot-pr:fix/diagnostics-null-code-332348-ab2b9bff63887b37 --repo microsoft/vscode
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.Note
This was originally intended as a pull request, but PR creation failed. The changes have been pushed to the branch
fix/diagnostics-null-code-332348-ab2b9bff63887b37.Original error: ERR_API: [2026-08-24T15:50:52.676Z] create pull request in microsoft/vscode failed (attempt 1)
Original error: Validation Failed: {"resource":"PullRequest","code":"custom","field":"fork_collab","message":"fork_collab Fork collab can't be granted by someone without permission"} - https://docs.github.com/rest/pulls/pulls#create-a-pull-request
Retryable: false
Suggestion: This error cannot be resolved by retrying. Please check the error details and fix the underlying issue.
To create the pull request manually:
gh pr create --title "fix: guard against null diagnostic code in Copilot CLI diagnosticsChanged (fixes #332348)" --base main --head vscodebot-pr:fix/diagnostics-null-code-332348-ab2b9bff63887b37 --repo microsoft/vscodeShow patch (28 lines)