diff --git a/scripts/run-with-env.mjs b/scripts/run-with-env.mjs index b71bfb506d7..3d152e91c57 100644 --- a/scripts/run-with-env.mjs +++ b/scripts/run-with-env.mjs @@ -4,6 +4,7 @@ import { resolveWindowsTaskkillPath } from "./lib/windows-taskkill.mjs"; const ENV_ASSIGNMENT_RE = /^[A-Za-z_][A-Za-z0-9_]*=/u; const USAGE = "Usage: node scripts/run-with-env.mjs KEY=value [KEY=value ...] -- command [args...]"; +const MAX_TIMER_TIMEOUT_MS = 2_147_000_000; /** * Detects help requests before the command separator. @@ -78,7 +79,7 @@ export function resolveForceKillDelayMs(env = process.env) { if (!Number.isSafeInteger(parsed) || parsed < 1) { throw new Error("OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS must be a positive integer"); } - return parsed; + return Math.min(parsed, MAX_TIMER_TIMEOUT_MS); } /** diff --git a/test/scripts/run-with-env.test.ts b/test/scripts/run-with-env.test.ts index 11fe181ac1b..7635dc91538 100644 --- a/test/scripts/run-with-env.test.ts +++ b/test/scripts/run-with-env.test.ts @@ -3,6 +3,7 @@ import { spawn, spawnSync, type ChildProcess } from "node:child_process"; import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; +import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion"; import { describe, expect, it, vi } from "vitest"; import { isRunWithEnvHelpRequest, @@ -152,6 +153,11 @@ describe("run-with-env", () => { it("rejects malformed force-kill grace configuration before spawning", () => { expect(resolveForceKillDelayMs({})).toBe(5_000); expect(resolveForceKillDelayMs({ OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: "250" })).toBe(250); + expect( + resolveForceKillDelayMs({ + OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: String(MAX_TIMER_TIMEOUT_MS + 1), + }), + ).toBe(MAX_TIMER_TIMEOUT_MS); for (const value of ["0", "-1", "1e3", "100ms"]) { expect(() => resolveForceKillDelayMs({ OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: value })).toThrow( "OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS must be a positive integer", @@ -393,7 +399,10 @@ describe("run-with-env", () => { ], { cwd: process.cwd(), - env: { ...process.env, OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: "1000" }, + env: { + ...process.env, + OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: String(MAX_TIMER_TIMEOUT_MS + 1), + }, stdio: "ignore", }, );