From c51eb759306858db2f79340ea70eafabb42ac25a Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Wed, 24 Dec 2025 19:36:23 +0700 Subject: [PATCH] Fix codex-mcp command exit codes --- .../server/agent/providers/codex-mcp-agent.ts | 28 +++++++++++++------ plan.md | 3 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/server/src/server/agent/providers/codex-mcp-agent.ts b/packages/server/src/server/agent/providers/codex-mcp-agent.ts index 961918b26..69fa94abd 100644 --- a/packages/server/src/server/agent/providers/codex-mcp-agent.ts +++ b/packages/server/src/server/agent/providers/codex-mcp-agent.ts @@ -1055,20 +1055,29 @@ class CodexMcpAgentSession implements AgentSession { const exitCodeRaw = (event as { exit_code?: unknown; exitCode?: unknown }).exit_code ?? (event as { exitCode?: unknown }).exitCode; const exitCode = typeof exitCodeRaw === "number" ? exitCodeRaw : undefined; - const output = (event as { output?: string; stdout?: string }).output ?? - (event as { stdout?: string }).stdout ?? - (event as { stderr?: string }).stderr ?? - ""; - const structuredOutput = + const output = (event as { output?: unknown; stdout?: unknown }).output ?? + (event as { stdout?: unknown }).stdout ?? + (event as { stderr?: unknown }).stderr; + const outputRecord = + output && typeof output === "object" ? (output as Record) : undefined; + const outputText = typeof output === "string" + ? output + : typeof outputRecord?.stdout === "string" + ? outputRecord.stdout + : typeof outputRecord?.stderr === "string" + ? outputRecord.stderr + : undefined; + const structuredOutput = + outputText !== undefined || typeof exitCode === "number" ? { type: "command" as const, command: extractCommandText(command) ?? "command", - output, + output: outputText ?? "", exitCode, cwd, } - : undefined; + : outputRecord; const emitEvent = () => { if (typeof exitCode === "number" && exitCode !== 0) { this.turnState && (this.turnState.sawError = true); @@ -1249,12 +1258,13 @@ class CodexMcpAgentSession implements AgentSession { ? (commandValue as string[]).join(" ") : "command"; + const outputText = typeof aggregatedOutput === "string" ? aggregatedOutput : undefined; const structuredOutput = - typeof aggregatedOutput === "string" + outputText !== undefined || typeof exitCode === "number" ? { type: "command" as const, command, - output: aggregatedOutput, + output: outputText ?? "", exitCode: typeof exitCode === "number" ? exitCode : undefined, cwd, } diff --git a/plan.md b/plan.md index 745b71196..ae7ba536b 100644 --- a/plan.md +++ b/plan.md @@ -115,7 +115,8 @@ Build a new Codex MCP provider side‑by‑side with the existing Codex SDK prov - [x] **Test (E2E)**: Run tests and verify fixes work. - **Done (2025-12-24 19:32)**: Ran `npm run test --workspace=@paseo/server`; 9 failures (1 in `codex-agent.test.ts` missing persisted shell_command entry, 8 in `codex-mcp-agent.test.ts` for exit code, thread/item events, error timeline, persistence metadata, and permission requests). -- [ ] **Fix**: Codex MCP command output should include exit codes for command tool calls. +- [x] **Fix**: Codex MCP command output should include exit codes for command tool calls. + - **Done (2025-12-24 19:36)**: Ensured command tool outputs include exit codes even when output text is missing. - [ ] **Fix**: Codex MCP thread/item event mapping should capture file_change, mcp_tool_call, web_search, and todo_list.