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<ExtensionErrorListener> to
optional single listener.
This commit is contained in:
Mario Zechner 2026-01-22 22:03:17 +01:00
parent e0742d8217
commit f54e71999f

View file

@ -221,8 +221,8 @@ export class AgentSession {
private _extensionUIContext?: ExtensionUIContext; private _extensionUIContext?: ExtensionUIContext;
private _extensionCommandContextActions?: ExtensionCommandContextActions; private _extensionCommandContextActions?: ExtensionCommandContextActions;
private _extensionShutdownHandler?: ShutdownHandler; private _extensionShutdownHandler?: ShutdownHandler;
private _extensionErrorListeners = new Set<ExtensionErrorListener>(); private _extensionErrorListener?: ExtensionErrorListener;
private _extensionErrorUnsubscribers: Array<() => void> = []; private _extensionErrorUnsubscriber?: () => void;
// Model registry for API key resolution // Model registry for API key resolution
private _modelRegistry: ModelRegistry; private _modelRegistry: ModelRegistry;
@ -1643,8 +1643,8 @@ export class AgentSession {
if (bindings.shutdownHandler !== undefined) { if (bindings.shutdownHandler !== undefined) {
this._extensionShutdownHandler = bindings.shutdownHandler; this._extensionShutdownHandler = bindings.shutdownHandler;
} }
if (bindings.onError) { if (bindings.onError !== undefined) {
this._extensionErrorListeners.add(bindings.onError); this._extensionErrorListener = bindings.onError;
} }
if (this._extensionRunner) { if (this._extensionRunner) {
@ -1657,13 +1657,10 @@ export class AgentSession {
runner.setUIContext(this._extensionUIContext); runner.setUIContext(this._extensionUIContext);
runner.bindCommandContext(this._extensionCommandContextActions); runner.bindCommandContext(this._extensionCommandContextActions);
for (const unsubscribe of this._extensionErrorUnsubscribers) { this._extensionErrorUnsubscriber?.();
unsubscribe(); this._extensionErrorUnsubscriber = this._extensionErrorListener
} ? runner.onError(this._extensionErrorListener)
this._extensionErrorUnsubscribers = []; : undefined;
for (const listener of this._extensionErrorListeners) {
this._extensionErrorUnsubscribers.push(runner.onError(listener));
}
} }
private _bindExtensionCore(runner: ExtensionRunner): void { private _bindExtensionCore(runner: ExtensionRunner): void {
@ -1840,7 +1837,7 @@ export class AgentSession {
this._extensionUIContext || this._extensionUIContext ||
this._extensionCommandContextActions || this._extensionCommandContextActions ||
this._extensionShutdownHandler || this._extensionShutdownHandler ||
this._extensionErrorListeners.size > 0; this._extensionErrorListener;
if (this._extensionRunner && hasBindings) { if (this._extensionRunner && hasBindings) {
await this._extensionRunner.emit({ type: "session_start" }); await this._extensionRunner.emit({ type: "session_start" });
} }