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}`); });