Skip to content
Closed
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
5 changes: 1 addition & 4 deletions apps/mobile/src/lib/threadActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2263,10 +2263,7 @@ export function buildThreadFeed(
entryRows.push(index);
continue;
}
const app =
item.type === "dynamic_tool" && item.status === "completed"
? mcpAppFromToolItem(item)
: undefined;
const app = item.type === "dynamic_tool" ? mcpAppFromToolItem(item) : undefined;
if (app) {
const entry: RawThreadFeedEntry = {
type: "mcp-app",
Expand Down
69 changes: 69 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5129,6 +5129,75 @@ describe("CodexAdapterV2 post-settle continuation", () => {
),
);

const MCP_APP_DEFERRED_RESULT = {
content: [{ type: "text", text: "An interactive form is being shown to the user." }],
structuredContent: { status: "awaiting_user_submission" },
};
// Codex reports a tool's `isError` result, which a write that defers to its
// form returns, as a failed call.
const mcpAppDeferredTranscript = makeCodexReplayTranscript({
scenario: MCP_APP_SCENARIO,
entries: mcpAppTranscript.entries.map((entry) =>
entry.type === "emit_inbound" && entry.label === "item/completed/app-tool"
? {
...entry,
frame: {
method: "item/completed",
params: {
item: {
...mcpAppToolItem("inProgress"),
status: "failed",
result: MCP_APP_DEFERRED_RESULT,
},
threadId: MCP_APP_NATIVE_THREAD,
turnId: MCP_APP_NATIVE_TURN,
completedAtMs: 1782622441500,
},
},
}
: entry,
),
});

it.effect("captures the app of a tool call that defers to its form", () =>
Effect.scoped(
Effect.gen(function* () {
const appCaptured = yield* Deferred.make<OrchestrationV2TurnItem>();
const harness = yield* makeCodexReplayHarness(mcpAppDeferredTranscript, (event) =>
event.type === "turn_item.updated" &&
event.turnItem.type === "dynamic_tool" &&
event.turnItem.status === "failed"
? Deferred.succeed(appCaptured, event.turnItem)
: Effect.void,
);
const now = yield* DateTime.now;

yield* harness.runtime.startTurn(
makeCodexTestTurnInput({
threadId: harness.threadId,
providerThread: harness.providerThread,
now,
attemptId: RunAttemptId.make("attempt-codex-mcp-app-deferred"),
text: MCP_APP_PROMPT,
}),
);
const item = yield* Deferred.await(appCaptured);

const output = item.type === "dynamic_tool" ? (item.output as Record<string, unknown>) : {};
assert.equal(
readMcpAppReference(output[MCP_APP_OUTPUT_KEY])?.resourceUri,
MCP_APP_RESOURCE,
);
assert.deepEqual(output.result, { ...MCP_APP_DEFERRED_RESULT, isError: true });
assert.isFalse(yield* harness.hasPendingBackgroundWork);
}).pipe(
Effect.provide(
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
),
),
),
);

const ORPHAN_WAIT_SCENARIO = "codex-orphaned-dynamic-tool";
const ORPHAN_WAIT_NATIVE_THREAD = "native-codex-orphan-wait-thread";
const ORPHAN_WAIT_NATIVE_TURN = "native-codex-orphan-wait-turn";
Expand Down
12 changes: 10 additions & 2 deletions apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3739,8 +3739,10 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
// Only reads and storage are cancellable; remove partial writes. Once stored, attach the app or delete it if the item settled.
Effect.uninterruptibleMask((restore) =>
Effect.gen(function* () {
// Codex reports an `isError` result as failed. Apps still render
// for it: a write tool that defers to its form returns one.
const reference =
item.status === "completed" && item.result != null && item.error == null
item.result != null && item.error == null
? yield* restore(
getNativeThreadId(context.providerThread).pipe(
Effect.flatMap((threadId) =>
Expand Down Expand Up @@ -3794,7 +3796,13 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
? artifacts.turnItem
: {
...artifacts.turnItem,
output: { [MCP_APP_OUTPUT_KEY]: reference, result: item.result },
output: {
[MCP_APP_OUTPUT_KEY]: reference,
result:
item.status === "failed"
? { ...item.result, isError: true }
: item.result,
},
};
yield* emitProviderEvent({
type: "node.updated",
Expand Down
17 changes: 17 additions & 0 deletions apps/web/src/session-logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,23 @@ describe("HTML renders in the timeline", () => {
expect(rowsFor(entries, false)).toEqual(["message", "turn-fold", "mcp-app", "message"]);
});

it("hosts an MCP app whose call failed, as a form-deferring write does", () => {
const mcpApp = {
attachmentId: "render-thread-app-html",
server: "github",
tool: "create_pull_request",
resourceUri: "ui://github-mcp-server/pr-create",
};
const call = renderCall("failed", {
t3McpApp: mcpApp,
result: { content: [], isError: true },
});
const entries = turn(
call.type === "dynamic_tool" ? { ...call, toolName: "github.create_pull_request" } : call,
);
expect(entries.find((entry) => entry.kind === "mcp-app")).toMatchObject({ mcpApp });
});

it("keeps a render visible when its superseded attempt folds", () => {
const attempt: OrchestrationV2RunAttempt = {
id: RunAttemptId.make("attempt-superseded"),
Expand Down
5 changes: 1 addition & 4 deletions apps/web/src/session-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,10 +711,7 @@ export function deriveTimelineEntriesFromVisibleTurnItems(
continue;
}

const mcpApp =
item.type === "dynamic_tool" && item.status === "completed"
? mcpAppFromToolItem(item)
: undefined;
const mcpApp = item.type === "dynamic_tool" ? mcpAppFromToolItem(item) : undefined;
if (mcpApp !== undefined) {
entries.push({
id: item.id,
Expand Down
Loading