Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(team): show turn_end_record_missing in slot rows only while it holds

Jack Rudenko6b51920472be
diff --git a/packages/cli/src/pane/accounting.test.ts b/packages/cli/src/pane/accounting.test.ts
index 1580515e..1f484ca2 100644
--- a/packages/cli/src/pane/accounting.test.ts
+++ b/packages/cli/src/pane/accounting.test.ts
@@ -52,6 +52,7 @@ function snap(over: Partial<PaneSnapshot> = {}): PaneSnapshot {
anomalies: [],
claudeCodeVersion: null,
shape: "one-shot",
+ turnEndRecordMissing: false,
...over,
};
}
@@ -222,6 +223,24 @@ describe("toSlotRow (§8 B)", () => {
expect(failed.idle_seconds).toBeNull();
});
+ test("R3-M4: the row's activity carries turn_end_record_missing only while the condition holds", () => {
+ const acct = mergeAccounting(snap(), null);
+ const id = { slot: "05", model: "m", spawnModel: null };
+ const live = toSlotRow(id, snap({ activity: "finishing", turnEndRecordMissing: true }), acct);
+ expect(live.activity).toBe("finishing: turn_end_record_missing");
+ // the anomaly is history; a slot that resumed work reads plainly
+ const resumed = toSlotRow(
+ id,
+ snap({
+ activity: "Bash",
+ turnEndRecordMissing: false,
+ anomalies: ["turn_end_record_missing"],
+ }),
+ acct
+ );
+ expect(resumed.activity).toBe("Bash");
+ });
+
test("a pane that never spawned has pane null", () => {
const row = toSlotRow(
{ slot: "04", model: "m", spawnModel: null },
diff --git a/packages/cli/src/pane/pane-session.ts b/packages/cli/src/pane/pane-session.ts
index a77ee4ab..f8157e04 100644
--- a/packages/cli/src/pane/pane-session.ts
+++ b/packages/cli/src/pane/pane-session.ts
@@ -316,6 +316,7 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {
private endedAtMs: number | null = null;
private claudeCodeVersion: string | null = null;
private anomalies = new Map<string, number>();
+ private turnEndMissing = false;
private exitScrollback = "";
private exitLastLine = "";
@@ -1101,12 +1102,22 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {
this.escapeSentAt = null;
}
- /** R3-M4: `finishing` with a static screen and no Stop-hook UI for N secondary windows. */
+ /**
+ * R3-M4: `finishing` with a static screen and no Stop-hook UI for N secondary windows.
+ * The condition is live (it clears the moment work resumes); the anomaly counts how often
+ * it began.
+ */
private checkTurnEndMissing(): void {
- if (this.activity !== "finishing" || !this.client) return;
+ if (this.activity !== "finishing") {
+ this.turnEndMissing = false;
+ return;
+ }
+ if (!this.client) return;
const quiet = Date.now() - this.screen.aboveBoxChangedAt;
- if (quiet >= TURN_END_MISSING_FACTOR * this.secondaryQuietMs && !stopHookRunning(this.screen))
- if (!this.anomalies.has("turn_end_record_missing")) this.anomaly("turn_end_record_missing");
+ const missing =
+ quiet >= TURN_END_MISSING_FACTOR * this.secondaryQuietMs && !stopHookRunning(this.screen);
+ if (missing && !this.turnEndMissing) this.anomaly("turn_end_record_missing");
+ this.turnEndMissing = missing;
}
/** Blocked detection (H7): AskUserQuestion from the transcript; permission needs the dialog too. */
@@ -1186,6 +1197,7 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {
}
private finishTurn(turn: SettledTurn, chatOffset: number | null, exitCode: number | null): void {
+ this.turnEndMissing = false;
this.answers.set(turn.index, turn.answer);
// owners ask for the current or the last settled turn: keep a few, not the session's all
for (const k of this.answers.keys()) if (k <= turn.index - KEPT_ANSWERS) this.answers.delete(k);
@@ -1406,6 +1418,11 @@ export class PaneSessionImpl implements PaneSession, RegisteredPane {
anomalies: [...this.anomalies].map(([k, n]) => (n > 1 ? `${k} ×${n}` : k)),
claudeCodeVersion: this.claudeCodeVersion,
shape: this.shape,
+ turnEndRecordMissing:
+ !terminal &&
+ this.phase === "RUNNING" &&
+ this.activity === "finishing" &&
+ this.turnEndMissing,
};
}
diff --git a/packages/cli/src/pane/slot-row.ts b/packages/cli/src/pane/slot-row.ts
index 8158db9b..e204afb3 100644
--- a/packages/cli/src/pane/slot-row.ts
+++ b/packages/cli/src/pane/slot-row.ts
@@ -33,7 +33,12 @@ export function toSlotRow(
turns_completed: snap.turnsCompleted,
last_activity_at: snap.lastActivityAt,
idle_seconds: idle,
- activity: terminal ? null : snap.activity,
+ // R3-M4: the row says so too (§8: an unknown activity value reads as busy)
+ activity: terminal
+ ? null
+ : snap.turnEndRecordMissing && snap.activity
+ ? `${snap.activity}: turn_end_record_missing`
+ : snap.activity,
pane: snap.paneId || null,
};
}
diff --git a/packages/cli/src/pane/test-helpers/fake-interactive-child.ts b/packages/cli/src/pane/test-helpers/fake-interactive-child.ts
index 789e975b..d78ac515 100755
--- a/packages/cli/src/pane/test-helpers/fake-interactive-child.ts
+++ b/packages/cli/src/pane/test-helpers/fake-interactive-child.ts
@@ -521,7 +521,21 @@ async function runScenario(name: string, d: Delivered): Promise<void> {
rec.text(answerFor(c));
showHistory(`⏺ ${answerFor(c)}`, finishedRow());
return;
- case "quiet_no_summary":
+ case "finishing_then_wake":
+ // an ending answer with no end-of-turn record (finishing, static screen), then a
+ // background task notification wakes the model and the turn ends normally
+ rec.text("first part");
+ showHistory("⏺ first part");
+ await sleep(gap("WAKE", 2500));
+ emit(T.bgNotify);
+ {
+ const id = rec.toolUse("Bash", { command: "sleep 2", description: "Sleep" });
+ showHistory("⏺ Sleeping", " ⎿ $ sleep 2");
+ await sleep(gap("WAKE_TOOL", 2000));
+ rec.toolResult(id, "", { stdout: "", stderr: "", interrupted: false, isImage: false });
+ }
+ return answerTurn(c);
+
rec.text(answerFor(c));
showHistory(`⏺ ${answerFor(c)}`, finishedRow());
return;
diff --git a/packages/cli/src/pane/types.ts b/packages/cli/src/pane/types.ts
index 095cd764..e22cec59 100644
--- a/packages/cli/src/pane/types.ts
+++ b/packages/cli/src/pane/types.ts
@@ -66,4 +66,10 @@ export interface PaneSnapshot {
claudeCodeVersion: string | null;
/** the session's shape now: a send to a one-shot session converts it to interactive */
shape: "one-shot" | "interactive";
+ /**
+ * R3-M4, LIVE: the turn is `finishing` with a static screen and no Stop-hook UI for 3
+ * secondary windows. False again as soon as activity leaves `finishing`; the anomaly of
+ * the same name stays in `anomalies` as history.
+ */
+ turnEndRecordMissing: boolean;
}
diff --git a/packages/cli/src/team-heartbeat-survival.test.ts b/packages/cli/src/team-heartbeat-survival.test.ts
index c05619e3..0eb604e5 100644
--- a/packages/cli/src/team-heartbeat-survival.test.ts
+++ b/packages/cli/src/team-heartbeat-survival.test.ts
@@ -8,7 +8,13 @@
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
import { readFileSync } from "node:fs";
import { join } from "node:path";
-import { runModels, setupSession, startModels, teamLiveMaps } from "./team-orchestrator.js";
+import {
+ runModels,
+ setupSession,
+ startModels,
+ teamLiveMaps,
+ teamRunRow,
+} from "./team-orchestrator.js";
import {
MAGMUX,
NO_MAGMUX_MESSAGE,
@@ -66,6 +72,41 @@ describe.skipIf(!MAGMUX)("team slot heartbeat survival", () => {
expect(response.split("ANSWER")).toHaveLength(2);
}, 30_000);
+ it("R3-M4: turn_end_record_missing shows in the row and the map while it holds, and clears when work resumes", async () => {
+ const sessionPath = teamDirOf(t);
+ setupSession(sessionPath, ["fake-finishing_then_wake"], "Answer in two parts.");
+ const handle = await startModels(
+ sessionPath,
+ paneRunOptions(
+ t,
+ { paneTimings: { replStableMs: 200, secondaryQuietMs: 300 } },
+ { FAKE_GAP_MS_WAKE: "3000" }
+ )
+ );
+ const slotId = handle.slots["fake-finishing_then_wake"] as string;
+ const rowActivity = () =>
+ teamRunRow(sessionPath)?.slots.find((s) => s.slot === slotId)?.activity ?? null;
+ await waitUntil(
+ () => teamLiveMaps(sessionPath)?.endRecordMissing.includes(slotId) === true,
+ "endRecordMissing",
+ 10_000
+ );
+ expect(teamLiveMaps(sessionPath)?.activity[slotId]).toBe("finishing: turn_end_record_missing");
+ expect(rowActivity()).toBe("finishing: turn_end_record_missing");
+ // the notification wakes the model and it runs a tool: working again, not wedged
+ await waitUntil(
+ () => teamLiveMaps(sessionPath)?.activity[slotId] === "Bash",
+ "activity Bash, plain",
+ 10_000
+ );
+ expect(teamLiveMaps(sessionPath)?.endRecordMissing ?? []).not.toContain(slotId);
+ expect(rowActivity()).toBe("Bash");
+ const status = await handle.done;
+ expect(status.models[slotId]?.state).toBe("COMPLETED");
+ // the anomaly stays as history in the slot's record (L6: nothing else pinned it)
+ expect(status.models[slotId]?.anomalies ?? []).toContain("turn_end_record_missing");
+ }, 30_000);
+
it("waits out a slow Stop hook after the answer, reading finishing meanwhile", async () => {
const sessionPath = teamDirOf(t);
setupSession(sessionPath, ["fake-slow_stop_hook"], "Answer, then let the hook run.");
diff --git a/packages/cli/src/team-orchestrator.ts b/packages/cli/src/team-orchestrator.ts
index ce94a792..8fed5cb4 100644
--- a/packages/cli/src/team-orchestrator.ts
+++ b/packages/cli/src/team-orchestrator.ts
@@ -662,10 +662,9 @@ export function teamLiveMaps(
const row = toSlotRow({ slot: e.id, model: e.model, spawnModel: e.spawnModel }, snap, e.acct);
if (row.idle_seconds !== null) idle[e.id] = row.idle_seconds;
liveBytes[e.id] = snap.liveAnswerBytes;
- const missing = snap.anomalies.includes("turn_end_record_missing");
- if (missing) endRecordMissing.push(e.id);
- if (row.activity !== null)
- activity[e.id] = missing ? `${row.activity}: turn_end_record_missing` : row.activity;
+ // the live condition, never the anomaly history: a slot that resumed work is not wedged
+ if (snap.turnEndRecordMissing) endRecordMissing.push(e.id);
+ if (row.activity !== null) activity[e.id] = row.activity;
}
return { idle, activity, liveBytes, endRecordMissing };
}