{"record":{"id":"7232227f65ec0537","repo":"janhq/jan","slug":"no-active-mlx-session-found-for-model-modelid","errorCode":null,"errorMessage":"No active MLX session found for model: ${modelId}","messagePattern":"No active MLX session found for model: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"extensions/mlx-extension/src/index.ts","lineNumber":355,"sourceCode":"        modelId,\n        modelPath,\n        port,\n        mlxConfig,\n        envs,\n        isEmbedding,\n        Number(this.timeout)\n      )\n      return sInfo\n    } catch (error) {\n      logger.error(`Error loading MLX model: ${JSON.stringify(error)}`)\n      throw error\n    }\n  }\n\n  override async unload(modelId: string): Promise<UnloadResult> {\n    const sInfo = await this.findSessionByModel(modelId)\n    if (!sInfo) {\n      throw new Error(`No active MLX session found for model: ${modelId}`)\n    }\n\n    try {\n      const result = await unloadMlxModel(sInfo.pid)\n      if (result.success) {\n        logger.info(`Successfully unloaded MLX model with PID ${sInfo.pid}`)\n      } else {\n        logger.warn(`Failed to unload MLX model: ${result.error}`)\n      }\n      return result\n    } catch (error) {\n      logger.error('Error unloading MLX model:', error)\n      return {\n        success: false,\n        error: `Failed to unload model: ${error}`,\n      }\n    }\n  }","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/extensions/mlx-extension/src/index.ts#L337-L373","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Verify the model is loaded (sessionInfo/findSessionByModel) before calling unload","Make unload idempotent on the caller side: catch this error and treat it as success","Ensure the exact same modelId string used at load is passed to unload","If a stale session exists but this error fires, restart the app to resync session state"],"exampleFix":"// before\nawait mlx.unload(modelId)\n// after\ntry {\n  await mlx.unload(modelId)\n} catch (e) {\n  if (!String(e).includes('No active MLX session')) throw e\n  logger.info(`${modelId} already unloaded`)\n}","handlingStrategy":"try-catch","validationCode":"// Only unload loaded models\nconst s = await mlx.getSessionInfo(modelId)\nif (s) await mlx.unload(modelId)","typeGuard":null,"tryCatchPattern":"try {\n  await mlx.unload(modelId)\n} catch (e) {\n  if (!String(e).includes('No active MLX session')) throw e\n  // treat as already-unloaded: idempotent cleanup\n}","preventionTips":["Track loaded model IDs client-side and only unload tracked ones","Make cleanup scripts idempotent by catching this error","Use exact modelId strings from load responses","Resync state via app restart after suspected stale sessions"],"tags":["mlx","session","lifecycle","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"}