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): rank quants by fidelity before the variant cap
[._.]/ Adam Eivyee7f2329e045
diff --git a/server/services/ollamaRegistryCatalog.js b/server/services/ollamaRegistryCatalog.jsindex a2ff9d45c0..7740067097 100644--- a/server/services/ollamaRegistryCatalog.js+++ b/server/services/ollamaRegistryCatalog.js@@ -29,10 +29,33 @@ const REGISTRY_TIMEOUT_MS = 12_000// this media type (template/params/license layers carry the other media types).const MANIFEST_ACCEPT = 'application/vnd.docker.distribution.manifest.v2+json'const MODEL_LAYER_MEDIA_TYPE = 'application/vnd.ollama.image.model'-// Upper bound on distinct quant variants probed per card. After dedup-by-quant-// at the target size this is rarely hit (a model ships ~4–8 quants), but it caps-// the manifest fan-out for a pathologically tag-heavy model.-const MAX_VARIANTS = 12+// Defensive upper bound on distinct quant variants probed per card. The dedup-by-quant+// at the target size already bounds the candidate set to the finite GGUF/Ollama quant+// vocabulary (~25–30 incl. every IQ/K-quant), so a real model never approaches this — it+// only guards a pathological/adversarial registry response. It is applied AFTER ranking+// candidates by descending fidelity (see fidelityRank) so that, in the impossible event+// it ever truncates, the high-fidelity builds a big-memory machine wants survive rather+// than whichever quants happened to appear first in the registry's tag order.+const MAX_VARIANTS = 32++// Descending-fidelity order of canonical (uppercase) quant labels, used only to order+// candidates before the defensive cap above. Higher index in this list = lower fidelity;+// unknown labels rank last. This is a registry-local ordering (distinct from+// huggingFaceCatalog's QUANT_PRIORITY, which is a curated *default-pick* preference, not a+// full fidelity ranking) — the RAM-aware default itself is chosen downstream from real+// manifest sizes, so this only decides which quants get probed if the cap ever bites.+const QUANT_FIDELITY = [+ 'F32', 'FP32', 'BF16', 'F16', 'FP16',+ 'Q8_0', 'Q6_K',+ 'Q5_K_M', 'Q5_K_S', 'Q5_1', 'Q5_0',+ 'Q4_K_XL', 'Q4_K_M', 'Q4_K_S', 'Q4_1', 'Q4_0', 'IQ4_NL', 'IQ4_XS',+ 'Q3_K_L', 'Q3_K_M', 'Q3_K_S', 'IQ3_M', 'IQ3_S', 'IQ3_XXS',+ 'Q2_K', 'IQ2_M', 'IQ2_S', 'IQ2_XS', 'IQ2_XXS', 'IQ1_M', 'IQ1_S'+]+function fidelityRank(quant) {+ const i = QUANT_FIDELITY.indexOf(String(quant).toUpperCase())+ return i === -1 ? QUANT_FIDELITY.length : i // unknown → lowest fidelity (sorted/dropped last)+}const tagsCache = new Map()const manifestCache = new Map()@@ -185,7 +208,12 @@ export async function fetchOllamaRegistryVariants(id, { paramsHint = null, timeoconst existing = byQuant.get(quant)if (!existing || preferTag(tag, existing)) byQuant.set(quant, tag)}- const chosen = [...byQuant.entries()].slice(0, MAX_VARIANTS)+ // Rank the deduped quants by descending fidelity BEFORE the defensive cap, so a+ // truncation (which a real model never triggers) can't drop the high-fidelity builds+ // by registry tag order. Every matching quant is kept for normal models.+ const chosen = [...byQuant.entries()]+ .sort(([qa], [qb]) => fidelityRank(qa) - fidelityRank(qb))+ .slice(0, MAX_VARIANTS)if (chosen.length === 0) return []// Manifest size fan-out is bounded by the dedup + cap above; fetch concurrently.diff --git a/server/services/ollamaRegistryCatalog.test.js b/server/services/ollamaRegistryCatalog.test.jsindex 390702dfa5..12445dd664 100644--- a/server/services/ollamaRegistryCatalog.test.js+++ b/server/services/ollamaRegistryCatalog.test.js@@ -128,6 +128,21 @@ describe('fetchOllamaRegistryVariants', () => {expect(variants.map((v) => v.installId)).toEqual(['mistral:7b-instruct-q4_K_M'])})+ it('keeps every quant at the target size, including high-fidelity builds, when a model publishes many', async () => {+ // 14 distinct quants at 7b — more than the old cap of 12. Listed low-to-high so a+ // tag-order slice would drop the high-fidelity ones; they must all survive.+ const quants = ['q2_K', 'q3_K_S', 'q3_K_M', 'q3_K_L', 'q4_0', 'q4_K_S', 'q4_K_M', 'q5_K_S', 'q5_K_M', 'q6_K', 'q8_0', 'f16', 'bf16', 'fp16']+ const tags = quants.map((q) => `7b-instruct-${q}`)+ const sizes = Object.fromEntries(tags.map((t, i) => [t, (i + 2) * 1_000_000_000]))+ fetch.mockImplementation(registry(tags, sizes))++ const variants = await fetchOllamaRegistryVariants('bigquant', { paramsHint: '7B' })+ const got = variants.map((v) => v.quant)+ expect(got).toHaveLength(14)+ // The high-fidelity builds a big-memory machine wants are present (not truncated away).+ expect(got).toEqual(expect.arrayContaining(['Q8_0', 'Q6_K', 'FP16', 'BF16', 'F16', 'Q2_K']))+ })+it('returns [] for an hf.co id (owned by the HF path)', async () => {const variants = await fetchOllamaRegistryVariants('hf.co/unsloth/Foo-GGUF:Q4_K_M', { paramsHint: '7B' })expect(variants).toEqual([])