Skip to content
Merged
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
18 changes: 18 additions & 0 deletions apps/mobile/src/lib/threadActivity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ const threadId = ThreadId.make("thread-1");
const sourceThreadId = ThreadId.make("thread-source");
const runId = RunId.make("run-1");

it("shows a captured MCP app for a failed deferred write", () => {
const mcpApp = {
attachmentId: "deferred-app-html",
server: "github",
tool: "create_pull_request",
resourceUri: "ui://github-mcp-server/pr-create",
};
const item: OrchestrationV2TurnItem = {
...base("deferred-app", "2026-08-29T00:00:00.000Z", 1),
type: "dynamic_tool",
toolName: "github.create_pull_request",
status: "failed",
input: {},
output: { t3McpApp: mcpApp, result: { content: [], isError: true } },
};
expect(buildThreadFeed([projected(item, 0)])).toMatchObject([{ type: "mcp-app", app: mcpApp }]);
});

it("keeps historical plan detail accessible from its paged turn item", () => {
const item = {
...base("historical-plan", "2026-08-29T00:00:00.000Z", 1),
Expand Down
5 changes: 1 addition & 4 deletions apps/mobile/src/lib/threadActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2204,10 +2204,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
67 changes: 67 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4535,6 +4535,73 @@ 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" },
};
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
10 changes: 8 additions & 2 deletions apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3699,7 +3699,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
Effect.uninterruptibleMask((restore) =>
Effect.gen(function* () {
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 @@ -3753,7 +3753,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 @@ -1487,6 +1487,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 @@ -769,10 +769,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