{"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":"Error","httpStatus":null,"severity":"error","filePath":"extensions/mlx-extension/src/index.ts","lineNumber":362,"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":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/janhq/jan/blob/fad3f12a147d138388a66f0d92a02b2675f65294/extensions/mlx-extension/src/index.ts#L344-L380","documentation":"Thrown by chat() at its very start when findSessionByModel(opts.model) returns no session. The chat request names a model (opts.model) that has no running MLX server, so inference cannot be routed. This mirrors error 48 but on the chat path and uses opts.model rather than a bare modelId.","triggerScenarios":"Sending a chatCompletionRequest whose model field is an unloaded/never-loaded model; the session was auto-unloaded by autoUnload when another model loaded; the model crashed and its session was purged before chat() ran.","commonSituations":"UI sends a message for a model the user switched away from (autoUnload cleared it); opts.model is a display name or stale id; crash left no session.","solutions":["Call engine.load(opts.model) before issuing chat, or ensure the model is in getLoadedModels().","If autoUnload is enabled, reload the requested model when the user switches back to it.","Normalize opts.model to the canonical model id used at import time."],"exampleFix":"// before\nconst result = await engine.chat(opts, abort)\n\n// after\nif (!(await engine.findSessionByModel(opts.model).catch(() => null))) {\n  await engine.load(opts.model)\n}\nconst result = await engine.chat(opts, abort)","handlingStrategy":"validation","validationCode":"if (!(await engine.findSessionByModel(opts.model).catch(() => null))) {\n  await engine.load(opts.model)\n}\nawait engine.chat(opts, abort)","typeGuard":null,"tryCatchPattern":"try {\n  return await engine.chat(opts, abort)\n} catch (e) {\n  if (/No active MLX session/.test(String(e))) {\n    await engine.load(opts.model)\n    return await engine.chat(opts, abort)\n  }\n  throw e\n}","preventionTips":["Ensure the target model is loaded before sending chat (respect autoUnload).","Normalize opts.model to the canonical model id.","Reload the model when the user switches back to it under autoUnload."],"tags":["session","chat","validation","mlx","typescript"],"backgroundTag":null,"analyzedSha":"fad3f12a147d138388a66f0d92a02b2675f65294","analyzedAt":"2026-08-12T20:33:47.516Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}