{"record":{"id":"d6a876ffe6612af9","repo":"immich-app/immich","slug":"machine-learning-request-json-stringify-config","errorCode":null,"errorMessage":"Machine learning request '${JSON.stringify(config)}' failed for all URLs","messagePattern":"Machine learning request '(.+?)' failed for all URLs","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/src/repositories/machine-learning.repository.ts","lineNumber":191,"sourceCode":"        const response = await fetch(new URL('predict', url), { method: 'POST', body: formData });\n        if (response.ok) {\n          this.setHealthy(url, true);\n          return response.json();\n        }\n\n        this.logger.warn(\n          `Machine learning request to \"${url}\" failed with status ${response.status}: ${response.statusText}`,\n        );\n      } catch (error: Error | unknown) {\n        this.logger.warn(\n          `Machine learning request to \"${url}\" failed: ${error instanceof Error ? error.message : error}`,\n        );\n      }\n\n      this.setHealthy(url, false);\n    }\n\n    throw new Error(`Machine learning request '${JSON.stringify(config)}' failed for all URLs`);\n  }\n\n  async detectFaces(imagePath: string, { modelName, minScore }: FaceDetectionOptions) {\n    const request = {\n      [ModelTask.FACIAL_RECOGNITION]: {\n        [ModelType.DETECTION]: { modelName, options: { minScore } },\n        [ModelType.RECOGNITION]: { modelName },\n      },\n    };\n    const response = await this.predict<FacialRecognitionResponse>({ imagePath }, request);\n    return {\n      imageHeight: response.imageHeight,\n      imageWidth: response.imageWidth,\n      faces: response[ModelTask.FACIAL_RECOGNITION],\n    };\n  }\n\n  async encodeImage(imagePath: string, { modelName }: CLIPConfig) {","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/immich-app/immich/blob/199723261c6ffa897fec8ccdaea6359e39c37cc3/server/src/repositories/machine-learning.repository.ts#L173-L209","documentation":"MachineLearningRepository.predict iterates all configured ML server URLs (healthy ones first, then unhealthy). Each failure — non-2xx HTTP status or a network/throw — is logged as a warning and the URL is marked unhealthy. If no URL succeeds, it throws Error('Machine learning request <config-json> failed for all URLs'). This is the catch-all when smart-search/face-detection/clip cannot reach any ML backend.","triggerScenarios":"All configured IMMICH_MACHINE_LEARNING_URL servers are down, returning errors, or unreachable when an ML prediction (detectFaces / encodeImage / encodeText) is attempted.","commonSituations":"ML container not started or crashing; wrong URL/port in env; network policy/firewall blocking the API; ML model files missing causing the server to 500; resource exhaustion (OOM) on the ML server.","solutions":["Check the ML server health/logs (/predict endpoint) and restart it if down.","Verify IMMICH_MACHINE_LEARNING_URL points to the correct reachable address from the server process.","Confirm required model files are present and the ML image matches the server version.","If running multiple ML URLs, ensure at least one is healthy; check the availability-check status logged by Immich."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// health-check ML URLs before sending real work\nfor (const url of ML_URLS) {\n  const ok = await fetch(new URL('/ping', url)).then((r) => r.ok).catch(() => false);\n  if (!ok) console.warn(`ML server unhealthy: ${url}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await ml.predict(payload, config);\n} catch (e) {\n  if (/failed for all URLs/.test((e as Error).message)) {\n    // alert ops, queue job for retry, degrade feature gracefully\n  } else throw e;\n}","preventionTips":["Run at least one healthy ML backend and monitor /predict availability.","Keep ML image version aligned with the server version and ensure models are downloaded.","Reserve memory for the ML server to avoid OOM-driven 500s."],"tags":["machine-learning","network","clip","facial-recognition","runtime"],"backgroundTag":null,"analyzedSha":"199723261c6ffa897fec8ccdaea6359e39c37cc3","analyzedAt":"2026-08-12T04:54:27.085Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}