Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(local-model): wait up to 120s for Ollama to start before a send
Dash418bf598b97e
diff --git a/apps/desktop/src/main/local-model-runtime/__tests__/ollamaRuntime.test.ts b/apps/desktop/src/main/local-model-runtime/__tests__/ollamaRuntime.test.tsindex 416e2d3934..5e1dd6f309 100644--- a/apps/desktop/src/main/local-model-runtime/__tests__/ollamaRuntime.test.ts+++ b/apps/desktop/src/main/local-model-runtime/__tests__/ollamaRuntime.test.ts@@ -116,6 +116,29 @@ describe('ollamaRuntime', () => {expect(status.kind).toBe('port-conflict');});+ it('keeps waiting past the default deadline when the caller extends it', async () => {+ // Cold sidecar starts were measured at ~19s; the default 15s gave up too early.+ let clock = 0;+ const run = (startTimeoutMs?: number) =>+ startOfficialOllamaApp({+ platform: 'darwin',+ appExists: () => true,+ openApp: async () => undefined,+ now: () => clock,+ sleep: async (ms) => {+ clock += ms;+ },+ startTimeoutMs,+ fetchImpl: async () => {+ if (clock < 20_000) throw new OllamaHttpError('refused', 'down');+ return new Response(JSON.stringify({ version: '0.34.4' }));+ },+ });+ expect((await run()).kind).toBe('stopped');+ clock = 0;+ expect((await run(120_000)).kind).toBe('ready');+ });+it('aborts start polling when the install signal fires', async () => {const abort = new AbortController();const pending = startOfficialOllamaApp({diff --git a/apps/desktop/src/main/local-model-runtime/__tests__/preflight.test.ts b/apps/desktop/src/main/local-model-runtime/__tests__/preflight.test.tsindex 443e9e69b1..e2806cadaa 100644--- a/apps/desktop/src/main/local-model-runtime/__tests__/preflight.test.ts+++ b/apps/desktop/src/main/local-model-runtime/__tests__/preflight.test.ts@@ -82,14 +82,14 @@ describe('ensureManagedOllamaReadyForSession', () => {expect(startLlamaCpp).not.toHaveBeenCalled();});- it('starts the sidecar with the caller userDataDir', async () => {+ it('starts the sidecar with the caller userDataDir and the session start wait', async () => {await ensureManagedOllamaReadyForSession({providerId: MANAGED_OLLAMA_PROVIDER_ID,remoteHostId: null,userDataDir: '/tmp/cindy-sidecar-data',});expect(startOfficialOllamaApp).toHaveBeenCalledWith(- expect.objectContaining({ userDataDir: '/tmp/cindy-sidecar-data' }),+ expect.objectContaining({ userDataDir: '/tmp/cindy-sidecar-data', startTimeoutMs: 120_000 }),);});diff --git a/apps/desktop/src/main/local-model-runtime/ollamaRuntime.ts b/apps/desktop/src/main/local-model-runtime/ollamaRuntime.tsindex a430209429..9e5c028ebc 100644--- a/apps/desktop/src/main/local-model-runtime/ollamaRuntime.ts+++ b/apps/desktop/src/main/local-model-runtime/ollamaRuntime.ts@@ -31,6 +31,8 @@ export interface OllamaRuntimeDeps {now?: () => number;sleep?: (ms: number) => Promise<void>;signal?: AbortSignal;+ /** Defaults to OLLAMA_START_TIMEOUT_MS. */+ startTimeoutMs?: number;}const defaultSleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));@@ -214,7 +216,7 @@ export async function startOfficialOllamaApp(deps: OllamaRuntimeDeps): Promise<L}const sleep = deps.sleep ?? defaultSleep;const now = deps.now ?? Date.now;- const deadline = now() + OLLAMA_START_TIMEOUT_MS;+ const deadline = now() + (deps.startTimeoutMs ?? OLLAMA_START_TIMEOUT_MS);while (now() < deadline) {if (deps.signal?.aborted) throw new Error('aborted');await sleepUntilAborted(sleep, OLLAMA_START_POLL_MS, deps.signal);diff --git a/apps/desktop/src/main/local-model-runtime/preflight.ts b/apps/desktop/src/main/local-model-runtime/preflight.tsindex 6c3979964b..57f6a2561d 100644--- a/apps/desktop/src/main/local-model-runtime/preflight.ts+++ b/apps/desktop/src/main/local-model-runtime/preflight.ts@@ -10,6 +10,9 @@ import { MANAGED_LLAMACPP_PROVIDER_ID } from '../../shared/llamaCpp.js';import { assertManagedLlamaCppProvider } from './managedLlamaCppProvider.js';import { getManagedLlamaCppService } from './llamaCppService.js';+/** A cold Ollama start can take well over 15s; a send waits instead of failing early. */+export const OLLAMA_SESSION_START_TIMEOUT_MS = 120_000;+function cindyUserDataDir(explicit?: string): string | undefined {if (explicit) return explicit;try {@@ -56,6 +59,7 @@ export async function ensureManagedOllamaReadyForSession(opts: {platform: process.platform,fetchImpl: (url, init) => fetch(url, init),userDataDir: cindyUserDataDir(opts.userDataDir),+ startTimeoutMs: OLLAMA_SESSION_START_TIMEOUT_MS,});if (ready.kind !== 'ready') {throw new Error(