From 46559bf7666c9a9b168fd4a5547d950761a2674c Mon Sep 17 00:00:00 2001 From: pandego <7780875+pandego@users.noreply.github.com> Date: Fri, 27 Feb 2026 13:41:05 +0100 Subject: [PATCH] fix(exec): apply default timeout to background sessions --- .../bash-tools.exec.background-abort.test.ts | 27 ++++--------------- src/agents/bash-tools.exec.ts | 6 +---- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/agents/bash-tools.exec.background-abort.test.ts b/src/agents/bash-tools.exec.background-abort.test.ts index 5c825177046..7eb487c554e 100644 --- a/src/agents/bash-tools.exec.background-abort.test.ts +++ b/src/agents/bash-tools.exec.background-abort.test.ts @@ -142,33 +142,16 @@ test("background exec still times out after tool signal abort", async () => { }); }); -test("background exec without explicit timeout ignores default timeout", async () => { +test("background exec without explicit timeout uses default timeout", async () => { const tool = createTestExecTool({ allowBackground: true, backgroundMs: 0, timeoutSec: BACKGROUND_TIMEOUT_SEC, }); - const result = await tool.execute("toolcall", { command: BACKGROUND_HOLD_CMD, background: true }); - expect(result.details.status).toBe("running"); - const sessionId = (result.details as { sessionId: string }).sessionId; - const waitMs = Math.max(ABORT_SETTLE_MS + 80, BACKGROUND_TIMEOUT_SEC * 1000 + 80); - - const startedAt = Date.now(); - await expect - .poll( - () => { - const running = getSession(sessionId); - const finished = getFinishedSession(sessionId); - return Date.now() - startedAt >= waitMs && !finished && running?.exited === false; - }, - { - timeout: waitMs + ABORT_WAIT_TIMEOUT_MS, - interval: POLL_INTERVAL_MS, - }, - ) - .toBe(true); - - cleanupRunningSession(sessionId); + await expectBackgroundSessionTimesOut({ + tool, + executeParams: { command: BACKGROUND_HOLD_CMD, background: true }, + }); }); test("yielded background exec still times out", async () => { diff --git a/src/agents/bash-tools.exec.ts b/src/agents/bash-tools.exec.ts index 105815cf3d8..0fbf718f581 100644 --- a/src/agents/bash-tools.exec.ts +++ b/src/agents/bash-tools.exec.ts @@ -456,11 +456,7 @@ export function createExecTool( } const explicitTimeoutSec = typeof params.timeout === "number" ? params.timeout : null; - const backgroundTimeoutBypass = - allowBackground && explicitTimeoutSec === null && (backgroundRequested || yieldRequested); - const effectiveTimeout = backgroundTimeoutBypass - ? null - : (explicitTimeoutSec ?? defaultTimeoutSec); + const effectiveTimeout = explicitTimeoutSec ?? defaultTimeoutSec; const getWarningText = () => (warnings.length ? `${warnings.join("\n")}\n\n` : ""); const usePty = params.pty === true && !sandbox;