From 79c06d71607b087e7b230fc6517d849d935f3268 Mon Sep 17 00:00:00 2001 From: zeroaltitude Date: Tue, 10 Mar 2026 00:21:30 -0700 Subject: [PATCH] fix: initialize postHookActions before handler loop, not just at drain Move postHookActions ??= [] to before the handler loop so handlers can safely push() during execution. Legacy callers without the field would otherwise TypeError on .push() inside the session-memory handler. Removed the now-redundant ?? [] at drain time. --- src/hooks/internal-hooks.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hooks/internal-hooks.ts b/src/hooks/internal-hooks.ts index fcc46806132..de3a7a79c0a 100644 --- a/src/hooks/internal-hooks.ts +++ b/src/hooks/internal-hooks.ts @@ -274,6 +274,11 @@ export function getRegisteredEventKeys(): string[] { * @param event - The event to trigger */ export async function triggerInternalHook(event: InternalHookEvent): Promise { + // Normalize postHookActions before entering the handler loop — handlers + // may push to this array during execution. Legacy callers that construct + // hook events without the field would otherwise hit a TypeError on .push(). + event.postHookActions ??= []; + const typeHandlers = handlers.get(event.type) ?? []; const specificHandlers = handlers.get(`${event.type}:${event.action}`) ?? []; @@ -297,10 +302,7 @@ export async function triggerInternalHook(event: InternalHookEvent): Promise { + await drainPostHookActions(event.postHookActions, (err) => { const message = err instanceof Error ? err.message : String(err); log.error(`Post-hook action error [${event.type}:${event.action}]: ${message}`); });