From f54e71999f7bfe3745b7962344ccf345090de0af Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 22 Jan 2026 22:03:17 +0100 Subject: [PATCH] fix(coding-agent): simplify extension error listener to single instance There's only ever one bindings instance per session, so the Set/Array approach was unnecessary. Changed from Set to optional single listener. --- .../coding-agent/src/core/agent-session.ts | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/coding-agent/src/core/agent-session.ts b/packages/coding-agent/src/core/agent-session.ts index 23f956d3..2da0677d 100644 --- a/packages/coding-agent/src/core/agent-session.ts +++ b/packages/coding-agent/src/core/agent-session.ts @@ -221,8 +221,8 @@ export class AgentSession { private _extensionUIContext?: ExtensionUIContext; private _extensionCommandContextActions?: ExtensionCommandContextActions; private _extensionShutdownHandler?: ShutdownHandler; - private _extensionErrorListeners = new Set(); - private _extensionErrorUnsubscribers: Array<() => void> = []; + private _extensionErrorListener?: ExtensionErrorListener; + private _extensionErrorUnsubscriber?: () => void; // Model registry for API key resolution private _modelRegistry: ModelRegistry; @@ -1643,8 +1643,8 @@ export class AgentSession { if (bindings.shutdownHandler !== undefined) { this._extensionShutdownHandler = bindings.shutdownHandler; } - if (bindings.onError) { - this._extensionErrorListeners.add(bindings.onError); + if (bindings.onError !== undefined) { + this._extensionErrorListener = bindings.onError; } if (this._extensionRunner) { @@ -1657,13 +1657,10 @@ export class AgentSession { runner.setUIContext(this._extensionUIContext); runner.bindCommandContext(this._extensionCommandContextActions); - for (const unsubscribe of this._extensionErrorUnsubscribers) { - unsubscribe(); - } - this._extensionErrorUnsubscribers = []; - for (const listener of this._extensionErrorListeners) { - this._extensionErrorUnsubscribers.push(runner.onError(listener)); - } + this._extensionErrorUnsubscriber?.(); + this._extensionErrorUnsubscriber = this._extensionErrorListener + ? runner.onError(this._extensionErrorListener) + : undefined; } private _bindExtensionCore(runner: ExtensionRunner): void { @@ -1840,7 +1837,7 @@ export class AgentSession { this._extensionUIContext || this._extensionCommandContextActions || this._extensionShutdownHandler || - this._extensionErrorListeners.size > 0; + this._extensionErrorListener; if (this._extensionRunner && hasBindings) { await this._extensionRunner.emit({ type: "session_start" }); }