{"record":{"id":"8574ace49702d4db","repo":"Crosstalk-Solutions/project-nomad","slug":"ollama-service-not-ready-yet","errorCode":null,"errorMessage":"Ollama service not ready yet","messagePattern":"Ollama service not ready yet","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"admin/app/jobs/download_model_job.ts","lineNumber":56,"sourceCode":"    const queue = queueService.getQueue(this.queue)\n    const client = await queue.client\n    await client.set(this.cancelKey(jobId), '1', { EX: 300 }) // 5 min TTL\n  }\n\n  async handle(job: Job) {\n    const { modelName } = job.data as DownloadModelJobParams\n\n    logger.info(`[DownloadModelJob] Attempting to download model: ${modelName}`)\n\n    const ollamaService = new OllamaService()\n\n    // Even if no models are installed, this should return an empty array if ready\n    const existingModels = await ollamaService.getModels()\n    if (!existingModels) {\n      logger.warn(\n        `[DownloadModelJob] Ollama service not ready yet for model ${modelName}. Will retry...`\n      )\n      throw new Error('Ollama service not ready yet')\n    }\n\n    logger.info(\n      `[DownloadModelJob] Ollama service is ready. Initiating download for ${modelName}`\n    )\n\n    // Register abort controller for this job — used both by in-process cancels (same process\n    // as the API server) and as the target of the Redis poll loop below.\n    const abortController = new AbortController()\n    DownloadModelJob.abortControllers.set(job.id!, abortController)\n\n    // Get Redis client for checking cancel signals from the API process\n    const queueService = QueueService.getInstance()\n    const cancelRedis = await queueService.getQueue(DownloadModelJob.queue).client\n\n    // Track whether cancellation was explicitly requested by the user. Only user-initiated\n    // cancels become UnrecoverableError — other failures (e.g., transient network errors)\n    // should still benefit from BullMQ's retry logic.","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/Crosstalk-Solutions/project-nomad/blob/0bd1c6f4f9888d577fe232de06ac144bb8337131/admin/app/jobs/download_model_job.ts#L38-L74","documentation":"Thrown by DownloadModelJob.handle() when ollamaService.getModels() returns a falsy value. getModels() presumably returns null/undefined when the Ollama HTTP API isn't responding yet (connection refused or timeout), so the job treats it as 'service not ready' and relies on BullMQ retrying with backoff — the log explicitly says 'Will retry...'.","triggerScenarios":"Ollama container/service is starting up and its API port isn't listening; getModels() catches the connection error and returns null; the model download job was enqueued immediately after install/start.","commonSituations":"Fresh install of the AI Assistant stack where Ollama takes longer to boot than the job's first attempt, Docker container restarting or OOM-killed, Ollama listening on a non-default port/URL, heavy disk/CPU load slowing startup.","solutions":["Wait — this error is retry-by-design; BullMQ will re-attempt with backoff while Ollama warms up.","Verify the service: curl http://localhost:11434/api/tags returns a JSON array.","If it keeps failing, check Ollama container logs (docker logs nomad_ollama) for crashes or port conflicts.","Confirm the Ollama URL configured in dockerService/ollamaService matches the deployed port."],"exampleFix":"# shell\n docker ps --filter name=ollama\ncurl -s http://localhost:11434/api/tags | head -c 200","handlingStrategy":"retry","validationCode":"const models = await ollamaService.getModels().catch(() => null)\nif (!models) { /* delay enqueue until Ollama is up */ }","typeGuard":null,"tryCatchPattern":"catch (err) {\n  if (err instanceof Error && err.message === 'Ollama service not ready yet') {\n    return // BullMQ backoff will retry; do not alert\n  }\n  throw err\n}","preventionTips":["Add a readiness probe on Ollama before enqueuing model jobs.","Use a sufficient backoff strategy on the worker for startup races.","Distinguish this retryable 'not ready' from the unrecoverable 'not installed' error."],"tags":["ollama","service-startup","retry","ai-assistant"],"backgroundTag":"service-not-ready","analyzedSha":"0bd1c6f4f9888d577fe232de06ac144bb8337131","analyzedAt":"2026-08-27T05:34:15.424Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}