{"record":{"id":"5530948fcdece88d","repo":"janhq/jan","slug":"no-running-mlx-session-found-for-model-modelid","errorCode":null,"errorMessage":"No running MLX session found for model: ${modelId}","messagePattern":"No running MLX session found for model: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"web-app/src/lib/model-factory.ts","lineNumber":1105,"sourceCode":"        const serviceHub = useServiceStore.getState().serviceHub\n\n        if (serviceHub) {\n          await serviceHub.models().startModel(provider, modelId)\n        }\n      } catch (error) {\n        console.error('Failed to start MLX model:', error)\n        throw engineFailure('model-errors:startModelFailed', error)\n      }\n    }\n\n    // Get session info which includes port and api_key\n    const sessionInfo = await invoke<SessionInfo | null>(\n      'plugin:mlx|find_mlx_session_by_model',\n      { modelId }\n    )\n\n    if (!sessionInfo) {\n      throw new Error(`No running MLX session found for model: ${modelId}`)\n    }\n\n    const baseUrl = `http://localhost:${sessionInfo.port}`\n    const authHeaders = {\n      Authorization: `Bearer ${sessionInfo.api_key}`,\n      Origin: 'tauri://localhost',\n    }\n\n    // Share the common fetch (param normalisation + error-body cleaning that\n    // rebuilds upstream errors from buffered text rather than re-decoding the\n    // raw stream) with every other provider, then layer MLX's /cancel-on-abort\n    // on top.\n    let baseCustomFetch = createCustomFetch(\n      httpFetch,\n      parameters,\n      false,\n      undefined,\n      true","sourceCodeStart":1087,"sourceCodeEnd":1123,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/web-app/src/lib/model-factory.ts#L1087-L1123","documentation":"Thrown when the MLX plugin command plugin:mlx|find_mlx_session_by_model returns null for the given modelId, so there is no running MLX server session to derive a base URL (localhost port) and auth headers from. The client cannot talk to the model server without that session info.","triggerScenarios":"Requesting an MLX model that was never loaded; the MLX session terminated (crash, OOM, manual stop); modelId typo or stale reference after re-download; Tauri backend restarted without relaunching the session.","commonSituations":"Selecting an MLX model in chat without starting it; macOS app sleep/quit ending the server; switching branches or model versions so the id no longer matches the running session.","solutions":["Start the MLX session for this model before sending requests.","Re-select the correct model id that matches the running session.","Check the MLX server didn't crash (logs) and restart it, then retry."],"exampleFix":"// before\nconst client = await createMlxClient('mlx-community/Llama-3-8B')\n// after\nconst session = await invoke('plugin:mlx|find_mlx_session_by_model', { modelId })\nif (!session) await invoke('plugin:mlx|start_mlx_session', { modelId })\nconst client = await createMlxClient(modelId)","handlingStrategy":"try-catch","validationCode":"const session = await invoke('plugin:mlx|find_mlx_session_by_model', { modelId })\nif (!session) await invoke('plugin:mlx|start_mlx_session', { modelId })","typeGuard":"const isMlxSession = (s) => !!s && typeof s.port === 'number'","tryCatchPattern":"try { return await createMlxClient(modelId) } catch (e) { if (e.message.startsWith('No running MLX session')) { await startMlxSession(modelId); return createMlxClient(modelId) } throw e }","preventionTips":["Gate MLX model selection on sessions reported by the plugin.","Handle backend crashes by restarting sessions on app resume.","Verify modelId against the downloaded-model list before use."],"tags":["mlx","session","local-server","tauri"],"backgroundTag":"resource-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"}