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 <noreply@anthropic.com>
This commit is contained in:
Prateek 2026-02-14 05:17:15 +05:30
parent 323fd2da21
commit 09e1a85b1c
1 changed files with 14 additions and 2 deletions

View File

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