fix: clean up extension error listener on session dispose (#2165)

The dispose() method was not cleaning up _extensionErrorUnsubscriber,
causing the extension error handler to remain subscribed after session
disposal. This leads to memory leaks across session reloads as old
error handlers accumulate on the extension runner.

Also wrap the unsubscriber call in _applyExtensionBindings() with
try-catch so that if the previous unsubscriber throws, the new
subscription is still set up correctly.
This commit is contained in:
Juan Francisco Lebrero 2026-03-23 12:51:38 -03:00 committed by GitHub
parent c25b57b922
commit c366f9769f

View file

@ -687,6 +687,8 @@ export class AgentSession {
* Call this when completely done with the session.
*/
dispose(): void {
this._extensionErrorUnsubscriber?.();
this._extensionErrorUnsubscriber = undefined;
this._disconnectFromAgent();
this._eventListeners = [];
}
@ -1928,7 +1930,11 @@ export class AgentSession {
runner.setUIContext(this._extensionUIContext);
runner.bindCommandContext(this._extensionCommandContextActions);
this._extensionErrorUnsubscriber?.();
try {
this._extensionErrorUnsubscriber?.();
} catch {
// Ignore errors from previous unsubscriber
}
this._extensionErrorUnsubscriber = this._extensionErrorListener
? runner.onError(this._extensionErrorListener)
: undefined;