diff --git a/apps/server/src/provider/AntigravityProvider.test.ts b/apps/server/src/provider/AntigravityProvider.test.ts index 88589d1c9a773..219b4c0f5dbbd 100644 --- a/apps/server/src/provider/AntigravityProvider.test.ts +++ b/apps/server/src/provider/AntigravityProvider.test.ts @@ -32,6 +32,7 @@ import { buildAntigravityModelsFromSession, makeAntigravityProvider, } from "./AntigravityProvider.ts"; +import { mergeProviderSnapshot } from "./ProviderRegistry.ts"; const decodeSettings = Schema.decodeSync(AntigravitySettings); const instanceId = ProviderInstanceId.make("antigravity-test"); @@ -255,7 +256,7 @@ describe("Antigravity model catalog", () => { ]); }); - it("offers each model the thinking levels it reported when selected", () => { + it("offers each model only the thinking levels it reported when selected", () => { const thinking = (currentValue: string) => ({ id: "thinking_level", @@ -295,8 +296,70 @@ describe("Antigravity model catalog", () => { expect(thinkingOf("gemini")).toMatchObject({ id: "thinking_level", currentValue: "high" }); expect(thinkingOf("claude")).toMatchObject({ id: "thinking_level", currentValue: "low" }); expect(thinkingOf("plain")).toBeUndefined(); - expect(thinkingOf("unseen")).toMatchObject({ id: "thinking_level" }); - expect(thinkingOf("unseen")).not.toHaveProperty("currentValue"); + expect(thinkingOf("unseen")).toBeUndefined(); + }); + + it("keeps each model's probed thinking levels after a restart observes only the active model", () => { + const thinking = (levels: ReadonlyArray) => + ({ + id: "thinking_level", + name: "Thinking Level", + category: "thought_level", + type: "select", + currentValue: "low", + options: levels.map((value) => ({ value, name: value })), + }) satisfies EffectAcpSchema.SessionConfigOption; + const deep = thinking(["low", "medium", "high", "xhigh"]); + const models = { + ...modelConfig, + currentValue: "neon", + options: [ + { value: "neon", name: "Neon" }, + { value: "carbon", name: "Carbon" }, + { value: "fixed", name: "Fixed effort" }, + ], + } satisfies EffectAcpSchema.SessionConfigOption; + const setup = { configOptions: [models, deep] }; + const provider = { + instanceId, + driver, + status: "ready", + enabled: true, + installed: true, + version: null, + auth: { status: "authenticated" }, + checkedAt: "2026-11-23T00:00:00.000Z", + slashCommands: [], + skills: [], + } as const; + // Sign-in or Refresh models walks every model, so each reports its own levels. + const probed = { + ...provider, + models: buildAntigravityModelsFromSession( + setup, + new Map([ + ["carbon", thinking(["low", "medium", "high"])], + ["fixed", null], + ]), + ), + } satisfies ServerProvider; + // After a restart the provider has observed only the session's model. + const restarted = { + ...provider, + checkedAt: "2026-11-23T01:00:00.000Z", + models: buildAntigravityModelsFromSession(setup, new Map([["neon", deep]])), + } satisfies ServerProvider; + + const merged = mergeProviderSnapshot(probed, restarted); + const levelsOf = (slug: string) => { + const descriptor = merged.models.find((model) => model.slug === slug)?.capabilities + ?.optionDescriptors?.[0]; + return descriptor?.type === "select" ? descriptor.options.map((option) => option.id) : []; + }; + + expect(levelsOf("neon")).toEqual(["low", "medium", "high", "xhigh"]); + expect(levelsOf("carbon")).toEqual(["low", "medium", "high"]); + expect(levelsOf("fixed")).toEqual([]); }); }); diff --git a/apps/server/src/provider/AntigravityProvider.ts b/apps/server/src/provider/AntigravityProvider.ts index f5e18f6bece9d..434a81a5123eb 100644 --- a/apps/server/src/provider/AntigravityProvider.ts +++ b/apps/server/src/provider/AntigravityProvider.ts @@ -65,14 +65,12 @@ type ThinkingConfig = NonNullable>; /** Thinking options each model reported when selected; `null` means it has none. */ export type AntigravityThinkingLevels = ReadonlyMap; -function thinkingCapabilities(config: ThinkingConfig | null | undefined, observed: boolean) { +function thinkingCapabilities(config: ThinkingConfig | null | undefined) { const descriptor = config ? acpProviderOptionDescriptors({ configOptions: [config], modeState: undefined })[0] : undefined; if (descriptor?.type !== "select") return EMPTY_MODEL_CAPABILITIES; - // Another model's selected level is not this model's default. - const { currentValue: _currentValue, ...unobserved } = descriptor; - return createModelCapabilities({ optionDescriptors: [observed ? descriptor : unobserved] }); + return createModelCapabilities({ optionDescriptors: [descriptor] }); } export function buildAntigravityModelsFromSession( @@ -113,10 +111,8 @@ export function buildAntigravityModelsFromSession( ...(entry.value === currentValue ? { isDefault: true, aliases: [ANTIGRAVITY_DEFAULT_MODEL] } : {}), - capabilities: - observed === undefined - ? thinkingCapabilities(currentThinking, false) - : thinkingCapabilities(observed, true), + // Levels differ per model; an unobserved model reports none so the registry keeps its cached ones. + capabilities: thinkingCapabilities(observed), }, ]; });