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): don't cache an OK-but-unparseable registry response

[._.]/ Adam Eivy3cc37a80d3af
diff --git a/server/services/ollamaRegistryCatalog.js b/server/services/ollamaRegistryCatalog.js
index cc5fc1df9f..b27f3cfc52 100644
--- a/server/services/ollamaRegistryCatalog.js
+++ b/server/services/ollamaRegistryCatalog.js
@@ -119,10 +119,15 @@ 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: null, emptyValue: null }) : null))
+ .then((res) => (res.ok ? readResponseJson(res, { fallback: TRANSIENT_FETCH, emptyValue: TRANSIENT_FETCH }) : null))
.catch(() => TRANSIENT_FETCH)
- if (result === TRANSIENT_FETCH) return null // transient — return null but don't cache
+ if (result === TRANSIENT_FETCH) return null // transient (throw or unparseable 200) — don't cache
const tags = Array.isArray(result?.tags) ? result.tags : null
cacheSet(tagsCache, repoPath, tags)
return tags
@@ -133,11 +138,13 @@ 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).
const result = await fetchWithTimeout(`${REGISTRY_BASE}/${safePath}/manifests/${safeTag}`, { headers: { Accept: MANIFEST_ACCEPT } }, timeoutMs)
- .then((res) => (res.ok ? readResponseJson(res, { fallback: null, emptyValue: null }) : null))
+ .then((res) => (res.ok ? readResponseJson(res, { fallback: TRANSIENT_FETCH, emptyValue: TRANSIENT_FETCH }) : null))
.catch(() => TRANSIENT_FETCH)
- if (result === TRANSIENT_FETCH) return null // transient — return null but don't cache
- const bytes = sumModelLayerBytes(result)
+ 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
cacheSet(manifestCache, key, bytes)
return bytes
}
diff --git a/server/services/ollamaRegistryCatalog.test.js b/server/services/ollamaRegistryCatalog.test.js
index 6e2eb1d12f..d6a5bf2438 100644
--- a/server/services/ollamaRegistryCatalog.test.js
+++ b/server/services/ollamaRegistryCatalog.test.js
@@ -154,4 +154,21 @@ describe('fetchOllamaRegistryVariants', () => {
const variants = await fetchOllamaRegistryVariants('flaky', { paramsHint: '3B' })
expect(variants.map((v) => v.installId)).toEqual(['flaky:3b-instruct-q4_K_M'])
})
+
+ it('does not cache an OK-but-unparseable (HTTP 200) tags response', async () => {
+ // A proxy/captive-portal error page served as 200: ok=true but body is not JSON.
+ // readResponseJson returns its fallback instead of throwing — this must still be
+ // treated as transient (not cached) so a recovered registry re-enriches.
+ const htmlError = {
+ ok: true, status: 200,
+ json: vi.fn(async () => { throw new Error('Unexpected token <') }),
+ text: vi.fn(async () => '<html>502 Bad Gateway</html>')
+ }
+ fetch.mockResolvedValueOnce(htmlError)
+ expect(await fetchOllamaRegistryVariants('proxied', { paramsHint: '3B' })).toEqual([])
+ // Not cached → the recovered registry produces variants on the next call.
+ fetch.mockImplementation(registry(['3b-instruct-q4_K_M'], { '3b-instruct-q4_K_M': 2_000_000_000 }))
+ const variants = await fetchOllamaRegistryVariants('proxied', { paramsHint: '3B' })
+ expect(variants.map((v) => v.installId)).toEqual(['proxied:3b-instruct-q4_K_M'])
+ })
})