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

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

fix(antigravity): check account access after installation (#32446)

Yash Singh committed Nov 7, 2026 at 05:41 UTC e3441535afbbdf7af5349f619b7cc96dc2da44ef
5 files changed +215 -60
apps/server/src/provider/providerInstallation.test.ts
+133 -54
@@ -7,6 +7,8 @@ import {
7 } from "@t3tools/contracts";
8 import * as HostProcess from "@t3tools/shared/HostProcess";
9 import * as Effect from "effect/Effect";
10 +import * as Deferred from "effect/Deferred";
11 +import * as SubscriptionRef from "effect/SubscriptionRef";
12 import * as FileSystem from "effect/FileSystem";
13 import * as Layer from "effect/Layer";
14 import * as Path from "effect/Path";
@@ -15,8 +17,9 @@ import * as Stream from "effect/Stream";
17 import * as ServerSettings from "../serverSettings.ts";
18 import * as CodexInstallation from "./CodexInstallation.ts";
19 import * as AntigravityInstallation from "./AntigravityInstallation.ts";
20 +import { ProviderDriverError } from "@t3tools/provider-core/server/errors";
21 import type { ProviderInstance } from "@t3tools/provider-core/server/driver";
19 -import { makeProviderInstallation } from "./providerInstallation.ts";
22 +import * as ProviderInstallation from "./providerInstallation.ts";
23 import * as ProviderInstanceRegistry from "./ProviderInstanceRegistry.ts";
24 import * as ProviderRegistry from "./ProviderRegistry.ts";
25
@@ -60,69 +63,145 @@ const makeHarness = Effect.fn("providerInstallation.test.makeHarness")(function*
63 } = {},
64 ) {
65 const calls: string[] = [];
66 + const refreshed = yield* Deferred.make<void>();
67 + const observed = yield* Deferred.make<void>();
68 + const listening = yield* Deferred.make<void>();
69 + const installationState = yield* SubscriptionRef.make(state);
70 let protectedPaths: ReadonlyArray<string> = [];
71 const configured = input.instance ?? instance();
65 - const router = yield* makeProviderInstallation().pipe(
66 - Effect.provide(
67 - Layer.mergeAll(
68 - ServerSettings.layerTest(input.settings),
69 - Layer.mock(ProviderInstanceRegistry.ProviderInstanceRegistry)({
70 - getInstance: (id) =>
71 - Effect.succeed(id === configured.instanceId ? configured : undefined),
72 - listInstances: Effect.succeed([configured]),
72 + const dependencies = Layer.mergeAll(
73 + ServerSettings.layerTest(input.settings),
74 + Layer.mock(ProviderInstanceRegistry.ProviderInstanceRegistry)({
75 + getInstance: (id) => Effect.succeed(id === configured.instanceId ? configured : undefined),
76 + listInstances: Effect.succeed([configured]),
77 + }),
78 + Layer.mock(ProviderRegistry.ProviderRegistry)({
79 + refreshInstance: () =>
80 + Effect.sync(() => {
81 + calls.push("refresh");
82 + return [];
83 + }).pipe(Effect.tap(() => Deferred.succeed(refreshed, undefined))),
84 + }),
85 + Layer.mock(CodexInstallation.CodexInstallation)({
86 + managedDirectory: "/unused-managed-codex",
87 + start: Effect.sync(() => {
88 + calls.push("codex-start");
89 + return { ...state, driver: ProviderDriverKind.make("codex") };
90 + }),
91 + cancel: () =>
92 + Effect.sync(() => {
93 + calls.push("codex-cancel");
94 + return { ...state, driver: ProviderDriverKind.make("codex") };
95 }),
74 - Layer.mock(ProviderRegistry.ProviderRegistry)({
75 - refreshInstance: () =>
76 - Effect.sync(() => {
77 - calls.push("refresh");
78 - return [];
79 - }),
96 + state: Effect.succeed({ ...state, driver: ProviderDriverKind.make("codex") }),
97 + changes: Stream.succeed({ ...state, driver: ProviderDriverKind.make("codex") }),
98 + remove: (paths) =>
99 + Effect.sync(() => {
100 + protectedPaths = paths ?? [];
101 + calls.push("codex-remove");
102 }),
81 - Layer.mock(CodexInstallation.CodexInstallation)({
82 - managedDirectory: "/unused-managed-codex",
83 - start: Effect.sync(() => {
84 - calls.push("codex-start");
85 - return { ...state, driver: ProviderDriverKind.make("codex") };
86 - }),
87 - cancel: () =>
88 - Effect.sync(() => {
89 - calls.push("codex-cancel");
90 - return { ...state, driver: ProviderDriverKind.make("codex") };
91 - }),
92 - state: Effect.succeed({ ...state, driver: ProviderDriverKind.make("codex") }),
93 - changes: Stream.succeed({ ...state, driver: ProviderDriverKind.make("codex") }),
94 - remove: (paths) =>
95 - Effect.sync(() => {
96 - protectedPaths = paths ?? [];
97 - calls.push("codex-remove");
98 - }),
103 + }),
104 + Layer.mock(AntigravityInstallation.AntigravityInstallation)({
105 + managedDirectory: "/unused-managed-runtime",
106 + start: Effect.sync(() => {
107 + calls.push("start");
108 + return { ...state, operationId: "install-1", phase: "downloading" as const };
109 + }).pipe(Effect.tap((started) => SubscriptionRef.set(installationState, started))),
110 + cancel: () =>
111 + Effect.sync(() => {
112 + calls.push("cancel");
113 + return state;
114 }),
100 - Layer.mock(AntigravityInstallation.AntigravityInstallation)({
101 - managedDirectory: "/unused-managed-runtime",
102 - start: Effect.sync(() => {
103 - calls.push("start");
104 - return state;
105 - }),
106 - cancel: () =>
107 - Effect.sync(() => {
108 - calls.push("cancel");
109 - return state;
110 - }),
111 - state: Effect.succeed(state),
112 - changes: Stream.succeed(state),
113 - remove: (paths) =>
114 - Effect.sync(() => {
115 - protectedPaths = paths ?? [];
116 - calls.push("remove");
117 - }),
115 + state: Effect.succeed(state),
116 + changes: input.instance?.refreshModels
117 + ? SubscriptionRef.changes(installationState).pipe(
118 + Stream.tap(() => Deferred.succeed(listening, undefined)),
119 + Stream.ensuring(Deferred.succeed(observed, undefined)),
120 + )
121 + : Stream.succeed(state),
122 + remove: (paths) =>
123 + Effect.sync(() => {
124 + protectedPaths = paths ?? [];
125 + calls.push("remove");
126 }),
119 - ),
120 - ),
127 + }),
128 );
122 - return { router, calls, protectedPaths: () => protectedPaths };
129 + const context = yield* Layer.build(ProviderInstallation.layer.pipe(Layer.provide(dependencies)));
130 + const connect = Effect.service(ProviderInstallation.ProviderInstallation).pipe(
131 + Effect.provide(context),
132 + );
133 + const router = yield* connect;
134 + return {
135 + router,
136 + connect,
137 + listening,
138 + calls,
139 + refreshed,
140 + observed,
141 + installationState,
142 + protectedPaths: () => protectedPaths,
143 + };
144 });
145
146 describe("provider installation routing", () => {
147 + it.effect.each([
148 + { phase: "succeeded", enabled: true, checkFails: false, expectedChecks: 1 },
149 + { phase: "succeeded", enabled: true, checkFails: true, expectedChecks: 1 },
150 + { phase: "succeeded", enabled: false, checkFails: false, expectedChecks: 0 },
151 + { phase: "cancelled", enabled: true, checkFails: false, expectedChecks: 0 },
152 + { phase: "failed", enabled: true, checkFails: false, expectedChecks: 0 },
153 + ] as const)(
154 + "checks account access once after installation is $phase, enabled=$enabled, checkFails=$checkFails",
155 + ({ phase, enabled, checkFails, expectedChecks }) =>
156 + Effect.gen(function* () {
157 + let checks = 0;
158 + const harness = yield* makeHarness({
159 + instance: Object.assign(instance(), {
160 + enabled,
161 + refreshModels: () =>
162 + Effect.sync(() => {
163 + checks++;
164 + }).pipe(
165 + Effect.andThen(
166 + checkFails
167 + ? Effect.fail(
168 + new ProviderDriverError({
169 + driver,
170 + instanceId,
171 + detail: "Sign in required.",
172 + }),
173 + )
174 + : Effect.void,
175 + ),
176 + ),
177 + }),
178 + });
179 + yield* Effect.gen(function* () {
180 + const first = yield* harness.connect;
181 + const second = yield* harness.connect;
182 + yield* Effect.all([first.start({ instanceId }), second.start({ instanceId })], {
183 + concurrency: "unbounded",
184 + });
185 + yield* Deferred.await(harness.listening);
186 + }).pipe(Effect.scoped);
187 + assert.isFalse(yield* Deferred.isDone(harness.observed));
188 + assert.strictEqual(checks, 0);
189 + yield* SubscriptionRef.set(harness.installationState, {
190 + ...state,
191 + operationId: "install-1",
192 + phase,
193 + installedVersion: phase === "succeeded" ? "1.5.1" : null,
194 + });
195 + yield* Deferred.await(harness.observed);
196 + if (expectedChecks > 0) yield* Deferred.await(harness.refreshed);
197 + assert.strictEqual(checks, expectedChecks);
198 + assert.deepEqual(
199 + harness.calls,
200 + expectedChecks > 0 ? ["start", "start", "refresh"] : ["start", "start"],
201 + );
202 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
203 + );
204 +
205 it.effect("keeps external installs manual without hiding shared install status", () =>
206 Effect.gen(function* () {
207 const harness = yield* makeHarness({
apps/server/src/provider/providerInstallation.ts
+76 -4
@@ -3,12 +3,18 @@ import {
3 CodexSettings,
4 ProviderDriverKind,
5 type ProviderInstallCancelInput,
6 + type ProviderInstallState,
7 type ProviderInstanceId,
8 ProviderSetupError,
9 type ProviderSetupInput,
10 } from "@t3tools/contracts";
11 import { resolveCommandPath } from "@t3tools/shared/shell";
12 +import * as Context from "effect/Context";
13 import * as Effect from "effect/Effect";
14 +import * as Layer from "effect/Layer";
15 +import * as FileSystem from "effect/FileSystem";
16 +import * as Path from "effect/Path";
17 +import * as Option from "effect/Option";
18 import * as Schema from "effect/Schema";
19 import * as Stream from "effect/Stream";
20
@@ -25,12 +31,34 @@ const hasBinaryPath = Schema.is(Schema.Struct({ binaryPath: Schema.String }));
31 const decodeCodexSettings = Schema.decodeUnknownEffect(CodexSettings);
32 const decodeAntigravitySettings = Schema.decodeUnknownEffect(AntigravitySettings);
33
28 -export const makeProviderInstallation = Effect.fn("makeProviderInstallation")(function* () {
34 +export class ProviderInstallation extends Context.Service<
35 + ProviderInstallation,
36 + {
37 + readonly start: (
38 + input: ProviderSetupInput,
39 + ) => Effect.Effect<ProviderInstallState, ProviderSetupError>;
40 + readonly cancel: (
41 + input: ProviderInstallCancelInput,
42 + ) => Effect.Effect<ProviderInstallState, ProviderSetupError>;
43 + readonly subscribe: (
44 + input: ProviderSetupInput,
45 + ) => Stream.Stream<ProviderInstallState, ProviderSetupError>;
46 + readonly remove: (
47 + input: ProviderSetupInput,
48 + ) => Effect.Effect<ProviderInstallState, ProviderSetupError>;
49 + }
50 +>()("t3/provider/providerInstallation") {}
51 +
52 +const make = Effect.fn("makeProviderInstallation")(function* () {
53 const antigravityInstallation = yield* AntigravityInstallation.AntigravityInstallation;
54 const codexInstallation = yield* CodexInstallation.CodexInstallation;
55 const instances = yield* ProviderInstanceRegistry.ProviderInstanceRegistry;
56 const providers = yield* ProviderRegistry.ProviderRegistry;
57 const settings = yield* ServerSettings.ServerSettingsService;
58 + const fileSystem = yield* FileSystem.FileSystem;
59 + const path = yield* Path.Path;
60 + const scope = yield* Effect.scope;
61 + const accountCheckOperations = new Map<ProviderInstanceId, string>();
62
63 const readEntries = Effect.fn("ProviderInstallation.readEntries")(function* (
64 instanceId: ProviderInstanceId,
@@ -106,8 +134,47 @@ export const makeProviderInstallation = Effect.fn("makeProviderInstallation")(fu
134 new ProviderSetupError({ instanceId, operation: error.operation, detail: error.detail });
135
136 const start = Effect.fn("ProviderInstallation.start")(function* (input: ProviderSetupInput) {
109 - const { installation } = yield* requireInstance(input.instanceId, "install", true);
110 - return yield* installation.start.pipe(Effect.mapError(failure(input.instanceId)));
137 + const { installation, driver } = yield* requireInstance(input.instanceId, "install", true);
138 + const started = yield* installation.start.pipe(Effect.mapError(failure(input.instanceId)));
139 + if (
140 + driver === ANTIGRAVITY &&
141 + started.operationId !== null &&
142 + accountCheckOperations.get(input.instanceId) !== started.operationId
143 + ) {
144 + accountCheckOperations.set(input.instanceId, started.operationId);
145 + // Installation outlives the request and may finish while every client is disconnected.
146 + yield* installation.changes.pipe(
147 + Stream.filter(
148 + (state) =>
149 + state.operationId !== started.operationId ||
150 + state.phase === "succeeded" ||
151 + state.phase === "failed" ||
152 + state.phase === "cancelled",
153 + ),
154 + Stream.runHead,
155 + Effect.flatMap(
156 + Effect.fnUntraced(function* (result) {
157 + if (
158 + Option.isNone(result) ||
159 + result.value.operationId !== started.operationId ||
160 + result.value.phase !== "succeeded"
161 + )
162 + return;
163 + const instance = yield* instances.getInstance(input.instanceId);
164 + if (
165 + instance?.driverKind !== ANTIGRAVITY ||
166 + !instance.enabled ||
167 + !instance.refreshModels
168 + )
169 + return;
170 + yield* instance.refreshModels().pipe(Effect.ignore({ log: true }));
171 + yield* providers.refreshInstance(input.instanceId);
172 + }),
173 + ),
174 + Effect.forkIn(scope),
175 + );
176 + }
177 + return started;
178 });
179
180 const cancel = Effect.fn("ProviderInstallation.cancel")(function* (
@@ -142,7 +209,10 @@ export const makeProviderInstallation = Effect.fn("makeProviderInstallation")(fu
209 const binaryPath = entry.config.binaryPath.trim();
210 const resolved = yield* resolveCommandPath(binaryPath, {
211 env: yield* mergeProviderInstanceEnvironment(entry.environment),
145 - });
212 + }).pipe(
213 + Effect.provideService(FileSystem.FileSystem, fileSystem),
214 + Effect.provideService(Path.Path, path),
215 + );
216 return resolved === null ? [binaryPath] : [binaryPath, resolved];
217 }),
218 );
@@ -160,3 +230,5 @@ export const makeProviderInstallation = Effect.fn("makeProviderInstallation")(fu
230
231 return { start, cancel, subscribe, remove };
232 });
233 +
234 +export const layer = Layer.effect(ProviderInstallation, make());
apps/server/src/server.ts
+2
@@ -108,6 +108,7 @@ import * as ManagedPolicy from "./policy/ManagedPolicy.ts";
108 import * as ProjectEnrichmentService from "./project/ProjectEnrichmentService.ts";
109 import * as NativeAppIconResolver from "./assets/NativeAppIconResolver.ts";
110 import * as AntigravityInstallation from "./provider/AntigravityInstallation.ts";
111 +import * as ProviderInstallation from "./provider/providerInstallation.ts";
112 import * as CodexInstallation from "./provider/CodexInstallation.ts";
113 import * as ProviderInstanceRegistry from "./provider/ProviderInstanceRegistry.ts";
114 import * as ProviderAdapterRegistry from "./orchestration-v2/ProviderAdapterRegistry.ts";
@@ -666,6 +667,7 @@ const layerRuntimeCoreDependenciesBase = Layer.mergeAll(
667 ).pipe(Layer.provide(DelegatedTaskQuestionReactor.layer), Layer.provide(ProjectionStoreV2.layer)),
668 ProviderUsageLimitsIngestion.layer,
669 layerProviderInstallationRefresh,
670 + ProviderInstallation.layer,
671 ReplayMarkers.layer,
672 Layer.effectDiscard(ProjectSettingsOverrideSweep.sweep),
673 ).pipe(
apps/server/src/ws.test.ts
+2
@@ -51,6 +51,7 @@ import * as AgentSessionImporter from "./project/AgentSessionImporter.ts";
51 import * as AgentSessionScanner from "./project/AgentSessionScanner.ts";
52 import * as AnalyticsService from "./telemetry/AnalyticsService.ts";
53 import * as AntigravityInstallation from "./provider/AntigravityInstallation.ts";
54 +import * as ProviderInstallation from "./provider/providerInstallation.ts";
55 import * as BackgroundPolicy from "./background/BackgroundPolicy.ts";
56 import * as CheckpointDiffQuery from "./checkpointing/CheckpointDiffQuery.ts";
57 import * as NativeChildWorkQuery from "./orchestration-v2/NativeChildWorkQuery.ts";
@@ -802,6 +803,7 @@ const layerUnusedConfigRpcServices = Layer.mergeAll(
803 Layer.mock(ProjectSetupScriptRunner.ProjectSetupScriptRunner)({}),
804 Layer.mock(ProjectStore.ProjectStoreV2)({}),
805 Layer.mock(ProviderAuthService.ProviderAuthService)({}),
806 + Layer.mock(ProviderInstallation.ProviderInstallation)({}),
807 Layer.mock(ProviderInstanceRegistry.ProviderInstanceRegistry)({}),
808 Layer.mock(ProviderLatestVersions.ProviderLatestVersions)({}),
809 Layer.mock(ProviderMaintenanceRunner.ProviderMaintenanceRunner)({}),
apps/server/src/ws.ts
+2 -2
@@ -178,7 +178,7 @@ import * as AcpRegistrySupport from "@t3tools/provider-acp-registry/server/AcpRe
178 import * as AcpRegistryRuntimeCoordinator from "@t3tools/provider-acp-registry/server/AcpRegistryRuntimeCoordinator";
179 import * as ProviderMaintenanceRunner from "./provider/providerMaintenanceRunner.ts";
180 import * as ProviderAuthService from "./provider/ProviderAuthService.ts";
181 -import { makeProviderInstallation } from "./provider/providerInstallation.ts";
181 +import * as ProviderInstallation from "./provider/providerInstallation.ts";
182 import * as ServerSelfUpdate from "./cloud/selfUpdate.ts";
183 import * as NpmRelease from "./cloud/npmRelease.ts";
184 import * as ServerLifecycleEvents from "./serverLifecycleEvents.ts";
@@ -1496,7 +1496,7 @@ export const layerWsRpc = (
1496 yield* AcpRegistryRuntimeCoordinator.AcpRegistryRuntimeCoordinator;
1497 const providerMaintenanceRunner = yield* ProviderMaintenanceRunner.ProviderMaintenanceRunner;
1498 const providerAuth = yield* ProviderAuthService.ProviderAuthService;
1499 - const providerInstallation = yield* makeProviderInstallation();
1499 + const providerInstallation = yield* ProviderInstallation.ProviderInstallation;
1500 const serverSelfUpdate = yield* ServerSelfUpdate.ServerSelfUpdate;
1501 const npmRelease = yield* NpmRelease.NpmRelease;
1502 const config = yield* ServerConfig.ServerConfig;