Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(models): Dedup fragt nach der Datei, nicht nach dem Modell

purple95735d86b7b9
diff --git a/src/lib/__tests__/lu-engine-groups.test.ts b/src/lib/__tests__/lu-engine-groups.test.ts
index ed5e9623..a32c27c5 100644
--- a/src/lib/__tests__/lu-engine-groups.test.ts
+++ b/src/lib/__tests__/lu-engine-groups.test.ts
@@ -11,7 +11,7 @@
* Run: npx vitest run src/lib/__tests__/lu-engine-groups.test.ts
*/
import { describe, it, expect } from 'vitest'
-import { splitLuEngineRows, groupInstalledByProvider, LU_ENGINE_GROUP } from '../lu-engine-rows'
+import { splitLuEngineRows, groupInstalledByProvider, dropDuplicateLuEngineRows, LU_ENGINE_GROUP } from '../lu-engine-rows'
const lu = (n: string) => ({ name: `openai::${n}`, model: n, provider: 'openai', providerName: 'LU Engine' })
const luOld = (n: string) => ({ name: `openai::${n}`, model: n, provider: 'openai', providerName: 'Built-in Engine' })
@@ -67,3 +67,58 @@ describe('groupInstalledByProvider', () => {
expect(groups.map((g) => g.label)).toEqual(['Other'])
})
})
+
+// ── A14 review, point 1: one file, not one model ─────────────────────────────
+
+describe('de-duplication asks about the FILE, never about the model', () => {
+ const luFile = (stem: string) => ({ name: `openai::${stem}`, model: stem, path: `/u/models/${stem}.gguf`, provider: 'openai', providerName: 'LU Engine' })
+ const lmsHas = (id: string) => [{ name: `openai::${id}`, model: id, provider: 'openai', providerName: 'LM Studio' }]
+
+ it('drops the row when LM Studio holds the very same quant', () => {
+ const kept = dropDuplicateLuEngineRows([luFile('Qwen2.5-0.5B-Instruct-Q8_0')], lmsHas('qwen2.5-0.5b-instruct@q8_0'))
+ expect(kept).toEqual([])
+ })
+
+ it('drops the row for an identical filename, whatever the quant is called', () => {
+ const kept = dropDuplicateLuEngineRows([luFile('Qwen2.5-0.5B-Instruct-Q8_0')], lmsHas('Qwen2.5-0.5B-Instruct-Q8_0.gguf'))
+ expect(kept).toEqual([])
+ })
+
+ // THE REVIEW FINDING. The Discover badge's matcher answers a catalogue
+ // question: a name with no quant means "any quant counts as installed". Used
+ // for de-duplication it made a quant-less GGUF in the LU Engine folder
+ // disappear behind whichever quant LM Studio happened to hold, and those are
+ // two different files with two different answer qualities.
+ it('keeps a quant-less GGUF beside any LM Studio quant of the same model', () => {
+ const row = luFile('Qwen2.5-0.5B-Instruct')
+ expect(dropDuplicateLuEngineRows([row], lmsHas('qwen2.5-0.5b-instruct@q4_k_m'))).toEqual([row])
+ expect(dropDuplicateLuEngineRows([row], lmsHas('qwen2.5-0.5b-instruct@q8_0'))).toEqual([row])
+ // And the mirror image: LM Studio holding a quant-less collapsed id does
+ // not swallow a named quant on our side either.
+ const q8 = luFile('Qwen2.5-0.5B-Instruct-Q8_0')
+ expect(dropDuplicateLuEngineRows([q8], lmsHas('qwen/qwen2.5-0.5b-instruct'))).toEqual([q8])
+ })
+
+ // NEGATIVE CONTROL: two quants of one model are two files.
+ it('keeps both when the quants differ', () => {
+ const row = luFile('Qwen2.5-0.5B-Instruct-Q8_0')
+ expect(dropDuplicateLuEngineRows([row], lmsHas('qwen2.5-0.5b-instruct@q4_k_m'))).toEqual([row])
+ })
+
+ // NEGATIVE CONTROL: Ollama is not LM Studio. Its blob store holds a second
+ // copy, so hiding the GGUF there would hide a real download.
+ it('never lets an Ollama row hide a GGUF', () => {
+ const row = luFile('Qwen2.5-0.5B-Instruct-Q8_0')
+ const ollamaRows = [{ name: 'qwen2.5:0.5b-instruct-q8_0', model: 'qwen2.5:0.5b-instruct-q8_0', provider: 'ollama', providerName: 'Ollama' }]
+ expect(dropDuplicateLuEngineRows([row], ollamaRows)).toEqual([row])
+ })
+
+ // NEGATIVE CONTROL: genuinely different models must never collapse, however
+ // similar the names look.
+ it('keeps two different models apart', () => {
+ const row = luFile('Qwen2.5-0.5B-Instruct-Q8_0')
+ expect(dropDuplicateLuEngineRows([row], lmsHas('gemma-3-4b-it@q8_0'))).toEqual([row])
+ // An abliterated finetune is a different model, same quant or not.
+ expect(dropDuplicateLuEngineRows([row], lmsHas('qwen2.5-0.5b-instruct-abliterated@q8_0'))).toEqual([row])
+ })
+})
diff --git a/src/lib/lmstudio-match.ts b/src/lib/lmstudio-match.ts
index 07464e64..0bb13919 100644
--- a/src/lib/lmstudio-match.ts
+++ b/src/lib/lmstudio-match.ts
@@ -66,7 +66,7 @@ export function modelIdentity(s: string): string {
}
/** An LM Studio entry in the installed-model list. */
-function isLmStudioEntry(m: InstalledModelLike): boolean {
+export function isLmStudioEntry(m: InstalledModelLike): boolean {
if (m.provider !== 'openai') return false
const pname = (m.providerName || '').toLowerCase()
return pname.includes('lm studio') || pname.includes('lmstudio')
@@ -83,6 +83,39 @@ export function isBuiltinEngineEntry(m: InstalledModelLike | null | undefined):
return isLuEngineName(m.providerName)
}
+/**
+ * Are these two ids the same FILE, not merely the same model.
+ *
+ * A14 review: `matchesLmStudioInstalled` is the wrong question for
+ * de-duplication and the difference is a whole quant. That matcher serves the
+ * Discover badge, where a catalogue row without a quant in its filename means
+ * "any quant of this counts as installed", so rule (2) returns a match for a
+ * quant-less name against ANY quant on disk. Reused for de-duplication it
+ * reads as: `Qwen2.5-0.5B-Instruct.gguf` in the LU Engine folder is the same
+ * thing as `qwen2.5-0.5b-instruct@q4_k_m` in LM Studio. It is not. It is a
+ * different file, a different download and a different answer quality, and
+ * hiding it would hide a model the user has.
+ *
+ * So this one never guesses across a missing quant:
+ * (a) the same normalised basename, which already carries the quant, or
+ * (b) the same model identity AND both sides naming the same quant.
+ * A name with no quant matches only under (a).
+ */
+export function isSameGgufFile(a: string, b: string): boolean {
+ const baseA = normalBase(a)
+ const baseB = normalBase(b)
+ if (!baseA || !baseB) return false
+ if (baseA === baseB) return true
+ const idA = modelIdentity(a)
+ const idB = modelIdentity(b)
+ // The length floor is the one `findInstalled` uses: a two-character identity
+ // collides with half the catalogue.
+ if (!idA || idA.length < 5 || idA !== idB) return false
+ const quantA = extractQuant(a)
+ const quantB = extractQuant(b)
+ return !!quantA && !!quantB && quantA === quantB
+}
+
/**
* True when any LM-Studio-installed model corresponds to the given GGUF
* filename. Order: exact basename / `publisher/`-suffix (already quant-precise),
diff --git a/src/lib/lu-engine-rows.ts b/src/lib/lu-engine-rows.ts
index ead118c1..881f85ef 100644
--- a/src/lib/lu-engine-rows.ts
+++ b/src/lib/lu-engine-rows.ts
@@ -20,7 +20,7 @@
* of blending into the list.
*/
-import { matchesLmStudioInstalled, isBuiltinEngineEntry, type InstalledModelLike } from './lmstudio-match'
+import { isSameGgufFile, isLmStudioEntry, isBuiltinEngineEntry, type InstalledModelLike } from './lmstudio-match'
/** The heading LU Engine rows sit under, in Installed and in the picker. */
export const LU_ENGINE_GROUP = 'LU Engine'
@@ -38,21 +38,44 @@ export const LU_ENGINE_GROUP = 'LU Engine'
* under its own names, so an Ollama row and a GGUF on disk are two copies of
* the model and not two views of one file, and collapsing them would hide a
* real second copy.
+ *
+ * A14 review: this asks `isSameGgufFile`, not the Discover badge's matcher.
+ * That one answers a catalogue question and treats a name without a quant as
+ * "any quant will do", so a quant-less GGUF in the LU Engine folder would have
+ * been swallowed by whatever quant LM Studio happened to hold. The two files
+ * differ; only one of them is on the user's disk twice. No quant on either
+ * side means no match here, so the row stays.
*/
export function dropDuplicateLuEngineRows<T extends InstalledModelLike>(
bundled: T[],
alreadyListed: InstalledModelLike[],
): T[] {
- if (bundled.length === 0 || alreadyListed.length === 0) return bundled
- return bundled.filter((row) => {
- const stem = row.model || row.name || ''
- if (!stem) return true
- // The matcher speaks GGUF filenames and the bundled row carries the file
- // stem, so the extension goes back on. It requires the quant to agree
- // whenever the filename names one, which is what keeps two quants of the
- // same model from collapsing into each other.
- return !matchesLmStudioInstalled(`${stem}.gguf`, alreadyListed)
- })
+ if (bundled.length === 0) return bundled
+ const lmStudio = alreadyListed.filter(isLmStudioEntry)
+ if (lmStudio.length === 0) return bundled
+ return bundled.filter((row) => !lmStudio.some((other) => sameFile(row, other)))
+}
+
+/** Every id a row can be recognised by. LM Studio reports its own key, our own
+ * rows carry the file stem, and both may carry a full path. */
+function idsOf(m: InstalledModelLike): string[] {
+ const raw = m as InstalledModelLike & { path?: unknown }
+ return [m.model, m.name, m.lmsKey, typeof raw.path === 'string' ? raw.path : undefined]
+ .filter((v): v is string => typeof v === 'string' && v.length > 0)
+}
+
+/** Two rows pointing at one file on disk. */
+function sameFile(a: InstalledModelLike, b: InstalledModelLike): boolean {
+ const idsA = idsOf(a)
+ const idsB = idsOf(b)
+ // The same path is the same file, whatever the two sides call the model.
+ for (const x of idsA) {
+ for (const y of idsB) {
+ if (x === y) return true
+ if (isSameGgufFile(x, y)) return true
+ }
+ }
+ return false
}
/**