diff --git a/extensions/codex/src/app-server/native-hook-relay.test.ts b/extensions/codex/src/app-server/native-hook-relay.test.ts index d3985ae2352..a4f2b953425 100644 --- a/extensions/codex/src/app-server/native-hook-relay.test.ts +++ b/extensions/codex/src/app-server/native-hook-relay.test.ts @@ -1,8 +1,10 @@ import type { NativeHookRelayRegistrationHandle } from "openclaw/plugin-sdk/agent-harness-runtime"; +import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime"; import { describe, expect, it } from "vitest"; import { buildCodexNativeHookRelayConfig, buildCodexNativeHookRelayDisabledConfig, + resolveCodexNativeHookRelayUnregisterGraceMs, } from "./native-hook-relay.js"; describe("Codex native hook relay config", () => { @@ -251,6 +253,12 @@ describe("Codex native hook relay config", () => { "hooks.Stop": [], }); }); + + it("caps oversized native hook cleanup grace before scheduling", () => { + expect(resolveCodexNativeHookRelayUnregisterGraceMs(Number.MAX_SAFE_INTEGER)).toBe( + MAX_TIMER_TIMEOUT_MS, + ); + }); }); function createRelay(options?: { diff --git a/extensions/codex/src/app-server/native-hook-relay.ts b/extensions/codex/src/app-server/native-hook-relay.ts index a0d3b939c1b..1f10d095659 100644 --- a/extensions/codex/src/app-server/native-hook-relay.ts +++ b/extensions/codex/src/app-server/native-hook-relay.ts @@ -5,6 +5,10 @@ import { type NativeHookRelayEvent, type NativeHookRelayRegistrationHandle, } from "openclaw/plugin-sdk/agent-harness-runtime"; +import { + addTimerTimeoutGraceMs, + finiteSecondsToTimerSafeMilliseconds, +} from "openclaw/plugin-sdk/number-runtime"; import type { CodexAppServerRuntimeOptions } from "./config.js"; import type { JsonObject, JsonValue } from "./protocol.js"; @@ -61,11 +65,11 @@ export function resolveCodexNativeHookRelayUnregisterGraceMs( ): number { const hookTimeoutMs = typeof hookTimeoutSec === "number" && Number.isFinite(hookTimeoutSec) && hookTimeoutSec > 0 - ? Math.ceil(hookTimeoutSec) * 1000 + ? (finiteSecondsToTimerSafeMilliseconds(Math.ceil(hookTimeoutSec)) ?? 0) : 0; return Math.max( CODEX_NATIVE_HOOK_RELAY_UNREGISTER_GRACE_MS, - hookTimeoutMs + CODEX_NATIVE_HOOK_RELAY_UNREGISTER_EXTRA_GRACE_MS, + addTimerTimeoutGraceMs(hookTimeoutMs, CODEX_NATIVE_HOOK_RELAY_UNREGISTER_EXTRA_GRACE_MS) ?? 0, ); }