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): catch diffusers LoRA filename; reject duplicate repos

[._.]/ Adam Eivy8441b7c0dc5b
diff --git a/server/lib/huggingfaceModel.js b/server/lib/huggingfaceModel.js
index 5dbc413cc8..0e6c35681b 100644
--- a/server/lib/huggingfaceModel.js
+++ b/server/lib/huggingfaceModel.js
@@ -173,7 +173,14 @@ const looksLikeLora = ({ repo, model }) => {
// (which typically also sets cardData.base_model) would auto-detect as the base
// family and register as a base model whose weights from_pretrained() can't load.
const files = modelSiblingFilenames(model).map((f) => f.toLowerCase());
- if (files.some((f) => /(^|\/)adapter_config\.json$/.test(f) || /(^|\/)adapter_model\.(safetensors|bin)$/.test(f))) {
+ if (files.some((f) =>
+ /(^|\/)adapter_config\.json$/.test(f)
+ || /(^|\/)adapter_model\.(safetensors|bin)$/.test(f)
+ // pytorch_lora_weights.safetensors is the canonical diffusers LoRA filename
+ // (same one pickHfLoraFile prefers) — a repo shipping it is a LoRA even
+ // without a lora tag/peft library.
+ || /(^|\/)pytorch_lora_weights\.safetensors$/.test(f)
+ )) {
return true;
}
return false;
diff --git a/server/lib/huggingfaceModel.test.js b/server/lib/huggingfaceModel.test.js
index 1dba94afdf..10f029ec33 100644
--- a/server/lib/huggingfaceModel.test.js
+++ b/server/lib/huggingfaceModel.test.js
@@ -84,6 +84,13 @@ describe('classifyHfMediaModel — strict refusal', () => {
})).toThrow(/LoRA adapter/);
});
+ it('refuses a diffusers LoRA repo by its pytorch_lora_weights.safetensors file (no lora tag)', () => {
+ expect(() => classifyHfMediaModel({
+ repo: 'someone/qwen-style',
+ model: hf({ files: ['pytorch_lora_weights.safetensors'], base: 'Qwen/Qwen-Image', pipeline: 'text-to-image' }),
+ })).toThrow(/LoRA adapter/);
+ });
+
it('refuses a PEFT adapter repo detected by its sibling files (no lora tag)', () => {
// adapter_config.json + adapter_model.safetensors is the standard PEFT
// layout; the repo advertises no lora tag but is still an adapter.
diff --git a/server/lib/mediaModels.js b/server/lib/mediaModels.js
index 5327654d74..024bdfce9d 100644
--- a/server/lib/mediaModels.js
+++ b/server/lib/mediaModels.js
@@ -781,6 +781,18 @@ export const addUserModelEntry = (entry, { kind }) => {
);
}
const current = (listKey === 'image' ? reg.image : reg.video?.[listKey]) || [];
+ // Also reject a duplicate REPO in the target list — the same weights under a
+ // different id (e.g. the UI placeholder `notapalindrome/ltx23-mlx-av-q4`,
+ // already shipped as the built-in `ltx23_distilled_q4`) would otherwise add a
+ // second pickable row for identical weights. Only meaningful when the entry
+ // carries a repo.
+ if (typeof entry.repo === 'string' && entry.repo.trim()
+ && current.some((m) => typeof m?.repo === 'string' && m.repo === entry.repo)) {
+ throw new ServerError(
+ `The HuggingFace repo "${entry.repo}" is already in this install's ${kind} registry (possibly as a built-in). It's already available in the model picker.`,
+ { status: 409, code: 'MODEL_REPO_ALREADY_EXISTS' },
+ );
+ }
persistRegistry(withList(reg, listKey, [...current, entry]));
console.log(`📝 Added user media model: ${entry.id} (${kind}) → ${entry.repo || '?'}`);
return entry;
diff --git a/server/lib/mediaModels.test.js b/server/lib/mediaModels.test.js
index bc94658a8a..2b4ee7d878 100644
--- a/server/lib/mediaModels.test.js
+++ b/server/lib/mediaModels.test.js
@@ -790,6 +790,15 @@ describe('user model entry mutators (#2124)', () => {
expect(() => addUserModelEntry(videoEntry, { kind: 'video' })).toThrow(/already/i);
});
+ it('rejects a duplicate repo even under a different id', async () => {
+ const { addUserModelEntry } = await import('./mediaModels.js');
+ addUserModelEntry(imageEntry, { kind: 'image' }); // repo: test/image
+ expect(() => addUserModelEntry(
+ { ...imageEntry, id: 'hf-different-id' },
+ { kind: 'image' },
+ )).toThrow(/already in this install's image registry/i);
+ });
+
it('conflict-checks only the target platform list, not every list', async () => {
// A video id present ONLY on the OTHER platform's list must remain addable
// on the current platform (shared media-models.json across macOS+Windows).