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): keep curated catalog ids stable for playground matching

[._.]/ Adam Eivy56f41c3deb6e
diff --git a/server/services/huggingFaceCatalog.js b/server/services/huggingFaceCatalog.js
index c15e84b257..534fdea9b3 100644
--- a/server/services/huggingFaceCatalog.js
+++ b/server/services/huggingFaceCatalog.js
@@ -401,14 +401,18 @@ function preferredQuantVariant(variants) {
return [...variants].sort((a, b) => rank(a.quant) - rank(b.quant))[0]
}
-// Promote a chosen variant onto the result's primary install fields so the
-// default card reflects it (id/quant) without the client having to re-pick. Only
-// overwrite the size when the variant actually has one — otherwise keep the
-// result's existing size (a curated entry's hard-coded estimate, or toResult's
-// label) instead of replacing it with a bare quant string.
-function applyVariant(result, variant) {
- result.id = variant.installId
+// Promote a chosen variant onto the result's primary fields so the default card
+// reflects it (quant/size/installed). `rewriteInstallId` controls whether the
+// result's `id` becomes the variant's install id: true for live HF results (their
+// id IS the install id), false for curated entries — those keep their stable
+// catalog id (other consumers, e.g. the playground, match installed models on it),
+// and the UI selects the recommended variant via its `recommended` flag instead.
+// Only overwrite the size when the variant actually has one — otherwise keep the
+// result's existing size (a curated hard-coded estimate) rather than a bare label.
+function applyVariant(result, variant, rewriteInstallId) {
+ if (rewriteInstallId) result.id = variant.installId
result.quant = variant.quant
+ result.installed = variant.installed
if (Number.isFinite(variant.sizeBytes)) {
result.sizeBytes = variant.sizeBytes
result.size = variant.size
@@ -667,28 +671,33 @@ function contextLengthOf(model) {
}
// Build the per-quant GGUF variant list onto `result` from a fetched repo record
-// and anchor the result on the RAM-aware (or QUANT_PRIORITY) default. Shared by
-// the live HF search and the curated-catalog enrichment so both cards behave the
-// same. Returns true when variants were applied, false when the repo has no
-// parseable GGUF quant (e.g. an MLX-only repo) so the caller can leave it as-is.
-function applyGgufVariants(result, model, { backend, usableBytes, installedIds }) {
+// and mark the RAM-aware (or QUANT_PRIORITY) default. Shared by the live HF search
+// and the curated-catalog enrichment so both cards behave the same. Returns true
+// when variants were applied, false when the repo has no parseable GGUF quant
+// (e.g. an MLX-only repo) so the caller can leave it as-is.
+//
+// `rewriteInstallId`: live HF results adopt the chosen variant's id as their own
+// (their id IS the install id); curated entries keep their stable catalog id (so
+// other consumers — the playground — still match installed models on it) and the
+// UI picks the chosen variant via its `recommended` flag.
+function applyGgufVariants(result, model, { backend, usableBytes, installedIds, rewriteInstallId = true }) {
const variants = buildVariants(model, backend, usableBytes)
if (variants.length === 0) return false
// Per-quant installed state — Ollama tracks each quant separately, so the card
// must gate Install on the *selected* variant, not one repo-wide flag.
for (const v of variants) v.installed = installIdInstalled(backend, v.installId, result.repository, installedIds)
- // Always anchor the result on one of its own variants so the install id and the
- // client's controlled <select> agree. Prefer the RAM-aware pick; otherwise the
- // QUANT_PRIORITY default (matched by quant); fall back to the largest variant.
+ // Prefer the RAM-aware pick; otherwise the QUANT_PRIORITY default (matched by the
+ // result's existing quant); fall back to the QUANT_PRIORITY-preferred variant.
// `usableBytes != null` (not truthiness): 0 is a real budget on a tiny machine —
// pick the smallest (all flagged too-large) rather than falling through as if
// memory were unknown.
const chosen = (usableBytes != null ? pickVariantForBudget(variants, usableBytes) : null)
|| variants.find((v) => v.quant && v.quant === result.quant)
|| preferredQuantVariant(variants)
- applyVariant(result, chosen)
- for (const v of variants) v.recommended = v.installId === result.id
- result.installed = chosen.installed
+ // Flag by identity (robust whether or not the id is rewritten) so the controlled
+ // <select> and the recommended marker always agree on the chosen variant.
+ for (const v of variants) v.recommended = v === chosen
+ applyVariant(result, chosen, rewriteInstallId)
result.variants = variants
return true
}
@@ -895,7 +904,9 @@ export async function enrichCatalogWithVariants(catalog, { backend, systemMemory
entry.repository = repo
// Seed the quant from the curator's id so the no-budget fallback anchors on it.
if (entry.quant == null) entry.quant = quantFromInstallId(backend, entry.id)
- const applied = applyGgufVariants(entry, model, { backend, usableBytes, installedIds })
+ // Keep the curated entry's stable id (rewriteInstallId: false) — the playground
+ // matches installed models on it; the UI installs the recommended variant.
+ const applied = applyGgufVariants(entry, model, { backend, usableBytes, installedIds, rewriteInstallId: false })
if (!applied) return // MLX-only / no parseable GGUF quant — leave the curated entry as-is
entry.format = 'gguf'
// Backfill the real size + native context window the curated list hard-codes.
diff --git a/server/services/huggingFaceCatalog.test.js b/server/services/huggingFaceCatalog.test.js
index fc2ebfb836..6749ea2bd8 100644
--- a/server/services/huggingFaceCatalog.test.js
+++ b/server/services/huggingFaceCatalog.test.js
@@ -572,8 +572,10 @@ describe('huggingFaceCatalog', () => {
expect(catalog[0].format).toBe('gguf')
expect(catalog[0].variants.map((v) => v.installId)).toEqual([`${repo}@Q8_0`, `${repo}@Q4_K_M`])
+ // The curated id stays STABLE (playground matches installed models on it) —
+ // the RAM-aware default is conveyed via the recommended variant instead.
+ expect(catalog[0].id).toBe(repo)
// 128 GB → highest-fidelity that fits becomes the recommended default.
- expect(catalog[0].id).toBe(`${repo}@Q8_0`)
expect(catalog[0].variants.find((v) => v.recommended).installId).toBe(`${repo}@Q8_0`)
expect(catalog[0].sizeBytes).toBe(8_000_000_000)
})
@@ -589,7 +591,9 @@ describe('huggingFaceCatalog', () => {
await enrichCatalogWithVariants(catalog, { backend: 'ollama', systemMemoryBytes: 128 * 1024 ** 3, installedIds: [] })
expect(catalog[0].variants.map((v) => v.installId)).toEqual([`hf.co/${repo}:Q8_0`, `hf.co/${repo}:UD-Q4_K_XL`])
- expect(catalog[0].id).toBe(`hf.co/${repo}:Q8_0`)
+ // Stable curated id; recommended variant carries the RAM-aware install id.
+ expect(catalog[0].id).toBe(`hf.co/${repo}:UD-Q4_K_XL`)
+ expect(catalog[0].variants.find((v) => v.recommended).installId).toBe(`hf.co/${repo}:Q8_0`)
})
it('falls back to the QUANT_PRIORITY quant (not HF file order) and keeps the curated size when HF omits sizes', async () => {
@@ -604,7 +608,8 @@ describe('huggingFaceCatalog', () => {
// QUANT_PRIORITY default, not the largest by file order.
await enrichCatalogWithVariants(catalog, { backend: 'lmstudio', systemMemoryBytes: 8 * 1024 ** 3, installedIds: [] })
- expect(catalog[0].id).toBe(`${repo}@Q4_K_M`)
+ expect(catalog[0].id).toBe(repo) // stable curated id
+ expect(catalog[0].variants.find((v) => v.recommended).installId).toBe(`${repo}@Q4_K_M`)
// The curated size estimate is preserved (not clobbered with a bare quant label).
expect(catalog[0].size).toBe('2.0 GB')
})