PEP-22: read a zombie agent's exit code from /proc when tmux never reaps it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
83b222b9e2
commit
d1c555a038
@ -10,9 +10,9 @@
|
||||
- [x] 2.3 `openspec validate`, проверка на своём PR, archive
|
||||
|
||||
Итог 2.1: локально 10 прогонов подряд зелёные (82→113 тестов после rebase, ~165 с), в job PR зелёный.
|
||||
В job всплыл настоящий баг: tmux помечает панель мёртвой раньше, чем знает код выхода → «упал (код null)»;
|
||||
`paneState` теперь дожидается статуса или сигнала (до 1 с). Убраны гонки
|
||||
«фиксированная пауза → один тик → assert»: ожидание диалога разрешения по событию `dialog`
|
||||
мока, баннер лимита (Codex) — `waitFor` с тиком вачдога.
|
||||
В job всплыл настоящий баг: tmux на Linux помечает панель мёртвой, но иногда так и не забирает
|
||||
процесс агента (зомби, родитель — сервер tmux), и код выхода неизвестен → «упал (код null)».
|
||||
`paneState` ждёт статус до 1 с, а для зомби берёт код из `/proc/<pid>/stat` (exit_code). На macOS
|
||||
(прод) не воспроизводится, но поведение то же.
|
||||
Решение: БД на прогон (`PEPPA_TEST_DB`), а не на файл — файлы идут последовательно
|
||||
(`--test-concurrency=1`), изоляции на прогон хватает для параллельных worktree.
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { execFile, spawn } from "node:child_process";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
const run = promisify(execFile);
|
||||
@ -46,16 +47,32 @@ export interface PaneState {
|
||||
|
||||
export async function paneState(name: string): Promise<PaneState> {
|
||||
// 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.
|
||||
// then there is neither an exit status nor a signal yet. On Linux tmux sometimes never reaps
|
||||
// it at all (seen in CI containers) — the zombie still holds its status in /proc.
|
||||
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(" ");
|
||||
const out = (await tmux("display-message", "-p", "-t", `=${name}:`, "#{pane_dead} #{pane_dead_status} #{pane_dead_signal} #{pane_pid}")).trim();
|
||||
const [dead, status, signal, pid] = out.split(" ");
|
||||
if (dead !== "1") return { dead: false, exitStatus: null };
|
||||
if (status || signal || attempt >= 10) return { dead: true, exitStatus: status ? Number(status) : null };
|
||||
if (status || signal) return { dead: true, exitStatus: status ? Number(status) : null };
|
||||
const zombie = zombieExitStatus(Number(pid));
|
||||
if (zombie !== undefined || attempt >= 10) return { dead: true, exitStatus: zombie ?? null };
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
}
|
||||
}
|
||||
|
||||
/** Exit code of a not-yet-reaped process from /proc (Linux); null if it died by a signal. */
|
||||
function zombieExitStatus(pid: number): number | null | undefined {
|
||||
try {
|
||||
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
|
||||
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
||||
if (fields[0] !== "Z") return undefined;
|
||||
const wait = Number(fields[49]); // field 52: exit_code, in waitpid() format
|
||||
return (wait & 0x7f) === 0 ? (wait >> 8) & 0xff : null;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/** Visible screen (plus `history` lines of scrollback) as plain text. */
|
||||
export async function capturePane(name: string, history = 0): Promise<string> {
|
||||
return tmux("capture-pane", "-p", "-J", "-t", `=${name}:`, "-S", String(-history));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user