Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(pane): store the exit code with the exit, so a settle in the capture window keeps it
Jack Rudenko3dce467709aa
diff --git a/packages/cli/src/pane/pane-hooks.integration.test.ts b/packages/cli/src/pane/pane-hooks.integration.test.tsindex 63d7b582..1e46d055 100644--- a/packages/cli/src/pane/pane-hooks.integration.test.ts+++ b/packages/cli/src/pane/pane-hooks.integration.test.ts@@ -1421,6 +1421,7 @@ wait $childasync function direct(o: {script: TurnScript[];hooks?: SessionHookBinding;+ exitCaptureDelayMs?: number;}): Promise<Direct> {const t = env(o.script);const uuid = newSessionUuid();@@ -1448,7 +1449,11 @@ wait $childonBlocked: () => ({ state: "FAILED", reason: "blocked" }),onTransition: (x) => void transitions.push([x.from, x.to]),onTurnRecorded: (turn) => void recorded.push(turn),- timings: { replStableMs: 200, corroborationMs: 200 },+ timings: {+ replStableMs: 200,+ corroborationMs: 200,+ ...(o.exitCaptureDelayMs ? { exitCaptureDelayMs: o.exitCaptureDelayMs } : {}),+ },...(o.hooks ? { hooks: o.hooks } : {}),});return { s, t, uuid, transitions, recorded, decided };@@ -1534,6 +1539,40 @@ wait $childT);+ test(+ "H-27b the end record settles inside the exit-capture window: the exit note keeps its code",+ async () => {+ // The interleaving H-27 hits under load, made deterministic: the exit event is+ // processed (the pane is known dead) and the session is still capturing the final+ // screen when a tick settles the turn on its end record. The note must carry the+ // code the exit event reported, never a bare "pane child exited".+ const ctl = controlled();+ const d = await direct({+ script: [{ delayMs: 1000, say: "ANS-ONE" }],+ hooks: ctl.binding,+ exitCaptureDelayMs: 4000,+ });+ try {+ await until(+ () => d.transitions.some(([, to]) => to === "RUNNING"),+ "the turn is RUNNING"+ );+ const exit = (+ d.s as unknown as { onPaneExit(e: { exitCode: number; lastLine: string }): void }+ ).onPaneExit.bind(d.s);+ exit({ exitCode: 0, lastLine: "" });+ const snap = await d.s.terminal;+ expect(ctl.calls).toEqual([]);+ expect(snap.state).toBe("COMPLETED");+ expect(snap.detail ?? "").toContain("pane child exited 0");+ expect(d.decided.map((t) => t.answer)).toEqual(["ANS-ONE"]);+ } finally {+ await directDone(d);+ }+ },+ T+ );+test("H-28 binding absent: today's events — no record callback, no SETTLING, chain fields at their no-hook values",async () => {diff --git a/packages/cli/src/pane/pane-session.ts b/packages/cli/src/pane/pane-session.tsindex e4c53f33..3c244227 100644--- a/packages/cli/src/pane/pane-session.ts+++ b/packages/cli/src/pane/pane-session.ts@@ -1046,9 +1046,13 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {/** The pane child exited (magmux `exit` event, or a dead pane found on reconnect). */private async onPaneExit(e: { exitCode?: unknown; lastLine?: unknown }): Promise<void> {if (this.paneExited || isTerminalPhase(this.phase)) return;- this.paneExited = true;const code = typeof e?.exitCode === "number" ? e.exitCode : null;const lastLine = typeof e?.lastLine === "string" ? e.lastLine : "";+ // The code is stored with the exit itself, not after the capture below: a tick that+ // settles the turn inside that window concludes with this code (H-27).+ this.paneExited = true;+ this.exitCode = code;+ this.exitLastLine = lastLine;// The final screen, with scrollback, so a long agent list cannot hide the refusal (L8).const slow = this.o.timings?.exitCaptureDelayMs;if (slow) await Bun.sleep(slow);@@ -1064,11 +1068,7 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {)this.exitScrollback = cap.result.text ?? "";}- this.step(() => {- this.exitCode = code;- this.exitLastLine = lastLine;- this.applyExitPath(code);- });+ this.step(() => this.applyExitPath(code));}/* ───────────────────────────── the step ───────────────────────────── */@@ -2482,7 +2482,7 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {return;}if (exitCode !== null || this.paneExited) {- const note = `pane child exited${exitCode === null ? "" : ` ${exitCode}`}`;+ const note = exitNoteOf(exitCode ?? this.exitCode);verdict = { ...verdict, detail: verdict.detail ? `${verdict.detail} · ${note}` : note };}this.applyVerdict(verdict);@@ -2540,7 +2540,7 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {}}if (!work) {- this.conclude(exited ? exitNoteOf(exitCode) : null);+ this.conclude(exited ? exitNoteOf(exitCode ?? this.exitCode) : null);return;}this.startHold(turn);