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. */