fix(codex): bound native hook cleanup grace

This commit is contained in:
Peter Steinberger
2026-05-30 18:09:49 -04:00
parent f71df664c9
commit 3d0dc15904
2 changed files with 14 additions and 2 deletions

View File

@@ -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?: {

View File

@@ -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,
);
}