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
address review (codex): isolate MLX query failures + bound curated enrichment
[._.]/ Adam Eivy3ec64f74c4e7
diff --git a/server/services/huggingFaceCatalog.js b/server/services/huggingFaceCatalog.jsindex 74415e82ac..e6376f9a8d 100644--- a/server/services/huggingFaceCatalog.js+++ b/server/services/huggingFaceCatalog.js@@ -5,6 +5,12 @@ import { ENGINES } from './pipeline/musicGen.js'const HF_API_BASE = 'https://huggingface.co/api/models'const HF_TIMEOUT_MS = 12_000+// Upper bound on how long the curated-catalog endpoint waits for HF variant+// enrichment. The curated catalog must stay usable offline (it was a pure local+// list before enrichment), so when HF is slow/down we return the catalog as-is+// after this budget; in-flight probes keep running and warm the repo cache, so+// the next load (or a recovered HF) enriches without delay.+const CATALOG_ENRICH_TIMEOUT_MS = 5_000const CATEGORY_IDS = new Set(LOCAL_LLM_CATEGORIES.map((c) => c.id))const CATEGORY_SEARCH = {@@ -766,7 +772,10 @@ export async function searchHuggingFaceModels({ backend, query = '', category =const wantMlx = appleSilicon && backend === 'lmstudio' && requestedCategory !== 'audio'const [ggufModelsRaw, mlxModelsRaw] = await Promise.all([fetchModels(search, fetchLimit, ggufOnly ? 'gguf' : null),- wantMlx ? fetchModels(search, fetchLimit, 'mlx') : Promise.resolve([])+ // 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([])])let models = ggufModelsRawif (models.length === 0 && ggufOnly) models = await fetchModels(search, fetchLimit, null)@@ -852,10 +861,10 @@ function quantFromInstallId(backend, id) {// with no HF repo (bare Ollama registry names) or an MLX-only repo (no GGUF// quants) are left untouched — the card then shows the curator's single id with// no picker. `usableBytes` makes the recommended quant fit this machine.-export async function enrichCatalogWithVariants(catalog, { backend, systemMemoryBytes = null, installedIds = [] } = {}) {+export async function enrichCatalogWithVariants(catalog, { backend, systemMemoryBytes = null, installedIds = [], timeoutMs = CATALOG_ENRICH_TIMEOUT_MS } = {}) {if (!isBackend(backend) || !Array.isArray(catalog)) return catalogconst usableBytes = usableMemoryBytes(systemMemoryBytes)- await Promise.allSettled(catalog.map(async (entry) => {+ const work = Promise.allSettled(catalog.map(async (entry) => {const repo = catalogRepoForBackend(backend, entry.id)if (!repo) returnconst model = await fetchRepoModel(repo)@@ -879,5 +888,16 @@ export async function enrichCatalogWithVariants(catalog, { backend, systemMemoryif (ctx != null) entry.contextLength = ctx}}))+ // Bound the wait so a slow/unreachable HF never stalls the (offline-capable)+ // catalog endpoint. Entries enrich in place, so whatever resolved within the+ // budget is already applied; the rest keep their hard-coded fields and their+ // probes keep running in the background to warm the repo cache for next time.+ if (timeoutMs > 0) {+ let timer+ const budget = new Promise((resolve) => { timer = setTimeout(resolve, timeoutMs); timer.unref?.() })+ await Promise.race([work.finally(() => clearTimeout(timer)), budget])+ } else {+ await work+ }return catalog}diff --git a/server/services/huggingFaceCatalog.test.js b/server/services/huggingFaceCatalog.test.jsindex 2ea7c88e30..f5345a5e14 100644--- a/server/services/huggingFaceCatalog.test.js+++ b/server/services/huggingFaceCatalog.test.js@@ -524,6 +524,21 @@ describe('huggingFaceCatalog', () => {expect(mlx.installed).toBe(true)expect(mlx.variants[0].installed).toBe(true)})++ it('still returns GGUF results when the optional MLX query fails', async () => {+ const ggufRepo = 'org/Survivor-GGUF'+ fetch.mockImplementation(async (url) => {+ const u = String(url)+ if (u.includes('filter=mlx')) throw new Error('mlx query boom')+ if (u.includes('filter=gguf')) return response([{ modelId: ggufRepo, downloads: 10, tags: ['gguf'], siblings: [{ rfilename: 'S-Q4_K_M.gguf', size: 4_000_000_000 }] }])+ if (u.includes('blobs=true')) return response({ id: ggufRepo, siblings: [{ rfilename: 'S-Q4_K_M.gguf', size: 4_000_000_000 }] })+ return response([])+ })++ const results = await searchHuggingFaceModels({ backend: 'lmstudio', query: 's', appleSilicon: true })++ expect(results.some((r) => r.repository === ggufRepo)).toBe(true)+ })})describe('curated catalog quant enrichment', () => {@@ -571,6 +586,33 @@ describe('huggingFaceCatalog', () => {// No HF repo means no network probe at all.expect(fetch).not.toHaveBeenCalled()})++ it('degrades gracefully (keeps the curated entry) when the HF probe fails', async () => {+ const repo = 'lmstudio-community/Unreachable-GGUF'+ fetch.mockRejectedValue(new Error('network down'))+ const catalog = [{ id: repo, key: 'unreachable', name: 'Unreachable', category: 'chat', size: '2.0 GB' }]+ await enrichCatalogWithVariants(catalog, { backend: 'lmstudio', systemMemoryBytes: 128 * 1024 ** 3 })++ expect(catalog[0].variants).toBeUndefined()+ expect(catalog[0].id).toBe(repo)+ expect(catalog[0].size).toBe('2.0 GB')+ })++ it('returns within the timeout budget when HF is slow instead of blocking the catalog', async () => {+ const repo = 'lmstudio-community/Slow-GGUF'+ // Resolves long after the budget; unref'd so the pending timer can't hang the run.+ fetch.mockImplementation(() => new Promise((resolve) => {+ const t = setTimeout(() => resolve(response({ id: repo, siblings: [{ rfilename: 'Slow-Q4_K_M.gguf', size: 4_000_000_000 }] })), 5000)+ t.unref?.()+ }))+ const catalog = [{ id: repo, key: 'slow', name: 'Slow', category: 'chat', size: '2.0 GB' }]++ const started = Date.now()+ await enrichCatalogWithVariants(catalog, { backend: 'lmstudio', systemMemoryBytes: 128 * 1024 ** 3, timeoutMs: 50 })++ expect(Date.now() - started).toBeLessThan(2000)+ expect(catalog[0].variants).toBeUndefined()+ })})describe('audio installed registry', () => {