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): explicit non-vision metadata wins; settle all import writes before cleanup

[._.]/ Adam Eivy869aa73d6269
diff --git a/server/lib/localModelHeuristics.js b/server/lib/localModelHeuristics.js
index e2e37bef7c..8ff64eae21 100644
--- a/server/lib/localModelHeuristics.js
+++ b/server/lib/localModelHeuristics.js
@@ -69,10 +69,18 @@ export function isVisionModel(model) {
if (!model) return false;
if (typeof model === 'string') return VISION_RE.test(model);
if (typeof model !== 'object') return false;
- // Explicit metadata wins over the name heuristic.
- if (model.type && String(model.type).toLowerCase() === 'vlm') return true;
+ // Explicit metadata is authoritative — in BOTH directions. LM Studio tags
+ // every model with a `type` (`vlm` / `llm` / `embeddings`), so a positive
+ // `vlm` (or a `vision` capability) confirms vision, and any OTHER explicit
+ // type means text-only even when the id happens to match the regex (e.g.
+ // `gemma3:1b` is `type:'llm'` — a text-only Gemma 3). Only fall through to
+ // the id heuristic when the backend gave us no capability metadata at all
+ // (Ollama's /api/tags), so a name-only guess never overrides a known type.
+ const type = model.type ? String(model.type).toLowerCase() : null;
+ if (type === 'vlm') return true;
if (Array.isArray(model.capabilities)
&& model.capabilities.some((c) => String(c).toLowerCase() === 'vision')) return true;
+ if (type) return false; // explicit non-vision type — don't regex-guess past it
const id = model.id || model.name || '';
return typeof id === 'string' && VISION_RE.test(id);
}
diff --git a/server/lib/localModelHeuristics.test.js b/server/lib/localModelHeuristics.test.js
index 0db0ad476b..3cc0f949dc 100644
--- a/server/lib/localModelHeuristics.test.js
+++ b/server/lib/localModelHeuristics.test.js
@@ -73,12 +73,20 @@ describe('localModelHeuristics', () => {
}
});
- it('prefers explicit backend capability metadata over the id heuristic', () => {
+ it('treats explicit backend metadata as authoritative in both directions', () => {
// LM Studio tags vision models type: 'vlm' even when the id is opaque.
expect(isVisionModel({ id: 'some-opaque-id', type: 'vlm' })).toBe(true);
expect(isVisionModel({ id: 'x', capabilities: ['vision'] })).toBe(true);
// A text model card with no vision markers stays false.
expect(isVisionModel({ id: 'llama3.1:8b', type: 'llm' })).toBe(false);
+ // An explicit non-vision type must NOT be overridden by an id that the
+ // regex would otherwise match — `gemma3:1b` is a text-only Gemma 3
+ // (type:'llm'), not a vision model, even though `gemma-?3` matches.
+ expect(isVisionModel({ id: 'gemma3:1b', type: 'llm' })).toBe(false);
+ expect(isVisionModel({ id: 'llava-phi3', type: 'embeddings' })).toBe(false);
+ // …but a regex-matching id with NO type metadata (Ollama /api/tags) still
+ // falls through to the heuristic.
+ expect(isVisionModel({ id: 'gemma3:4b' })).toBe(true);
});
it('handles non-values', () => {
diff --git a/server/services/loraDatasets.js b/server/services/loraDatasets.js
index 9d69105586..1f1eb82598 100644
--- a/server/services/loraDatasets.js
+++ b/server/services/loraDatasets.js
@@ -253,11 +253,12 @@ export async function importGalleryImages(id, { filenames = [] } = {}) {
await ensureDir(datasetImagesDir(id));
// sharp transcodes are independent CPU/disk work — run them concurrently
// (single-user trust model; the per-id write queue still serializes the one
- // dataset mutation below). A single failure rejects the whole import; track
- // every file actually written so a partial failure doesn't strand orphaned
- // PNGs (written but never recorded in the dataset).
+ // dataset mutation below). Use allSettled, NOT all: a rejection from all()
+ // returns before sibling toFile() calls finish, so files written *after* the
+ // first failure would escape cleanup and orphan. allSettled waits for every
+ // transcode to land before we either commit them all or unlink them all.
const written = [];
- const entries = await Promise.all(filenames.map(async (filename) => {
+ const results = await Promise.allSettled(filenames.map(async (filename) => {
// Reuse the gallery's own path-traversal/extension guard.
assertGalleryFilename(filename);
const sourcePath = join(PATHS.images, basename(filename));
@@ -276,10 +277,15 @@ export async function importGalleryImages(id, { filenames = [] } = {}) {
);
});
return makeImageEntry({ imageId, file, source: 'gallery', info });
- })).catch(async (err) => {
+ }));
+ const failure = results.find((r) => r.status === 'rejected');
+ if (failure) {
+ // All transcodes have settled now, so `written` is complete — no late write
+ // can re-orphan a file after this cleanup.
await Promise.all(written.map((p) => unlink(p).catch(() => {})));
- throw err;
- });
+ throw failure.reason;
+ }
+ const entries = results.map((r) => r.value);
await updateDataset(id, (current) => ({ ...current, images: [...current.images, ...entries] }));
console.log(`🖼️ Dataset ${id} ← imported ${entries.length} gallery image(s)`);
return entries;