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 misclassify base_model fine-tunes as LoRAs; reject dup across active lists

[._.]/ Adam Eivy12c7055ef420
diff --git a/server/lib/huggingfaceModel.js b/server/lib/huggingfaceModel.js
index 37ddcf6488..d00af6d517 100644
--- a/server/lib/huggingfaceModel.js
+++ b/server/lib/huggingfaceModel.js
@@ -151,21 +151,22 @@ export const inspectModelFiles = (model) => {
};
};
-// A repo is a LoRA ADAPTER (not a base model) when its card declares a
-// `base_model` it adapts, or its id/tags carry the lora marker. The base-model
-// installer must refuse these — a LoRA has the video LoRA installer
-// (/api/loras/install/huggingface) and would otherwise register as a bogus base
-// entry the render path can't load. `peft`/`adapter` library tags are the
-// diffusers signal for an adapter package.
+// A repo is a LoRA ADAPTER (not a base model) when its id/tags carry a LoRA
+// marker or it's a PEFT/adapter package. The base-model installer must refuse
+// these — a LoRA has the video LoRA installer (/api/loras/install/huggingface)
+// and would otherwise register as a bogus base entry the render path can't load.
+//
+// Deliberately does NOT key on `cardData.base_model` alone: full fine-tunes and
+// derived base models legitimately set `base_model` on their card while shipping
+// complete weights, so treating that as an adapter signal would wrongly refuse
+// valid base models. Only adapter-specific signals count — the `base_model`
+// field is used to distinguish an adapter ONLY when a LoRA/PEFT marker is also
+// present (handled by the markers below), never on its own.
const looksLikeLora = ({ repo, model }) => {
const blob = `${String(repo || '').toLowerCase()} ${(Array.isArray(model?.tags) ? model.tags : []).join(' ').toLowerCase()}`;
if (/\blora\b|\blycoris\b|\blocon\b|\bdora\b/.test(blob)) return true;
const lib = typeof model?.library_name === 'string' ? model.library_name.toLowerCase() : '';
- if (lib === 'peft') return true;
- // A base_model reference in the card means "this adapts that model" → adapter.
- const bm = model?.cardData?.base_model;
- if (typeof bm === 'string' && bm.trim()) return true;
- if (Array.isArray(bm) && bm.some((b) => typeof b === 'string' && b.trim())) return true;
+ if (lib === 'peft' || lib === 'adapter-transformers') return true;
return false;
};
diff --git a/server/lib/huggingfaceModel.test.js b/server/lib/huggingfaceModel.test.js
index eda327d91a..06e11cdf02 100644
--- a/server/lib/huggingfaceModel.test.js
+++ b/server/lib/huggingfaceModel.test.js
@@ -84,6 +84,17 @@ describe('classifyHfMediaModel — strict refusal', () => {
})).toThrow(/LoRA adapter/);
});
+ it('does NOT treat a full base model as a LoRA just because its card sets base_model', () => {
+ // Full fine-tunes / derived base models legitimately declare base_model but
+ // ship complete weights — they must remain addable (no lora/peft marker).
+ expect(classifyHfMediaModel({
+ repo: 'someone/qwen-image-finetune',
+ model: hf({ files: ['model.safetensors'], base: 'Qwen/Qwen-Image', pipeline: 'text-to-image' }),
+ kind: 'image',
+ runner: 'qwen',
+ })).toMatchObject({ kind: 'image', runner: 'qwen' });
+ });
+
it('refuses a quantized FLUX.2 repo (needs sibling tokenizer/base repos)', () => {
expect(() => classifyHfMediaModel({
repo: 'Disty0/FLUX.2-klein-9B-SDNQ-4bit-dynamic',
diff --git a/server/lib/mediaModels.js b/server/lib/mediaModels.js
index 53041ae707..5327654d74 100644
--- a/server/lib/mediaModels.js
+++ b/server/lib/mediaModels.js
@@ -767,18 +767,20 @@ export const addUserModelEntry = (entry, { kind }) => {
}
const reg = loadMediaModels();
const listKey = kind === 'video' ? (IS_WIN ? 'windows' : 'macos') : 'image';
- // Conflict-check only the TARGET list, not every list. A shared
- // media-models.json used across a macOS + Windows peer stores a video model
- // per-platform; the same repo must remain addable on the other platform's
- // list even though it already exists on the first — a global scan would
- // wrongly 409 and leave no self-service way to enable it there.
- const current = (listKey === 'image' ? reg.image : reg.video?.[listKey]) || [];
- if (current.some((m) => m?.id === entry.id)) {
+ // Conflict-check against the ACTIVE-on-this-install lists — the current
+ // platform's video list + the image list — via findModelLocation (which
+ // scopes to exactly those). This rejects a collision between the current
+ // video list and the image list (both mutable through the same :id-only
+ // PATCH/DELETE, so a dup would make one row unaddressable), while still
+ // allowing the same custom video id to be added on the OTHER platform's list
+ // of a shared media-models.json (that list isn't scanned, so no false 409).
+ if (findModelLocation(reg, entry.id)) {
throw new ServerError(
- `A model with id "${entry.id}" is already in the ${kind} registry for this platform (repo already added?). Remove it first to re-add.`,
+ `A model with id "${entry.id}" is already in this install's registry (repo already added?). Remove it first to re-add.`,
{ status: 409, code: 'MODEL_ALREADY_EXISTS' },
);
}
+ const current = (listKey === 'image' ? reg.image : reg.video?.[listKey]) || [];
persistRegistry(withList(reg, listKey, [...current, entry]));
console.log(`📝 Added user media model: ${entry.id} (${kind}) → ${entry.repo || '?'}`);
return entry;