Repository navigation
fix(server): Antigravity health checks re-read a stale model list #39118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,9 +13,11 @@ import { | |
| } from "@t3tools/shared/nodeRuntime"; | ||
| import * as Digest from "effect/crypto/Digest"; | ||
| import * as SecureRandom from "effect/crypto/SecureRandom"; | ||
| import * as Clock from "effect/Clock"; | ||
| import * as Deferred from "effect/Deferred"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Exit from "effect/Exit"; | ||
| import * as FiberHandle from "effect/FiberHandle"; | ||
| import * as FileSystem from "effect/FileSystem"; | ||
| import * as Path from "effect/Path"; | ||
| import * as Schema from "effect/Schema"; | ||
|
|
@@ -84,6 +86,8 @@ const isAcpRequestError = Schema.is(AcpErrors.AcpRequestError); | |
| const isAcpErrorDetails = Schema.is(Schema.Struct({ details: Schema.String })); | ||
| const REFRESH_FAILED = | ||
| "Could not refresh Antigravity models. The previous model list is unchanged."; | ||
| // Models come only from a session, so a health check re-reads them at most this often. | ||
| const MODEL_REFRESH_INTERVAL_MS = 6 * 60 * 60 * 1_000; | ||
| const PYTHON_SOCKS_REQUIRED = "python-socks is required to use a SOCKS proxy"; | ||
|
|
||
| // Keep upstream diagnostics in cause; only recognized, fixed text reaches clients. | ||
|
|
@@ -354,14 +358,23 @@ export const AntigravityDriver: ProviderDriver< | |
| }; | ||
| }); | ||
|
|
||
| let modelsReadAtMs = Number.NEGATIVE_INFINITY; | ||
| const onSessionStarted = Effect.fn("AntigravityDriver.onSessionStarted")(function* ( | ||
| started: AcpSessionRuntime.AcpSessionRuntimeStartResult, | ||
| cwd?: string, | ||
| ) { | ||
| modelsReadAtMs = yield* Clock.currentTimeMillis; | ||
| yield* provider.onSessionStarted(started, cwd); | ||
| }); | ||
|
|
||
| const publishCatalog = Effect.fn("AntigravityDriver.publishCatalog")(function* ( | ||
| started: AcpSessionRuntime.AcpSessionRuntimeStartResult, | ||
| runtime: Pick< | ||
| AcpSessionRuntime.AcpSessionRuntime["Service"], | ||
| "getEvents" | "drainEvents" | "setModel" | ||
| >, | ||
| ) { | ||
| yield* provider.onSessionStarted(started); | ||
| yield* onSessionStarted(started); | ||
| yield* Stream.runForEach(runtime.getEvents(), (event) => { | ||
| if (event._tag === "EventStreamBarrier") { | ||
| return Deferred.succeed(event.acknowledge, undefined).pipe(Effect.asVoid); | ||
|
|
@@ -398,9 +411,11 @@ export const AntigravityDriver: ProviderDriver< | |
|
|
||
| // The probe must not spawn. The agent is a PyInstaller one-file bundle | ||
| // that unpacks about 1 GB per launch, and the health check runs every | ||
| // minute. | ||
| // minute. It only starts a background model refresh once the list is stale. | ||
| const refreshStaleModels = yield* Deferred.make<Effect.Effect<void>>(); | ||
| const probe = Effect.gen(function* () { | ||
| yield* modelCatalog.refreshInBackground; | ||
| yield* Deferred.await(refreshStaleModels).pipe(Effect.flatten); | ||
| if (authConfigIssue !== null) { | ||
| return yield* new ProviderSetupError({ | ||
| instanceId, | ||
|
|
@@ -480,7 +495,7 @@ export const AntigravityDriver: ProviderDriver< | |
| ), | ||
| ), | ||
| profileDirectory, | ||
| onSessionStarted: provider.onSessionStarted, | ||
| onSessionStarted, | ||
| onSessionEvent: (event, cwd) => { | ||
| if (event._tag === "ConfigOptionsUpdated") { | ||
| return provider.onConfigOptionsUpdated(event.configOptions); | ||
|
|
@@ -555,6 +570,32 @@ export const AntigravityDriver: ProviderDriver< | |
| ), | ||
| ); | ||
|
|
||
| // Credentials that need no sign-in click; otherwise the launch would only ask for one. | ||
| const canReadModels = | ||
| authConfigIssue !== null | ||
| ? Effect.succeed(false) | ||
| : !antigravityAuthUsesBrowser(auth.authMethod) | ||
| ? Effect.succeed(true) | ||
| : fileSystem | ||
| .exists(path.join(profileDirectory, "antigravity-acp", "acp_token.json")) | ||
| .pipe(Effect.orElseSucceed(() => false)); | ||
| const modelRefresh = yield* FiberHandle.make(); | ||
| yield* Deferred.succeed( | ||
| refreshStaleModels, | ||
| Effect.gen(function* () { | ||
| const now = yield* Clock.currentTimeMillis; | ||
| if (now - modelsReadAtMs < MODEL_REFRESH_INTERVAL_MS || !(yield* canReadModels)) return; | ||
| modelsReadAtMs = now; | ||
|
Comment on lines
+587
to
+588
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recheck model freshness after the token-file lookup. With browser authentication, Evaluate As per coding guidelines, “Make sure all changes are considerate of performance impact.” The existing probe comment states that each launch unpacks about 1 GB.
|
||
| yield* FiberHandle.run( | ||
| modelRefresh, | ||
| // A fixed message: the cause can carry the agent's raw reply to the key. | ||
| refreshModels().pipe( | ||
| Effect.catch(() => Effect.logWarning("Antigravity could not refresh its model list.")), | ||
| ), | ||
| ); | ||
| }), | ||
| ); | ||
|
|
||
| return { | ||
| instanceId, | ||
| driverKind: DRIVER, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert that the five-hour probe does not refresh.
A faulty five-hour interval can satisfy this test. Its second acquisition occurs at five hours. The six-hour probe starts nothing, but Line 575 consumes the earlier signal and the final count is still two.
Wait for the first refresh's completion before advancing time. After the five-hour probe, assert that only one acquisition occurred. Then require the second acquisition after the six-hour probe. Acquisition alone occurs before the session updates
modelsReadAtMs.As per path instructions, tests must “cover breakable behavior,” including the logic changed by a bug fix.
Source: Path instructions