From 6ce75db150fcb584cef1f3147cabb2db12570163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Padez?= Date: Wed, 22 Jul 2026 22:09:43 +0000 Subject: [PATCH] task runner: keepalive ping so long silent tasks don't get killed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit a script task that goes silent for a while (e.g. ffmpeg's faststart pass rewrites a huge file for minutes with no output) would hit Bun's default 120s websocket idle timeout → close(ws) → killTree killed the task mid-run, corrupting the output. now the executor pings the socket every 30s while a task runs, resetting the idle timer. Co-Authored-By: Claude Opus 4.8 --- src/servers/api/tasks/task-executor.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/servers/api/tasks/task-executor.ts b/src/servers/api/tasks/task-executor.ts index ed951787..e6544e11 100644 --- a/src/servers/api/tasks/task-executor.ts +++ b/src/servers/api/tasks/task-executor.ts @@ -235,6 +235,13 @@ async function handleRun(ws: ServerWebSocket, msg: RunMessage) { }, }); + // Keep the WebSocket alive during long silent phases (e.g. ffmpeg's faststart pass rewrites a huge + // file for minutes with no output). Bun's default 120s idle timeout would otherwise close the + // socket → close(ws) → killTree kills the task mid-run. A ping resets the idle timer. + const keepAlive = setInterval(() => { + try { ws.ping(); } catch { /* socket gone */ } + }, 30_000); + const stdoutReader = proc.stdout.getReader(); const stderrReader = proc.stderr.getReader(); const decoder = new TextDecoder(); @@ -257,6 +264,7 @@ async function handleRun(ws: ServerWebSocket, msg: RunMessage) { proc.exited, ]); + clearInterval(keepAlive); activeProcs.delete(ws); cleanup(); send(ws, { type: 'exit', code: exitCode });