Skip to content

Commit 29f340c

Browse files
committed
fix(server): Antigravity sessions no longer fail when the browser preflight is slow
The browser-suppression preflight was cut off after 5 seconds, so a busy machine failed every session open. Allow 30 seconds and remember a successful verification per runtime executable so later opens skip the spawn. Failures are not cached.
1 parent e27a03e commit 29f340c

2 files changed

Lines changed: 99 additions & 1 deletion

File tree

‎apps/server/src/provider/antigravityAuthSupport.test.ts‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ import * as Layer from "effect/Layer";
1010
import * as Path from "effect/Path";
1111
import * as Result from "effect/Result";
1212
import * as Schema from "effect/Schema";
13+
import * as Sink from "effect/Sink";
1314
import * as Stream from "effect/Stream";
15+
import * as Deferred from "effect/Deferred";
16+
import * as Fiber from "effect/Fiber";
1417
import * as Ndjson from "effect/encoding/Ndjson";
18+
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
19+
import * as TestClock from "effect/testing/TestClock";
1520
import * as AcpErrors from "effect-acp/errors";
1621
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
1722

@@ -639,6 +644,90 @@ it.layer(NodeServices.layer)("Antigravity profile preparation", (it) => {
639644
}),
640645
);
641646

647+
// Stands in for the helper process: it prints the expected marker, then exits after
648+
// `exitDelay`. `started` completes once the exit wait begins, so the TestClock is only
649+
// advanced after the preflight timer and the delay are both registered.
650+
const preflightHelper = (exitDelay: Effect.Effect<void>) => {
651+
const spawns = { count: 0 };
652+
const started = Deferred.makeUnsafe<void>();
653+
const spawner = ChildProcessSpawner.make(() =>
654+
Effect.sync(() => {
655+
spawns.count += 1;
656+
return ChildProcessSpawner.makeHandle({
657+
pid: ChildProcessSpawner.ProcessId(1),
658+
exitCode: Deferred.succeed(started, undefined).pipe(
659+
Effect.andThen(exitDelay),
660+
Effect.as(ChildProcessSpawner.ExitCode(0)),
661+
),
662+
isRunning: Effect.succeed(false),
663+
kill: () => Effect.void,
664+
unref: Effect.succeed(Effect.void),
665+
stdin: Sink.drain,
666+
stdout: Stream.empty,
667+
stderr: Stream.encodeText(
668+
Stream.make(
669+
`${ANTIGRAVITY_AUTH_BROWSER_MARKER}"https://example.invalid/t3-antigravity-browser-preflight"\n`,
670+
),
671+
),
672+
all: Stream.empty,
673+
getInputFd: () => Sink.drain,
674+
getOutputFd: () => Stream.empty,
675+
});
676+
}),
677+
);
678+
return { spawner, spawns, started };
679+
};
680+
681+
const prepareWithHelper = Effect.fn(function* (
682+
runtimeExecutablePath: string,
683+
spawner: ChildProcessSpawner.ChildProcessSpawner["Service"],
684+
) {
685+
const fs = yield* FileSystem.FileSystem;
686+
const path = yield* Path.Path;
687+
const directory = yield* fs.makeTempDirectoryScoped();
688+
return yield* prepareAntigravityProfile({
689+
profileDirectory: path.join(directory, "profile"),
690+
userHome: path.join(directory, "home"),
691+
runtimeExecutablePath,
692+
platform: "linux",
693+
baseEnv: {},
694+
}).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner));
695+
});
696+
697+
it.effect("waits out a slow preflight and skips it once the helper was verified", () =>
698+
Effect.gen(function* () {
699+
const helper = preflightHelper(Effect.sleep("20 seconds"));
700+
const fiber = yield* prepareWithHelper("/fake/slow-node", helper.spawner).pipe(
701+
Effect.forkChild,
702+
);
703+
yield* Deferred.await(helper.started);
704+
yield* TestClock.adjust("20 seconds");
705+
yield* Fiber.join(fiber);
706+
707+
yield* prepareWithHelper("/fake/slow-node", helper.spawner);
708+
expect(helper.spawns.count).toBe(1);
709+
}),
710+
);
711+
712+
it.effect("fails a hung preflight after 30 seconds and verifies again on the next open", () =>
713+
Effect.gen(function* () {
714+
const hung = preflightHelper(Effect.never);
715+
const fiber = yield* prepareWithHelper("/fake/hung-node", hung.spawner).pipe(
716+
Effect.result,
717+
Effect.forkChild,
718+
);
719+
yield* Deferred.await(hung.started);
720+
yield* TestClock.adjust("29 seconds");
721+
expect(fiber.pollUnsafe()).toBeUndefined();
722+
yield* TestClock.adjust("1 second");
723+
expect(Result.isFailure(yield* Fiber.join(fiber))).toBe(true);
724+
725+
const recovered = preflightHelper(Effect.void);
726+
yield* prepareWithHelper("/fake/hung-node", recovered.spawner);
727+
expect(recovered.spawns.count).toBe(1);
728+
}),
729+
);
730+
642731
it.effect("rejects Python BROWSER delimiter collisions before starting a helper", () =>
643732
Effect.gen(function* () {
644733
const fs = yield* FileSystem.FileSystem;

‎apps/server/src/provider/antigravityAuthSupport.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ const browserHelperSource =
5858
`process.stderr.on("error",()=>process.exit(0)).write(` +
5959
`"${ANTIGRAVITY_AUTH_BROWSER_MARKER}"+JSON.stringify(process.argv[1])+"\\n",` +
6060
`()=>process.exit(0))`;
61+
62+
// A cold or busy machine can take several seconds to start Node, so the
63+
// preflight gets generous headroom rather than failing the session open.
64+
const browserHelperPreflightTimeout = "30 seconds";
65+
// Only successes are remembered: the result depends on the runtime executable,
66+
// so later session opens skip the spawn while a failure is re-checked each time.
67+
const verifiedBrowserHelpers = new Set<string>();
6168
const browserPreflightUrl = "https://example.invalid/t3-antigravity-browser-preflight";
6269

6370
const removedEnvironmentKeys = new Set([
@@ -392,7 +399,7 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(
392399
}).pipe(
393400
Effect.scoped,
394401
Effect.timeoutOrElse({
395-
duration: "5 seconds",
402+
duration: browserHelperPreflightTimeout,
396403
orElse: () =>
397404
Effect.fail(authSupportError("Antigravity browser suppression verification timed out.")),
398405
}),
@@ -401,6 +408,8 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(
401408
? error
402409
: authSupportError("Antigravity browser suppression could not be verified."),
403410
),
411+
Effect.tap(() => Effect.sync(() => verifiedBrowserHelpers.add(helperExecutable))),
412+
Effect.when(Effect.sync(() => !verifiedBrowserHelpers.has(helperExecutable))),
404413
);
405414

406415
for (const directory of [geminiHome, acpDirectory, tempDirectory]) {

0 commit comments

Comments
 (0)