Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/server/src/orchestration/ActivityPayloadProjection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,25 @@ describe("projectActivityPayload", () => {
expect(JSON.stringify(projected.payload).length).toBeLessThan(500);
});

it("does not restore a failed status for a successful Codex MCP result", () => {
const projected = projectActivityPayload(
activity({
itemType: "mcp_tool_call",
status: "completed",
data: {
item: {
type: "mcpToolCall",
status: "failed",
result: { content: [{ type: "text", text: "diff details" }] },
error: null,
},
},
}),
);

expect((projected.payload as Record<string, unknown>).status).toBe("completed");
});

it("slims Claude-shaped mcp_tool_call data (toolName/input/result block)", () => {
const projected = projectActivityPayload(
activity({
Expand Down
9 changes: 8 additions & 1 deletion apps/server/src/orchestration/ActivityPayloadProjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ function projectAcpContent(value: unknown): Record<string, unknown> | undefined
return summary ? { content: summary } : undefined;
}

function hasSuccessfulMcpResult(data: Record<string, unknown>): boolean {
const item = asRecord(data.item);
return item?.type === "mcpToolCall" && item.result != null && item.error == null;
}

/**
* Removes activity payload fields that no current client reads while retaining
* the full payload in persistence and the event store.
Expand All @@ -344,7 +349,9 @@ export function projectActivityPayload(

const itemStatus = asRecord(data.item)?.status;
const projectedPayload =
payload.status === "completed" && (itemStatus === "failed" || itemStatus === "declined")
payload.status === "completed" &&
(itemStatus === "failed" || itemStatus === "declined") &&
!hasSuccessfulMcpResult(data)
? { ...payload, status: itemStatus }
: payload;

Expand Down
15 changes: 14 additions & 1 deletion apps/server/src/provider/Layers/CodexAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,16 @@ lifecycleLayer("CodexAdapterLive lifecycle", (it) => {
error: { message: "Build failed" },
status: "failed",
},
{
type: "mcpToolCall",
id: "successful-mcp-with-failed-status",
server: "t3-code",
tool: "inspectTaskChanges",
arguments: {},
error: null,
result: { content: [{ type: "text", text: "diff details" }] },
status: "failed",
},
{
type: "fileChange",
id: "declined-change",
Expand Down Expand Up @@ -774,7 +784,10 @@ lifecycleLayer("CodexAdapterLive lifecycle", (it) => {
if (firstEvent._tag !== "Some" || firstEvent.value.type !== "item.completed") {
return;
}
NodeAssert.equal(firstEvent.value.payload.status, item.status);
NodeAssert.equal(
firstEvent.value.payload.status,
item.id === "successful-mcp-with-failed-status" ? "completed" : item.status,
);
}
}),
);
Expand Down
39 changes: 31 additions & 8 deletions apps/server/src/provider/Layers/CodexAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,36 @@ function itemDetail(itemType: CanonicalItemType, item: CodexLifecycleItem): stri
return undefined;
}

function hasSuccessfulToolResult(item: CodexLifecycleItem): boolean {
if (item.type !== "mcpToolCall") {
return false;
}
return item.result != null && item.error == null;
}

function itemLifecycleStatus(
item: CodexLifecycleItem,
lifecycle: "item.started" | "item.updated" | "item.completed",
): "inProgress" | "failed" | "declined" | "completed" | undefined {
if (lifecycle === "item.started") {
return "inProgress";
}

if (lifecycle !== "item.completed") {
return undefined;
}

if (
"status" in item &&
(item.status === "failed" || item.status === "declined") &&
!hasSuccessfulToolResult(item)
) {
return item.status;
}

return "completed";
}
Comment thread
cursor[bot] marked this conversation as resolved.

function toRequestTypeFromMethod(method: string): CanonicalRequestType {
switch (method) {
case "item/commandExecution/requestApproval":
Expand Down Expand Up @@ -476,14 +506,7 @@ function mapItemLifecycle(
}

const detail = itemDetail(itemType, item);
const status =
lifecycle === "item.started"
? "inProgress"
: lifecycle === "item.completed"
? "status" in item && (item.status === "failed" || item.status === "declined")
? item.status
: "completed"
: undefined;
const status = itemLifecycleStatus(item, lifecycle);

return {
...runtimeEventBase(event, canonicalThreadId),
Expand Down
Loading