fix: make initializeGlobalHookRunner idempotent (#50025)

This commit is contained in:
Julian Streibel 2026-03-19 15:31:55 +01:00
parent 57feef7ba6
commit f7a3bb0614

View File

@ -35,6 +35,14 @@ function getHookRunnerGlobalState(): HookRunnerGlobalState {
*/
export function initializeGlobalHookRunner(registry: PluginRegistry): void {
const state = getHookRunnerGlobalState();
// Preserve an existing hook runner that has registered hooks.
// Subsequent ensureRuntimePluginsLoaded calls (e.g. from non-default agent runs)
// may build a fresh registry with fewer/no hooks due to cache key divergence;
// replacing the working runner would silently drop all plugin hooks.
if (state.hookRunner && state.registry && state.registry.typedHooks.length > 0) {
log.debug("hook runner already initialized with hooks; skipping re-initialization");
return;
}
state.registry = registry;
state.hookRunner = createHookRunner(registry, {
logger: {