{"record":{"id":"e42cec2df835b933","repo":"janhq/jan","slug":"no-active-session-found-for-model-modelid","errorCode":null,"errorMessage":"No active session found for model: ${modelId}","messagePattern":"No active session found for model: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"extensions/llamacpp-extension/src/index.ts","lineNumber":2357,"sourceCode":"        if (!result.success) {\n          logger.warn(\n            `Pre-eviction of ${victim} reported failure: ${result.error}`\n          )\n        } else {\n          logger.info(\n            `Pre-evicted chat model ${victim} to make room for ${incomingModelId}`\n          )\n        }\n      } catch (e) {\n        logger.warn(`Pre-eviction of ${victim} threw:`, e)\n      }\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 session found for model: ${modelId}`)\n    }\n    try {\n      const result = await unloadLlamaModel(modelId)\n      if (result.success) {\n        this.loadedChatOrder = this.loadedChatOrder.filter((m) => m !== modelId)\n        logger.info(`Successfully unloaded model ${modelId}`)\n      } else {\n        logger.warn(`Failed to unload model ${modelId}: ${result.error}`)\n      }\n      return result\n    } catch (error) {\n      logger.error('Error in unload command:', error)\n      return {\n        success: false,\n        error: `Failed to unload model: ${error}`,\n      }\n    }\n  }","sourceCodeStart":2339,"sourceCodeEnd":2375,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/extensions/llamacpp-extension/src/index.ts#L2339-L2375","documentation":"unload(modelId) looks up the active session with findSessionByModel; if no session exists for that model it throws 'No active session found for model: <modelId>' because there is nothing to unload. The model was never loaded, or it was already unloaded.","triggerScenarios":"Calling unload() for a modelId that has no live session — never loaded, already unloaded, unload raced with another unload, or the app restarted (in-memory sessions lost).","commonSituations":"Calling unload in cleanup code for a model whose load failed; double-invoking unload from both UI and auto-unload/eviction logic; assuming models persist sessions across app restarts.","solutions":["Check that the model has an active session before calling unload (catch and treat as already-unloaded)","Track which models you loaded and only unload those","Make unload idempotent in your wrapper by catching this error and returning success","Avoid unloading models auto-evicted by the chat-capacity manager"],"exampleFix":"// before\nawait unload(modelId) // throws if not loaded\n// after\ntry {\n  await unload(modelId)\n} catch (e) {\n  if (!String(e.message).includes('No active session')) throw e\n}","handlingStrategy":"try-catch","validationCode":"const s = await findSessionByModel(modelId)\nif (s) await unload(modelId) // only unload live sessions","typeGuard":null,"tryCatchPattern":"try {\n  await unload(modelId)\n} catch (e) {\n  if (e.message.startsWith('No active session found')) return { success: true } // idempotent\n  throw e\n}","preventionTips":["Make unload idempotent in wrapper code","Only unload models you know you loaded","Remember sessions are in-memory and lost on restart","Coordinate unload calls between UI and eviction logic"],"tags":["session-not-found","unload","state"],"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"}