Fix Codex MCP error timeline on failed turns

This commit is contained in:
Mohamed Boudra
2025-12-24 20:41:33 +07:00
parent 3652f08e3d
commit a6300d358c
2 changed files with 11 additions and 3 deletions

View File

@@ -36,6 +36,7 @@ type TurnState = {
sawAssistant: boolean;
sawReasoning: boolean;
sawError: boolean;
sawErrorTimeline: boolean;
completed: boolean;
failed: boolean;
};
@@ -474,6 +475,7 @@ class CodexMcpAgentSession implements AgentSession {
sawAssistant: false,
sawReasoning: false,
sawError: false,
sawErrorTimeline: false,
completed: false,
failed: false,
};
@@ -793,6 +795,12 @@ class CodexMcpAgentSession implements AgentSession {
if (event.item.type === "reasoning") {
this.turnState && (this.turnState.sawReasoning = true);
}
if (event.item.type === "error") {
if (this.turnState) {
this.turnState.sawError = true;
this.turnState.sawErrorTimeline = true;
}
}
}
if (event.type === "turn_completed") {
this.turnState && (this.turnState.completed = true);
@@ -1149,13 +1157,12 @@ class CodexMcpAgentSession implements AgentSession {
(event as { error?: { message?: string } }).error ??
((data as { error?: { message?: string } } | null)?.error ?? null);
const error = errorRecord?.message ?? "Codex MCP turn failed";
if (!this.turnState?.sawError) {
if (!this.turnState?.sawErrorTimeline) {
this.emitEvent({
type: "timeline",
provider: "codex-mcp",
item: { type: "error", message: error },
});
this.turnState && (this.turnState.sawError = true);
}
this.emitEvent({ type: "turn_failed", provider: "codex-mcp", error });
break;

View File

@@ -268,7 +268,8 @@ Build a new Codex MCP provider sidebyside with the existing Codex SDK prov
- [x] **Fix**: Codex MCP thread/item event mapping for file_change, mcp_tool_call, web_search, and todo_list still failing.
- **Done (2025-12-24 20:38)**: Normalized MCP provider event payloads to surface item events and thread/item types consistently for timeline mapping.
- [ ] **Fix**: Codex MCP should emit error timeline items for failed turns (currently none).
- [x] **Fix**: Codex MCP should emit error timeline items for failed turns (currently none).
- **Done (2025-12-24 20:41)**: Tracked error timeline emission separately so failed turns always emit an error item before `turn_failed`.
- [ ] **Fix**: Codex MCP persistence/resume should include conversation_id metadata (resume error).