Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(daemon): don't mark opencode task as failed when turnDone triggered exit

Gener56178546c9e1
diff --git a/src/cli/daemon/agent/__tests__/opencode.test.ts b/src/cli/daemon/agent/__tests__/opencode.test.ts
index 029428e9e..6cc1d5d72 100644
--- a/src/cli/daemon/agent/__tests__/opencode.test.ts
+++ b/src/cli/daemon/agent/__tests__/opencode.test.ts
@@ -466,4 +466,54 @@ describe("OpenCodeBackend", () => {
const messages = await collectMessages(session.messages);
expect(messages).toContainEqual({ type: "text", content: "我是トニー大木" });
});
+
+ it("v1.14+: non-zero exit after turnDone still reports completed", async () => {
+ const session = backend.execute("hello", { cwd: "/tmp" });
+ const mock = getMock();
+
+ mock.stdout.push(JSON.stringify({
+ type: "text",
+ sessionID: "ses_x",
+ part: { type: "text", text: "Done!" },
+ }) + "\n");
+ mock.stdout.push(JSON.stringify({
+ type: "step_finish",
+ sessionID: "ses_x",
+ part: { type: "step-finish", reason: "stop" },
+ }) + "\n");
+ await tick();
+
+ expect(mock.proc.kill).toHaveBeenCalledWith("SIGTERM");
+ // Process exits with non-zero due to SIGTERM (143)
+ mock.proc.emit("close", 143);
+
+ const result = await session.result;
+ expect(result.status).toBe("completed");
+ expect(result.output).toBe("Done!");
+ });
+
+ it("non-zero exit with output but no turnDone still reports completed", async () => {
+ const session = backend.execute("hello", { cwd: "/tmp" });
+ const mock = getMock();
+
+ mock.stdout.push(JSON.stringify({ type: "message", role: "assistant", content: "Got it" }) + "\n");
+ await tick();
+ // Process crashes after producing output
+ mock.proc.emit("close", 1);
+
+ const result = await session.result;
+ expect(result.status).toBe("completed");
+ expect(result.output).toBe("Got it");
+ });
+
+ it("non-zero exit with no output and no turnDone reports failed", async () => {
+ const session = backend.execute("hello", { cwd: "/tmp" });
+ const mock = getMock();
+
+ await tick();
+ mock.proc.emit("close", 1);
+
+ const result = await session.result;
+ expect(result.status).toBe("failed");
+ });
});
diff --git a/src/cli/daemon/agent/opencode.ts b/src/cli/daemon/agent/opencode.ts
index 4d10e29a1..d74c35e64 100644
--- a/src/cli/daemon/agent/opencode.ts
+++ b/src/cli/daemon/agent/opencode.ts
@@ -204,8 +204,10 @@ export class OpenCodeBackend implements AgentBackend {
if (timedOut) {
resultStatus = "timeout";
- } else if (code !== 0 && resultStatus === "completed") {
- resultStatus = "failed";
+ } else if (code !== 0 && resultStatus === "completed" && !turnDoneTriggered) {
+ if (!lastOutput) {
+ resultStatus = "failed";
+ }
}
const stderr = stderrChunks.join("");