Skip to content

Commit 095a44c

Browse files
committed
fix(scripts): clamp run-with-env kill timer
1 parent 29eba5a commit 095a44c

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎scripts/run-with-env.mjs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { resolveWindowsTaskkillPath } from "./lib/windows-taskkill.mjs";
44

55
const ENV_ASSIGNMENT_RE = /^[A-Za-z_][A-Za-z0-9_]*=/u;
66
const USAGE = "Usage: node scripts/run-with-env.mjs KEY=value [KEY=value ...] -- command [args...]";
7+
const MAX_TIMER_TIMEOUT_MS = 2_147_000_000;
78

89
/**
910
* Detects help requests before the command separator.
@@ -78,7 +79,7 @@ export function resolveForceKillDelayMs(env = process.env) {
7879
if (!Number.isSafeInteger(parsed) || parsed < 1) {
7980
throw new Error("OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS must be a positive integer");
8081
}
81-
return parsed;
82+
return Math.min(parsed, MAX_TIMER_TIMEOUT_MS);
8283
}
8384

8485
/**

‎test/scripts/run-with-env.test.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { spawn, spawnSync, type ChildProcess } from "node:child_process";
33
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
44
import { tmpdir } from "node:os";
55
import path from "node:path";
6+
import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion";
67
import { describe, expect, it, vi } from "vitest";
78
import {
89
isRunWithEnvHelpRequest,
@@ -152,6 +153,11 @@ describe("run-with-env", () => {
152153
it("rejects malformed force-kill grace configuration before spawning", () => {
153154
expect(resolveForceKillDelayMs({})).toBe(5_000);
154155
expect(resolveForceKillDelayMs({ OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: "250" })).toBe(250);
156+
expect(
157+
resolveForceKillDelayMs({
158+
OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: String(MAX_TIMER_TIMEOUT_MS + 1),
159+
}),
160+
).toBe(MAX_TIMER_TIMEOUT_MS);
155161
for (const value of ["0", "-1", "1e3", "100ms"]) {
156162
expect(() => resolveForceKillDelayMs({ OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: value })).toThrow(
157163
"OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS must be a positive integer",
@@ -393,7 +399,10 @@ describe("run-with-env", () => {
393399
],
394400
{
395401
cwd: process.cwd(),
396-
env: { ...process.env, OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: "1000" },
402+
env: {
403+
...process.env,
404+
OPENCLAW_RUN_WITH_ENV_FORCE_KILL_MS: String(MAX_TIMER_TIMEOUT_MS + 1),
405+
},
397406
stdio: "ignore",
398407
},
399408
);

0 commit comments

Comments
 (0)