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 fail a settled scene when downstream advance throws

[._.]/ Adam Eivy4183c5c0455e
diff --git a/server/services/creativeDirector/sceneEvaluator.js b/server/services/creativeDirector/sceneEvaluator.js
index 0aad530667..3050318d4c 100644
--- a/server/services/creativeDirector/sceneEvaluator.js
+++ b/server/services/creativeDirector/sceneEvaluator.js
@@ -265,7 +265,18 @@ export async function applySceneVerdict(project, scene, verdict, llm = null, run
: recordRun(project.id, { kind: 'evaluate', sceneId: scene.sceneId || null, ...runPatch })
).catch((err) => console.log(`⚠️ CD vision run record failed: ${err.message}`));
- const advanceAfterSceneSettled = await loadAdvance();
+ // Advancing to the next scene / stitch is a downstream orchestration step —
+ // fire-and-forget and self-healing (idempotent, re-triggered on the next
+ // Start/Resume/completion), exactly how the PATCH route calls it. Its failure
+ // must NOT propagate out of applySceneVerdict: dispatchSceneEvaluation's catch
+ // would otherwise overwrite the scene we just correctly settled
+ // (accepted/pending) with 'failed' for a purely downstream error (e.g. an
+ // ffmpeg stitch failure on the final accepted scene).
+ const advance = async () => {
+ const advanceAfterSceneSettled = await loadAdvance();
+ return advanceAfterSceneSettled(project.id).catch((err) =>
+ console.log(`⚠️ CD advance after scene ${scene.sceneId} settled failed: ${err.message}`));
+ };
if (verdict.accepted) {
await updateScene(project.id, scene.sceneId, { status: 'accepted', evaluation });
@@ -279,7 +290,7 @@ export async function applySceneVerdict(project, scene, verdict, llm = null, run
});
}
console.log(`✅ CD scene ${scene.sceneId} accepted by vision (${llm?.provider || 'local'}/${llm?.model || '?'})`);
- return advanceAfterSceneSettled(project.id);
+ return advance();
}
if (retryCount < CD_MAX_SCENE_RETRIES) {
@@ -288,12 +299,12 @@ export async function applySceneVerdict(project, scene, verdict, llm = null, run
if (verdict.imageStrength !== undefined) patch.imageStrength = verdict.imageStrength;
await updateScene(project.id, scene.sceneId, patch);
console.log(`🔁 CD scene ${scene.sceneId} rejected by vision — retry ${patch.retryCount}/${CD_MAX_SCENE_RETRIES}`);
- return advanceAfterSceneSettled(project.id);
+ return advance();
}
await updateScene(project.id, scene.sceneId, { status: 'failed', evaluation });
console.log(`⛔ CD scene ${scene.sceneId} failed by vision — retries exhausted`);
- return advanceAfterSceneSettled(project.id);
+ return advance();
}
/**
diff --git a/server/services/creativeDirector/sceneEvaluator.test.js b/server/services/creativeDirector/sceneEvaluator.test.js
index 153848606f..435a0ccb3c 100644
--- a/server/services/creativeDirector/sceneEvaluator.test.js
+++ b/server/services/creativeDirector/sceneEvaluator.test.js
@@ -279,6 +279,19 @@ describe('dispatchSceneEvaluation', () => {
expect(mocks.updateRun).toHaveBeenCalledWith('p1', running[1].runId, expect.objectContaining({ status: 'completed' }));
});
+ it('does NOT overwrite an accepted scene with failed when downstream advance throws', async () => {
+ mocks.listVisionModels.mockResolvedValue([{ providerId: 'ollama', backend: 'ollama', id: 'qwen2.5-vl', vision: true }]);
+ mocks.getProviderById.mockImplementation(async (id) => (id === 'ollama' ? OLLAMA : null));
+ mocks.runPromptThroughProvider.mockResolvedValue({ text: '{"accepted": true}', model: 'qwen2.5-vl', provider: OLLAMA });
+ // The next-scene/stitch step fails (e.g. ffmpeg) — must not corrupt the settled scene.
+ mocks.advanceAfterSceneSettled.mockRejectedValue(new Error('ffmpeg stitch failed'));
+ await expect(dispatchSceneEvaluation(project, scene)).resolves.not.toThrow();
+ expect(mocks.updateScene).toHaveBeenCalledWith('p1', 's1', expect.objectContaining({ status: 'accepted' }));
+ // The dispatch catch must NOT have fired to mark the scene failed.
+ const failedCall = mocks.updateScene.mock.calls.find((c) => c[2]?.status === 'failed');
+ expect(failedCall).toBeUndefined();
+ });
+
it('marks the running run failed when the vision call throws, then falls back to the agent', async () => {
mocks.listVisionModels.mockResolvedValue([{ providerId: 'ollama', backend: 'ollama', id: 'qwen2.5-vl', vision: true }]);
mocks.getProviderById.mockImplementation(async (id) => (id === 'ollama' ? OLLAMA : null));