fix: prevent approval from reappearing after interrupt during execution (#571)

Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
Charles Packer
2026-01-16 19:14:39 -08:00
committed by GitHub
parent 0750281d13
commit 28943757a3
4 changed files with 65 additions and 6 deletions

View File

@@ -57,6 +57,7 @@ function spawnWithLauncher(
const stdoutChunks: Buffer[] = [];
const stderrChunks: Buffer[] = [];
let timedOut = false;
let killTimer: ReturnType<typeof setTimeout> | null = null;
const timeoutId = setTimeout(() => {
timedOut = true;
@@ -65,6 +66,13 @@ function spawnWithLauncher(
const abortHandler = () => {
childProcess.kill("SIGTERM");
if (!killTimer) {
killTimer = setTimeout(() => {
if (childProcess.exitCode === null && !childProcess.killed) {
childProcess.kill("SIGKILL");
}
}, 2000);
}
};
if (options.signal) {
options.signal.addEventListener("abort", abortHandler, { once: true });
@@ -82,6 +90,10 @@ function spawnWithLauncher(
childProcess.on("error", (err) => {
clearTimeout(timeoutId);
if (killTimer) {
clearTimeout(killTimer);
killTimer = null;
}
if (options.signal) {
options.signal.removeEventListener("abort", abortHandler);
}
@@ -90,6 +102,10 @@ function spawnWithLauncher(
childProcess.on("close", (code) => {
clearTimeout(timeoutId);
if (killTimer) {
clearTimeout(killTimer);
killTimer = null;
}
if (options.signal) {
options.signal.removeEventListener("abort", abortHandler);
}