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

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

fix(antigravity): thread sessions spawn with their T3 thread and MCP environment (#36495)

Luis Marsiglia committed Nov 18, 2026 at 09:26 UTC c67deb12ddd893b3771c7c6f8fdfada11654a7ec
3 files changed +107 -8
apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts
+7 -1
@@ -70,11 +70,17 @@ const AntigravityProviderCapabilitiesV2 = {
70 },
71 } satisfies OrchestrationV2ProviderCapabilities;
72
73 +/** Thread variables reach the driver here; `makeAntigravityAcpRuntime` never reads them. */
74 +export type AntigravityAdapterV2RuntimeInput = Omit<
75 + AntigravityAcpRuntimeInput,
76 + "spawn" | "childProcessSpawner"
77 +> & { readonly processEnvironment?: NodeJS.ProcessEnv };
78 +
79 export interface AntigravityAdapterV2Options {
80 readonly instanceId: ProviderInstanceId;
81 readonly selfInvocation: SelfInvocation;
82 readonly makeRuntime: (
77 - input: Omit<AntigravityAcpRuntimeInput, "spawn" | "childProcessSpawner">,
83 + input: AntigravityAdapterV2RuntimeInput,
84 ) => Effect.Effect<
85 AcpSessionRuntime.AcpSessionRuntime["Service"],
86 EffectAcpErrors.AcpError | ProviderSetupError,
apps/server/src/provider/Drivers/AntigravityDriver.test.ts
+83 -1
@@ -3,6 +3,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
3 import { expect, it } from "@effect/vitest";
4 import {
5 ANTIGRAVITY_DEFAULT_MODEL,
6 + EnvironmentId,
7 ProviderInstanceId,
8 ProviderSessionId,
9 ThreadId,
@@ -57,7 +58,12 @@ function shellQuote(value: string): string {
58 }
59
60 const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
60 - options: { readonly config?: Partial<AntigravitySettings>; readonly enabled?: boolean } = {},
61 + options: {
62 + readonly config?: Partial<AntigravitySettings>;
63 + readonly enabled?: boolean;
64 + /** Extra instance variables, such as ones a parent T3 turn already exported. */
65 + readonly environment?: ReadonlyArray<{ readonly name: string; readonly value: string }>;
66 + } = {},
67 ) {
68 const fs = yield* FileSystem.FileSystem;
69 const path = yield* Path.Path;
@@ -136,6 +142,7 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
142 args: ReadonlyArray<string>;
143 cwd: string | undefined;
144 extendEnv: boolean | undefined;
145 + environment: Record<string, string | undefined>;
146 profileDirectory: string | undefined;
147 harnessPath: string | undefined;
148 forceFileStorage: string | undefined;
@@ -191,6 +198,7 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
198 args: command.args.map(String),
199 cwd: command.options.cwd,
200 extendEnv: command.options.extendEnv,
201 + environment: Object.fromEntries(Object.keys(environment).map((name) => [name, env(name)])),
202 profileDirectory: env("GEMINI_HOME"),
203 harnessPath: env("ANTIGRAVITY_HARNESS_PATH"),
204 forceFileStorage: env("AGY_ACP_FORCE_FILE_STORAGE"),
@@ -221,6 +229,7 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
229 { name: "GEMINI_HOME", value: "/must-not-be-used" },
230 { name: "ANTIGRAVITY_HARNESS_PATH", value: "/must-not-be-used" },
231 { name: "BROWSER", value: "must-not-run" },
232 + ...(options.environment ?? []),
233 ].map((variable) => ({ ...variable, sensitive: false })),
234 }).pipe(
235 Effect.provide(layerInstallation),
@@ -447,6 +456,79 @@ it.layer(layerTest)("AntigravityDriver", (it) => {
456 }),
457 );
458
459 + it.effect.skipIf(windowsHost)(
460 + "gives a thread session its own T3 thread and MCP fallback environment",
461 + () =>
462 + Effect.gen(function* () {
463 + const h = yield* makeHarness({
464 + environment: [
465 + { name: "T3CODE_THREAD_ID", value: "thread-antigravity-ambient" },
466 + { name: "T3_ACP_MCP_ENDPOINT", value: "http://127.0.0.1:9/ambient" },
467 + { name: "T3_ACP_MCP_AUTHORIZATION", value: "Bearer ambient-token" },
468 + { name: "T3_ACP_MCP_NODE", value: "/ambient/node" },
469 + { name: "T3_ACP_MCP_ENTRYPOINT", value: "/ambient/entrypoint.mjs" },
470 + ],
471 + });
472 + yield* h.refresh();
473 + const endpoint = "http://127.0.0.1:43126/mcp";
474 + const threadId = ThreadId.make("thread-antigravity-process-environment");
475 + yield* (yield* McpProviderSessions.McpProviderSessions).set({
476 + environmentId: EnvironmentId.make("environment-antigravity-process-environment"),
477 + threadId,
478 + providerSessionId: "mcp-session-antigravity-process-environment",
479 + providerInstanceId: h.instance.instanceId,
480 + endpoint,
481 + authorizationHeader: "Bearer antigravity-thread-token",
482 + browserToolsAvailable: false,
483 + });
484 + // Running from source, the fallback entrypoint is this process's script.
485 + const entrypoint = h.path.resolve(process.argv[1]!);
486 + yield* Effect.scoped(
487 + Effect.gen(function* () {
488 + const workspace = yield* h.fs.makeTempDirectoryScoped({ prefix: "t3-ag-environment-" });
489 + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
490 + runtimeMode: "approval-required",
491 + interactionMode: "default",
492 + cwd: workspace,
493 + });
494 + const modelSelection = { instanceId: h.instance.instanceId, model: "gemini-test-low" };
495 + const session = yield* h.instance.orchestrationAdapter.openSession({
496 + threadId,
497 + providerSessionId: ProviderSessionId.make(
498 + "provider-session-antigravity-process-environment",
499 + ),
500 + modelSelection,
501 + runtimePolicy,
502 + });
503 + yield* session.ensureThread({ threadId, modelSelection, runtimePolicy });
504 + }),
505 + );
506 +
507 + // Gemini Enterprise can strip the native MCP servers, and the documented `acp-mcp-call`
508 + // fallback reads these from the shell.
509 + const agentLaunches = h.launches.filter(
510 + (launch) => launch.command === h.first.executablePath,
511 + );
512 + expect(agentLaunches).toHaveLength(2);
513 + expect(agentLaunches[1]?.environment).toMatchObject({
514 + T3CODE_THREAD_ID: threadId,
515 + T3_ACP_MCP_ENDPOINT: endpoint,
516 + T3_ACP_MCP_AUTHORIZATION: "Bearer antigravity-thread-token",
517 + T3_ACP_MCP_NODE: process.execPath,
518 + T3_ACP_MCP_ENTRYPOINT: entrypoint,
519 + });
520 + // Model refresh and sign-in launches are not part of a thread.
521 + expect(agentLaunches[0]?.environment).toMatchObject({
522 + T3CODE_THREAD_ID: "thread-antigravity-ambient",
523 + T3_ACP_MCP_ENDPOINT: "http://127.0.0.1:9/ambient",
524 + T3_ACP_MCP_AUTHORIZATION: "Bearer ambient-token",
525 + T3_ACP_MCP_NODE: "/ambient/node",
526 + T3_ACP_MCP_ENTRYPOINT: "/ambient/entrypoint.mjs",
527 + });
528 + yield* h.assertClosed;
529 + }),
530 + );
531 +
532 it.effect.skipIf(windowsHost)(
533 "closes refresh processes and clears account metadata when Google sign-in is required",
534 () =>
apps/server/src/provider/Drivers/AntigravityDriver.ts
+17 -6
@@ -58,7 +58,10 @@ import {
58 } from "../acp/AntigravitySessionFiles.ts";
59 import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
60 import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests";
61 -import { makeAntigravityAdapterV2 } from "../../orchestration-v2/Adapters/AntigravityAdapterV2.ts";
61 +import {
62 + makeAntigravityAdapterV2,
63 + type AntigravityAdapterV2RuntimeInput,
64 +} from "../../orchestration-v2/Adapters/AntigravityAdapterV2.ts";
65 import { makeAcpNativeLoggerFactory } from "@t3tools/provider-acp/server/nativeLogging";
66 import { ProviderDriverError } from "../Errors.ts";
67 import { makeAntigravityProvider } from "../AntigravityProvider.ts";
@@ -198,7 +201,7 @@ export const AntigravityDriver: ProviderDriver<
201 );
202
203 const makeRuntime = Effect.fn("AntigravityDriver.makeRuntime")(function* (
201 - input: Omit<AntigravityAcpRuntimeInput, "spawn" | "childProcessSpawner">,
204 + input: AntigravityAdapterV2RuntimeInput,
205 ): Effect.fn.Return<
206 AcpSessionRuntime.AcpSessionRuntime["Service"],
207 AcpErrors.AcpError | ProviderSetupError,
@@ -267,16 +270,23 @@ export const AntigravityDriver: ProviderDriver<
270 ),
271 ),
272 );
273 + // `buildAntigravityAcpSpawnInput` sets `extendEnv: false`, so thread variables only reach the
274 + // agent's shell through `baseEnv`.
275 + const { processEnvironment: threadEnvironment, ...runtimeInput } = input;
276 + const spawnEnvironment =
277 + threadEnvironment === undefined
278 + ? processEnvironment
279 + : { ...processEnvironment, ...threadEnvironment };
280 const runtime = yield* makeAntigravityAcpRuntime({
271 - ...input,
281 + ...runtimeInput,
282 runtimeVersion: executable.version,
283 authMethod: auth.authMethod,
284 childProcessSpawner: spawner,
285 spawn: buildAntigravityAcpSpawnInput({
286 installation: executable,
287 profile,
278 - cwd: input.cwd,
279 - baseEnv: processEnvironment,
288 + cwd: runtimeInput.cwd,
289 + baseEnv: spawnEnvironment,
290 auth,
291 runtimeTempDirectory,
292 }),
@@ -291,7 +301,8 @@ export const AntigravityDriver: ProviderDriver<
301 .start()
302 .pipe(
303 Effect.tapError((cause): Effect.Effect<void> =>
294 - input.onAuthorizationUrl === undefined && isAntigravitySignInRequiredError(cause)
304 + runtimeInput.onAuthorizationUrl === undefined &&
305 + isAntigravitySignInRequiredError(cause)
306 ? provider.onAuthRequired
307 : Effect.void,
308 ),