@devries-cameron20 / t3code-1 / commits / a1621a81af
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): show MCP App forms from failed tool results (#25225)

Co-authored-by: shivam <91240327+shivamhwp@users.noreply.github.com>

maria committed Oct 29, 2026 at 18:03 UTC a1621a81af727fe40bdb2a351860b2704827d31c
6 files changed +112 -10
apps/mobile/src/lib/threadActivity.test.ts
+18
@@ -38,6 +38,24 @@ const threadId = ThreadId.make("thread-1");
38 const sourceThreadId = ThreadId.make("thread-source");
39 const runId = RunId.make("run-1");
40
41 +it("shows a captured MCP app for a failed deferred write", () => {
42 + const mcpApp = {
43 + attachmentId: "deferred-app-html",
44 + server: "github",
45 + tool: "create_pull_request",
46 + resourceUri: "ui://github-mcp-server/pr-create",
47 + };
48 + const item: OrchestrationV2TurnItem = {
49 + ...base("deferred-app", "2026-08-29T00:00:00.000Z", 1),
50 + type: "dynamic_tool",
51 + toolName: "github.create_pull_request",
52 + status: "failed",
53 + input: {},
54 + output: { t3McpApp: mcpApp, result: { content: [], isError: true } },
55 + };
56 + expect(buildThreadFeed([projected(item, 0)])).toMatchObject([{ type: "mcp-app", app: mcpApp }]);
57 +});
58 +
59 it("keeps historical plan detail accessible from its paged turn item", () => {
60 const item = {
61 ...base("historical-plan", "2026-08-29T00:00:00.000Z", 1),
apps/mobile/src/lib/threadActivity.ts
+1 -4
@@ -2102,10 +2102,7 @@ export function buildThreadFeed(
2102 entryRows.push(index);
2103 continue;
2104 }
2105 - const app =
2106 - item.type === "dynamic_tool" && item.status === "completed"
2107 - ? mcpAppFromToolItem(item)
2108 - : undefined;
2105 + const app = item.type === "dynamic_tool" ? mcpAppFromToolItem(item) : undefined;
2106 if (app) {
2107 const entry: RawThreadFeedEntry = {
2108 type: "mcp-app",
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+67
@@ -5138,6 +5138,73 @@ describe("CodexAdapterV2 post-settle continuation", () => {
5138 ),
5139 );
5140
5141 + const MCP_APP_DEFERRED_RESULT = {
5142 + content: [{ type: "text", text: "An interactive form is being shown to the user." }],
5143 + structuredContent: { status: "awaiting_user_submission" },
5144 + };
5145 + const mcpAppDeferredTranscript = makeCodexReplayTranscript({
5146 + scenario: MCP_APP_SCENARIO,
5147 + entries: mcpAppTranscript.entries.map((entry) =>
5148 + entry.type === "emit_inbound" && entry.label === "item/completed/app-tool"
5149 + ? {
5150 + ...entry,
5151 + frame: {
5152 + method: "item/completed",
5153 + params: {
5154 + item: {
5155 + ...mcpAppToolItem("inProgress"),
5156 + status: "failed",
5157 + result: MCP_APP_DEFERRED_RESULT,
5158 + },
5159 + threadId: MCP_APP_NATIVE_THREAD,
5160 + turnId: MCP_APP_NATIVE_TURN,
5161 + completedAtMs: 1782622441500,
5162 + },
5163 + },
5164 + }
5165 + : entry,
5166 + ),
5167 + });
5168 +
5169 + it.effect("captures the app of a tool call that defers to its form", () =>
5170 + Effect.scoped(
5171 + Effect.gen(function* () {
5172 + const appCaptured = yield* Deferred.make<OrchestrationV2TurnItem>();
5173 + const harness = yield* makeCodexReplayHarness(mcpAppDeferredTranscript, (event) =>
5174 + event.type === "turn_item.updated" &&
5175 + event.turnItem.type === "dynamic_tool" &&
5176 + event.turnItem.status === "failed"
5177 + ? Deferred.succeed(appCaptured, event.turnItem)
5178 + : Effect.void,
5179 + );
5180 + const now = yield* DateTime.now;
5181 +
5182 + yield* harness.runtime.startTurn(
5183 + makeCodexTestTurnInput({
5184 + threadId: harness.threadId,
5185 + providerThread: harness.providerThread,
5186 + now,
5187 + attemptId: RunAttemptId.make("attempt-codex-mcp-app-deferred"),
5188 + text: MCP_APP_PROMPT,
5189 + }),
5190 + );
5191 + const item = yield* Deferred.await(appCaptured);
5192 +
5193 + const output = item.type === "dynamic_tool" ? (item.output as Record<string, unknown>) : {};
5194 + assert.equal(
5195 + readMcpAppReference(output[MCP_APP_OUTPUT_KEY])?.resourceUri,
5196 + MCP_APP_RESOURCE,
5197 + );
5198 + assert.deepEqual(output.result, { ...MCP_APP_DEFERRED_RESULT, isError: true });
5199 + assert.isFalse(yield* harness.hasPendingBackgroundWork);
5200 + }).pipe(
5201 + Effect.provide(
5202 + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
5203 + ),
5204 + ),
5205 + ),
5206 + );
5207 +
5208 const ORPHAN_WAIT_SCENARIO = "codex-orphaned-dynamic-tool";
5209 const ORPHAN_WAIT_NATIVE_THREAD = "native-codex-orphan-wait-thread";
5210 const ORPHAN_WAIT_NATIVE_TURN = "native-codex-orphan-wait-turn";
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+8 -2
@@ -3744,7 +3744,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
3744 Effect.uninterruptibleMask((restore) =>
3745 Effect.gen(function* () {
3746 const reference =
3747 - item.status === "completed" && item.result != null && item.error == null
3747 + item.result != null && item.error == null
3748 ? yield* restore(
3749 getNativeThreadId(context.providerThread).pipe(
3750 Effect.flatMap((threadId) =>
@@ -3798,7 +3798,13 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
3798 ? artifacts.turnItem
3799 : {
3800 ...artifacts.turnItem,
3801 - output: { [MCP_APP_OUTPUT_KEY]: reference, result: item.result },
3801 + output: {
3802 + [MCP_APP_OUTPUT_KEY]: reference,
3803 + result:
3804 + item.status === "failed"
3805 + ? { ...item.result, isError: true }
3806 + : item.result,
3807 + },
3808 };
3809 yield* emitProviderEvent({
3810 type: "node.updated",
apps/web/src/session-logic.test.ts
+17
@@ -1307,6 +1307,23 @@ describe("HTML renders in the timeline", () => {
1307 expect(rowsFor(entries, false)).toEqual(["message", "turn-fold", "mcp-app", "message"]);
1308 });
1309
1310 + it("hosts an MCP app whose call failed, as a form-deferring write does", () => {
1311 + const mcpApp = {
1312 + attachmentId: "render-thread-app-html",
1313 + server: "github",
1314 + tool: "create_pull_request",
1315 + resourceUri: "ui://github-mcp-server/pr-create",
1316 + };
1317 + const call = renderCall("failed", {
1318 + t3McpApp: mcpApp,
1319 + result: { content: [], isError: true },
1320 + });
1321 + const entries = turn(
1322 + call.type === "dynamic_tool" ? { ...call, toolName: "github.create_pull_request" } : call,
1323 + );
1324 + expect(entries.find((entry) => entry.kind === "mcp-app")).toMatchObject({ mcpApp });
1325 + });
1326 +
1327 it("keeps a render visible when its superseded attempt folds", () => {
1328 const attempt: OrchestrationV2RunAttempt = {
1329 id: RunAttemptId.make("attempt-superseded"),
apps/web/src/session-logic.ts
+1 -4
@@ -711,10 +711,7 @@ export function deriveTimelineEntriesFromVisibleTurnItems(
711 continue;
712 }
713
714 - const mcpApp =
715 - item.type === "dynamic_tool" && item.status === "completed"
716 - ? mcpAppFromToolItem(item)
717 - : undefined;
714 + const mcpApp = item.type === "dynamic_tool" ? mcpAppFromToolItem(item) : undefined;
715 if (mcpApp !== undefined) {
716 entries.push({
717 id: item.id,