janhq/jan · error

No active MLX session found for model

Error message

No active MLX session found for model: ${modelId}

What it means

unload(modelId) looks up the active session via findSessionByModel and throws this error when none exists — you cannot unload a model that is not loaded. The modelId is interpolated into the message to identify the missing session.

Solutions

  1. Verify the model is loaded (sessionInfo/findSessionByModel) before calling unload
  2. Make unload idempotent on the caller side: catch this error and treat it as success
  3. Ensure the exact same modelId string used at load is passed to unload
  4. If a stale session exists but this error fires, restart the app to resync session state

Example fix

// before
await mlx.unload(modelId)
// after
try {
  await mlx.unload(modelId)
} catch (e) {
  if (!String(e).includes('No active MLX session')) throw e
  logger.info(`${modelId} already unloaded`)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Only unload loaded models
const s = await mlx.getSessionInfo(modelId)
if (s) await mlx.unload(modelId)

Try / catch

try {
  await mlx.unload(modelId)
} catch (e) {
  if (!String(e).includes('No active MLX session')) throw e
  // treat as already-unloaded: idempotent cleanup
}

Prevention

When it happens

Trigger: Calling unload(modelId) for a model never loaded, one already unloaded, one whose load failed midway, or with a typo'd/model-id mismatch (different string than the one used at load).

Common situations: Cleanup scripts unloading a list of models where some were never loaded, retrying unload after a previous unload succeeded, or model IDs changed after a model directory rename.

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/7232227f65ec0537. Report an issue: GitHub.

Appendix: source

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

        modelId,
        modelPath,
        port,
        mlxConfig,
        envs,
        isEmbedding,
        Number(this.timeout)
      )
      return sInfo
    } catch (error) {
      logger.error(`Error loading MLX model: ${JSON.stringify(error)}`)
      throw error
    }
  }

  override async unload(modelId: string): Promise<UnloadResult> {
    const sInfo = await this.findSessionByModel(modelId)
    if (!sInfo) {
      throw new Error(`No active MLX session found for model: ${modelId}`)
    }

    try {
      const result = await unloadMlxModel(sInfo.pid)
      if (result.success) {
        logger.info(`Successfully unloaded MLX model with PID ${sInfo.pid}`)
      } else {
        logger.warn(`Failed to unload MLX model: ${result.error}`)
      }
      return result
    } catch (error) {
      logger.error('Error unloading MLX model:', error)
      return {
        success: false,
        error: `Failed to unload model: ${error}`,
      }
    }
  }

View on GitHub (pinned to 7205d770c1)