{"record":{"id":"ca0bd35c49debb9a","repo":"janhq/jan","slug":"no-active-mlx-session-found-for-model-opts-mode","errorCode":null,"errorMessage":"No active MLX session found for model: ${opts.model}","messagePattern":"No active MLX session found for model: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"extensions/mlx-extension/src/index.ts","lineNumber":392,"sourceCode":"\n  private async findSessionByModel(modelId: string): Promise<SessionInfo> {\n    try {\n      return await invoke<SessionInfo>('plugin:mlx|find_mlx_session_by_model', {\n        modelId,\n      })\n    } catch (e) {\n      logger.error(e)\n      throw new Error(String(e))\n    }\n  }\n\n  override async chat(\n    opts: chatCompletionRequest,\n    abortController?: AbortController\n  ): Promise<chatCompletion | AsyncIterable<chatCompletionChunk>> {\n    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","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/extensions/mlx-extension/src/index.ts#L374-L410","documentation":"chat(opts) resolves the session for opts.model via findSessionByModel and throws this error if none is active — you cannot chat with a model that has no running MLX server session. The requested model id is included in the message.","triggerScenarios":"Sending a chat completion request whose opts.model does not match any loaded MLX session — model never loaded, unloaded by auto-unload/another request, or a model-id string mismatch (e.g. different casing or path).","commonSituations":"Client apps pointing at a model that finished auto-unloading, load failing earlier so chat proceeds against nothing, or switching model registries where IDs differ.","solutions":["Load the model (mlx.load(opts.model)) before sending chat requests","Verify opts.model exactly matches the modelId used at load","Re-load and retry if the session was auto-unloaded (check unload/auto-unload settings)","Enumerate loaded sessions first and route the request to a loaded model"],"exampleFix":"// before\nconst res = await mlx.chat({ model: modelId, ... })\n// after\nif (!(await mlx.getSessionInfo(modelId))) await mlx.load(modelId)\nconst res = await mlx.chat({ model: modelId, ... })","handlingStrategy":"validation","validationCode":"// Ensure model is loaded before chat\nconst session = await mlx.getSessionInfo(opts.model)\nif (!session) await mlx.load(opts.model)","typeGuard":null,"tryCatchPattern":"try {\n  const res = await mlx.chat(opts)\n} catch (e) {\n  if (String(e).includes('No active MLX session')) {\n    await mlx.load(opts.model)\n    return mlx.chat(opts)\n  }\n  throw e\n}","preventionTips":["Always load a model before issuing chat requests","Keep model ID strings consistent between load and chat","Disable or tune auto-unload if sessions disappear mid-conversation","Check loaded-session list when routing requests"],"tags":["mlx","chat","session","not-found"],"backgroundTag":"record-not-found","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"}