Skip to content

Commit d935233

Browse files
neo-clonclaude
andcommitted
fix(acp): an html_render that reports its page takes the kept page
The MCP server keeps the page of every html_render call for agents that report a call without its result. A completed call that already reported its page skipped the kept pages, so its page stayed behind, and a later call with the same arguments that arrived without a result could show it. A call now takes its kept page the first time it completes, whether or not it reported the page. A call that reported its page takes that very page by attachment, not the oldest page kept for its arguments, so it never takes the page of another call that is still running. A repeated completion finds the call's page in its stored state and takes nothing more. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d55f3e5 commit d935233

4 files changed

Lines changed: 97 additions & 15 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,12 +534,13 @@ describe("AntigravityAdapterV2 html_render pages", () => {
534534
let sessionUpdate: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
535535
const instanceId = ProviderInstanceId.make("antigravity-html-render-test");
536536
const threadId = ThreadId.make("thread-antigravity-html-render");
537-
const page = (name: string) => ({
537+
const page = (name: string, title = "Revenue") => ({
538538
attachmentId: `${threadId}-${name}-html`,
539-
title: "Revenue",
539+
title,
540540
height: 240,
541541
});
542542
const revenue = { html: "<p>Revenue</p>", title: "Revenue", height: 240 };
543+
const margin = { ...revenue, html: "<p>Margin</p>", title: "Margin" };
543544
const renderError = {
544545
content: [{ type: "text", text: "html_render failed" }],
545546
isError: true,
@@ -589,9 +590,13 @@ describe("AntigravityAdapterV2 html_render pages", () => {
589590
yield* start("trajectory:3", revenue);
590591
yield* start("trajectory:4", revenue);
591592
yield* start("trajectory:5", revenue);
593+
yield* start("trajectory:6", margin);
594+
yield* start("trajectory:7", margin);
592595
// T3's MCP server publishes while each call runs.
593596
yield* mcpSessions.recordHtmlRender(threadId, revenue, page("first"));
594597
yield* mcpSessions.recordHtmlRender(threadId, revenue, page("second"));
598+
yield* mcpSessions.recordHtmlRender(threadId, margin, page("seventh", "Margin"));
599+
yield* mcpSessions.recordHtmlRender(threadId, margin, page("sixth", "Margin"));
595600
yield* send({
596601
sessionUpdate: "tool_call_update",
597602
toolCallId: "trajectory:1",
@@ -633,6 +638,32 @@ describe("AntigravityAdapterV2 html_render pages", () => {
633638
status: "completed",
634639
rawOutput: { result: renderError },
635640
});
641+
// A call that reports its page takes that page, not the
642+
// older one another call published with the same arguments,
643+
// and a repeated completion takes nothing more.
644+
yield* send({
645+
sessionUpdate: "tool_call_update",
646+
toolCallId: "trajectory:6",
647+
status: "completed",
648+
rawOutput: {
649+
result: {
650+
content: [{ type: "text", text: "Shown to the reader." }],
651+
structuredContent: { htmlRender: page("sixth", "Margin") },
652+
},
653+
},
654+
});
655+
yield* send({
656+
sessionUpdate: "tool_call_update",
657+
toolCallId: "trajectory:6",
658+
status: "completed",
659+
rawOutput: "Render margin chart",
660+
});
661+
yield* send({
662+
sessionUpdate: "tool_call_update",
663+
toolCallId: "trajectory:7",
664+
status: "completed",
665+
rawOutput: "Render margin chart",
666+
});
636667
return { stopReason: "end_turn" as const };
637668
}),
638669
})),
@@ -752,8 +783,21 @@ describe("AntigravityAdapterV2 html_render pages", () => {
752783
page: undefined,
753784
output: renderError.content,
754785
});
786+
assert.deepEqual(tool("trajectory:6"), {
787+
status: "completed",
788+
toolName: "t3-code.html_render",
789+
page: page("sixth", "Margin"),
790+
output: { htmlRender: page("sixth", "Margin") },
791+
});
792+
assert.deepEqual(tool("trajectory:7"), {
793+
status: "completed",
794+
toolName: "t3-code.html_render",
795+
page: page("seventh", "Margin"),
796+
output: { htmlRender: page("seventh", "Margin") },
797+
});
755798
// Each page goes to one call; the unclaimed one stays for a later call.
756799
assert.deepEqual(yield* mcpSessions.takeHtmlRender(threadId, revenue), page("second"));
800+
assert.strictEqual(yield* mcpSessions.takeHtmlRender(threadId, margin), undefined);
757801
}).pipe(Effect.provide(layerSession), Effect.scoped),
758802
);
759803
});

