Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: auto-load LM Studio model before memory classification
Adam Eivy781f503d3dba
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex f64ade4bf0..3ba42987a8 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -28,3 +28,4 @@- **Pending task edit form unresponsive** — save/cancel buttons on the edit form for pending tasks did not respond to taps; dnd-kit's sortable wrapper interfered with pointer events inside sortable items. Sorting is now disabled while editing, pointer events are stopped from propagating through the edit form, and button touch targets are enlarged to 40px minimum height- **Broken worktree detection** — worktree cleanup now verifies `rev-parse --show-toplevel` matches the expected worktree path before trusting `git status`; prevents broken worktrees (missing `.git` file) from resolving to a parent repo and incorrectly blocking removal- **Agent prompt missing commit step** — agent instructions now explicitly include "commit and push" in the numbered steps and the simplify section reinforces committing after review, preventing agents from completing work without pushing changes+- **Memory classifier — LM Studio no-model-loaded failures** — memory classification calls to LM Studio failed with `400 "No models loaded"` when the server had no model in memory. The classifier now discovers downloaded LLMs via `GET /api/v0/models`, auto-loads the configured model (or first available LLM) via `POST /api/v1/models/load`, and retries with the actually-loaded model id — mirroring the existing embedding auto-load path in `memoryEmbeddings.js`diff --git a/server/services/memoryClassifier.js b/server/services/memoryClassifier.jsindex 3ac3be2339..1fb142c06f 100644--- a/server/services/memoryClassifier.js+++ b/server/services/memoryClassifier.js@@ -162,10 +162,83 @@ Most outputs should produce ZERO memories. Only extract when you observe somethiReturn: {"memories": [...], "rejected": [...]}`;}+/**+ * Derive the LM Studio base URL from the chat/completions endpoint+ */+function getBaseUrl(endpoint) {+ return endpoint.replace(/\/v1\/chat\/completions\/?$/, '').replace(/\/+$/, '');+}++/**+ * Ensure an LLM model is loaded in LM Studio. If none is loaded, discover+ * downloaded LLM models via `/api/v0/models` and auto-load one via+ * `/api/v1/models/load`. Prefers the configured model when available,+ * otherwise falls back to any downloaded LLM.+ *+ * @returns {Promise<string|null>} The id of a loaded LLM model, or null+ */+async function ensureLLMModelLoaded(config) {+ const baseUrl = getBaseUrl(config.endpoint);++ const controller = new AbortController();+ const timeoutId = setTimeout(() => controller.abort(), 5000);+ const listResponse = await fetch(`${baseUrl}/api/v0/models`, {+ method: 'GET',+ signal: controller.signal+ }).catch(() => null).finally(() => clearTimeout(timeoutId));++ if (!listResponse?.ok) return null;++ const payload = await listResponse.json().catch(() => null);+ const allModels = payload?.data || [];+ const llmModels = allModels.filter(m => m.type === 'llm');++ if (llmModels.length === 0) {+ console.warn('⚠️ No LLM models downloaded in LM Studio — download one in the Discover tab');+ return null;+ }++ // If any LLM is already loaded, prefer the configured one; otherwise use any loaded LLM+ const loaded = llmModels.filter(m => m.state === 'loaded');+ if (loaded.length > 0) {+ const match = loaded.find(m => m.id === config.model || m.id.includes(config.model));+ return (match || loaded[0]).id;+ }++ // Need to load one — prefer configured model, else first available+ const preferred = llmModels.find(m => m.id === config.model || m.id.includes(config.model))+ || llmModels[0];++ console.log(`📦 Auto-loading LLM model: ${preferred.id}`);++ const loadController = new AbortController();+ const loadTimeout = setTimeout(() => loadController.abort(), 120000);+ const loadResponse = await fetch(`${baseUrl}/api/v1/models/load`, {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ model: preferred.id }),+ signal: loadController.signal+ }).catch(err => ({ ok: false, _err: err.message })).finally(() => clearTimeout(loadTimeout));++ if (!loadResponse.ok) {+ const errText = loadResponse._err || await loadResponse.text?.().catch(() => 'unknown error') || 'unknown error';+ console.error(`❌ Failed to auto-load LLM model ${preferred.id}: ${errText}`);+ return null;+ }++ console.log(`✅ LLM model loaded: ${preferred.id}`);+ return preferred.id;+}+/*** Call LM Studio API for classification*/async function callLLM(prompt, config) {+ // Make sure a model is loaded before sending the request — LM Studio returns+ // 400 "No models loaded" otherwise.+ const loadedModel = await ensureLLMModelLoaded(config);+ const modelToUse = loadedModel || config.model;+const controller = new AbortController();const timeoutId = setTimeout(() => controller.abort(), config.timeout);@@ -176,7 +249,7 @@ async function callLLM(prompt, config) {'Authorization': `Bearer lm-studio`},body: JSON.stringify({- model: config.model,+ model: modelToUse,messages: [{role: 'system',