Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(cli): treat Codex non-zero exit as completed when agent produced output

Gener6f5b67f17d63
diff --git a/src/cli/daemon/agent/__tests__/codex.test.ts b/src/cli/daemon/agent/__tests__/codex.test.ts
index 1cbf689e6..30edab815 100644
--- a/src/cli/daemon/agent/__tests__/codex.test.ts
+++ b/src/cli/daemon/agent/__tests__/codex.test.ts
@@ -881,19 +881,37 @@ describe("CodexBackend", () => {
expect(result.status).toBe("completed");
});
- it("non-zero exit code before turn completes → status failed", async () => {
+ it("non-zero exit code before turn completes (no output) → status failed", async () => {
const session = backend.execute("hello", { cwd: "/tmp" });
const mock = getMock();
await completeHandshake();
sendNotification("turn/started", { turn: { id: "turn_1" } });
- // Process exits before turn/completed
+ // Process exits before turn/completed and without any agent output
mock.proc.emit("close", 1);
const result = await session.result;
expect(result.status).toBe("failed");
});
+ it("non-zero exit code before turn completes but agent produced output → status completed", async () => {
+ const session = backend.execute("hello", { cwd: "/tmp" });
+ const mock = getMock();
+
+ await completeHandshake("thread_abc");
+ sendNotification("turn/started", { threadId: "thread_abc", turn: { id: "turn_1" } });
+ sendNotification("item/completed", {
+ threadId: "thread_abc",
+ item: { type: "agentMessage", id: "msg_1", text: "Hi. What can I help with?" },
+ });
+ // Process exits with non-zero code (e.g. MCP transport crash) without turn/completed
+ mock.proc.emit("close", 1);
+
+ const result = await session.result;
+ expect(result.status).toBe("completed");
+ expect(result.output).toBe("Hi. What can I help with?");
+ });
+
it("turn completed successfully + non-zero exit + turnError → status failed with turnError", async () => {
const session = backend.execute("hello", { cwd: "/tmp" });
const mock = getMock();
diff --git a/src/cli/daemon/agent/codex.ts b/src/cli/daemon/agent/codex.ts
index 6c70f828c..4737d6a23 100644
--- a/src/cli/daemon/agent/codex.ts
+++ b/src/cli/daemon/agent/codex.ts
@@ -507,7 +507,11 @@ export class CodexBackend implements AgentBackend {
if (timedOut) {
resultStatus = "timeout";
} else if (code !== 0 && resultStatus === "completed" && !turnCompletedSuccessfully) {
- resultStatus = "failed";
+ // If agent already produced output, treat as completed despite non-zero exit
+ // (e.g. MCP transport errors can crash the process after a successful response)
+ if (!lastOutput) {
+ resultStatus = "failed";
+ }
}
const stderr = stderrChunks.join("").replace(/\x1b\[[0-9;]*m/g, "");
diff --git a/src/cli/package.json b/src/cli/package.json
index 19d739561..ee8051a22 100644
--- a/src/cli/package.json
+++ b/src/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@alook/cli",
- "version": "0.0.19",
+ "version": "0.0.20",
"description": "Alook CLI — register and run always-on AI coding agents.",
"license": "Apache-2.0",
"homepage": "https://github.com/alookai/alook#readme",