janhq/jan · error

No active MLX session found for model

Error message

No active MLX session found for model: ${opts.model}

What it means

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.

Solutions

  1. Load the model (mlx.load(opts.model)) before sending chat requests
  2. Verify opts.model exactly matches the modelId used at load
  3. Re-load and retry if the session was auto-unloaded (check unload/auto-unload settings)
  4. Enumerate loaded sessions first and route the request to a loaded model

Example fix

// before
const res = await mlx.chat({ model: modelId, ... })
// after
if (!(await mlx.getSessionInfo(modelId))) await mlx.load(modelId)
const res = await mlx.chat({ model: modelId, ... })
Defensive patterns

Strategy: validation

Validate before calling

// Ensure model is loaded before chat
const session = await mlx.getSessionInfo(opts.model)
if (!session) await mlx.load(opts.model)

Try / catch

try {
  const res = await mlx.chat(opts)
} catch (e) {
  if (String(e).includes('No active MLX session')) {
    await mlx.load(opts.model)
    return mlx.chat(opts)
  }
  throw e
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of janhq/jan@7205d770c1 (2026-09-17). Data as JSON: /api/errors/ca0bd35c49debb9a. Report an issue: GitHub.

Appendix: source

Thrown at extensions/mlx-extension/src/index.ts:392

  private async findSessionByModel(modelId: string): Promise<SessionInfo> {
    try {
      return await invoke<SessionInfo>('plugin:mlx|find_mlx_session_by_model', {
        modelId,
      })
    } catch (e) {
      logger.error(e)
      throw new Error(String(e))
    }
  }

  override async chat(
    opts: chatCompletionRequest,
    abortController?: AbortController
  ): Promise<chatCompletion | AsyncIterable<chatCompletionChunk>> {
    const sessionInfo = await this.findSessionByModel(opts.model)
    if (!sessionInfo) {
      throw new Error(`No active MLX session found for model: ${opts.model}`)
    }

    // Check if the process is alive
    const isAlive = await invoke<boolean>('plugin:mlx|is_mlx_process_running', {
      pid: sessionInfo.pid,
    })

    if (isAlive) {
      try {
        await fetch(`http://localhost:${sessionInfo.port}/health`)
      } catch (e) {
        this.unload(sessionInfo.model_id)
        throw new Error('MLX model appears to have crashed! Please reload!')
      }
    } else {
      throw new Error('MLX model has crashed! Please reload!')
    }

View on GitHub (pinned to 7205d770c1)