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(voice): skip lms load when model already loaded — was spawning duplicates
Adam Eivy421e4274c26b
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 8021152bd0..0fbde12a77 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -38,6 +38,8 @@## Fixed+- **Voice preload spawned a duplicate model instance on every server restart** — `lms load <model>` is *not* idempotent in practice; calling it on an already-loaded model spawns a SECOND instance in LM Studio (we observed 3 simultaneous copies of `qwen/qwen3-4b-2507` in one user's setup, eating 7+ GB extra). When VRAM was nearly full, the duplicate load failed with "Model loading was stopped due to insufficient system resources" and the preload reported as failed even though the original instance was fine. `preloadModel` now calls `lms ps --json`, parses `modelKey`s from the response, and skips the `lms load` if the chosen model is already loaded. Logs `🎙️ voice: <model> already loaded — skipping preload` when this fires.+- **Daily Log "let's make a daily log" opened the page but didn't start dictation, leaving the user stuck routing each utterance through the LLM** — the assistant then narrated `Appending to daily log: "..."` without actually calling `daily_log_append`, so nothing got written. Two changes: (1) `daily_log_open` tool description now says `startDictation` defaults to true for any create/write-intent phrasing ("make"/"start"/"new"/"create"/"dictate"/"record"/"talk into"/"log something"), with `startDictation=false` reserved for explicit view-only verbs ("show me"/"open"/"go to" without any write verb). (2) System prompt enumerates the create-intent phrases that should map to `daily_log_open(startDictation=true)` and explicitly tells the model to STAY QUIET after the call so the dictation system handles every following utterance without an LLM in the loop. Live-tested on qwen3-4b: 4/4 create-intent phrasings now route to dictation; 1/1 view-intent phrasing routes to navigation only.- **Daily Log dictation silently flipped off mid-session after a brief network hiccup** — Socket.IO auto-reconnects on transient drops (idle tabs, sleeping laptops, flaky Tailscale), but each new connection spawns a fresh `state.dictation = { enabled: false }` on the server. The client UI still showed "Dictating" because no event told it otherwise, so subsequent utterances were routed to the LLM (Conversation panel) instead of appended to the journal. `voiceClient.js` now caches the last `setDictation` request and re-emits it on every socket `connect` event so the server's per-socket state always matches what the UI thinks it requested. Idempotent — re-emitting `enabled: true` for the same date is a no-op when state already matches.diff --git a/server/services/voice/bootstrap.js b/server/services/voice/bootstrap.jsindex eedee30e2d..08841ce3a9 100644--- a/server/services/voice/bootstrap.js+++ b/server/services/voice/bootstrap.js@@ -300,11 +300,29 @@ export const ensureToolCapableModel = async (cfg) => {return { failed: chain };};+// Returns the set of model keys currently loaded in LM Studio (per `lms ps`).+// `lms load` is NOT idempotent in practice — re-loading an already-loaded+// model spawns a SECOND instance of it, doubling VRAM. Worse, when VRAM is+// full the second load fails with "Model loading was stopped due to+// insufficient system resources" and our preload reports as failed even+// though the original instance is fine. Always check `lms ps` first.+const listLoadedModelKeys = async () => {+ const lms = await which('lms');+ if (!lms) return new Set();+ const { stdout } = await pexec(lms, ['ps', '--json'], { timeout: 10_000 })+ .catch(() => ({ stdout: '' }));+ try {+ const arr = JSON.parse(stdout || '[]');+ return new Set(arr.map((m) => m.modelKey).filter(Boolean));+ } catch {+ return new Set();+ }+};+// Pre-warm the model that 'auto' will pick on the first turn so the user-// doesn't pay a 5–30 s cold-load on their first question. `lms load` is-// idempotent — if the model is already loaded LM Studio returns success-// immediately. We mirror the resolveModel preference order: tool-capable,-// non-reasoning, smallest first.+// doesn't pay a 5–30 s cold-load on their first question. Skip when the+// chosen model is already loaded — see `listLoadedModelKeys` for why "skip+// if loaded" matters more than just being efficient.export const preloadModel = async (cfg) => {if (!cfg?.enabled) return { skipped: 'voice-disabled' };if (cfg?.llm?.model && cfg.llm.model !== 'auto') return { skipped: 'explicit-model' };@@ -325,6 +343,17 @@ export const preloadModel = async (cfg) => {const target = sortPreferred(candidates)[0] || sortPreferred(installed)[0];if (!target) return { skipped: 'no-candidate' };+ // CRITICAL: skip the load if the model is already in `lms ps`. Otherwise+ // every server restart spawns another instance of the same model in+ // LM Studio (3 copies of qwen3-4b reported in the wild), eating multiples+ // of its VRAM and causing OOM-style "Model loading was stopped due to+ // insufficient system resources" errors when nothing is actually wrong.+ const loaded = await listLoadedModelKeys();+ if (loaded.has(target)) {+ console.log(`🎙️ voice: ${target} already loaded — skipping preload`);+ return { skipped: 'already-loaded', model: target };+ }+// `lms load` blocks until ready (5-30s cold). Run as fire-and-forget so// reconcile returns immediately; whisper/TTS can come up in parallel.console.log(`🎙️ voice: preloading ${target} (warming GPU/cache for first turn)`);