From 09e1a85b1c9fabcdc0a1ff02cc9f99006ad3083b Mon Sep 17 00:00:00 2001 From: Prateek Date: Sat, 14 Feb 2026 05:17:15 +0530 Subject: [PATCH] fix: clean up tmux session when launch command send-keys fails If send-keys fails after new-session succeeds, the orphaned tmux session was left running and unmanaged. Now wraps send-keys in try/catch that kills the session before rethrowing. Co-Authored-By: Claude Opus 4.6 --- packages/plugins/runtime-tmux/src/index.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/plugins/runtime-tmux/src/index.ts b/packages/plugins/runtime-tmux/src/index.ts index a69e2fa62..d74e09af7 100644 --- a/packages/plugins/runtime-tmux/src/index.ts +++ b/packages/plugins/runtime-tmux/src/index.ts @@ -54,8 +54,20 @@ export function create(): Runtime { // Create tmux session in detached mode await tmux("new-session", "-d", "-s", sessionName, "-c", config.workspacePath, ...envArgs); - // Send the launch command - await tmux("send-keys", "-t", sessionName, config.launchCommand, "Enter"); + // Send the launch command — clean up the session if this fails + try { + await tmux("send-keys", "-t", sessionName, config.launchCommand, "Enter"); + } catch (err: unknown) { + try { + await tmux("kill-session", "-t", sessionName); + } catch { + // Best-effort cleanup + } + const msg = err instanceof Error ? err.message : String(err); + throw new Error(`Failed to send launch command to session "${sessionName}": ${msg}`, { + cause: err, + }); + } return { id: sessionName,