fix: tolerate invalid tool-call JSON in language model wrapper (fixes #322123) (#322127)

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.

Co-authored-by: vs-code-engineering[bot] <122617954+vs-code-engineering[bot]@users.noreply.github.com>
This commit is contained in:
vs-code-engineering[bot]
2026-06-21 08:52:11 +00:00
committed by GitHub
parent cfb41fb566
commit cb128cbeff

View File

@@ -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));
}
}