microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
160.21k stars 28.06k forks source link

Chat leaks text models #216577

Open bpasero opened 2 weeks ago

bpasero commented 2 weeks ago

When I get a code block as response, I see 2 text models being created with URIs such as:

vscode-copilot-chat-code-block://6c0321c2-3c9c-4f8a-8b14-c9a737ff5a39/response_5/0#%7B%22references%22%3A%5B%5D%7D

vscode-chat-code-block://e7d2cd80-6c6b-470c-af0c-21391c43e841/response_3/0#%7B%22references%22%3A%5B%5D%7D

When opening a new chat I only see the model of vscode-chat-code-block getting disposed.

I think this could be the source of many listener leak warnings in error telemetry.

//cc @jrieken

bhavyaus commented 2 weeks ago

Sorry. The triage bot closed it incorrectly. Will reopen as soon as the fix is in.

mjbvz commented 1 week ago

vscode-copilot-chat-code-block is created by the copilot extension. It is cleaned up automatically by the extension host

@jrieken It would be great if we could avoid this. Here's how these documents are used:

I'd love to just have the vscode-chat-code-block doc. Maybe we could add re-entry logic so that when an exclusive provider calls a command such as executeHoverProvider inside its provide function, the command does not go back to call the exclusive provider

jrieken commented 1 week ago

I would not do any re-entry logic. Granted the extension (chat) does not call open and is just a provider, the duplicated models should only be around for a short time, e.g the execution of a particular language feature like hover,

mjbvz commented 1 week ago

To support IntelliSense across code blocks, we need to make sure extensions have TextDocuments for all of them. Unfortunately that means we can't just have one duplicate model, all of them have to be duplicated

Having to keep duplicates open for every single document is not a good solution but I can't think of any other way to get this working with our current apis

jrieken commented 1 week ago

Instead of opening all code blocks from a session as text documents (and fighting to keep them open) could we just register a file system for chat code blocks? With that language extensions can simply read all documents/files at their pace and in their ways? I don't know how this plays with TypeScript specifically but I would assume that's generally the better approach and is also more similar to scenarios like web. So, it would be