Skip to content

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

fix(team): write a slot's terminal row even when its response file fails

Jack Rudenko511b1227dbf0
diff --git a/packages/cli/src/team-orchestrator.ts b/packages/cli/src/team-orchestrator.ts
index 4df0eff2..8e200ed2 100644
--- a/packages/cli/src/team-orchestrator.ts
+++ b/packages/cli/src/team-orchestrator.ts
@@ -1234,9 +1234,18 @@ async function startModelsIn(
);
/** `response-<id>.md` in one write, byte-exact; remembered so it is written once. */
+ /**
+ * The slot's response file. A failed write (disk full, the directory removed mid-run)
+ * must not throw out of the verdict or the terminal patch: the slot's terminal row is
+ * still written, and the failure goes to the slot's error log instead.
+ */
function writeResponse(e: SlotEntry, text: string): string {
- writeFileSync(join(path, `response-${e.id}.md`), text, "utf-8");
e.answer = text;
+ try {
+ writeFileSync(join(path, `response-${e.id}.md`), text, "utf-8");
+ } catch (err) {
+ persistErrorLog(errorLogPathOf(e.id), `response file not written: ${String(err)}`, []);
+ }
return text;
}
diff --git a/packages/cli/src/team-response-write.test.ts b/packages/cli/src/team-response-write.test.ts
new file mode 100644
index 00000000..cde98cbd
--- /dev/null
+++ b/packages/cli/src/team-response-write.test.ts
@@ -0,0 +1,48 @@
+/**
+ * A slot whose response file cannot be written still ends with its terminal row in
+ * status.json (the write failure goes to the slot's error log), instead of keeping its
+ * last non-terminal state forever while `run` says SETTLED.
+ */
+
+import { afterEach, beforeEach, describe, expect, it } from "bun:test";
+import { mkdirSync, readFileSync } from "node:fs";
+import { join } from "node:path";
+import { getStatus, setupSession, startModels } from "./team-orchestrator.js";
+import {
+ MAGMUX,
+ NO_MAGMUX_MESSAGE,
+ type PaneTestEnv,
+ finishPaneTest,
+ makePaneTestEnv,
+ paneRunOptions,
+ teamDirOf,
+} from "./test-helpers/team-pane.js";
+
+if (!MAGMUX) console.warn(NO_MAGMUX_MESSAGE);
+
+let t: PaneTestEnv;
+
+beforeEach(() => {
+ t = makePaneTestEnv();
+});
+
+afterEach(async () => {
+ const report = await finishPaneTest(t);
+ expect(report).toEqual({ processes: [], files: [] });
+});
+
+describe.skipIf(!MAGMUX)("team response file", () => {
+ it("an unwritable response file: the slot still ends COMPLETED in status.json", async () => {
+ const sessionPath = teamDirOf(t);
+ const manifest = setupSession(sessionPath, ["fake-answer"], "Answer.");
+ const slotId = Object.keys(manifest.models)[0] as string;
+ mkdirSync(join(sessionPath, `response-${slotId}.md`)); // writing it now fails (EISDIR)
+ const handle = await startModels(sessionPath, paneRunOptions(t));
+ const status = await handle.done;
+ expect(status.models[slotId]?.state).toBe("COMPLETED");
+ expect(getStatus(sessionPath).models[slotId]?.state).toBe("COMPLETED");
+ expect(readFileSync(join(sessionPath, "errors", `${slotId}.log`), "utf8")).toContain(
+ "response file not written"
+ );
+ }, 30_000);
+});