Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ function managedProviders(

function canManageProvider(provider: ServerProvider) {
return Boolean(
provider.setup?.canAuthenticate || (provider.driver === "acpRegistry" && provider.installed),
provider.setup?.canAuthenticate ||
provider.setup?.canInstall ||
(provider.driver === "acpRegistry" && provider.installed),
);
}

Expand All @@ -143,6 +145,10 @@ function ProviderAccount({
const instanceId = provider.instanceId;
const target = { environmentId, input: { instanceId } };
const auth = useEnvironmentQuery(serverEnvironment.providerAuthState(target));
const installation = useEnvironmentQuery(
provider.setup?.canInstall ? serverEnvironment.providerInstallState(target) : null,
);
const [installationDetailsOpen, setInstallationDetailsOpen] = useState(false);
const options = { reportFailure: false, reportDefect: false };
const start = useAtomCommand(serverEnvironment.startProviderAuth, options);
const respond = useAtomCommand(serverEnvironment.respondProviderAuth, options);
Expand Down Expand Up @@ -408,6 +414,58 @@ function ProviderAccount({
<ProviderAccountSummary key={email} name={name} status={status} email={email} />
{trailing}
</View>
{installation.data?.phase === "failed" && installation.data.diagnostics ? (
<View className="gap-2 px-4 pb-3">
<Text selectable accessibilityRole="alert" className="text-danger-foreground">
{installation.data.message}
</Text>
<Pressable
accessibilityRole="button"
accessibilityState={{ expanded: installationDetailsOpen }}
onPress={() => setInstallationDetailsOpen((open) => !open)}
>
<Text className="text-sm text-foreground">Installation details</Text>
</Pressable>
{installationDetailsOpen ? (
<>
<Text className="text-sm text-foreground-muted">
{installation.data.diagnostics.step}
</Text>
{installation.data.operationId ? (
<Text selectable className="font-mono text-xs text-foreground-muted">
Attempt: {installation.data.operationId}
</Text>
) : null}
{installation.data.diagnostics.systemError ? (
<Text className="text-sm text-foreground-muted">
{installation.data.diagnostics.systemError}
</Text>
) : null}
{installation.data.diagnostics.exitCode !== null ? (
<Text className="text-sm text-foreground-muted">
Exit code: {installation.data.diagnostics.exitCode}
</Text>
) : null}
{installation.data.diagnostics.signal !== null ? (
<Text className="text-sm text-foreground-muted">
Exit signal: {installation.data.diagnostics.signal}
</Text>
) : null}
<ScrollView className="max-h-48" nestedScrollEnabled>
<Text selectable className="font-mono text-sm text-foreground">
{installation.data.diagnostics.stderr ||
"No startup error output was captured for this check."}
</Text>
</ScrollView>
{installation.data.diagnostics.truncated ? (
<Text className="text-sm text-foreground-muted">
Some startup output was omitted or truncated.
</Text>
) : null}
</>
) : null}
</View>
) : null}
{interaction?.type === "deviceCode" ||
interaction?.type === "terminal" ||
interaction?.type === "credentials" ||
Expand Down
55 changes: 53 additions & 2 deletions apps/server/src/provider/AntigravityInstallation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,56 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst
}),
);

it.effect("retains startup diagnostics when ACP initialization times out", () =>
Effect.gen(function* () {
const entered = yield* Deferred.make<void>();
const spawner = ChildProcessSpawner.make(() =>
Effect.succeed(
ChildProcessSpawner.makeHandle({
pid: ChildProcessSpawner.ProcessId(1),
exitCode: Effect.never,
isRunning: Effect.succeed(true),
kill: () => Effect.void,
unref: Effect.succeed(Effect.void),
stdin: Sink.drain,
stdout: Stream.never,
stderr: Stream.succeed(
new TextEncoder().encode(
"Could not initialize local harness\nAuthorization: Bearer private-fixture-token\n",
),
).pipe(Stream.tap(() => Deferred.succeed(entered, undefined))),
all: Stream.empty,
getInputFd: () => Sink.drain,
getOutputFd: () => Stream.empty,
}),
),
);
const { installation } = yield* makeHarness({
previous: true,
useDefaultValidation: true,
spawner,
});
yield* installation.start;
yield* Deferred.await(entered);
yield* TestClock.adjust("90 seconds");
const failed = yield* terminalState(installation);
expect(failed).toMatchObject({
phase: "failed",
diagnostics: {
step: "Antigravity initialization",
stderr: "Could not initialize local harness\nAuthorization: [redacted]",
exitCode: null,
signal: null,
truncated: false,
},
});
yield* expectPreviousRelease(installation);
expect((yield* installation.start).diagnostics).toBeNull();
const running = yield* installation.state;
expect((yield* installation.cancel(running.operationId!)).diagnostics).toBeNull();
}),
);

it.effect.each(["downloaded", "existing", "concurrent"] as const)(
"reports a verification timeout for a %s runtime without changing the active release",
(source) =>
Expand Down Expand Up @@ -765,8 +815,9 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst
yield* TestClock.adjust("90 seconds");
expect(yield* terminalState(installation)).toMatchObject({
phase: "failed",
message:
"Antigravity runtime verification timed out after 90 seconds. Check this environment's server logs for startup errors, then retry installation.",
message: expect.stringContaining(
"Antigravity runtime verification timed out after 90 seconds.",
),
});
if (source !== "existing") yield* Deferred.await(stagingReleased);
yield* expectPreviousRelease(installation);
Expand Down
74 changes: 59 additions & 15 deletions apps/server/src/provider/AntigravityInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { resolveProviderCompatibility } from "./providerCompatibility.ts";
import { cliArchiveTarCommand } from "@t3tools/shared/cliRelease";
import { compareSemverVersions } from "@t3tools/shared/semver";
import * as EffectNodeStream from "@effect/platform-node/NodeStream";
import { ProviderDriverKind, type ProviderInstallState } from "@t3tools/contracts";
import {
ProviderDriverKind,
ProviderInstallDiagnostics,
type ProviderInstallState,
} from "@t3tools/contracts";
import * as HostProcess from "@t3tools/shared/HostProcess";
import { resolveNodeExecutable, nodeRuntimeUnavailableMessage } from "@t3tools/shared/nodeRuntime";
import { resolveCommandPath } from "@t3tools/shared/shell";
Expand Down Expand Up @@ -48,6 +52,7 @@ import {
prepareAntigravityProfile,
} from "./antigravityAuthSupport.ts";
import { type AntigravityReleaseAsset } from "./antigravityRelease.ts";
import { makeInstallationDiagnostics } from "./installationDiagnostics.ts";

const DRIVER = ProviderDriverKind.make("antigravity");
const DOWNLOAD_TIMEOUT = "45 minutes";
Expand Down Expand Up @@ -78,6 +83,7 @@ export class AntigravityInstallationError extends Schema.TaggedError<Antigravity
{
operation: Schema.String,
detail: Schema.String,
diagnostics: Schema.optionalKey(ProviderInstallDiagnostics),
cause: Schema.optional(Schema.Defect()),
},
) {
Expand Down Expand Up @@ -192,6 +198,7 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
const platform = yield* HostProcess.Platform;
const arch = yield* HostProcess.Architecture;
const environment = yield* HostProcess.Environment;
const homeDirectory = yield* HostProcess.HomeDirectory;
let releaseAsset = options.releaseAsset ?? null;
const supported =
options.releaseAsset === undefined
Expand Down Expand Up @@ -444,20 +451,19 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
),
);

const validationTimeoutError = installationError(
"verify",
"Antigravity runtime verification timed out after 90 seconds. Review Installation details or this environment's server log, then retry installation.",
);
const withValidationTimeout = Effect.timeoutOrElse({
duration: VALIDATION_TIMEOUT,
orElse: () =>
Effect.fail(
installationError(
"verify",
"Antigravity runtime verification timed out after 90 seconds. Check this environment's server logs for startup errors, then retry installation.",
),
),
orElse: () => Effect.fail(validationTimeoutError),
});
const validate =
const validateRuntime =
options.validate ??
Effect.fn("AntigravityInstallation.validate")(
function* (executable: AntigravityExecutable, expectedVersion: string) {
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const validationScope = yield* Effect.scope;
const profileDirectory = yield* Effect.acquireRelease(
fs.makeTempDirectory({ prefix: "t3-antigravity-validate-" }),
Expand Down Expand Up @@ -527,7 +533,6 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
},
Effect.provideService(FileSystem.FileSystem, fs),
Effect.provideService(Path.Path, path),
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
Effect.provideService(SecureRandom.SecureRandom, random),
Effect.mapError((cause) => {
if (isInstallationError(cause)) return cause;
Expand All @@ -541,6 +546,43 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
}),
);

const validate = Effect.fn("AntigravityInstallation.verify")(function* (
executable: AntigravityExecutable,
expectedVersion: string,
) {
const capture = yield* makeInstallationDiagnostics("Antigravity initialization").pipe(
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
Effect.provideService(HostProcess.Environment, environment),
Effect.provideService(HostProcess.HomeDirectory, homeDirectory),
);
return yield* validateRuntime(executable, expectedVersion).pipe(
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, capture.spawner),
Effect.scoped,
withValidationTimeout,
Effect.mapError(
(error) =>
new AntigravityInstallationError({
...error,
diagnostics: {
...capture.snapshot(isAcpProcessExitedError(error.cause) ? error.cause : undefined),
...(error === validationTimeoutError ? { exitCode: null, signal: null } : {}),
},
}),
),
Effect.tapError((error) =>
SubscriptionRef.get(state).pipe(
Effect.flatMap(({ operationId }) =>
Effect.logWarning("Managed runtime verification failed", {
driver: DRIVER,
operationId,
diagnostics: error.diagnostics,
}),
),
),
),
);
});

const install = Effect.fn("AntigravityInstallation.install")(
function* (asset: AntigravityReleaseAsset | AntigravityCliReleaseAsset) {
yield* ensureEligible(asset.version);
Expand Down Expand Up @@ -616,7 +658,7 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
);
}
yield* report("verifying", "Checking the installed runtime.");
yield* validate(existing, asset.version).pipe(Effect.scoped, withValidationTimeout);
yield* validate(existing, asset.version);
yield* activate();
return;
}
Expand Down Expand Up @@ -873,7 +915,7 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
managedVersionDirectory: pairDirectory,
},
asset.version,
).pipe(Effect.scoped, withValidationTimeout);
);
const record: InstalledRelease = {
releaseId,
version: asset.version,
Expand All @@ -896,7 +938,7 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
completedRelease(releaseId).pipe(
Effect.flatMap((existing) =>
existing.version === asset.version
? validate(existing, asset.version).pipe(Effect.scoped, withValidationTimeout)
? validate(existing, asset.version)
: Effect.fail(
installationError(
"activate",
Expand Down Expand Up @@ -1014,6 +1056,7 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
version: reuse?.version ?? asset?.version ?? null,
installedVersion: current.installedVersion,
canRemove: current.canRemove,
diagnostics: null,
message:
reuse === undefined
? "Downloading Google's official Antigravity runtime."
Expand All @@ -1024,8 +1067,6 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
reuse === undefined
? install(asset!)
: validate(reuse, reuse.version!).pipe(
Effect.scoped,
withValidationTimeout,
Effect.andThen(ensureEligible(reuse.version!)),
Effect.andThen(
SubscriptionRef.update(state, (value) => ({
Expand All @@ -1050,6 +1091,8 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
return {
...value,
phase: cancelled ? "cancelled" : "failed",
diagnostics:
cancelled || Option.isNone(error) ? null : (error.value.diagnostics ?? null),
message: cancelled
? "Installation cancelled. The previous runtime is unchanged."
: Option.isSome(error)
Expand Down Expand Up @@ -1134,6 +1177,7 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
installedVersion: null,
canRemove: false,
message: null,
diagnostics: null,
}) satisfies ProviderInstallState,
);
}).pipe(Effect.uninterruptible),
Expand Down
Loading
Loading