Skip to content

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

fix: stop voice bootstrap chasing a dead LM Studio API server (#7541)

[._.]/ Adam Eivya8fbc4af3424
diff --git a/server/services/voice/bootstrap.js b/server/services/voice/bootstrap.js
index eba159c0da..9181cb0f6c 100644
--- a/server/services/voice/bootstrap.js
+++ b/server/services/voice/bootstrap.js
@@ -247,13 +247,23 @@ const isEffectiveLmStudioVoiceProvider = async (cfg) => {
return !(provider && provider.type === 'api' && provider.endpoint);
};
-const listLmStudioModels = async () => {
+// Sentinel + validate: `null` = the API server could not be reached or
+// answered with a non-OK status (we could not ask); `[]` = it answered with
+// zero models (we asked, legitimately empty). Callers must branch on `null`
+// explicitly rather than on `.length` — see AGENTS.md "Sentinel + validate".
+export const listLmStudioModels = async () => {
const res = await fetch(`${LMS_BASE()}/v1/models`, { signal: AbortSignal.timeout(5000) }).catch(() => null);
- if (!res?.ok) return [];
+ if (!res?.ok) return null;
const body = await res.json().catch(() => ({}));
return (body?.data || []).map((m) => m.id);
};
+// Matches the `lms` CLI's own message when the LM Studio API server itself
+// is unreachable — distinct from a model-specific failure (404, gated repo,
+// bad id). Detecting this lets the install chain abort immediately instead
+// of repeating the identical failure for every remaining entry.
+const isLmStudioConnectError = (message) => /failed to start or connect to\b.*lm studio/i.test(String(message || ''));
+
// Approximate parameter count from id, mirroring `sizeRank` in llm.js but
// hoisted here so bootstrap doesn't need to import it. Returns Infinity for
// model ids without a `<n>B` suffix (utility models, embeddings, etc.).
@@ -280,6 +290,10 @@ export const ensureToolCapableModel = async (cfg) => {
if (!(await isEffectiveLmStudioVoiceProvider(cfg))) return { skipped: 'non-lmstudio-provider', provider: cfg?.llm?.provider };
const installed = await listLmStudioModels();
+ if (installed === null) {
+ console.warn(`🎙️ voice: LM Studio API server unreachable at ${LMS_BASE()} — start LM Studio (or set voice.llm.provider) before voice can install a tool-capable model`);
+ return { skipped: 'lmstudio-unreachable' };
+ }
// Tool-capable AND non-reasoning AND under the size cap. The size cap is
// important: a user with only `mistral-small-24B` installed gets a model
// that thrashes VRAM on every turn; we'd rather download Qwen2.5-7B and
@@ -311,8 +325,19 @@ export const ensureToolCapableModel = async (cfg) => {
maxBuffer: 64 * 1024 * 1024,
timeout: 30 * 60 * 1000,
}).catch((err) => ({ stdout: '', stderr: err?.message || String(err) }));
+ // Pick the last non-empty line from stderr (LM Studio CLI trails newlines)
+ // so the warning is actionable instead of an empty `()`. Combine with
+ // stdout when stderr is empty — `lms` sometimes routes errors to stdout.
+ const lastMeaningfulLine = (s) => String(s || '').split('\n').map((l) => l.trim()).filter(Boolean).pop() || '';
+ const reason = lastMeaningfulLine(stderr) || lastMeaningfulLine(stdout) || 'unknown';
+ // The API server going unreachable mid-chain is a shared cause every
+ // remaining entry would hit identically — abort instead of repeating it.
+ if (isLmStudioConnectError(reason)) {
+ console.warn(`🎙️ voice: LM Studio API server unreachable at ${LMS_BASE()} — aborting install chain (${target} failed: ${reason.slice(0, 160)})`);
+ return { skipped: 'lmstudio-unreachable' };
+ }
const after = await listLmStudioModels();
- const newOnes = after.filter((id) => !before.has(id));
+ const newOnes = (after ?? []).filter((id) => !before.has(id));
const fastNew = newOnes.find(
(id) => isToolCapable(id) && !isReasoningModel(id) && sizeOf(id) <= FAST_VOICE_MODEL_MAX_B
);
@@ -320,11 +345,6 @@ export const ensureToolCapableModel = async (cfg) => {
console.log(`🎙️ voice: fast tool-capable model ready — ${fastNew}`);
return { installed: fastNew };
}
- // Pick the last non-empty line from stderr (LM Studio CLI trails newlines)
- // so the warning is actionable instead of an empty `()`. Combine with
- // stdout when stderr is empty — `lms` sometimes routes errors to stdout.
- const lastMeaningfulLine = (s) => String(s || '').split('\n').map((l) => l.trim()).filter(Boolean).pop() || '';
- const reason = lastMeaningfulLine(stderr) || lastMeaningfulLine(stdout) || 'unknown';
console.warn(`🎙️ voice: ${target} unavailable (${reason.slice(0, 160)}) — trying next`);
}
console.warn(`🎙️ voice: exhausted install chain ${chain.join(', ')} — set voice.llm.model explicitly in Settings`);
@@ -361,6 +381,7 @@ export const preloadModel = async (cfg) => {
const lms = await which('lms');
if (!lms) return { skipped: 'no-lms-cli' };
const installed = await listLmStudioModels();
+ if (installed === null) return { skipped: 'lmstudio-unreachable' };
if (!installed.length) return { skipped: 'no-models' };
const sortPreferred = (list) => list.slice().sort((a, b) => {
diff --git a/server/services/voice/bootstrap.lmStudioUnreachable.test.js b/server/services/voice/bootstrap.lmStudioUnreachable.test.js
new file mode 100644
index 0000000000..91dca9e46a
--- /dev/null
+++ b/server/services/voice/bootstrap.lmStudioUnreachable.test.js
@@ -0,0 +1,84 @@
+import { afterEach, beforeEach, expect, it, vi } from 'vitest';
+
+vi.mock('fs', () => ({ existsSync: vi.fn(() => false) }));
+vi.mock('../../lib/processEnv.js', () => ({ whichFirst: vi.fn(async () => null) }));
+vi.mock('../pm2.js', () => ({ execPm2: vi.fn(async () => ({})), getAppStatus: vi.fn(async () => null) }));
+vi.mock('../../lib/fetchWithTimeout.js', () => ({ fetchWithTimeout: vi.fn(async () => ({})) }));
+vi.mock('net', () => ({ createServer: vi.fn(() => ({})) }));
+vi.mock('./llm.js', () => ({ isToolCapable: vi.fn(() => false), isReasoningModel: vi.fn(() => false) }));
+vi.mock('../providers.js', () => ({ getProviderById: vi.fn() }));
+vi.mock('../../lib/childProcess.js', () => ({ execFile: vi.fn() }));
+vi.mock('../settings.js', () => ({ getSettings: vi.fn(), updateSettings: vi.fn() }));
+
+const { whichFirst } = await import('../../lib/processEnv.js');
+const { execFile } = await import('../../lib/childProcess.js');
+const { VOICE_DEFAULTS } = await import('./config.js');
+const { ensureToolCapableModel, preloadModel, listLmStudioModels } = await import('./bootstrap.js');
+
+const toolCfg = () => ({
+ ...VOICE_DEFAULTS,
+ enabled: true,
+ llm: {
+ ...VOICE_DEFAULTS.llm,
+ provider: 'lmstudio',
+ model: 'auto',
+ tools: { ...VOICE_DEFAULTS.llm.tools, enabled: true },
+ },
+});
+
+// `execFile` is promisified in bootstrap.js. Node's real child_process.execFile
+// carries a promisify-custom symbol that resolves to a single `{stdout, stderr}`
+// object; mimic that here (rather than the generic multi-arg-callback array
+// behavior `util.promisify` falls back to) so the mock matches production shape.
+const respondWith = (stderr) => execFile.mockImplementation((...args) => {
+ const callback = args[args.length - 1];
+ callback(null, { stdout: '', stderr });
+});
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ whichFirst.mockImplementation(async () => null);
+});
+
+afterEach(() => {
+ vi.unstubAllGlobals();
+});
+
+it('listLmStudioModels returns null when the API server cannot be reached', async () => {
+ vi.stubGlobal('fetch', vi.fn(async () => { throw new Error('ECONNREFUSED'); }));
+ await expect(listLmStudioModels()).resolves.toBeNull();
+});
+
+it('listLmStudioModels returns null when the API server answers non-OK', async () => {
+ vi.stubGlobal('fetch', vi.fn(async () => ({ ok: false, status: 500 })));
+ await expect(listLmStudioModels()).resolves.toBeNull();
+});
+
+it('listLmStudioModels returns [] on a 200 with an empty data array', async () => {
+ vi.stubGlobal('fetch', vi.fn(async () => ({ ok: true, json: async () => ({ data: [] }) })));
+ await expect(listLmStudioModels()).resolves.toEqual([]);
+});
+
+it('ensureToolCapableModel invokes no lms get when LM Studio is unreachable', async () => {
+ vi.stubGlobal('fetch', vi.fn(async () => { throw new Error('ECONNREFUSED'); }));
+ whichFirst.mockImplementation(async (bin) => (bin === 'lms' ? '/usr/local/bin/lms' : null));
+ const result = await ensureToolCapableModel(toolCfg());
+ expect(result).toEqual({ skipped: 'lmstudio-unreachable' });
+ expect(execFile).not.toHaveBeenCalled();
+});
+
+it('preloadModel reports lmstudio-unreachable distinctly from no-models', async () => {
+ vi.stubGlobal('fetch', vi.fn(async () => { throw new Error('ECONNREFUSED'); }));
+ whichFirst.mockImplementation(async (bin) => (bin === 'lms' ? '/usr/local/bin/lms' : null));
+ const result = await preloadModel(toolCfg());
+ expect(result).toEqual({ skipped: 'lmstudio-unreachable' });
+});
+
+it('ensureToolCapableModel aborts the remaining install chain on a connect-class lms get failure', async () => {
+ vi.stubGlobal('fetch', vi.fn(async () => ({ ok: true, json: async () => ({ data: [] }) })));
+ whichFirst.mockImplementation(async (bin) => (bin === 'lms' ? '/usr/local/bin/lms' : null));
+ respondWith('Error: Failed to start or connect to local LM Studio API server.');
+ const result = await ensureToolCapableModel(toolCfg());
+ expect(result).toEqual({ skipped: 'lmstudio-unreachable' });
+ expect(execFile).toHaveBeenCalledTimes(1);
+});