fix(cli): run plugin gateway_stop hooks before message exit (#16580)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 8542ac77ae
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
Gustavo Madeira Santana
2026-02-14 17:33:08 -05:00
committed by GitHub
parent 3821d74019
commit 8217d77ece
5 changed files with 121 additions and 19 deletions

View File

@@ -44,7 +44,7 @@ import {
import { scheduleGatewayUpdateCheck } from "../infra/update-startup.js";
import { startDiagnosticHeartbeat, stopDiagnosticHeartbeat } from "../logging/diagnostic.js";
import { createSubsystemLogger, runtimeForLogger } from "../logging/subsystem.js";
import { getGlobalHookRunner } from "../plugins/hook-runner-global.js";
import { getGlobalHookRunner, runGlobalGatewayStopSafely } from "../plugins/hook-runner-global.js";
import { getTotalQueueSize } from "../process/command-queue.js";
import { runOnboardingWizard } from "../wizard/onboarding.js";
import { createAuthRateLimiter, type AuthRateLimiter } from "./auth-rate-limit.js";
@@ -720,19 +720,11 @@ export async function startGatewayServer(
return {
close: async (opts) => {
// Run gateway_stop plugin hook before shutdown
{
const hookRunner = getGlobalHookRunner();
if (hookRunner?.hasHooks("gateway_stop")) {
try {
await hookRunner.runGatewayStop(
{ reason: opts?.reason ?? "gateway stopping" },
{ port },
);
} catch (err) {
log.warn(`gateway_stop hook failed: ${String(err)}`);
}
}
}
await runGlobalGatewayStopSafely({
event: { reason: opts?.reason ?? "gateway stopping" },
ctx: { port },
onError: (err) => log.warn(`gateway_stop hook failed: ${String(err)}`),
});
if (diagnosticsEnabled) {
stopDiagnosticHeartbeat();
}