Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 5, 2025

Event handlers for onDidDisposeSession and onDidChangeInstances were registered inside registerTerminalInstanceWithToolSession, creating duplicate listeners on each call. This caused memory leaks and redundant cleanup operations.

Changes:

  • Move both event handlers to constructor (registered once)
  • Update onDidDisposeSession handler to look up terminal instances by session ID from _terminalInstancesByToolSessionId map
// Before: registered per-call, causing duplicates
registerTerminalInstanceWithToolSession(...) {
  this._register(this._chatService.onDidDisposeSession(...));
  this._register(this._terminalService.onDidChangeInstances(...));
}

// After: registered once in constructor
constructor(...) {
  this._register(this._chatService.onDidDisposeSession(e => {
    for (const resource of e.sessionResource) {
      const sessionId = LocalChatSessionUri.parseLocalSessionId(resource);
      const instance = this._terminalInstancesByToolSessionId.get(sessionId);
      // cleanup if found
    }
  }));
  this._register(this._terminalService.onDidChangeInstances(...));
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…onstructor to avoid duplicate listeners

Co-authored-by: osortega <48293249+osortega@users.noreply.github.com>
Copilot AI changed the title [WIP] Update session disposal in local agents provider Fix duplicate event handler registration in TerminalChatService Dec 5, 2025
Copilot AI requested a review from osortega December 5, 2025 06:45
Copilot finished work on behalf of osortega December 5, 2025 06:45
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.

2 participants