Skip to content

Commit fd394ac

Browse files
neo-clonclaude
andcommitted
fix(acp): Antigravity html_render pages show in the thread
Antigravity's live ACP stream titles an MCP call "Running <tool>" with no server or MCP _meta, and reports the step's own summary as rawOutput instead of the MCP result. A completed html_render therefore projected as a generic "Running html_render" row whose output was text like "Render revenue chart", so no client showed the page, although T3 had published it. Identity recovery now accepts Antigravity's "Running <tool>" title, gated on the T3 tool inventory like the other bare-name conventions. HtmlRender.publish keeps each page it published, with its arguments, in McpProviderSessions, the per-thread state the T3 MCP server already shares with provider adapters. When a recovered html_render call completes without a readable page reference, the shared ACP adapter takes the thread's oldest kept page with the same title and height and projects it as the call's output. Failed calls and calls with no matching page stay as reported. Kept pages are bounded and dropped when the thread's MCP session is cleared. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 339179f commit fd394ac

9 files changed

Lines changed: 350 additions & 17 deletions

File tree

‎apps/server/src/htmlRender/HtmlRender.test.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import * as NodeServices from "@effect/platform-node/NodeServices";
33
import { describe, expect, it } from "@effect/vitest";
44
import { ThreadId } from "@t3tools/contracts";
5+
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
56
import * as HostProcess from "@t3tools/shared/HostProcess";
67
import {
78
HTML_RENDER_MEASURE_FONTS,
@@ -49,6 +50,7 @@ const layerHtmlRender = (
4950
}),
5051
),
5152
),
53+
Layer.provideMerge(McpProviderSessions.layer),
5254
Layer.provideMerge(ServerConfig.layerTest(process.cwd(), { prefix: "t3-html-render-" })),
5355
Layer.provideMerge(NodeServices.layer),
5456
);
@@ -175,9 +177,11 @@ describe("HtmlRender", () => {
175177
const fileSystem = yield* FileSystem.FileSystem;
176178
const config = yield* ServerConfig.ServerConfig;
177179
const htmlRender = yield* HtmlRender.HtmlRender;
180+
const mcpSessions = yield* McpProviderSessions.McpProviderSessions;
181+
const threadId = ThreadId.make("thread-html-render");
178182

179183
const reference = yield* htmlRender.publish({
180-
threadId: ThreadId.make("thread-html-render"),
184+
threadId,
181185
html: "<p>Quarterly revenue</p>",
182186
title: " Revenue ",
183187
height: 9_000,
@@ -197,6 +201,15 @@ describe("HtmlRender", () => {
197201
const html = yield* fileSystem.readFileString(stored ?? "");
198202
expect(html).toContain('<style id="t3-theme">');
199203
expect(html).toContain("<p>Quarterly revenue</p>");
204+
// The thread's provider session can attach the page to a call reported
205+
// without its result, matched by the call's own arguments, once.
206+
const page = { title: " Revenue ", height: 9_000 };
207+
expect(yield* mcpSessions.takeHtmlRender(ThreadId.make("thread-other"), page)).toBe(
208+
undefined,
209+
);
210+
expect(yield* mcpSessions.takeHtmlRender(threadId, { ...page, height: 400 })).toBe(undefined);
211+
expect(yield* mcpSessions.takeHtmlRender(threadId, page)).toEqual(reference);
212+
expect(yield* mcpSessions.takeHtmlRender(threadId, page)).toBe(undefined);
200213
}).pipe(Effect.provide(layerTest)),
201214
);
202215

@@ -223,6 +236,13 @@ describe("HtmlRender", () => {
223236
expect(yield* storedPages).toHaveLength(1);
224237
yield* Fiber.interrupt(publishing);
225238
expect(yield* storedPages).toEqual([]);
239+
const mcpSessions = yield* McpProviderSessions.McpProviderSessions;
240+
expect(
241+
yield* mcpSessions.takeHtmlRender(ThreadId.make("thread-html-cancel"), {
242+
title: "X",
243+
height: 200,
244+
}),
245+
).toBe(undefined);
226246
}).pipe(
227247
Effect.provide(
228248
layerHtmlRender(

‎apps/server/src/htmlRender/HtmlRender.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ThreadId } from "@t3tools/contracts";
2+
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
23
import * as HostProcess from "@t3tools/shared/HostProcess";
34
import {
45
clampHtmlRenderHeight,
@@ -101,7 +102,8 @@ export class HtmlRender extends Context.Service<
101102
/**
102103
* Stores a prepared page as a thread attachment for clients to show inline,
103104
* measuring its height at each client width when the preview browser is
104-
* already installed.
105+
* already installed. The thread's provider session keeps the reference for
106+
* an agent that reports the call without its result.
105107
*/
106108
readonly publish: (input: {
107109
readonly threadId: ThreadId;
@@ -335,6 +337,7 @@ const make = Effect.gen(function* () {
335337
const fileSystem = yield* FileSystem.FileSystem;
336338
const config = yield* ServerConfig.ServerConfig;
337339
const previewBrowser = yield* PreviewBrowser.PreviewBrowser;
340+
const mcpSessions = yield* McpProviderSessions.McpProviderSessions;
338341
const services = yield* Effect.context<
339342
FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner
340343
>();
@@ -439,12 +442,14 @@ const make = Effect.gen(function* () {
439442
// publish that fails or is interrupted before returning removes it.
440443
Effect.onError(() => fileSystem.remove(filePath, { force: true }).pipe(Effect.ignore)),
441444
);
442-
return {
445+
const reference: HtmlRenderReference = {
443446
attachmentId,
444447
title: input.title.trim().slice(0, HTML_RENDER_MAX_TITLE_LENGTH) || "HTML",
445448
height: clampHtmlRenderHeight(input.height),
446449
...(heights === undefined ? {} : { heights }),
447-
} satisfies HtmlRenderReference;
450+
};
451+
yield* mcpSessions.recordHtmlRender(input.threadId, input, reference);
452+
return reference;
448453
});
449454

450455
const preview = Effect.fn("HtmlRender.preview")(function* (input: {

‎apps/server/src/mcp/toolkits/core.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
type OrchestrationV2ProjectedTurnItem,
1919
type OrchestrationV2ThreadShell,
2020
} from "@t3tools/contracts";
21+
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
2122
import * as Effect from "effect/Effect";
2223
import * as TestClock from "effect/testing/TestClock";
2324
import * as Layer from "effect/Layer";
@@ -293,6 +294,7 @@ it.effect("returns an HTML render reference that Codex and Claude tool rows both
293294
Effect.provide(
294295
McpHttpServer.layerHtmlToolkit.pipe(
295296
Layer.provideMerge(McpServer.McpServer.layer),
297+
Layer.provide(McpProviderSessions.layer),
296298
Layer.provide(PreviewBrowser.layer),
297299
Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "t3-mcp-html-render-" })),
298300
Layer.provide(NodeServices.layer),

‎apps/server/src/mcp/toolkits/worktree/registration.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { expect, it } from "@effect/vitest";
66
import { NodeHttpServer } from "@effect/platform-node";
77
import * as NodeServices from "@effect/platform-node/NodeServices";
88
import { ProviderInstanceId, ThreadId } from "@t3tools/contracts";
9+
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
910
import * as Effect from "effect/Effect";
1011
import * as Layer from "effect/Layer";
1112
import * as Schema from "effect/Schema";
@@ -57,6 +58,7 @@ const layerStubServices = Layer.mergeAll(
5758
Layer.mock(SourceControlRepositoryService.SourceControlRepositoryService)({}),
5859
Layer.mock(ThreadLaunchService.ThreadLaunchService)({}),
5960
Layer.mock(ThreadSearch.ThreadSearch)({}),
61+
McpProviderSessions.layer,
6062
);
6163

6264
const ToolsListPayload = Schema.fromJsonString(

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

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ThreadId,
1212
} from "@t3tools/contracts";
1313
import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime";
14+
import { htmlRenderFromToolItem } from "@t3tools/shared/toolOutput";
1415
import * as Crypto from "effect/Crypto";
1516
import * as DateTime from "effect/DateTime";
1617
import * as Effect from "effect/Effect";
@@ -518,3 +519,202 @@ describe("AntigravityAdapterV2 client file system under restrictive policies", (
518519
}).pipe(Effect.provide(layerSession), Effect.scoped),
519520
);
520521
});
522+
523+
describe("AntigravityAdapterV2 html_render pages", () => {
524+
it.effect("shows the page html_render published when the agent reports only a summary", () =>
525+
Effect.gen(function* () {
526+
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
527+
const path = yield* Path.Path;
528+
const crypto = yield* Crypto.Crypto;
529+
const mcpSessions = yield* McpProviderSessions.McpProviderSessions;
530+
const mockAgentPath = yield* path.fromFileUrl(
531+
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
532+
);
533+
type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
534+
let sessionUpdate: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
535+
const instanceId = ProviderInstanceId.make("antigravity-html-render-test");
536+
const threadId = ThreadId.make("thread-antigravity-html-render");
537+
const page = (name: string) => ({
538+
attachmentId: `${threadId}-${name}-html`,
539+
title: "Revenue",
540+
height: 240,
541+
});
542+
const revenue = { html: "<p>Revenue</p>", title: "Revenue", height: 240 };
543+
const adapter = yield* makeAntigravityAdapterV2({
544+
instanceId,
545+
selfInvocation: yield* resolveSelfInvocation(),
546+
makeRuntime: (input) =>
547+
makeAntigravityAcpRuntime({
548+
...input,
549+
childProcessSpawner,
550+
spawn: {
551+
command: process.execPath,
552+
args: [mockAgentPath],
553+
cwd: input.cwd,
554+
env: { T3_ACP_ANTIGRAVITY: "1" },
555+
},
556+
}).pipe(
557+
Effect.provideService(Crypto.Crypto, crypto),
558+
Effect.map((runtime): RuntimeService => ({
559+
...runtime,
560+
handleSessionUpdate: (handler) =>
561+
Effect.sync(() => {
562+
sessionUpdate = handler;
563+
}).pipe(Effect.andThen(runtime.handleSessionUpdate(handler))),
564+
prompt: () =>
565+
Effect.gen(function* () {
566+
const send = (update: EffectAcpSchema.SessionUpdate) =>
567+
sessionUpdate === undefined
568+
? Effect.die("the adapter must handle session updates")
569+
: sessionUpdate({ sessionId: "mock-session-1", update });
570+
// agy_acp_server 1.3.0 and 1.4.0 without a permission prompt:
571+
// the title is "Running <tool>", rawInput holds only the
572+
// tool's arguments, and the completion reports the step's
573+
// own summary as rawOutput instead of the MCP result.
574+
const start = (toolCallId: string, rawInput: typeof revenue) =>
575+
send({
576+
sessionUpdate: "tool_call",
577+
toolCallId,
578+
title: "Running html_render",
579+
kind: "other",
580+
status: "in_progress",
581+
rawInput,
582+
});
583+
yield* start("trajectory:1", revenue);
584+
yield* start("trajectory:2", { ...revenue, title: "Costs" });
585+
yield* start("trajectory:3", revenue);
586+
// T3's MCP server publishes while each call runs.
587+
yield* mcpSessions.recordHtmlRender(threadId, revenue, page("first"));
588+
yield* mcpSessions.recordHtmlRender(threadId, revenue, page("second"));
589+
yield* send({
590+
sessionUpdate: "tool_call_update",
591+
toolCallId: "trajectory:1",
592+
status: "completed",
593+
rawOutput: "Render revenue chart",
594+
});
595+
// A call with no page published for its arguments stays as reported.
596+
yield* send({
597+
sessionUpdate: "tool_call_update",
598+
toolCallId: "trajectory:2",
599+
status: "completed",
600+
rawOutput: "Render costs chart",
601+
});
602+
// A failed call does not claim a page.
603+
yield* send({
604+
sessionUpdate: "tool_call_update",
605+
toolCallId: "trajectory:3",
606+
status: "failed",
607+
rawOutput: "MCP call timed out",
608+
});
609+
return { stopReason: "end_turn" as const };
610+
}),
611+
})),
612+
),
613+
withProcess: (_stop, task) => task,
614+
defaultModel: Effect.succeed(undefined),
615+
});
616+
const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
617+
runtimeMode: "full-access",
618+
interactionMode: "default",
619+
cwd: process.cwd(),
620+
});
621+
const modelSelection = { instanceId, model: "gemini-test-low" } as const;
622+
const session = yield* adapter.openSession({
623+
threadId,
624+
providerSessionId: ProviderSessionId.make("provider-session-antigravity-html-render"),
625+
modelSelection,
626+
runtimePolicy,
627+
});
628+
const providerThread = yield* session.ensureThread({
629+
threadId,
630+
modelSelection,
631+
runtimePolicy,
632+
});
633+
const now = yield* DateTime.now;
634+
yield* session.startTurn({
635+
appThread: {
636+
createdBy: "user",
637+
creationSource: "web",
638+
id: threadId,
639+
projectId: ProjectId.make("project-antigravity-html-render"),
640+
title: "Antigravity html_render",
641+
providerInstanceId: instanceId,
642+
modelSelection,
643+
runtimeMode: "full-access",
644+
interactionMode: "default",
645+
branch: null,
646+
worktreePath: process.cwd(),
647+
activeProviderThreadId: providerThread.id,
648+
lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
649+
forkedFrom: null,
650+
createdAt: now,
651+
updatedAt: now,
652+
archivedAt: null,
653+
settledOverride: null,
654+
settledAt: null,
655+
lastVisitedAt: null,
656+
deletedAt: null,
657+
},
658+
threadId,
659+
runId: RunId.make("run-antigravity-html-render"),
660+
runOrdinal: 1,
661+
providerTurnOrdinal: 1,
662+
attemptId: RunAttemptId.make("attempt-antigravity-html-render"),
663+
rootNodeId: NodeId.make("node-antigravity-html-render"),
664+
providerThread,
665+
message: {
666+
createdBy: "user",
667+
creationSource: "web",
668+
messageId: MessageId.make("message-antigravity-html-render"),
669+
text: "chart the revenue",
670+
attachments: [],
671+
},
672+
modelSelection,
673+
runtimePolicy,
674+
});
675+
const events = yield* session.events.pipe(
676+
Stream.takeUntil((event) => event.type === "turn.terminal"),
677+
Stream.runCollect,
678+
);
679+
const finalItem = (nativeId: string) =>
680+
Array.from(events).findLast(
681+
(event) =>
682+
event.type === "turn_item.updated" &&
683+
event.turnItem.nativeItemRef?.nativeId === nativeId,
684+
);
685+
const tool = (nativeId: string) => {
686+
const event = finalItem(nativeId);
687+
const item = event?.type === "turn_item.updated" ? event.turnItem : undefined;
688+
return item?.type === "dynamic_tool"
689+
? {
690+
status: item.status,
691+
toolName: item.toolName,
692+
page: htmlRenderFromToolItem(item),
693+
output: item.output,
694+
}
695+
: undefined;
696+
};
697+
698+
assert.deepEqual(tool("trajectory:1"), {
699+
status: "completed",
700+
toolName: "t3-code.html_render",
701+
page: page("first"),
702+
output: { htmlRender: page("first") },
703+
});
704+
assert.deepEqual(tool("trajectory:2"), {
705+
status: "completed",
706+
toolName: "t3-code.html_render",
707+
page: undefined,
708+
output: "Render costs chart",
709+
});
710+
assert.deepEqual(tool("trajectory:3"), {
711+
status: "failed",
712+
toolName: "t3-code.html_render",
713+
page: undefined,
714+
output: "MCP call timed out",
715+
});
716+
// Each page goes to one call; the unclaimed one stays for a later call.
717+
assert.deepEqual(yield* mcpSessions.takeHtmlRender(threadId, revenue), page("second"));
718+
}).pipe(Effect.provide(layerSession), Effect.scoped),
719+
);
720+
});

0 commit comments

Comments
 (0)