fix: expand exec abort/timeout coverage

This commit is contained in:
Peter Steinberger
2026-01-16 10:43:08 +00:00
parent 9c4c9c5edd
commit f49d0e5476
3 changed files with 109 additions and 6 deletions

View File

@@ -262,22 +262,28 @@ export function createExecTool(
fn();
};
const onAbort = () => {
// Tool-call abort should not kill backgrounded sessions; timeouts still must.
const onAbortSignal = () => {
if (yielded || session.backgrounded) return;
killSession(session);
};
if (signal?.aborted) onAbort();
// Timeouts always terminate, even for backgrounded sessions.
const onTimeout = () => {
timedOut = true;
killSession(session);
};
if (signal?.aborted) onAbortSignal();
else if (signal) {
signal.addEventListener("abort", onAbort, { once: true });
signal.addEventListener("abort", onAbortSignal, { once: true });
}
const effectiveTimeout =
typeof params.timeout === "number" ? params.timeout : defaultTimeoutSec;
if (effectiveTimeout > 0) {
timeoutTimer = setTimeout(() => {
timedOut = true;
onAbort();
onTimeout();
}, effectiveTimeout * 1000);
}