fix(exec): apply default timeout to background sessions

This commit is contained in:
pandego 2026-02-27 13:41:05 +01:00
parent 84a88b2ace
commit 46559bf766
2 changed files with 6 additions and 27 deletions

View File

@ -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 () => {

View File

@ -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;