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([issue-12608]): report error when LM Studio is down in listManagedBackendModels and fail migrateBackend
[._.]/ Adam Eivya5eb94a962bd
diff --git a/server/services/localLlm.js b/server/services/localLlm.jsindex fcb30b3479..3833271c82 100644--- a/server/services/localLlm.js+++ b/server/services/localLlm.js@@ -764,9 +764,15 @@ export async function listManagedBackendModels(backend, forceRefresh = false) {if (!isBackend(backend)) return { models: null, error: `unknown backend '${backend}'` }const models = await listModels(backend, forceRefresh).catch((err) => ({ error: err?.message || 'model list failed' }))if (!Array.isArray(models)) return { models: null, error: models.error }- const error = backend === 'ollama'+ let error = backend === 'ollama'? ollamaManager.getLastInstalledModelsError(): lmStudioManager.getLastListError()+ if (backend === 'lmstudio' && !error) {+ const status = await lmStudioManager.getStatus().catch(() => null)+ if (!status?.available) {+ error = 'LM Studio is unavailable'+ }+ }return { models, error: error || null }}@@ -1262,8 +1268,12 @@ export async function migrateBackend(to, { mode = 'link', onProgress = () => {}const from = otherBackend(to)onProgress({ event: 'start', message: `Reading models installed on ${from}…` })- const sourceModels = await listModels(from, true) // fresh source list for an accurate migration- if (sourceModels.length === 0) {+ const { models: sourceModels, error } = await listManagedBackendModels(from, true)+ if (error) {+ onProgress({ event: 'error', message: error })+ return { success: false, error }+ }+ if (!sourceModels || sourceModels.length === 0) {const message = `No models installed on ${from} to move.`onProgress({ event: 'complete', message })return { success: true, from, to, mode, results: [] }diff --git a/server/services/localLlm.test.js b/server/services/localLlm.test.jsindex b3008ca375..b16bd72802 100644--- a/server/services/localLlm.test.js+++ b/server/services/localLlm.test.js@@ -155,7 +155,7 @@ const mocks = vi.hoisted(() => ({evictDownloadedQuant: vi.fn(async (id) => ({ success: true, modelId: id })),getModelsDir: vi.fn(async () => '/tmp/portos-lmstudio-models'),downloadModel: vi.fn(async (id) => ({ success: true, modelId: id })),- getStatus: vi.fn(async () => ({ available: false, baseUrl: 'y', loadedModels: 0 })),+ getStatus: vi.fn(async () => ({ available: true, baseUrl: 'y', loadedModels: 0 })),resetCache: vi.fn(),isAppInstalled: vi.fn(() => false),getLastListError: vi.fn(() => null),@@ -664,6 +664,21 @@ describe('localLlm', () => {expect(r.results).toHaveLength(2);});+ it('fails when the source backend is down', async () => {+ // Source lmstudio is down: empty models, getLastListError is null, getStatus reports unavailable+ mocks.lmstudio.getAvailableModels.mockResolvedValueOnce([]);+ mocks.lmstudio.getStatus.mockResolvedValueOnce({ available: false });++ const events = [];+ const r = await svc.migrateBackend('ollama', { onProgress: (e) => events.push(e) });++ expect(r.success).toBe(false);+ expect(r.error).toBe('LM Studio is unavailable');+ expect(events.at(-1)).toEqual({ event: 'error', message: 'LM Studio is unavailable' });+ expect(mocks.ollama.pullModel).not.toHaveBeenCalled();+ expect(mocks.ollama.importModelFromGguf).not.toHaveBeenCalled();+ });+it('returns success with no results when the source backend has no models', async () => {// Target ollama → source lmstudio (empty).mocks.lmstudio.getAvailableModels.mockResolvedValueOnce([]);@@ -1428,16 +1443,27 @@ describe('listManagedBackendModels', () => {expect(await svc.listManagedBackendModels('ollama')).toEqual({ models: [], error: null });});- // The failed read still surfaces the empty array the manager is holding — the- // `error` is what separates it from the genuinely-empty case above, so a- // caller keying on `models.length` alone would still get this wrong.- it('separates an unreadable list from an empty one', async () => {+ // When LM Studio is unreachable, getAvailableModels returns [] and sets+ // lastListError = null (the status card reads available separately).+ // listManagedBackendModels consults the availability probe to surface+ // 'LM Studio is unavailable' so callers do not mistake an outage for an+ // empty model catalog.+ it('separates an unreadable LM Studio list from an empty one when probe reports unavailable', async () => {mocks.lmstudio.getAvailableModels.mockResolvedValueOnce([]);- mocks.lmstudio.getLastListError.mockReturnValueOnce('LM Studio is unavailable');+ mocks.lmstudio.getLastListError.mockReturnValueOnce(null);+ mocks.lmstudio.getStatus.mockResolvedValueOnce({ available: false });expect(await svc.listManagedBackendModels('lmstudio')).toEqual({ models: [], error: 'LM Studio is unavailable' });});+ it('reports a reachable LM Studio backend with no models as a genuinely empty list', async () => {+ mocks.lmstudio.getAvailableModels.mockResolvedValueOnce([]);+ mocks.lmstudio.getLastListError.mockReturnValueOnce(null);+ mocks.lmstudio.getStatus.mockResolvedValueOnce({ available: true });+ expect(await svc.listManagedBackendModels('lmstudio'))+ .toEqual({ models: [], error: null });+ });+it('reports a listing that threw outright, with no models', async () => {mocks.ollama.getInstalledModels.mockRejectedValueOnce(new Error('Ollama unreachable'));expect(await svc.listManagedBackendModels('ollama'))diff --git a/server/services/persistentMindTaskCapability.test.js b/server/services/persistentMindTaskCapability.test.jsindex b965164a5a..1b7ca2dc7d 100644--- a/server/services/persistentMindTaskCapability.test.js+++ b/server/services/persistentMindTaskCapability.test.js@@ -227,6 +227,19 @@ describe('persistent mind CoS-task capability', () => {expect(catalog.providers[0].models.map((model) => model.id)).toEqual(['qwen3-coder:30b']);});+ it('keeps the record list when LM Studio is down and returns an empty list with error', async () => {+ mocks.providers = [{+ id: 'opencode-lmstudio', name: 'OpenCode (LM Studio)', type: 'cli', enabled: true, command: 'opencode',+ lmstudioBacked: true, models: ['qwen2.5-coder-7b-instruct', 'llama-3.2-3b-instruct'], defaultModel: 'qwen2.5-coder-7b-instruct',+ }];+ mocks.listManagedBackendModels.mockResolvedValue({ models: [], error: 'LM Studio is unavailable' });++ const catalog = await readPersistentMindTaskCatalog();+ expect(mocks.listManagedBackendModels).toHaveBeenCalledWith('lmstudio');+ expect(catalog.providers[0].models.map((model) => model.id))+ .toEqual(['qwen2.5-coder-7b-instruct', 'llama-3.2-3b-instruct']);+ });+// A cloud provider enumerates its own catalog, so a retired id is still refused.it('still refuses a retired model on a non-local provider', async () => {const [result] = await executePersistentMindTaskRequests({