From 6cbac2bf4cdb031c8ad4bea2387917d5a4cb0664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=81=D0=B5=D0=BB=D1=8C?= Date: Fri, 13 Nov 2026 14:37:46 +0500 Subject: [PATCH] PEP-22: runner waits for tmux to reap the agent before reading its exit status Co-Authored-By: Claude Opus 5.5 --- packages/runner/src/tmux.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/runner/src/tmux.ts b/packages/runner/src/tmux.ts index fedf053f..5f14e7bf 100644 --- a/packages/runner/src/tmux.ts +++ b/packages/runner/src/tmux.ts @@ -45,9 +45,15 @@ export interface PaneState { } export async function paneState(name: string): Promise { - const out = (await tmux("display-message", "-p", "-t", `=${name}:`, "#{pane_dead} #{pane_dead_status}")).trim(); - const [dead, status] = out.split(" "); - return { dead: dead === "1", exitStatus: status ? Number(status) : null }; + // tmux marks the pane dead when the pty closes, which can come before it reaps the child: + // for a moment there is neither an exit status nor a signal. Give it a second to catch up. + for (let attempt = 0; ; attempt++) { + const out = (await tmux("display-message", "-p", "-t", `=${name}:`, "#{pane_dead} #{pane_dead_status} #{pane_dead_signal}")).trim(); + const [dead, status, signal] = out.split(" "); + if (dead !== "1") return { dead: false, exitStatus: null }; + if (status || signal || attempt >= 10) return { dead: true, exitStatus: status ? Number(status) : null }; + await new Promise((r) => setTimeout(r, 100)); + } } /** Visible screen (plus `history` lines of scrollback) as plain text. */