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): fix installed-default UI gating + don't cache transient 5xx/429
[._.]/ Adam Eivyb710a20740c5
diff --git a/server/services/huggingFaceCatalog.js b/server/services/huggingFaceCatalog.jsindex e0cc0cfaa5..ebbd4c9c4c 100644--- a/server/services/huggingFaceCatalog.js+++ b/server/services/huggingFaceCatalog.js@@ -924,12 +924,8 @@ function quantFromInstallId(backend, id) {async function applyOllamaRegistryVariants(entry, { usableBytes, installedIds }) {const candidates = await fetchOllamaRegistryVariants(entry.id, { paramsHint: entry.params })if (candidates.length === 0) return false- // The bare curated id (`llama3.2`, pulled as `:latest`) install is recorded on the- // entry's pre-enrichment `installed` flag — getCatalog matched it latest-normalized.- // The per-quant variants below use exact `<name>:<tag>` ids that never include that- // alias, so capture the default install now and OR it back after applyVariant- // overwrites `installed`; otherwise an already-installed model shows "Install" and a- // click pulls a duplicate specific-quant tag.+ // Whether the user already pulled the curator's default build (`entry.id`, e.g.+ // `llama3.2` stored as `:latest`). getCatalog set entry.installed latest-normalized.const installedAsDefault = entry.installed === trueconst variants = candidates.map((c) => {@@ -947,15 +943,42 @@ async function applyOllamaRegistryVariants(entry, { usableBytes, installedIds })// Per-quant installed state — Ollama tracks each `<name>:<tag>` build separately,// so the card gates Install on the selected variant (matches applyGgufVariants).for (const v of variants) v.installed = installIdInstalled('ollama', v.installId, entry.repository, installedIds)+ // The discovered quant variants use exact `<name>:<tag>` ids that never include the+ // default `:latest` alias, so an already-installed default build matches none of them.+ // The card gates Install on the SELECTED variant's `installed` (LocalLlmTab uses+ // `chosenVariant.installed`), so without representing the default build the card would+ // show Install for a model the user already has and pull a duplicate tag. Surface the+ // installed default as its own variant (install id = the curator's id, the real tag the+ // user pulled) when no discovered quant variant is itself installed.+ const hasInstalledVariant = variants.some((v) => v.installed)+ const defaultBuildPresent = variants.some((v) => v.installId === entry.id)+ if (installedAsDefault && !hasInstalledVariant && !defaultBuildPresent) {+ const sizeBytes = Number.isFinite(entry.sizeBytes) ? entry.sizeBytes : null+ variants.unshift({+ quant: entry.quant || quantFromInstallId('ollama', entry.id) || 'default',+ format: 'gguf',+ installId: entry.id,+ sizeBytes,+ size: formatBytes(sizeBytes) || entry.size || 'installed',+ fit: classifyFit(sizeBytes, usableBytes),+ installed: true+ })+ }// Seed the quant from the curator's id (`gpt-oss:20b` has no quant tag, so this// is usually null) so the no-RAM-budget fallback can anchor on it.if (entry.quant == null) entry.quant = quantFromInstallId('ollama', entry.id)- // Keep the curated entry's stable id (rewriteInstallId: false) — the playground- // matches installed models on it; the UI installs the recommended variant.- applyChosenVariant(entry, variants, { usableBytes, rewriteInstallId: false })- // Preserve the card-level "installed" state from the pre-existing default/:latest- // build — the user has a build of this model even if no specific quant variant matches.- if (installedAsDefault) entry.installed = true+ // Initial selection: prefer the already-installed default build (so the card reads+ // Installed, its pre-enrichment behavior) over a RAM-aware re-pull; otherwise the+ // RAM-aware pick. The other quants stay listed with their true per-tag installed+ // state + fit hints for explicit selection. Keep the stable curated id either way.+ const installedDefault = variants.find((v) => v.installId === entry.id && v.installed)+ if (installedDefault) {+ for (const v of variants) v.recommended = v === installedDefault+ applyVariant(entry, installedDefault, false)+ entry.variants = variants+ } else {+ applyChosenVariant(entry, variants, { usableBytes, rewriteInstallId: false })+ }entry.format = 'gguf'return true}diff --git a/server/services/huggingFaceCatalog.test.js b/server/services/huggingFaceCatalog.test.jsindex 57ea68ed3b..d61b9f3e04 100644--- a/server/services/huggingFaceCatalog.test.js+++ b/server/services/huggingFaceCatalog.test.js@@ -720,23 +720,45 @@ describe('huggingFaceCatalog', () => {expect(catalog[0].variants.find((v) => v.installId === 'gpt-pick:20b-q8_0').installed).toBe(false)})- it('preserves the card-level installed state for a default/:latest bare Ollama install', async () => {+ it('surfaces the installed default build as a selected variant for a default/:latest bare Ollama install', async () => {__resetOllamaRegistryCache()fetch.mockImplementation(ollamaRegistry(['3b-instruct-q4_K_M', '3b-instruct-q8_0'],{ '3b-instruct-q4_K_M': 2_000_000_000, '3b-instruct-q8_0': 3_500_000_000 }))// getCatalog flagged this installed (the user pulled `defllama`, stored as :latest).- // None of the exact `<name>:<tag>` variants matches that alias.+ // None of the exact `<name>:<tag>` quant variants matches that alias.const catalog = [{ id: 'defllama', key: 'defllama', name: 'Def Llama 3B', category: 'chat', params: '3B', size: '2.0 GB', installed: true }]await enrichCatalogWithVariants(catalog, {backend: 'ollama', systemMemoryBytes: 128 * 1024 ** 3, installedIds: ['defllama:latest']})- // The card still reads as installed (a build is present) even though no specific- // quant variant matches — so it won't show "Install" and pull a duplicate tag.+ // The installed default build is surfaced as its own variant (install id = the+ // curator's id) and selected, so the card reads Installed (LocalLlmTab gates on the+ // chosen variant) instead of offering a duplicate pull.expect(catalog[0].installed).toBe(true)- expect(catalog[0].variants.every((v) => v.installed === false)).toBe(true)+ const defaultVariant = catalog[0].variants.find((v) => v.installId === 'defllama')+ expect(defaultVariant).toMatchObject({ installed: true, recommended: true })+ // The discovered quant variants keep their true (not-installed) per-tag state.+ expect(catalog[0].variants.filter((v) => v.installId !== 'defllama').every((v) => v.installed === false)).toBe(true)+ expect(catalog[0].variants.filter((v) => v.recommended).length).toBe(1)+ })++ it('does NOT add a default variant when a specific quant tag is already installed', async () => {+ __resetOllamaRegistryCache()+ fetch.mockImplementation(ollamaRegistry(+ ['3b-instruct-q4_K_M', '3b-instruct-q8_0'],+ { '3b-instruct-q4_K_M': 2_000_000_000, '3b-instruct-q8_0': 3_500_000_000 }+ ))+ // The user has the exact q8 build — the per-quant flag already shows Installed,+ // so no synthesized default build is needed.+ const catalog = [{ id: 'qllama', key: 'qllama', name: 'Q Llama 3B', category: 'chat', params: '3B', size: '2.0 GB', installed: true }]+ await enrichCatalogWithVariants(catalog, {+ backend: 'ollama', systemMemoryBytes: 128 * 1024 ** 3, installedIds: ['qllama:3b-instruct-q8_0']+ })++ expect(catalog[0].variants.some((v) => v.installId === 'qllama')).toBe(false)+ expect(catalog[0].variants.find((v) => v.installId === 'qllama:3b-instruct-q8_0').installed).toBe(true)})it('leaves a bare Ollama name untouched when the model is not on the registry', async () => {diff --git a/server/services/ollamaRegistryCatalog.js b/server/services/ollamaRegistryCatalog.jsindex b27f3cfc52..a2ff9d45c0 100644--- a/server/services/ollamaRegistryCatalog.js+++ b/server/services/ollamaRegistryCatalog.js@@ -37,10 +37,10 @@ const MAX_VARIANTS = 12const tagsCache = new Map()const manifestCache = new Map()const CACHE_MAX = 500-// A transient fetch failure (network down / timeout / malformed body) — distinct-// from a genuine HTTP non-OK (404 / gated). The former must NOT be cached (it-// would permanently disable enrichment until the registry recovers); the latter-// is a real "no data" answer worth caching.+// A transient fetch failure (network down / timeout / malformed body / 5xx / 429)+// — distinct from a genuine permanent non-OK (404 / 410 / 403). The former must+// NOT be cached (it would permanently disable enrichment until the registry+// recovers); the latter is a real "no such model" answer worth caching.const TRANSIENT_FETCH = Symbol('ollama-registry-transient')function cacheSet(cache, key, value) {@@ -49,6 +49,18 @@ function cacheSet(cache, key, value) {cache.set(key, value)}+// Resolve a fetch Response into either the parsed JSON body, `null` (a permanent+// "no data" answer worth caching — model genuinely absent), or TRANSIENT_FETCH (a+// retry-worthy failure that must NOT be cached). Permanent = 404 Not Found / 410+// Gone / 403 Forbidden; everything else non-OK (500/502/503/408/429/…) is transient,+// as is an OK response whose body won't parse (a proxy/captive-portal error page+// served as HTTP 200 — `readResponseJson` returns its fallback rather than throwing).+const PERMANENT_NOT_FOUND = new Set([403, 404, 410])+function resolveRegistryBody(res) {+ if (res.ok) return readResponseJson(res, { fallback: TRANSIENT_FETCH, emptyValue: TRANSIENT_FETCH })+ return PERMANENT_NOT_FOUND.has(res.status) ? null : TRANSIENT_FETCH+}+// Split a curated Ollama install id into its registry path + optional tag.// `gpt-oss:20b` → { name: 'gpt-oss', repoPath: 'library/gpt-oss', tag: '20b' }// `llama3.2` → { name: 'llama3.2', repoPath: 'library/llama3.2', tag: null }@@ -119,15 +131,10 @@ async function fetchTags(repoPath, timeoutMs) {// repoPath is derived from a curated id, but encode each segment defensively so// a stray character can't reshape the request path.const safePath = repoPath.split('/').map(encodeURIComponent).join('/')- // Route an OK-but-unparseable body (a proxy/captive-portal error page served as- // HTTP 200) through the transient sentinel — `readResponseJson` returns its- // fallback rather than throwing, so without this a single malformed 200 would- // cache `null` and permanently disable this model's enrichment until restart.- // A genuine non-OK (404/gated) stays `null` and IS cached (a real "no data").const result = await fetchWithTimeout(`${REGISTRY_BASE}/${safePath}/tags/list`, { headers: { Accept: 'application/json' } }, timeoutMs)- .then((res) => (res.ok ? readResponseJson(res, { fallback: TRANSIENT_FETCH, emptyValue: TRANSIENT_FETCH }) : null))+ .then(resolveRegistryBody).catch(() => TRANSIENT_FETCH)- if (result === TRANSIENT_FETCH) return null // transient (throw or unparseable 200) — don't cache+ if (result === TRANSIENT_FETCH) return null // transient (throw / 5xx / 429 / unparseable 200) — don't cacheconst tags = Array.isArray(result?.tags) ? result.tags : nullcacheSet(tagsCache, repoPath, tags)return tags@@ -138,13 +145,12 @@ async function fetchManifestModelBytes(repoPath, tag, timeoutMs) {if (manifestCache.has(key)) return manifestCache.get(key)const safePath = repoPath.split('/').map(encodeURIComponent).join('/')const safeTag = encodeURIComponent(tag)- // Same transient-vs-cacheable distinction as fetchTags: an unparseable 200 is- // transient (don't cache); a non-OK is a real "no size" answer (cache null).+ // Same transient-vs-cacheable distinction as fetchTags (see resolveRegistryBody).const result = await fetchWithTimeout(`${REGISTRY_BASE}/${safePath}/manifests/${safeTag}`, { headers: { Accept: MANIFEST_ACCEPT } }, timeoutMs)- .then((res) => (res.ok ? readResponseJson(res, { fallback: TRANSIENT_FETCH, emptyValue: TRANSIENT_FETCH }) : null))+ .then(resolveRegistryBody).catch(() => TRANSIENT_FETCH)- if (result === TRANSIENT_FETCH) return null // transient (throw or unparseable 200) — don't cache- const bytes = sumModelLayerBytes(result) // result is null (non-OK) or the manifest object+ if (result === TRANSIENT_FETCH) return null // transient (throw / 5xx / 429 / unparseable 200) — don't cache+ const bytes = sumModelLayerBytes(result) // result is null (permanent non-OK) or the manifest objectcacheSet(manifestCache, key, bytes)return bytes}diff --git a/server/services/ollamaRegistryCatalog.test.js b/server/services/ollamaRegistryCatalog.test.jsindex d6a5bf2438..390702dfa5 100644--- a/server/services/ollamaRegistryCatalog.test.js+++ b/server/services/ollamaRegistryCatalog.test.js@@ -135,10 +135,21 @@ describe('fetchOllamaRegistryVariants', () => {})it('returns [] when the model is absent from the registry (tags 404)', async () => {- fetch.mockResolvedValue(response({}, false))+ fetch.mockResolvedValue(response({}, false)) // status 404 → permanentexpect(await fetchOllamaRegistryVariants('ghost-model', { paramsHint: '3B' })).toEqual([])})+ it('does not cache a transient non-OK status (503/429) — only permanent 404/410/403', async () => {+ // 503 Service Unavailable on tags/list — transient, must NOT be cached.+ const unavailable = { ok: false, status: 503, json: vi.fn(async () => ({})), text: vi.fn(async () => '') }+ fetch.mockResolvedValueOnce(unavailable)+ expect(await fetchOllamaRegistryVariants('rate-limited', { paramsHint: '3B' })).toEqual([])+ // The recovered registry re-enriches (the 503 wasn't cached as "no such model").+ fetch.mockImplementation(registry(['3b-instruct-q4_K_M'], { '3b-instruct-q4_K_M': 2_000_000_000 }))+ const variants = await fetchOllamaRegistryVariants('rate-limited', { paramsHint: '3B' })+ expect(variants.map((v) => v.installId)).toEqual(['rate-limited:3b-instruct-q4_K_M'])+ })+it('keeps a null size when the manifest is unavailable', async () => {fetch.mockImplementation(registry(['7b-instruct-q4_K_M'], {})) // no size for the tagconst variants = await fetchOllamaRegistryVariants('mistral', { paramsHint: '7B' })