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 transient HF fetch failures

[._.]/ Adam Eivye351fd58b25d
diff --git a/server/services/huggingFaceCatalog.js b/server/services/huggingFaceCatalog.js
index 534fdea9b3..327fd63929 100644
--- a/server/services/huggingFaceCatalog.js
+++ b/server/services/huggingFaceCatalog.js
@@ -629,12 +629,19 @@ async function fetchModels(search, limit, filter) {
const repoModelCache = new Map()
const REPO_MODEL_CACHE_MAX = 500
+// A transient fetch failure (network down / timeout / malformed body) — distinct
+// from a genuine HTTP non-OK (404 / gated / private). The former must NOT be
+// cached (it would permanently disable enrichment for the process until HF
+// recovers); the latter is a real "no data" answer worth caching.
+const TRANSIENT_FETCH = Symbol('transient-fetch')
// Fetch (and cache) the per-model record WITH per-file sizes. The search
// endpoint returns siblings without sizes; only `?blobs=true` carries them, and
// the box is debounced per keystroke, so cache by repo to avoid re-fetching.
// `null` = fetched-but-unavailable (gated / private / 404), cached (per the
// absent-vs-empty sentinel rule) so a sizeless repo isn't re-probed every search.
+// A transient failure returns null too, but is NOT cached, so a recovered HF
+// re-enriches on the next request instead of staying blank until restart.
async function fetchRepoModel(repoId) {
if (repoModelCache.has(repoId)) return repoModelCache.get(repoId)
// repoId comes from the HF search response (untrusted upstream) — encode each
@@ -642,7 +649,8 @@ async function fetchRepoModel(repoId) {
const safeRepoPath = String(repoId).split('/').map(encodeURIComponent).join('/')
const model = await fetchWithTimeout(`${HF_API_BASE}/${safeRepoPath}?blobs=true`, { headers: hfHeaders() }, HF_TIMEOUT_MS)
.then((res) => (res.ok ? res.json() : null))
- .catch(() => null)
+ .catch(() => TRANSIENT_FETCH)
+ if (model === TRANSIENT_FETCH) return null // transient — return null but don't cache
// Evict oldest entry when the cap is reached (insertion-order iteration).
if (repoModelCache.size >= REPO_MODEL_CACHE_MAX) {
repoModelCache.delete(repoModelCache.keys().next().value)
diff --git a/server/services/huggingFaceCatalog.test.js b/server/services/huggingFaceCatalog.test.js
index 6749ea2bd8..55569536f4 100644
--- a/server/services/huggingFaceCatalog.test.js
+++ b/server/services/huggingFaceCatalog.test.js
@@ -411,6 +411,29 @@ describe('huggingFaceCatalog', () => {
expect(result.id).toBe(`${repo}@Q4_K_M`)
expect(result.variants.find((v) => v.recommended).installId).toBe(result.id)
})
+
+ it('does not cache a transient blobs-fetch failure — re-enriches once HF recovers', async () => {
+ const repo = 'org/Flaky-GGUF'
+ let blobsCalls = 0
+ fetch.mockImplementation(async (url) => {
+ const u = String(url)
+ if (u.includes('blobs=true')) {
+ blobsCalls += 1
+ if (blobsCalls === 1) throw new Error('transient network error')
+ return response({ id: repo, siblings: [{ rfilename: 'M-Q4_K_M.gguf', size: 4_000_000_000 }] })
+ }
+ return response([{ modelId: repo, downloads: 10, tags: ['gguf'], siblings: [{ rfilename: 'M-Q4_K_M.gguf' }] }])
+ })
+
+ const [first] = await searchHuggingFaceModels({ backend: 'ollama', query: 'flaky', systemMemoryBytes: 128 * 1024 ** 3 })
+ // Transient failure → no variants, and crucially NOT cached as a null result.
+ expect(first.variants).toBeUndefined()
+
+ const [second] = await searchHuggingFaceModels({ backend: 'ollama', query: 'flaky', systemMemoryBytes: 128 * 1024 ** 3 })
+ // Retried (the null wasn't cached) → enrichment succeeds this time.
+ expect(second.variants).toBeTruthy()
+ expect(second.sizeBytes).toBe(4_000_000_000)
+ })
})
describe('sort order', () => {