Skip to content

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

fix(team): give a settled disk-read run a finished_at without completedAt

Jack Rudenkofb27b07e4f47
diff --git a/packages/cli/src/team-orchestrator.ts b/packages/cli/src/team-orchestrator.ts
index 385a6824..e9954f50 100644
--- a/packages/cli/src/team-orchestrator.ts
+++ b/packages/cli/src/team-orchestrator.ts
@@ -1,5 +1,5 @@
import { randomBytes, randomUUID } from "node:crypto";
-import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
+import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
import { basename, join, resolve } from "node:path";
import { type SpawnPlan, prehydrateCredentialsForSpawn } from "./auth/credentials/prehydrate.js";
import { ENV } from "./config.js";
@@ -539,14 +539,29 @@ export function teamRunRowFromDisk(path: string, status: TeamStatus): TeamRunRow
path,
kind: status.kind ?? (basename(path) === "judging" ? "judge" : "run"),
started_at: status.startedAt,
- finished_at:
- settled && completions.length ? new Date(Math.max(...completions)).toISOString() : null,
+ // a SETTLED run always has finished_at (§8 A): pre-contract CANCELLED rows carry no
+ // completedAt, so the file's own last write stands in, else the start
+ finished_at: settled
+ ? new Date(
+ completions.length
+ ? Math.max(...completions)
+ : (statusMtimeMs(path) ?? Date.parse(status.startedAt))
+ ).toISOString()
+ : null,
state: settled ? "SETTLED" : "ACTIVE",
outcome: settled ? outcomeOf(slots.map((s) => s.state)) : null,
slots,
};
}
+function statusMtimeMs(path: string): number | null {
+ try {
+ return statSync(join(path, "status.json")).mtimeMs;
+ } catch {
+ return null;
+ }
+}
+
function readManifestOrNull(path: string): TeamManifest | null {
try {
return JSON.parse(readFileSync(join(path, "manifest.json"), "utf-8")) as TeamManifest;
diff --git a/packages/cli/src/team-status-payload.test.ts b/packages/cli/src/team-status-payload.test.ts
index cc031ec5..640b6279 100644
--- a/packages/cli/src/team-status-payload.test.ts
+++ b/packages/cli/src/team-status-payload.test.ts
@@ -1,4 +1,7 @@
import { describe, expect, test } from "bun:test";
+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
import { buildTeamStatusPayload, teamStatusNote } from "./mcp-server.js";
import { CAPABILITIES, type TeamRunRow } from "./pane/index.js";
import { type ModelStatus, type TeamStatus, teamRunRowFromDisk } from "./team-orchestrator.js";
@@ -67,6 +70,28 @@ describe("teamStatusNote", () => {
});
});
+describe("teamRunRowFromDisk", () => {
+ test("a SETTLED run whose rows carry no completedAt still has a finished_at", () => {
+ const dir = mkdtempSync(join(tmpdir(), "team-disk-row-"));
+ try {
+ const status = {
+ startedAt: "2026-09-09T00:00:00.000Z",
+ models: {
+ "01": { ...slot("CANCELLED", 0), completedAt: undefined },
+ "02": { ...slot("CANCELLED", 0), completedAt: undefined },
+ },
+ } as unknown as TeamStatus;
+ writeFileSync(join(dir, "status.json"), JSON.stringify(status));
+ const row = teamRunRowFromDisk(dir, status);
+ expect(row.state).toBe("SETTLED");
+ expect(typeof row.finished_at).toBe("string");
+ expect(Date.parse(row.finished_at as string)).toBeGreaterThan(Date.parse(status.startedAt));
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+ });
+});
+
describe("buildTeamStatusPayload", () => {
test("a pre-contract slot state reads in the closed SlotState set, as run does", () => {
const status = {