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): treat null verdict fields as absent + scan all local vision candidates

[._.]/ Adam Eivyb4f9c0126413
diff --git a/server/services/creativeDirector/sceneEvaluator.js b/server/services/creativeDirector/sceneEvaluator.js
index 0891d47e5a..33d8a3a7c0 100644
--- a/server/services/creativeDirector/sceneEvaluator.js
+++ b/server/services/creativeDirector/sceneEvaluator.js
@@ -51,17 +51,22 @@ const VISION_EVAL_MAX_TOKENS = 600;
// assignment (below) may still point at any configured API vision provider.
const LOCAL_VISION_BACKENDS = new Set(['ollama', 'lmstudio']);
-// Only `accepted` is load-bearing — everything else is advisory. Coerce loose
-// numbers/strings, and `.catch(undefined)` so an out-of-range or unparseable
-// optional field just drops out instead of rejecting the whole verdict (which
-// would needlessly fall the scene back to the Opus agent). A model that emits
-// `"score": 85` meaning 85% shouldn't nuke an otherwise-usable accept/reject.
+// Only `accepted` is load-bearing — everything else is advisory. Map an
+// explicit JSON `null` to `undefined` (absent) BEFORE coercion: `z.coerce`
+// would otherwise turn `null` into `"null"` / `0`, so a model emitting
+// `"refinedPrompt": null` would overwrite the scene prompt with the literal
+// string "null", and `"imageStrength": null` would force strength to 0 instead
+// of leaving it unchanged. Then `.catch(undefined)` drops an out-of-range or
+// unparseable value rather than rejecting the whole verdict (a model emitting
+// `"score": 85` meaning 85% shouldn't nuke an otherwise-usable accept/reject).
+const nullToUndefined = (v) => (v === null ? undefined : v);
+const optNumber = z.preprocess(nullToUndefined, z.coerce.number().min(0).max(1).optional().catch(undefined));
const verdictSchema = z.object({
accepted: z.boolean(),
- score: z.coerce.number().min(0).max(1).optional().catch(undefined),
- notes: z.coerce.string().max(2000).optional().catch(undefined),
- refinedPrompt: z.coerce.string().max(8000).optional().catch(undefined),
- imageStrength: z.coerce.number().min(0).max(1).optional().catch(undefined),
+ score: optNumber,
+ notes: z.preprocess(nullToUndefined, z.coerce.string().max(2000).optional().catch(undefined)),
+ refinedPrompt: z.preprocess(nullToUndefined, z.coerce.string().max(8000).optional().catch(undefined)),
+ imageStrength: optNumber,
});
/**
@@ -111,11 +116,15 @@ export async function resolveVisionEvalTarget() {
// to auto-resolution so a healthy local VLM is still preferred.
}
+ // Scan ALL local vision candidates, not just the first: the first entry may
+ // belong to a disabled/missing provider (e.g. Ollama off) while a later one
+ // (e.g. LM Studio) is usable. Stopping at the first would wrongly fall back
+ // to the Opus agent.
const visionModels = await listVisionModels().catch(() => []);
- const local = visionModels.find((m) => LOCAL_VISION_BACKENDS.has(m.backend));
- if (local) {
- const provider = await usableApiProvider(local.providerId);
- if (provider) return { provider, model: local.id };
+ for (const m of visionModels) {
+ if (!LOCAL_VISION_BACKENDS.has(m.backend)) continue;
+ const provider = await usableApiProvider(m.providerId);
+ if (provider) return { provider, model: m.id };
}
return null;
}
diff --git a/server/services/creativeDirector/sceneEvaluator.test.js b/server/services/creativeDirector/sceneEvaluator.test.js
index c0796056f4..a63d52aaa0 100644
--- a/server/services/creativeDirector/sceneEvaluator.test.js
+++ b/server/services/creativeDirector/sceneEvaluator.test.js
@@ -90,6 +90,15 @@ describe('parseVisionVerdict', () => {
expect(v.notes).toBe('great');
});
+ it('treats explicit JSON null optional fields as absent, not "null"/0', () => {
+ const v = parseVisionVerdict('{"accepted": false, "score": null, "notes": null, "refinedPrompt": null, "imageStrength": null}');
+ expect(v.accepted).toBe(false);
+ expect(v.score).toBeUndefined();
+ expect(v.notes).toBeUndefined();
+ expect(v.refinedPrompt).toBeUndefined();
+ expect(v.imageStrength).toBeUndefined();
+ });
+
it('throws when there is no JSON object', () => {
expect(() => parseVisionVerdict('the render looks fine to me')).toThrow();
});
@@ -130,6 +139,20 @@ describe('resolveVisionEvalTarget', () => {
expect(target).toEqual({ provider: OLLAMA, model: 'llama3.2-vision' });
});
+ it('skips a disabled/missing local provider and uses the next usable one', async () => {
+ mocks.listVisionModels.mockResolvedValue([
+ { providerId: 'ollama', backend: 'ollama', id: 'qwen2.5-vl', vision: true },
+ { providerId: 'lmstudio', backend: 'lmstudio', id: 'llava', vision: true },
+ ]);
+ mocks.getProviderById.mockImplementation(async (id) => {
+ if (id === 'ollama') return { id: 'ollama', type: 'api', enabled: false }; // disabled
+ if (id === 'lmstudio') return { id: 'lmstudio', type: 'api', enabled: true };
+ return null;
+ });
+ const target = await resolveVisionEvalTarget();
+ expect(target).toEqual({ provider: { id: 'lmstudio', type: 'api', enabled: true }, model: 'llava' });
+ });
+
it('returns null when no vision-capable API provider exists', async () => {
mocks.listVisionModels.mockResolvedValue([{ providerId: 'claude-code', backend: 'cli', id: 'opus', vision: true }]);
const target = await resolveVisionEvalTarget();