{"record":{"id":"fc7402d6012dc2a2","repo":"janhq/jan","slug":"mlx-model-has-crashed-please-reload","errorCode":null,"errorMessage":"MLX model has crashed! Please reload!","messagePattern":"MLX model has crashed! Please reload!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"extensions/mlx-extension/src/index.ts","lineNumber":408,"sourceCode":"    const sessionInfo = await this.findSessionByModel(opts.model)\n    if (!sessionInfo) {\n      throw new Error(`No active MLX session found for model: ${opts.model}`)\n    }\n\n    // Check if the process is alive\n    const isAlive = await invoke<boolean>('plugin:mlx|is_mlx_process_running', {\n      pid: sessionInfo.pid,\n    })\n\n    if (isAlive) {\n      try {\n        await fetch(`http://localhost:${sessionInfo.port}/health`)\n      } catch (e) {\n        this.unload(sessionInfo.model_id)\n        throw new Error('MLX model appears to have crashed! Please reload!')\n      }\n    } else {\n      throw new Error('MLX model has crashed! Please reload!')\n    }\n\n    const baseUrl = `http://localhost:${sessionInfo.port}/v1`\n    const url = `${baseUrl}/chat/completions`\n    const headers = {\n      'Content-Type': 'application/json',\n      'Authorization': `Bearer ${sessionInfo.api_key}`,\n    }\n\n    const body = JSON.stringify(opts)\n\n    if (opts.stream) {\n      return this.handleStreamingResponse(url, headers, body, abortController)\n    }\n\n    const response = await fetch(url, {\n      method: 'POST',\n      headers,","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/extensions/mlx-extension/src/index.ts#L390-L426","documentation":"chat() first checks an isAlive flag for the MLX server session; if the session process is already known to be dead, it throws this error immediately without attempting the health fetch. The session is unusable and must be reloaded.","triggerScenarios":"Calling chat() when the MLX server subprocess tracked in sessionInfo has already exited (isAlive === false) — e.g. after a prior crash, manual kill, or abnormal termination.","commonSituations":"The model was unloaded by the OS OOM killer, the user killed the process, the app was suspended/resumed and the subprocess died, or a previous chat call unloaded the model on failure.","solutions":["Reload the model to start a new MLX server session before retrying","Check system logs (dmesg/journalctl) for OOM kills of the mlx server process","Reduce model size or context length if the server is being OOM-killed","Update the mlx extension/server if crashes are reproducible"],"exampleFix":"// before\nconst res = await chat(messages, model)\n// after\nlet res\ntry {\n  res = await chat(messages, model)\n} catch {\n  await model.reload()\n  res = await chat(messages, model)\n}","handlingStrategy":"try-catch","validationCode":"if (!sessionInfo.isAlive) {\n  await reloadModel(model.id) // proactively reload before chat\n}","typeGuard":"const sessionUsable = (s) => Boolean(s && s.isAlive && s.port)","tryCatchPattern":"try {\n  return await chat(messages, model)\n} catch (e) {\n  if (String(e.message).includes('has crashed')) {\n    await reloadModel(model.id)\n    return chat(messages, model)\n  }\n  throw e\n}","preventionTips":["Wrap chat calls with a reload-and-retry helper","Watch for child-process exit events to reload eagerly","Check for OOM kills in system logs","Keep conversation context bounded to reduce server memory pressure"],"tags":["mlx","crash","process-lifecycle","local-server"],"backgroundTag":"process-crashed","analyzedSha":"7205d770c1e097c3daf35a911176410e93bc5564","analyzedAt":"2026-09-17T14:27:30.100Z","contentChangedAt":"2026-09-17T14:27:30.100Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}