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): shape family-scoped cards from the version that targets the family

[._.]/ Adam Eivy03779e832d5d
diff --git a/server/services/civitaiSuggestions.js b/server/services/civitaiSuggestions.js
index 8d12822976..c11dbf3738 100644
--- a/server/services/civitaiSuggestions.js
+++ b/server/services/civitaiSuggestions.js
@@ -88,6 +88,26 @@ const buildCard = (model) => {
};
};
+// Shape a model for a family-scoped list (top-N or keyword search) so the card
+// reflects the version that actually targets `runnerFamily` — NOT
+// modelVersions[0]. Civitai's `baseModels` filter matches a model if ANY of its
+// versions is in the family, but the newest version (what buildCard uses) may
+// target a different base model. Left unhandled, the card's badge, versionId,
+// and installUrl point at that wrong version and a "quick install" pulls an
+// incompatible LoRA. Reorder the first installable family-matching version to
+// the front so every field buildCard derives comes from it; drop the model if
+// no installable version maps to the family.
+const buildFamilyCard = (model, runnerFamily) => {
+ const versions = Array.isArray(model?.modelVersions) ? model.modelVersions : [];
+ const match = versions.find((v) => {
+ if (baseModelToRunner(v?.baseModel) !== runnerFamily) return false;
+ const files = Array.isArray(v.files) ? v.files : [];
+ return files.some((f) => /\.safetensors$/i.test(f?.name || ''));
+ });
+ if (!match) return null;
+ return buildCard({ ...model, modelVersions: [match, ...versions.filter((v) => v !== match)] });
+};
+
// For a curated entry: walk every modelVersions[] entry (not just the
// primary) and build a per-runner-family install map. The UI renders one
// "Install for X" button per entry — clicking it installs the family-
@@ -175,7 +195,9 @@ const fetchSuggestionsFor = async (runnerFamily, { fetchImpl, force = false } =
apiKey,
fetchImpl,
});
- const cards = items.map(buildCard).filter(Boolean);
+ // buildFamilyCard (not buildCard) so a multi-base-model model's card reflects
+ // its family-matching version, not whatever version is newest overall.
+ const cards = items.map((m) => buildFamilyCard(m, runnerFamily)).filter(Boolean);
cache.set(runnerFamily, { fetchedAt: now(), items: cards });
return cards;
};
@@ -200,7 +222,9 @@ export const searchLorasInFamily = async ({ runnerFamily, query = '', cursor = n
return {
runnerFamily,
query: typeof query === 'string' ? query.trim() : '',
- items: items.map(buildCard).filter(Boolean),
+ // buildFamilyCard so a keyword hit on a multi-base-model model installs the
+ // version that targets THIS family, not its newest (possibly incompatible) one.
+ items: items.map((m) => buildFamilyCard(m, runnerFamily)).filter(Boolean),
nextCursor: nextCursor || null,
};
};
diff --git a/server/services/civitaiSuggestions.test.js b/server/services/civitaiSuggestions.test.js
index 5542ab9707..80bf8aa0ef 100644
--- a/server/services/civitaiSuggestions.test.js
+++ b/server/services/civitaiSuggestions.test.js
@@ -229,6 +229,53 @@ describe('getSuggestions', () => {
expect(out.items[0].modelId).toBe(7002);
});
+ it('searchLorasInFamily shapes the card from the family-matching version, not modelVersions[0]', async () => {
+ // A multi-base-model model whose NEWEST version is Flux.1 D but which also
+ // carries a Z-Image version (which is why it matched a z-image search).
+ const fetchImpl = async (url) => {
+ if (/api\/v1\/models\/\d+$/.test(url)) return mockJsonResponse(buildModel(1, 'C', 'Flux.1 D'));
+ return mockJsonResponse({
+ items: [{
+ id: 5000,
+ name: 'Multi-base style',
+ type: 'LORA',
+ creator: { username: 'someone' },
+ stats: { downloadCount: 10 },
+ modelVersions: [
+ { id: 900, baseModel: 'Flux.1 D', trainedWords: [], images: [], files: [{ name: 'flux.safetensors', primary: true, sizeKB: 100 }] },
+ { id: 800, baseModel: 'ZImageTurbo', trainedWords: [], images: [], files: [{ name: 'z.safetensors', primary: true, sizeKB: 90 }] },
+ ],
+ }],
+ });
+ };
+ const out = await svc.searchLorasInFamily({ runnerFamily: 'z-image', query: 'style', fetchImpl });
+ expect(out.items.length).toBe(1);
+ // Card must reflect the Z-Image version (800), not the newer Flux.1 D one (900).
+ expect(out.items[0].versionId).toBe(800);
+ expect(out.items[0].runnerFamily).toBe('z-image');
+ expect(out.items[0].installUrl).toMatch(/modelVersionId=800/);
+ });
+
+ it('searchLorasInFamily drops a model with no installable version for the family', async () => {
+ const fetchImpl = async (url) => {
+ if (/api\/v1\/models\/\d+$/.test(url)) return mockJsonResponse(buildModel(1, 'C', 'Flux.1 D'));
+ return mockJsonResponse({
+ items: [{
+ id: 5001,
+ name: 'Wrong family only',
+ type: 'LORA',
+ modelVersions: [
+ { id: 700, baseModel: 'Flux.1 D', files: [{ name: 'a.safetensors', primary: true, sizeKB: 50 }] },
+ ],
+ }],
+ });
+ };
+ // Civitai shouldn't return this for a z-image search, but if it does we must
+ // not surface a Flux card under the Z-Image header.
+ const out = await svc.searchLorasInFamily({ runnerFamily: 'z-image', query: 'x', fetchImpl });
+ expect(out.items.length).toBe(0);
+ });
+
it('searchLorasInFamily does not touch the cached suggestions (live, uncached)', async () => {
let searchCalls = 0;
const fetchImpl = async (url) => {