Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): wait six minutes for the model list only on Antigravity

Elian Doran5efb04c81f5e
diff --git a/apps/client/src/services/llm_chat.spec.ts b/apps/client/src/services/llm_chat.spec.ts
index aa3da0f53c..8fc699913d 100644
--- a/apps/client/src/services/llm_chat.spec.ts
+++ b/apps/client/src/services/llm_chat.spec.ts
@@ -54,9 +54,15 @@ describe("fetchProviderModels", () => {
server.postWithTimeout = vi.fn(async () => ({ models })) as typeof server.postWithTimeout;
const query = { provider: "openai", apiKey: "sk-test", baseURL: "http://localhost:11434/v1" };
await expect(fetchProviderModels(query)).resolves.toBe(models);
- // Long enough for a first Google Antigravity sign-in, which runs inside this request. The
- // model-selection screen shows a failure inline, so no toast repeats it.
- expect(server.postWithTimeout).toHaveBeenCalledWith("llm-chat/provider-models", 6 * 60_000, query, undefined, { silentBadRequest: true });
+ // The model-selection screen shows a failure inline, so no toast repeats it.
+ expect(server.postWithTimeout).toHaveBeenCalledWith("llm-chat/provider-models", 60_000, query, undefined, { silentBadRequest: true });
+ });
+
+ it("waits as long as the provider asks for", async () => {
+ server.postWithTimeout = vi.fn(async () => ({ models: [] })) as typeof server.postWithTimeout;
+ const query = { provider: "openai" };
+ await fetchProviderModels(query, 90_000);
+ expect(server.postWithTimeout).toHaveBeenCalledWith("llm-chat/provider-models", 90_000, query, undefined, { silentBadRequest: true });
});
it("defaults to an empty array when models is absent", async () => {
diff --git a/apps/client/src/services/llm_chat.ts b/apps/client/src/services/llm_chat.ts
index 9b6e91f1ec..7e6f54d314 100644
--- a/apps/client/src/services/llm_chat.ts
+++ b/apps/client/src/services/llm_chat.ts
@@ -11,12 +11,8 @@ export interface ProviderModelsQuery {
baseURL?: string;
}
-/**
- * How long the model list can take. Longer than the server's own 5-minute wait
- * for a Google Antigravity sign-in (`SIGN_IN_TIMEOUT_MS`), which runs inside
- * this request the first time the models are listed.
- */
-const PROVIDER_MODELS_TIMEOUT_MS = 6 * 60_000;
+/** How long the model list can take, unless the provider states its own limit. */
+const PROVIDER_MODELS_TIMEOUT_MS = 60_000;
/**
* Fetch the live model list for a provider from its credentials. Used by the
@@ -24,10 +20,10 @@ const PROVIDER_MODELS_TIMEOUT_MS = 6 * 60_000;
* not be saved yet. A server-side failure (e.g. a bad API key) rejects with a
* clean message the screen can display, and shows no toast.
*/
-export async function fetchProviderModels(query: ProviderModelsQuery): Promise<LlmModelInfo[]> {
+export async function fetchProviderModels(query: ProviderModelsQuery, timeoutMs = PROVIDER_MODELS_TIMEOUT_MS): Promise<LlmModelInfo[]> {
try {
const response = await server.postWithTimeout<{ models?: LlmModelInfo[] }>(
- "llm-chat/provider-models", PROVIDER_MODELS_TIMEOUT_MS, query, undefined, { silentBadRequest: true });
+ "llm-chat/provider-models", timeoutMs, query, undefined, { silentBadRequest: true });
return response.models ?? [];
} catch (error) {
throw new Error(serverErrorMessage(error));
diff --git a/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx b/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx
index c359a23895..38b5d723da 100644
--- a/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx
+++ b/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx
@@ -81,6 +81,8 @@ export interface ProviderType {
* an advanced override (vendor APIs), or not applicable. Defaults to `"advanced"`.
*/
baseUrl?: "required" | "advanced" | "none";
+ /** How long listing the provider's models can take, when it needs longer than the default minute. */
+ modelListTimeoutMs?: number;
/**
* Which section of the provider list this card belongs to — how it is billed,
* mirroring the three the user guide describes: metered API keys, a fixed-fee
@@ -127,7 +129,9 @@ export const PROVIDER_TYPES: ProviderType[] = [
{ id: "copilot-agent", name: "GitHub Copilot", group: "subscription", defaultBaseUrl: "", iconUrl: PROVIDER_ICONS["copilot-agent"], connectionDescription: t("llm.copilot_agent_description"), beta: true, apiKey: "none", baseUrl: "none", needsHostProcess: true },
// Gemini on a Google account through Google's Antigravity ACP server; the server
// signs in itself, opening the Google sign-in page the first time models are listed.
- { id: "antigravity-agent", name: "Google Antigravity", group: "subscription", defaultBaseUrl: "", iconUrl: PROVIDER_ICONS["antigravity-agent"], connectionDescription: t("llm.antigravity_agent_description"), beta: true, apiKey: "none", baseUrl: "none", needsHostProcess: true },
+ // That sign-in runs inside the model-list request, so the request outlasts the
+ // server's own 5-minute wait for it (`SIGN_IN_TIMEOUT_MS`).
+ { id: "antigravity-agent", name: "Google Antigravity", group: "subscription", defaultBaseUrl: "", iconUrl: PROVIDER_ICONS["antigravity-agent"], connectionDescription: t("llm.antigravity_agent_description"), beta: true, apiKey: "none", baseUrl: "none", needsHostProcess: true, modelListTimeoutMs: 6 * 60_000 },
// The three self-hosted cards share one server-side provider; they differ only in
// the endpoint they prefill and the setup hint they show.
// No blurbs: the group heading already says local/self-hosted, and how to start
@@ -396,6 +400,7 @@ export default function AddProviderModal({ show, onHidden, onSave, existingProvi
<CardSection>
<ModelSelection
query={modelQuery}
+ timeoutMs={providerType?.modelListTimeoutMs}
selected={selectedModels}
onChange={setSelectedModels}
autoSelectDefaults={seedDefaultModels}
diff --git a/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.spec.tsx b/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.spec.tsx
index 84d6877280..ac439e26e4 100644
--- a/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.spec.tsx
@@ -73,11 +73,17 @@ describe("ModelSelection", () => {
const query = { provider: "openai", apiKey: "sk-test", baseURL: "http://x/v1" };
const el = await renderSelection({ query, selected: MODELS, onChange: vi.fn() });
- expect(fetchProviderModelsMock).toHaveBeenCalledWith(query);
+ expect(fetchProviderModelsMock).toHaveBeenCalledWith(query, undefined);
const names = [...el.querySelectorAll(".checkbox-stub")].map(node => node.getAttribute("data-name"));
expect(names).toEqual(["model-gpt-4.1", "model-gpt-4o", "model-custom"]);
});
+ it("passes the provider's own timeout to the fetch", async () => {
+ const query = { provider: "antigravity-agent" };
+ await renderSelection({ query, timeoutMs: 6 * 60_000, selected: [], onChange: vi.fn() });
+ expect(fetchProviderModelsMock).toHaveBeenCalledWith(query, 6 * 60_000);
+ });
+
it("auto-selects the server-recommended models when nothing is selected yet", async () => {
const onChange = vi.fn();
await renderSelection({ query: { provider: "openai" }, selected: [], onChange, autoSelectDefaults: true });
diff --git a/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.tsx b/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.tsx
index 3333e6ccd8..23f9075219 100644
--- a/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.tsx
+++ b/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.tsx
@@ -13,6 +13,8 @@ import NoItems from "../../../react/NoItems";
interface ModelSelectionProps {
/** Credentials describing the provider whose models should be listed. */
query: ProviderModelsQuery;
+ /** How long the fetch can take, when the provider needs longer than the default. */
+ timeoutMs?: number;
/** Currently selected models (full metadata), controlled by the parent. */
selected: LlmModelInfo[];
onChange: (selected: LlmModelInfo[]) => void;
@@ -34,7 +36,7 @@ interface ModelSelectionProps {
* keep. The picked set (with full metadata) is what the chat picker later shows,
* so no live fetch is needed during normal chatting.
*/
-export default function ModelSelection({ query, selected, onChange, autoSelectDefaults, troubleshooting }: ModelSelectionProps) {
+export default function ModelSelection({ query, timeoutMs, selected, onChange, autoSelectDefaults, troubleshooting }: ModelSelectionProps) {
const [models, setModels] = useState<LlmModelInfo[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | undefined>();
@@ -46,7 +48,7 @@ export default function ModelSelection({ query, selected, onChange, autoSelectDe
let active = true;
setLoading(true);
setError(undefined);
- fetchProviderModels(query)
+ fetchProviderModels(query, timeoutMs)
.then(fetched => {
if (!active) return;
setModels(fetched);
diff --git a/apps/server/src/services/llm/providers/acp_agent.ts b/apps/server/src/services/llm/providers/acp_agent.ts
index bbe229c474..d65b86e09d 100644
--- a/apps/server/src/services/llm/providers/acp_agent.ts
+++ b/apps/server/src/services/llm/providers/acp_agent.ts
@@ -228,7 +228,7 @@ export abstract class AcpAgentProvider implements LlmProvider {
}
/**
- * The models this account may use, as the installed CLI reports them.
+ * The models this account can use, as the installed CLI reports them.
*
* There is no `/models` endpoint to call: the catalog arrives on the
* `session/new` response, which reflects the CLI's version and the plan the
@@ -548,7 +548,7 @@ export abstract class AcpAgentProvider implements LlmProvider {
protected agentCwd(): string {
const state = this.state();
if (!state.agentCwd) {
- // Resolve to an absolute path — TRILIUM_DATA_DIR may be relative (dev
+ // Resolve to an absolute path — TRILIUM_DATA_DIR can be relative (dev
// runs use TRILIUM_DATA_DIR=data) and a relative spawn cwd would move
// with the server process's own cwd.
const cwd = path.resolve(dataDirs.TRILIUM_DATA_DIR, this.agentDirName);