fix(coding-agent): reject oversized bash timeouts

closes #6181
This commit is contained in:
Vegard Stikbakke
2026-06-30 15:01:02 +02:00
parent 0ac3cfe09b
commit cbcf4e04c3
4 changed files with 50 additions and 7 deletions
+1
View File
@@ -10,6 +10,7 @@
### Fixed
- Fixed oversized harness shell execution timeouts to fail with a clear validation error instead of being clamped to an immediate timeout ([#6181](https://github.com/earendil-works/pi/issues/6181)).
- Fixed `Agent.prepareNextTurn` to keep receiving the run abort signal instead of the next-turn context.
## [0.80.2] - 2026-06-23
+22 -2
View File
@@ -28,6 +28,23 @@ import {
toError,
} from "../types.ts";
const MAX_TIMEOUT_MS = 2_147_483_647;
const MAX_TIMEOUT_SECONDS = MAX_TIMEOUT_MS / 1000;
function resolveTimeoutMs(timeout: number | undefined): Result<number | undefined, ExecutionError> {
if (timeout === undefined) return ok(undefined);
if (!Number.isFinite(timeout)) {
return err(new ExecutionError("timeout", "Invalid timeout: must be a finite number of seconds"));
}
if (timeout <= 0) return ok(undefined);
const timeoutMs = timeout * 1000;
if (timeoutMs > MAX_TIMEOUT_MS) {
return err(new ExecutionError("timeout", `Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`));
}
return ok(timeoutMs);
}
function resolvePath(cwd: string, path: string): string {
return isAbsolute(path) ? path : resolve(cwd, path);
}
@@ -258,6 +275,9 @@ export class NodeExecutionEnv implements ExecutionEnv {
},
): Promise<Result<{ stdout: string; stderr: string; exitCode: number }, ExecutionError>> {
if (options?.abortSignal?.aborted) return err(new ExecutionError("aborted", "aborted"));
const timeoutMsResult = resolveTimeoutMs(options?.timeout);
if (!timeoutMsResult.ok) return err(timeoutMsResult.error);
const timeoutMs = timeoutMsResult.value;
const cwd = options?.cwd ? resolvePath(this.cwd, options.cwd) : this.cwd;
const shellConfig = await getShellConfig(this.shellPath);
@@ -310,13 +330,13 @@ export class NodeExecutionEnv implements ExecutionEnv {
}
timeoutId =
typeof options?.timeout === "number"
timeoutMs !== undefined
? setTimeout(() => {
timedOut = true;
if (child?.pid) {
killProcessTree(child.pid);
}
}, options.timeout * 1000)
}, timeoutMs)
: undefined;
if (options?.abortSignal) {