Skip to content

Commit a76b2a7

Browse files
committed
fix(server): retry transient Agent Platform metadata failures
1 parent 4829b18 commit a76b2a7

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

‎apps/server/src/provider/Drivers/AntigravityDriver.test.ts‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as Path from "effect/Path";
1414
import * as Redacted from "effect/Redacted";
1515
import * as Result from "effect/Result";
1616
import * as Schema from "effect/Schema";
17+
import * as TestClock from "effect/testing/TestClock";
1718
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
1819
import { HttpClient, HttpClientError, HttpClientResponse } from "effect/http";
1920

@@ -115,7 +116,12 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
115116
const first = yield* makeExecutable("runtime 'one");
116117
const second = yield* makeExecutable("runtime two");
117118
const signedOut = yield* makeExecutable("runtime signed-out", true);
118-
const controls = { selected: first, failResolution: false, beforeAcquire: Effect.void };
119+
const controls = {
120+
selected: first,
121+
failResolution: false,
122+
beforeAcquire: Effect.void,
123+
metadataServer: options.metadataServer ?? false,
124+
};
119125
const acquisitions: Array<{ binaryPath: string | undefined; path: string | undefined }> = [];
120126
const releases: Array<string | null> = [];
121127
const launches: Array<{
@@ -169,7 +175,7 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
169175
return Effect.die("Unexpected quota request");
170176
}
171177
metadataRequests.push(request.url);
172-
return options.metadataServer
178+
return controls.metadataServer
173179
? Effect.succeed(
174180
HttpClientResponse.fromWeb(
175181
request,
@@ -433,12 +439,19 @@ it.layer(layerTest)("AntigravityDriver", (it) => {
433439
{ name: "GCE_METADATA_HOST", value: "metadata.internal:8080" },
434440
],
435441
metadataHost: "metadata.internal:8080",
436-
metadataServer: true,
442+
metadataServer: false,
437443
});
444+
const error = yield* h.refresh().pipe(Effect.flip);
445+
expect(error.detail).toContain("gcloud auth application-default login");
446+
h.controls.metadataServer = true;
447+
yield* TestClock.adjust("30 seconds");
438448
yield* h.refresh();
439449
yield* h.refresh();
440450
expect((yield* h.instance.snapshot.getSnapshot).auth.status).toBe("authenticated");
441-
expect(h.metadataRequests).toEqual(["http://metadata.internal:8080"]);
451+
expect(h.metadataRequests).toEqual([
452+
"http://metadata.internal:8080",
453+
"http://metadata.internal:8080",
454+
]);
442455
yield* h.assertClosed;
443456
}).pipe(Effect.scoped),
444457
);

‎apps/server/src/provider/Drivers/AntigravityDriver.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,12 @@ export const AntigravityDriver: ProviderDriver<
134134
processEnvironment,
135135
yield* HostProcess.HomeDirectory,
136136
);
137-
// Probe the metadata server at most once per instance, as the Go client does per process.
138-
const onGoogleCloud = yield* Effect.cached(
137+
// Bound probe frequency while allowing recovery from transient metadata failures.
138+
const onGoogleCloud = yield* Effect.cachedWithTTL(
139139
probeGoogleMetadataServer(processEnvironment.GCE_METADATA_HOST || undefined).pipe(
140140
Effect.provideService(HttpClient.HttpClient, httpClient),
141141
),
142+
"30 seconds",
142143
);
143144
// Recheck on every use so credentials created after startup take effect.
144145
const authIssue = antigravityAuthIssue(auth, {

0 commit comments

Comments
 (0)