janhq/jan · error

No active session found for model

Error message

No active session found for model: ${modelId}

What it means

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.

Solutions

  1. Check that the model has an active session before calling unload (catch and treat as already-unloaded)
  2. Track which models you loaded and only unload those
  3. Make unload idempotent in your wrapper by catching this error and returning success
  4. Avoid unloading models auto-evicted by the chat-capacity manager

Example fix

// before
await unload(modelId) // throws if not loaded
// after
try {
  await unload(modelId)
} catch (e) {
  if (!String(e.message).includes('No active session')) throw e
}
Defensive patterns

Strategy: try-catch

Validate before calling

const s = await findSessionByModel(modelId)
if (s) await unload(modelId) // only unload live sessions

Try / catch

try {
  await unload(modelId)
} catch (e) {
  if (e.message.startsWith('No active session found')) return { success: true } // idempotent
  throw e
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

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

Appendix: source

Thrown at extensions/llamacpp-extension/src/index.ts:2357

        if (!result.success) {
          logger.warn(
            `Pre-eviction of ${victim} reported failure: ${result.error}`
          )
        } else {
          logger.info(
            `Pre-evicted chat model ${victim} to make room for ${incomingModelId}`
          )
        }
      } catch (e) {
        logger.warn(`Pre-eviction of ${victim} threw:`, e)
      }
    }
  }

  override async unload(modelId: string): Promise<UnloadResult> {
    const sInfo = await this.findSessionByModel(modelId)
    if (!sInfo) {
      throw new Error(`No active session found for model: ${modelId}`)
    }
    try {
      const result = await unloadLlamaModel(modelId)
      if (result.success) {
        this.loadedChatOrder = this.loadedChatOrder.filter((m) => m !== modelId)
        logger.info(`Successfully unloaded model ${modelId}`)
      } else {
        logger.warn(`Failed to unload model ${modelId}: ${result.error}`)
      }
      return result
    } catch (error) {
      logger.error('Error in unload command:', error)
      return {
        success: false,
        error: `Failed to unload model: ${error}`,
      }
    }
  }

View on GitHub (pinned to 7205d770c1)