From f42b54873f2b083af57ad356273968d759b02720 Mon Sep 17 00:00:00 2001 From: "vs-code-engineering[bot]" <122617954+vs-code-engineering[bot]@users.noreply.github.com> Date: Fri, 19 Jun 2026 16:17:50 +0000 Subject: [PATCH] fix: tolerate invalid tool-call JSON in language model wrapper (fixes #322123) The model can stream malformed JSON for tool-call arguments. The language model wrapper threw a bare Error from a fire-and-forget finished callback, producing an unhandled rejection in error telemetry without cleanly aborting the response. Align with the other tool-call consumers (langModelServer, messagesApi) by logging the diagnostic and falling back to empty parameters so the tool call is still surfaced to the consuming extension. --- .../conversation/vscode-node/languageModelAccess.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/extensions/copilot/src/extension/conversation/vscode-node/languageModelAccess.ts b/extensions/copilot/src/extension/conversation/vscode-node/languageModelAccess.ts index 4017dc52bc67b0..ea6cf633086222 100644 --- a/extensions/copilot/src/extension/conversation/vscode-node/languageModelAccess.ts +++ b/extensions/copilot/src/extension/conversation/vscode-node/languageModelAccess.ts @@ -834,14 +834,19 @@ export class CopilotLanguageModelWrapper extends Disposable { } if (delta.copilotToolCalls) { for (const call of delta.copilotToolCalls) { + // Anthropic models send "" (empty string) for tools with no parameters. + let parameters: object; try { - // Anthropic models send "" (empty string) for tools with no parameters. - const parameters = JSON.parse(call.arguments || '{}'); - progress.report(new vscode.LanguageModelToolCallPart(call.id, call.name, parameters)); + parameters = JSON.parse(call.arguments || '{}'); } catch (err) { + // The model can stream malformed JSON for tool arguments. Log it for + // diagnostics and fall back to empty parameters so the tool call is still + // surfaced to the extension (matching other tool-call consumers) instead of + // leaking an unhandled rejection out of this fire-and-forget callback. this._logService.error(err, `Got invalid JSON for tool call: ${call.arguments}`); - throw new Error('Invalid JSON for tool call'); + parameters = {}; } + progress.report(new vscode.LanguageModelToolCallPart(call.id, call.name, parameters)); } }