@devries-cameron20 / t3code Mirror · read-only / commits / 356e6d02d5
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 04:15 UTC

fix(server): t3_preview_close reports the server browser's refusal (#17429)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Scott Norteman committed Oct 18, 2026 at 15:26 UTC 356e6d02d54aa49688fcdde1254676c276a78fb8
3 files changed +88 -5
apps/server/src/mcp/toolkits/previewControls/handlers.test.ts
+85
@@ -4,8 +4,10 @@ import { expect, it } from "@effect/vitest";
4 import {
5 DEFAULT_SERVER_SETTINGS,
6 EnvironmentId,
7 + PreviewAutomationControlInterruptedError,
8 ProjectId,
9 ProviderInstanceId,
10 + SERVER_BROWSER_AUTOMATION_CLIENT_ID,
11 ThreadId,
12 } from "@t3tools/contracts";
13 import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
@@ -101,3 +103,86 @@ it.effect.each([
103 }),
104 ),
105 );
106 +
107 +it.effect("close reports why the server browser refused to close a tab", () =>
108 + Effect.scoped(
109 + Effect.gen(function* () {
110 + const threadId = ThreadId.make("preview-controls-thread");
111 + const scope: McpInvocationContext.McpInvocationScope = {
112 + environmentId: EnvironmentId.make("preview-controls-environment"),
113 + requestNamespace: "preview-controls-provider-session",
114 + thread: {
115 + threadId,
116 + providerSessionId: "preview-controls-provider-session",
117 + providerInstanceId: ProviderInstanceId.make("codex"),
118 + },
119 + client: undefined,
120 + capabilities: new Set(["preview"]),
121 + issuedAt: 0,
122 + };
123 + const manager = yield* Preview.make.pipe(
124 + Effect.provide(
125 + Layer.merge(
126 + ServerConfig.layerTest(process.cwd(), { prefix: "t3-preview-controls-" }).pipe(
127 + Layer.provide(NodeServices.layer),
128 + ),
129 + NodeCrypto.layer,
130 + ),
131 + ),
132 + );
133 + const tab = yield* manager.open({
134 + threadId,
135 + url: "http://localhost:3000",
136 + runtime: "server",
137 + });
138 + const layerDependencies = Layer.mergeAll(
139 + Layer.mock(PreviewAutomationBroker.PreviewAutomationBroker)({
140 + invoke: () =>
141 + Effect.fail(
142 + new PreviewAutomationControlInterruptedError({
143 + operation: "close",
144 + environmentId: scope.environmentId,
145 + threadId,
146 + providerSessionId: "preview-controls-provider-session",
147 + providerInstanceId: ProviderInstanceId.make("codex"),
148 + clientId: SERVER_BROWSER_AUTOMATION_CLIENT_ID,
149 + connectionId: "server-browser-connection",
150 + requestId: "close-request",
151 + tabId: tab.tabId,
152 + timeoutMs: 1_000,
153 + remoteTag: "PreviewAutomationControlInterruptedError",
154 + remoteMessageLength: 0,
155 + cause: null,
156 + reason: "agentMismatch",
157 + }),
158 + ),
159 + }),
160 + Layer.succeed(Preview.PreviewManager, manager),
161 + Layer.succeed(McpInvocationContext.McpInvocationContext, scope),
162 + McpToolAccessTestkit.liveThreadsLayer,
163 + Layer.mock(ServerSettings.ServerSettingsService)({
164 + getSettings: Effect.succeed({
165 + ...DEFAULT_SERVER_SETTINGS,
166 + enableAgentBrowserAccess: true,
167 + }),
168 + }),
169 + );
170 + const toolkit = yield* PreviewControlsToolkit.pipe(
171 + Effect.provide(
172 + McpToolAccess.HandlersLayer.layer(PreviewControlsHandlers.layer).pipe(
173 + Layer.provide(layerDependencies),
174 + ),
175 + ),
176 + );
177 +
178 + const closed = yield* toolkit
179 + .handle("t3_preview_close", { tabId: tab.tabId })
180 + .pipe(Stream.unwrap, Stream.runCollect, Effect.provide(layerDependencies));
181 +
182 + expect(closed.at(-1)?.result).toMatchObject({
183 + _tag: "PreviewAutomationControlInterruptedError",
184 + reason: "agentMismatch",
185 + });
186 + }),
187 + ),
188 +);
apps/server/src/mcp/toolkits/previewControls/handlers.ts
+1 -3
@@ -32,9 +32,7 @@ export const layer = McpToolAccess.toLayer(PreviewControlsToolkit, {
32 sessions.some((session) => session.tabId === input.tabId && session.runtime === "server")
33 ) {
34 const broker = yield* PreviewAutomationBroker.PreviewAutomationBroker;
35 - yield* broker
36 - .invoke({ scope, operation: "close", input: {}, tabId: input.tabId })
37 - .pipe(Effect.mapError(unavailable));
35 + yield* broker.invoke({ scope, operation: "close", input: {}, tabId: input.tabId });
36 return {};
37 }
38 yield* manager
apps/server/src/mcp/toolkits/previewControls/tools.ts
+2 -2
@@ -1,7 +1,7 @@
1 import {
2 NonNegativeInt,
3 OrchestratorMcpFailure,
4 - PreviewAutomationUnavailableError,
4 + PreviewAutomationError,
5 PreviewListResult,
6 PreviewTabId,
7 } from "@t3tools/contracts";
@@ -13,7 +13,7 @@ import * as PreviewAutomationBroker from "../../PreviewAutomationBroker.ts";
13 import * as McpInvocationContext from "../../McpInvocationContext.ts";
14
15 const shared = {
16 - failure: Schema.Union([OrchestratorMcpFailure, PreviewAutomationUnavailableError]),
16 + failure: Schema.Union([PreviewAutomationError, OrchestratorMcpFailure]),
17 failureMode: "return" as const,
18 dependencies: [
19 McpInvocationContext.McpInvocationContext,