Skip to content

Copilot CLI: Handle errors during tool invocation formatting#4697

Queued
DonJayamanne wants to merge 1 commit intomainfrom
don/ambitious-landfowl
Queued

Copilot CLI: Handle errors during tool invocation formatting#4697
DonJayamanne wants to merge 1 commit intomainfrom
don/ambitious-landfowl

Conversation

@DonJayamanne
Copy link
Collaborator

No description provided.

@DonJayamanne DonJayamanne self-assigned this Mar 25, 2026
@DonJayamanne DonJayamanne marked this pull request as ready for review March 25, 2026 21:57
Copilot AI review requested due to automatic review settings March 25, 2026 21:57
@DonJayamanne DonJayamanne enabled auto-merge March 25, 2026 21:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves resilience of Copilot CLI chat tool-invocation rendering by catching exceptions thrown by tool invocation formatters so a single formatter bug doesn’t break the overall session UI.

Changes:

  • Wrap tool completion “post formatter” execution in a try/catch and attempt a generic completion fallback on failure.
  • Wrap tool invocation “pre formatter” execution in a try/catch and (optionally) log formatter failures.
  • Extend createCopilotCLIToolInvocation(...) to accept an optional ILogger for error reporting.
Comments suppressed due to low confidence (2)

src/extension/chatSessions/copilotcli/common/copilotCLITools.ts:933

  • createCopilotCLIToolInvocation now swallows formatter exceptions, but if the formatter throws before setting invocationMessage/pastTenseMessage/toolSpecificData, the UI may show a blank or unhelpful tool invocation. Consider setting a generic Using tool: ... / Used tool: ... message (and optionally input args) before calling the formatter, and in the catch block ensure a minimal fallback display is filled in (not just logging).
	try {
		(formatter as Formatter)(invocation, toolCall, editId, workingDirectory);
	} catch (err) {
		logger?.error(err, `Failed to format tool invocation for tool: ${toolCall.toolName}`);
	}

src/extension/chatSessions/copilotcli/common/copilotCLITools.ts:884

  • The new optional logger parameter isn’t currently passed by any call sites in this module (e.g. processToolExecutionStart still calls createCopilotCLIToolInvocation(..., editId, workingDirectory)), so formatter errors will generally be swallowed without any log in production. Either plumb an ILogger down from the caller (and/or make it required) or use an existing logger available in this codepath so failures are observable.
export function createCopilotCLIToolInvocation(data: {
	toolCallId: string; toolName: string; arguments?: unknown; mcpServerName?: string | undefined;
	mcpToolName?: string | undefined;
}, editId?: string, workingDirectory?: URI, logger?: ILogger): ChatToolInvocationPart | ChatResponseMarkdownPart | ChatResponseThinkingProgressPart | undefined {

@DonJayamanne DonJayamanne added this pull request to the merge queue Mar 25, 2026
Any commits made after this event will not be merged.
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Mar 25, 2026
@DonJayamanne DonJayamanne added this pull request to the merge queue Mar 26, 2026
Any commits made after this event will not be merged.
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Mar 26, 2026
@DonJayamanne DonJayamanne added this pull request to the merge queue Mar 26, 2026
Any commits made after this event will not be merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants