Skip to content

Conversation

@DonJayamanne
Copy link
Collaborator

@DonJayamanne DonJayamanne commented Nov 25, 2025

@DonJayamanne DonJayamanne self-assigned this Nov 25, 2025
currentResponseParts.push(new ChatResponseCodeblockUriPart(uri, true, editId));
currentResponseParts.push(new ChatResponseMarkdownPart('\n````\n'));
currentResponseParts.push(new ChatResponseTextEditPart(uri, []));
currentResponseParts.push(new ChatResponseTextEditPart(uri, true));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Re-emit the edits with the undo stop ids

}
}

const requestDetails: { requestId: string; toolIdEditMap: Record<string, string> } = { requestId, toolIdEditMap: {} };
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Keeping a map of request Id and undo stop ids (that map to SDK requests and tool calls)

@DonJayamanne DonJayamanne marked this pull request as ready for review November 25, 2025 05:24
Copilot AI review requested due to automatic review settings November 25, 2025 05:24
@vs-code-engineering vs-code-engineering bot added this to the November 2025 milestone Nov 25, 2025
Copilot finished reviewing on behalf of DonJayamanne November 25, 2025 05:29
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 implements functionality to restore edits for background chat sessions by introducing request ID tracking and undo stop ID support. This allows the system to correlate VS Code chat request IDs with SDK request IDs and track edit operations across session boundaries, which is necessary for restoring edits when sessions are reopened.

Key changes:

  • Added requestId parameter to handleRequest method to track VS Code chat request IDs through the session lifecycle
  • Introduced undoStopId to ChatResponseCodeblockUriPart for tracking individual edit operations
  • Changed externalEdit return type from generic T to string to return edit IDs for tracking purposes

Reviewed changes

Copilot reviewed 17 out of 19 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
test/e2e/cli.stest.ts Updated all test calls to handleRequest to include the new requestId parameter (empty string for tests)
src/util/common/test/shims/chatTypes.ts Added isEdit and undoStopId properties to ChatResponseCodeblockUriPart and updated constructor signature; modified ChatResponseExternalEditPart.applied to return Thenable<string>
src/util/common/chatResponseStreamImpl.ts Changed externalEdit to return Promise<string> instead of generic Thenable<T> and updated callback parameter type to Thenable<unknown>
src/extension/vscode.proposed.chatParticipantPrivate.d.ts Added optional id field to ChatRequestTurn2 for tracking chat request IDs and updated constructor signature
src/extension/vscode.proposed.chatParticipantAdditions.d.ts Added undoStopId to ChatResponseCodeblockUriPart, changed externalEdit return type to Thenable<string>, and updated ChatResponseExternalEditPart.applied type
src/extension/test/node/testHelpers.ts Updated MockChatResponseStream.externalEdit to match new signature returning Promise<string>
src/extension/replay/vscode-node/chatReplaySessionProvider.ts Updated ChatRequestTurn2 constructor call to include undefined for the new id parameter
src/extension/prompt/node/chatParticipantRequestHandler.ts Added type casting to access editedFileEvents from ChatRequestTurn2 while maintaining compatibility with base ChatRequestTurn
src/extension/linkify/common/responseStreamWithLinkification.ts Updated externalEdit signature to match new return type
src/extension/chatSessions/vscode-node/test/copilotCLIChatSessionParticipant.spec.ts Updated test mock to include requestId parameter in handleRequest signature
src/extension/chatSessions/vscode-node/copilotCloudSessionContentBuilder.ts Updated ChatRequestTurn2 constructor call to include undefined for the new id parameter
src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts Updated to pass request.id as the first parameter to handleRequest
src/extension/chatSessions/vscode-node/claudeChatSessionContentProvider.ts Updated ChatRequestTurn2 constructor call to include undefined for the new id parameter
src/extension/agents/copilotcli/node/test/copilotcliSession.spec.ts Updated all test calls to handleRequest to include the new requestId parameter (empty string for tests)
src/extension/agents/copilotcli/node/copilotcliSession.ts Added requestId parameter to handleRequest, implemented edit ID tracking with toolIdEditMap, and updated getChatHistory to pass request ID lookup function; stores request details in SDK after completion
src/extension/agents/copilotcli/node/copilotCli.ts Added request map storage in workspace state with getRequestId and setRequestId methods, includes 7-day pruning of old entries
src/extension/agents/copilotcli/common/test/copilotCLITools.spec.ts Updated test expectations to handle new tuple return type from processToolExecutionComplete
src/extension/agents/copilotcli/common/copilotCLITools.ts Modified buildChatHistoryFromEvents to accept optional request ID lookup function; updated tool execution tracking to use tuples; added logic to insert ChatResponseCodeblockUriPart with edit IDs for completed edits; updated formatter signatures to accept optional editId parameter
src/extension/agents/common/externalEditTracker.ts Changed completeEdit to return Promise<string | undefined> instead of Promise<void> to propagate the edit ID from VS Code
Comments suppressed due to low confidence (2)

src/extension/agents/copilotcli/common/copilotCLITools.ts:590

  • The editId parameter is declared but never used in this function. Either remove it if it's not needed, or implement the intended functionality if it was meant to be used.
function formatCreateToolInvocation(invocation: ChatToolInvocationPart, toolCall: CreateTool, editId?: string): void {
	const args = toolCall.arguments;
	const display = args.path ? formatUriForFileWidget(Uri.file(args.path)) : '';

	if (display) {
		invocation.invocationMessage = new MarkdownString(l10n.t("Created {0}", display));
	} else {
		invocation.invocationMessage = new MarkdownString(l10n.t("Created file"));
	}
}

src/extension/agents/copilotcli/common/copilotCLITools.ts:555

  • The editId parameter is declared but never used in this function. Either remove it if it's not needed, or implement the intended functionality if it was meant to be used.
function formatStrReplaceEditorInvocation(invocation: ChatToolInvocationPart, toolCall: StringReplaceEditorTool, editId?: string): void {
	if (!toolCall.arguments.path) {
		return;
	}
	const args = toolCall.arguments;
	const display = formatUriForFileWidget(Uri.file(args.path));
	switch (args.command) {
		case 'view':
			formatViewToolInvocation(invocation, { toolName: 'view', arguments: args } as ViewTool);
			break;
		case 'edit':
			formatEditToolInvocation(invocation, { toolName: 'edit', arguments: args } as EditTool);
			break;
		case 'insert':
			formatInsertToolInvocation(invocation, { toolName: 'insert', arguments: args } as InsertTool);
			break;
		case 'create':
			formatCreateToolInvocation(invocation, { toolName: 'create', arguments: args } as CreateTool);
			break;
		case 'undo_edit':
			formatUndoEdit(invocation, { toolName: 'undo_edit', arguments: args } as UndoEditTool);
			break;
		default:
			invocation.invocationMessage = new MarkdownString(l10n.t("Modified {0}", display));
	}
}

connor4312
connor4312 previously approved these changes Nov 25, 2025
@DonJayamanne DonJayamanne added this pull request to the merge queue Nov 26, 2025
Merged via the queue into main with commit 708e2da Nov 26, 2025
16 checks passed
@DonJayamanne DonJayamanne deleted the don/permanent-sailfish branch November 26, 2025 12:41
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.

4 participants