Skip to content

Commit 61db243

Browse files
axisrowclaude
andcommitted
fix: reject sub-millisecond initialize timeout overrides
The `parsed <= 0` guard ran before `Math.floor`, so a positive fraction such as `0.5` passed validation and then floored to `0`. request() only arms its timer when `timeoutMs > 0`, so that silently disarmed the handshake deadline entirely and a wedged spawned app-server would hang forever — exactly the failure mode this deadline exists to prevent (fork #29/#31). Floor first, then validate. A sub-millisecond budget is unusable input, so it falls back to the 10s default rather than clamping to an instantly-failing 1ms. Math.floor(NaN)/Math.floor(Infinity) stay non-finite, so the existing garbage-input cases are unaffected. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01LA3HNpq2wRzWpRDBnHusvw
1 parent 5a8a376 commit 61db243

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎plugins/codex/scripts/lib/app-server.mjs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ export function resolveSpawnedInitializeTimeoutMs(env = process.env) {
4848
return DEFAULT_SPAWNED_INITIALIZE_TIMEOUT_MS;
4949
}
5050

51-
const parsed = Number(rawValue);
51+
// Validate *after* flooring: a positive fraction like 0.5 passes a `parsed > 0`
52+
// check but floors to 0, and request() only arms its timer when timeoutMs > 0.
53+
// That would silently disarm the handshake deadline and let a wedged spawned
54+
// app-server hang forever — the failure mode this deadline exists to prevent
55+
// (fork #29/#31). A sub-millisecond budget is unusable input, so fall back to
56+
// the default rather than clamping it to an instantly-failing 1ms.
57+
const parsed = Math.floor(Number(rawValue));
5258
if (!Number.isFinite(parsed) || parsed <= 0) {
5359
return DEFAULT_SPAWNED_INITIALIZE_TIMEOUT_MS;
5460
}
55-
return Math.floor(parsed);
61+
return parsed;
5662
}
5763

5864
// Bound the broker socket's graceful close the same way the spawned client

‎tests/spawned-initialize-timeout-override.test.mjs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ test("resolveSpawnedInitializeTimeoutMs honours the env override", () => {
2626
);
2727
});
2828

29+
// A positive fraction passes a `parsed > 0` check but floors to 0, and request()
30+
// only installs its timer when timeoutMs > 0 — so a sub-millisecond override
31+
// would silently disarm the handshake deadline entirely and let a wedged
32+
// spawned app-server hang forever (the #29/#31 class this deadline exists to
33+
// prevent). Never resolve to 0.
34+
test("resolveSpawnedInitializeTimeoutMs never resolves a positive override to 0", () => {
35+
for (const rawValue of ["0.5", "0.9", "1e-9", "0.0001"]) {
36+
const resolved = resolveSpawnedInitializeTimeoutMs({
37+
[SPAWNED_INITIALIZE_TIMEOUT_ENV]: rawValue
38+
});
39+
assert.ok(resolved > 0, `${rawValue} resolved to ${resolved}, which disarms the deadline`);
40+
// Sub-millisecond is unusable input, so it falls back to the default rather
41+
// than becoming a 1ms deadline that would fail instantly.
42+
assert.equal(resolved, DEFAULT_SPAWNED_INITIALIZE_TIMEOUT_MS);
43+
}
44+
});
45+
2946
test("resolveSpawnedInitializeTimeoutMs falls back to the default on unusable values", () => {
3047
for (const rawValue of [undefined, "", " ", "abc", "-1", "NaN", "Infinity"]) {
3148
assert.equal(

0 commit comments

Comments
 (0)