-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Remove chatSessionTracker #279690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove chatSessionTracker #279690
Conversation
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @bpaseroMatched files:
|
There was a problem hiding this 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 removes the ChatSessionTracker class and refactors session change tracking to be centralized in ChatSessionsService. The tracker previously monitored editor groups and local chat sessions, emitting change events. This functionality is now handled by registering model progress listeners directly in the ChatSessionsService constructor via an autorun that watches chat models.
Key changes:
- Centralized model progress listener registration in
ChatSessionsServiceusing autorun - Removed
ChatSessionTrackerclass and its usage throughout the codebase - Simplified
LocalAgentsSessionsProviderby removing local event listening logic - Updated
SessionsDataSourceto no longer integrate hybrid sessions
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/chat/browser/chatSessions/chatSessionTracker.ts | Deleted the entire ChatSessionTracker class |
| src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts | Added autorun to register model progress listeners; refactored registerModelProgressListener to accept models iterable instead of individual model |
| src/vs/workbench/contrib/chat/browser/chatSessions/view/chatSessionsView.ts | Removed ChatSessionTracker instantiation and usage |
| src/vs/workbench/contrib/chat/browser/chatSessions/view/sessionsViewPane.ts | Removed ChatSessionTracker parameter and LocalAgentsSessionsProvider-specific event listener |
| src/vs/workbench/contrib/chat/browser/chatSessions/view/sessionsTreeRenderer.ts | Removed ChatSessionTracker parameter and hybrid session integration logic |
| src/vs/workbench/contrib/chat/browser/agentSessions/localAgentSessionsProvider.ts | Removed local model listener registration logic |
| src/vs/workbench/contrib/chat/common/chatSessionsService.ts | Updated interface signature for registerModelProgressListener |
| src/vs/workbench/contrib/chat/test/common/mockChatSessionsService.ts | Updated mock implementation signature |
| src/vs/workbench/contrib/chat/test/browser/localAgentSessionsProvider.test.ts | Removed tests for the deleted event handling functionality |
src/vs/workbench/contrib/chat/browser/chatSessions/view/sessionsTreeRenderer.ts
Show resolved
Hide resolved
src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts
Outdated
Show resolved
Hide resolved
src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts
Outdated
Show resolved
Hide resolved
src/vs/workbench/contrib/chat/browser/agentSessions/localAgentSessionsProvider.ts
Show resolved
Hide resolved
src/vs/workbench/contrib/chat/test/common/mockChatSessionsService.ts
Outdated
Show resolved
Hide resolved
|
Copilot seems to have good points, and CI is red... |
src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts
Outdated
Show resolved
Hide resolved
src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts
Outdated
Show resolved
Hide resolved
src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts
Outdated
Show resolved
Hide resolved
src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts
Outdated
Show resolved
Hide resolved
…ega/remove-chat-session-tracker
roblourens
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there also be a change in LocalAgentsSessionsProvider for it to just watch local models?
src/vs/workbench/api/test/browser/mainThreadChatSessions.test.ts
Outdated
Show resolved
Hide resolved
…ega/remove-chat-session-tracker
|
@osortega CI failing |
| disposables.add(autorun(reader => { | ||
| const models = this._chatService.chatModels.read(reader); | ||
| const onProgress = this._chatSessionsService.registerModelProgressListener(Array.from(models), chatSessionType); | ||
| disposables.add(onProgress(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are re-adding a new event listener every time the autorun runs - I don't think that what you want, the listeners will accumulate over time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixed it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is still an issue? It's adding a new disposable on every autorun iteration and they accumulate over time
src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts
Outdated
Show resolved
Hide resolved
src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts
Outdated
Show resolved
Hide resolved
roblourens
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this fix a bug or is it just code cleanup?
| } | ||
| this._registeredModels.add(model); | ||
| public registerModelProgressListener(models: IChatModel[], type: string): Event<void> { | ||
| const changeEmitter = this._register(new Emitter<void>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still very funky overall to me. Someone can call the service and create disposables that stick around forever and have no way to be disposed. They should be owned by the calling method. We can merge it as long as it's not leaking but we just still need to revisit this for next month.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roblourens we can collect all disposables and return it to the caller but does that mean that the caller needs to listen to onDispose for each model and know when to dispose the model specific disposables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand what you meant, pushed a fix so that the caller has access to the disposables.
The function also adds disposables that listens to the disposae event of each model
| for (const model of models) { | ||
| if (model.sessionResource.scheme === type && !this._registeredModels.has(model)) { | ||
| this._registeredModels.add(model); | ||
| const modelDisposables = this._register(new DisposableStore()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't register modelDisposables on the class if it has an independent lifecycle (which it does because it tracks the model and you clear it below). Doing this creates a memory leak because the reference to the DisposableStore and everything it touches will be retained by the ChatSessionsService forever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it so that it returns the disposable store to the caller
connor4312
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some code-level things you probably want to fix
src/vs/workbench/contrib/chat/browser/agentSessions/localAgentSessionsProvider.ts
Outdated
Show resolved
Hide resolved
src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts
Outdated
Show resolved
Hide resolved
src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts
Outdated
Show resolved
Hide resolved
| // Use autorun to listen for state changes | ||
| this._register(autorunSelfDisposable(reader => { | ||
| const state = toolInvocation.state.read(reader); | ||
| const listeners = new ResourceMap<IDisposable>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we actually want to return a DisposableStore containing both the autorunIterableDelta and something like
store.add(toDisposable(() => {
for (const listener of listeners) { listener.dispose(); }
}));otherwise they might get orphaned
src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts
Outdated
Show resolved
Hide resolved
…ega/remove-chat-session-tracker
Comments addressed and already approved
…ega/remove-chat-session-tracker
No description provided.