fix(cli): sped up exit shutdown handlers

Run session_shutdown extension handlers concurrently under the existing shutdown cap so /exit and /quit do not wait one full timeout per hanging extension.

Fixes #2736
This commit is contained in:
roboomp
2026-06-16 04:49:58 +00:00
parent e24f789de4
commit df510d3b1d
3 changed files with 60 additions and 5 deletions
@@ -543,7 +543,9 @@ export class ExtensionRunner {
event.type === "session_before_tree"
);
}
#isSessionShutdownEvent(event: RunnerEmitEvent): event is Extract<RunnerEmitEvent, { type: "session_shutdown" }> {
return event.type === "session_shutdown";
}
async #runHandlerWithTimeout<TEvent extends { type: string }, TResult>(
handler: (event: TEvent, ctx: ExtensionContext) => Promise<TResult | undefined> | TResult | undefined,
event: TEvent,
@@ -588,6 +590,20 @@ export class ExtensionRunner {
const ctx = this.createContext();
let result: SessionBeforeEventResult | SessionCompactingResult | undefined;
if (this.#isSessionShutdownEvent(event)) {
const timeoutMs = handlerTimeoutForEvent(event.type);
const promises: Promise<unknown>[] = [];
for (const ext of this.extensions) {
const handlers = ext.handlers.get(event.type);
if (!handlers || handlers.length === 0) continue;
for (const handler of handlers) {
promises.push(this.#runHandlerWithTimeout(handler, event, ctx, ext, timeoutMs));
}
}
await Promise.all(promises);
return result as RunnerEmitResult<TEvent>;
}
for (const ext of this.extensions) {
const handlers = ext.handlers.get(event.type);
if (!handlers || handlers.length === 0) continue;