{"record":{"id":"ca60537a3eacc45e","repo":"janhq/jan","slug":"string-e-ca6053","errorCode":null,"errorMessage":"String(e)","messagePattern":"String\\(e\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"extensions/mlx-extension/src/index.ts","lineNumber":382,"sourceCode":"      }\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  }\n\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) {","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/extensions/mlx-extension/src/index.ts#L364-L400","documentation":"findSessionByModel wraps the Tauri invoke('plugin:mlx|find_mlx_session_by_model'); on any native-side failure it logs the error and rethrows it as String(e). Callers of load/unload/chat therefore see the raw native error text without a stack trace.","triggerScenarios":"Any session lookup when the Tauri mlx plugin errors — plugin not registered, IPC failure, app backend crashed, or malformed modelId causing a native-side failure.","commonSituations":"Calling MLX APIs before the app's native plugin layer is ready, after an app update changed plugin commands, or in environments (e.g. web build) where the Tauri IPC is unavailable.","solutions":["Check logs — the original error is logged before rethrow","Ensure the Tauri mlx plugin is installed/registered for the current build","Retry after the app's backend has fully initialized (invoke before ready fails)","Validate modelId is a non-empty, correctly formatted identifier before lookup","Update the app if plugin command names changed between versions"],"exampleFix":"// before\nconst s = await mlx.getSessionInfo(modelId)\n// after\nlet s = null\ntry {\n  s = await mlx.getSessionInfo(modelId)\n} catch (e) {\n  logger.warn('MLX session lookup failed, treating as not loaded', e)\n}","handlingStrategy":"try-catch","validationCode":"// Guard modelId before native lookup\nif (typeof modelId !== 'string' || modelId.trim() === '') {\n  throw new Error('modelId is required for MLX session lookup')\n}","typeGuard":"function hasSessionInfo(v: unknown): v is SessionInfo {\n  return !!v && typeof v === 'object' && 'pid' in v && typeof (v as SessionInfo).pid === 'number'\n}","tryCatchPattern":"try {\n  const s = await mlx.getSessionInfo(modelId)\n} catch (e) {\n  logger.warn('MLX session lookup failed; treating as no session', e)\n  const s = null\n}","preventionTips":["Wait for app/plugin initialization before MLX API calls","Validate modelId format before invoking native commands","Check logs for the logged root cause of IPC failures","Keep the app updated so plugin command names match"],"tags":["mlx","tauri","ipc","native"],"backgroundTag":"api-request-failed","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"}