‎packages/provider-acp/src/server/adapter.ts‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3373,19 +3373,31 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
33733373
const outputIsError =
33743374
compactDynamicToolOutput(output)?.isError === true ||
33753375
compactDynamicToolOutput(rawOutputRecord?.result)?.isError === true;
3376-
const page =
3376+
const renderCompleted =
33773377
status === "completed" &&
33783378
resolveT3McpToolId(toolName) === HTML_RENDER_TOOL_NAME &&
3379-
!outputIsError &&
3380-
htmlRenderFromToolItem({ toolName, output }) === undefined
3381-
? (htmlRenderFromToolItem({
3382-
toolName,
3383-
output:
3384-
previous?.data.rawOutput === undefined
3385-
? undefined
3386-
: acpMcpToolCallOutput(previous.data.rawOutput),
3387-
}) ?? (yield* mcpSessions.takeHtmlRender(context.input.threadId, input)))
3379+
!outputIsError;
3380+
const reportedPage = renderCompleted
3381+
? htmlRenderFromToolItem({ toolName, output })
3382+
: undefined;
3383+
const previousPage = renderCompleted
3384+
? htmlRenderFromToolItem({
3385+
toolName,
3386+
output:
3387+
previous?.data.rawOutput === undefined
3388+
? undefined
3389+
: acpMcpToolCallOutput(previous.data.rawOutput),
3390+
})
3391+
: undefined;
3392+
// The MCP server keeps the page of every call, so a call that
3393+
// reports its page still takes it the first time it completes;
3394+
// left behind, it would show for a later call with the same
3395+
// arguments.
3396+
const keptPage =
3397+
renderCompleted && previousPage === undefined
3398+
? yield* mcpSessions.takeHtmlRender(context.input.threadId, input, reportedPage)
33883399
: undefined;
3400+
const page = reportedPage === undefined ? (previousPage ?? keptPage) : undefined;
33893401
if (page !== undefined) {
33903402
context.tools.set(toolCall.toolCallId, {
33913403
...toolCall,

‎packages/provider-core/src/server/McpProviderSessions.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,25 @@ describe("McpProviderSessions html_render pages", () => {
3636
);
3737
}).pipe(Effect.provide(McpProviderSessions.layer)),
3838
);
39+
40+
it.effect("takes the very page a call reported", () =>
41+
Effect.gen(function* () {
42+
const sessions = yield* McpProviderSessions.McpProviderSessions;
43+
const revenue = { title: "Revenue", height: 240 };
44+
yield* sessions.recordHtmlRender(threadId, revenue, page("first"));
45+
yield* sessions.recordHtmlRender(threadId, revenue, page("second"));
46+
47+
// A page this thread never kept leaves the kept pages for their calls.
48+
assert.strictEqual(
49+
yield* sessions.takeHtmlRender(threadId, revenue, page("unknown")),
50+
undefined,
51+
);
52+
assert.deepStrictEqual(
53+
yield* sessions.takeHtmlRender(threadId, revenue, page("second")),
54+
page("second"),
55+
);
56+
assert.deepStrictEqual(yield* sessions.takeHtmlRender(threadId, revenue), page("first"));
57+
assert.strictEqual(yield* sessions.takeHtmlRender(threadId, revenue), undefined);
58+
}).pipe(Effect.provide(McpProviderSessions.layer)),
59+
);
3960
});

‎packages/provider-core/src/server/McpProviderSessions.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ export class McpProviderSessions extends Context.Service<
4141
) => Effect.Effect<void>;
4242
/**
4343
* Removes and returns the oldest kept page the thread published with these
44-
* arguments, so each page goes to at most one call.
44+
* arguments, so each page goes to at most one call. A call that reported
45+
* its page takes that very page, so it never takes another call's.
4546
*/
4647
readonly takeHtmlRender: (
4748
threadId: ThreadId,
4849
input: { readonly title?: unknown; readonly height?: unknown },
50+
reported?: HtmlRenderReference,
4951
) => Effect.Effect<HtmlRenderReference | undefined>;
5052
}
5153
>()("@t3tools/provider-core/server/McpProviderSessions") {}
@@ -73,7 +75,7 @@ const make = Effect.gen(function* () {
7375
-MAX_KEPT_HTML_RENDERS,
7476
),
7577
),
76-
takeHtmlRender: (threadId, input) =>
78+
takeHtmlRender: (threadId, input, reported) =>
7779
Ref.modify(htmlRenders, (kept) => {
7880
// Agents can report a numeric argument as a string, e.g. "240".
7981
const height =
@@ -82,7 +84,10 @@ const make = Effect.gen(function* () {
8284
: input.height;
8385
const index = kept.findIndex(
8486
(page) =>
85-
page.threadId === threadId && page.title === input.title && page.height === height,
87+
page.threadId === threadId &&
88+
(reported === undefined
89+
? page.title === input.title && page.height === height
90+
: page.reference.attachmentId === reported.attachmentId),
8691
);
8792
return index === -1
8893
? [undefined, kept]

0 commit comments

Comments
 (0)