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

address review (codex): raw ids for catalog overlay + MLX-specific search terms

[._.]/ Adam Eivyb82aae827ec6
diff --git a/server/routes/localLlm.js b/server/routes/localLlm.js
index f4a341eea6..a7a20a0889 100644
--- a/server/routes/localLlm.js
+++ b/server/routes/localLlm.js
@@ -63,17 +63,21 @@ router.get('/vision-models', asyncHandler(async (_req, res) => {
router.get('/catalog', asyncHandler(async (req, res) => {
const { backend, q } = req.query
if (!isBackend(backend)) throw new ServerError('backend must be "ollama" or "lmstudio"', { status: 400 })
- // Per-quant installed detection needs LM Studio's quantization on the id
- // (`<id>@<quant>`) — mirror the HF-search route so a single installed quant
- // doesn't flag every quant of a repo as installed.
- const installed = (await listModels(backend)).map((m) => (
+ const installedModels = await listModels(backend)
+ // getCatalog/searchCatalog normalize raw ids (no `@quant` suffix) — feed them the
+ // RAW ids so the offline installed overlay is correct even when HF enrichment
+ // fails/times out. Variant enrichment gets the quant-augmented ids (`<id>@<quant>`)
+ // for per-quant installed detection (a single installed quant must not flag every
+ // quant of a repo as installed) — it overwrites the overlay on success.
+ const installedRaw = installedModels.map((m) => m.id)
+ const installedForVariants = installedModels.map((m) => (
backend === 'lmstudio' && m.quantization ? `${m.id}@${m.quantization}` : m.id
))
- const models = q ? searchCatalog(backend, q, installed) : getCatalog(backend, installed)
+ const models = q ? searchCatalog(backend, q, installedRaw) : getCatalog(backend, installedRaw)
// Total system memory drives the RAM-aware recommended quant (unified memory on
// Apple Silicon also backs the GPU, so a big box can default to higher fidelity).
const systemMemoryBytes = os.totalmem()
- await enrichCatalogWithVariants(models, { backend, systemMemoryBytes, installedIds: installed })
+ await enrichCatalogWithVariants(models, { backend, systemMemoryBytes, installedIds: installedForVariants })
res.json({ backend, models, systemMemoryGb: Math.round(systemMemoryBytes / 1024 ** 3) })
}))
diff --git a/server/routes/localLlm.test.js b/server/routes/localLlm.test.js
index b0b9eb2c5a..6f90f241c8 100644
--- a/server/routes/localLlm.test.js
+++ b/server/routes/localLlm.test.js
@@ -3,6 +3,7 @@ import express from 'express';
import { request } from '../lib/testHelper.js';
import localLlmRoutes from './localLlm.js';
import { runLocalLlmTest, compareLocalLlmModels } from '../services/localLlmPlayground.js';
+import { listModels } from '../services/localLlm.js';
import { getLoadedModels, unloadModel } from '../services/ollamaManager.js';
import { localLlmCompareSchema, localLlmTestSchema } from '../lib/validation.js';
import { errorEvents } from '../lib/errorHandler.js';
@@ -34,6 +35,15 @@ vi.mock('../services/ollamaManager.js', () => ({
unloadModel: vi.fn(),
}));
+// Mock the HF catalog service so /catalog tests don't hit the network. The no-op
+// enrichCatalogWithVariants simulates the offline/failed-enrichment case (it leaves
+// the catalog's getCatalog overlay untouched), which is exactly when the route's
+// raw-id installed overlay must be correct.
+vi.mock('../services/huggingFaceCatalog.js', () => ({
+ searchHuggingFaceModels: vi.fn(async () => []),
+ enrichCatalogWithVariants: vi.fn(async (catalog) => catalog),
+}));
+
function makeApp() {
const app = express();
app.use(express.json());
@@ -47,6 +57,20 @@ describe('local LLM playground routes', () => {
vi.clearAllMocks();
});
+ it('GET /catalog keeps an installed LM Studio recommendation installed when HF enrichment is a no-op', async () => {
+ // The route appends LM Studio's quantization to the enrichment installed list,
+ // but getCatalog's normalizer can't parse `@quant` — so the offline overlay must
+ // get the RAW ids, or an already-installed model wrongly shows Install when HF is down.
+ listModels.mockResolvedValue([{ id: 'lmstudio-community/Llama-3.2-3B-Instruct-GGUF', quantization: 'Q4_K_M' }]);
+
+ const res = await request(makeApp()).get('/api/local-llm/catalog?backend=lmstudio');
+
+ expect(res.status).toBe(200);
+ const entry = res.body.models.find((m) => m.id === 'lmstudio-community/Llama-3.2-3B-Instruct-GGUF');
+ expect(entry).toBeTruthy();
+ expect(entry.installed).toBe(true);
+ });
+
it('runs a single local model test with validated defaults', async () => {
runLocalLlmTest.mockResolvedValue({
backend: 'ollama',
diff --git a/server/services/huggingFaceCatalog.js b/server/services/huggingFaceCatalog.js
index e6376f9a8d..ce3e98725c 100644
--- a/server/services/huggingFaceCatalog.js
+++ b/server/services/huggingFaceCatalog.js
@@ -764,6 +764,11 @@ export async function searchHuggingFaceModels({ backend, query = '', category =
// would all be filtered out.
const ggufOnly = requestedCategory !== 'audio'
const search = normalizeText(query) || CATEGORY_SEARCH[requestedCategory] || 'gguf'
+ // The default/category browse phrase contains "gguf" — sending that to the MLX
+ // query (`filter=mlx&search=…gguf`) filters out MLX-only repos. Use a parallel
+ // phrase with "gguf" swapped for "mlx" (or a bare "mlx") so the default browse
+ // surfaces MLX repos, not just hand-typed queries that happen to match one.
+ const mlxSearch = normalizeText(query) || CATEGORY_SEARCH[requestedCategory]?.replace(/\bgguf\b/gi, 'mlx') || 'mlx'
const fetchLimit = Math.max(limit * 3, 30)
// MLX is only installable via LM Studio on Apple Silicon (see toMlxResult), so
// run the extra MLX query only there — never for Ollama, non-Apple hosts, or
@@ -775,7 +780,7 @@ export async function searchHuggingFaceModels({ backend, query = '', category =
// MLX is optional enrichment — a transient/API-specific MLX-query failure must
// not blank the primary GGUF results, so swallow it to an empty list. (The
// GGUF query still throws on failure, preserving the original error behaviour.)
- wantMlx ? fetchModels(search, fetchLimit, 'mlx').catch(() => []) : Promise.resolve([])
+ wantMlx ? fetchModels(mlxSearch, fetchLimit, 'mlx').catch(() => []) : Promise.resolve([])
])
let models = ggufModelsRaw
if (models.length === 0 && ggufOnly) models = await fetchModels(search, fetchLimit, null)
diff --git a/server/services/huggingFaceCatalog.test.js b/server/services/huggingFaceCatalog.test.js
index f5345a5e14..f11f0f23d3 100644
--- a/server/services/huggingFaceCatalog.test.js
+++ b/server/services/huggingFaceCatalog.test.js
@@ -525,6 +525,22 @@ describe('huggingFaceCatalog', () => {
expect(mlx.variants[0].installed).toBe(true)
})
+ it('queries MLX with MLX-specific terms (not the gguf browse phrase) on a default browse', async () => {
+ fetch.mockImplementation(urlRouter([
+ ['filter=mlx', []],
+ ['filter=gguf', []],
+ ]))
+
+ await searchHuggingFaceModels({ backend: 'lmstudio', category: 'coding', appleSilicon: true }) // no query
+
+ const mlxCall = fetch.mock.calls.find(([u]) => String(u).includes('filter=mlx'))
+ expect(mlxCall).toBeTruthy()
+ // The category browse phrase ('…code gguf') must be rewritten for MLX, or
+ // `filter=mlx&search=…gguf` filters every MLX-only repo out of the browse.
+ expect(String(mlxCall[0])).not.toMatch(/search=[^&]*gguf/)
+ expect(String(mlxCall[0])).toMatch(/search=[^&]*mlx/)
+ })
+
it('still returns GGUF results when the optional MLX query fails', async () => {
const ggufRepo = 'org/Survivor-GGUF'
fetch.mockImplementation(async (url) => {