From 25dd58ed66449b5c19647d92cdaf536bf01abf4a Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sun, 9 Aug 2026 23:34:17 +0200 Subject: [PATCH] fix(extensions): skip settled registration barriers --- .../src/extensibility/extensions/runner.ts | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/coding-agent/src/extensibility/extensions/runner.ts b/packages/coding-agent/src/extensibility/extensions/runner.ts index 9144cae45..4a5322964 100644 --- a/packages/coding-agent/src/extensibility/extensions/runner.ts +++ b/packages/coding-agent/src/extensibility/extensions/runner.ts @@ -360,7 +360,7 @@ export class ExtensionRunner { #getMemoryFn?: () => MemoryRuntimeContext | undefined; #commandDiagnostics: Array<{ type: string; message: string; path: string }> = []; #toolRegistrationScope = new AsyncLocalStorage(); - #toolRegistrationBarrier: Promise = Promise.resolve(); + #toolRegistrationBarrier: Promise | undefined; #initialized = false; /** * Buffer for `credential_disabled` events received via {@link emitCredentialDisabled} @@ -531,7 +531,8 @@ export class ExtensionRunner { this.runtime.getActiveTools = actions.getActiveTools; this.runtime.getAllTools = actions.getAllTools; this.runtime.setActiveTools = async toolNames => { - await this.#toolRegistrationBarrier; + const registrationBarrier = this.#toolRegistrationBarrier; + if (registrationBarrier) await registrationBarrier; await actions.setActiveTools(toolNames); }; this.runtime.getCommands = actions.getCommands; @@ -704,10 +705,14 @@ export class ExtensionRunner { const subscriptions: Array<{ extension: Extension; listener: ToolRegistrationListener }> = []; for (const extension of this.extensions) { const trackRegistration = (pending: Promise): void => { - this.#toolRegistrationBarrier = pending.then( + const registrationBarrier = pending.then( () => undefined, () => undefined, ); + this.#toolRegistrationBarrier = registrationBarrier; + void registrationBarrier.then(() => { + if (this.#toolRegistrationBarrier === registrationBarrier) this.#toolRegistrationBarrier = undefined; + }); const scope = this.#toolRegistrationScope.getStore(); if (scope && !scope.closed) { scope.pending.add(pending); @@ -1043,10 +1048,13 @@ export class ExtensionRunner { } catch (error) { handlerFailure ??= { error }; } - // Also wait for detached registrations that were scheduled before this handler - // completed. Their failures are reported at registration time, not attributed - // to this unrelated handler. - await this.#toolRegistrationBarrier; + const registrationBarrier = this.#toolRegistrationBarrier; + if (registrationBarrier) { + // Also wait for detached registrations that were scheduled before this + // handler completed. Their failures are reported at registration time, + // not attributed to this unrelated handler. + await registrationBarrier; + } if (handlerFailure) { const message = handlerFailure.error instanceof Error ? handlerFailure.error.message : String(handlerFailure.error);