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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): lock scene evaluation from dispatch entry to cover slow provider discovery
[._.]/ Adam Eivy8c69c1e2f265
diff --git a/server/services/creativeDirector/sceneEvaluator.js b/server/services/creativeDirector/sceneEvaluator.jsindex 9a9d2febd8..50fd1daedd 100644--- a/server/services/creativeDirector/sceneEvaluator.js+++ b/server/services/creativeDirector/sceneEvaluator.js@@ -307,6 +307,15 @@ export async function applySceneVerdict(project, scene, verdict, llm = null, runreturn advance();}+// In-process re-entrancy guard keyed on project:sceneId, acquired SYNCHRONOUSLY+// at the top of dispatch — before any await — so it closes the whole window,+// including slow (cache-cold) provider discovery, not just the vision call. Both+// dispatch call sites (sceneRunner render-completion + completionHook orphan+// resume) go through here, so a concurrent advanceAfterSceneSettled can't start+// a second evaluation of the same render. The persisted running-run marker below+// is the cross-path/observability backstop; this Set is the primary guard.+const inflightSceneEval = new Set();+/*** Single entry point the orchestrator calls to settle a rendered scene. Tries* the local-vision path; on no-provider or ANY failure falls back to the@@ -315,6 +324,20 @@ export async function applySceneVerdict(project, scene, verdict, llm = null, run* process.*/export async function dispatchSceneEvaluation(project, scene) {+ const lockKey = `${project.id}:${scene.sceneId}`;+ if (inflightSceneEval.has(lockKey)) {+ console.log(`⏳ CD scene ${scene.sceneId} evaluation already in flight — skipping duplicate dispatch`);+ return null;+ }+ inflightSceneEval.add(lockKey);+ try {+ return await runSceneEvaluation(project, scene);+ } finally {+ inflightSceneEval.delete(lockKey);+ }+}++async function runSceneEvaluation(project, scene) {let result;try {result = await evaluateSceneWithVision(project, scene);diff --git a/server/services/creativeDirector/sceneEvaluator.test.js b/server/services/creativeDirector/sceneEvaluator.test.jsindex 435a0ccb3c..02b8f177d3 100644--- a/server/services/creativeDirector/sceneEvaluator.test.js+++ b/server/services/creativeDirector/sceneEvaluator.test.js@@ -302,6 +302,24 @@ describe('dispatchSceneEvaluation', () => {expect(mocks.enqueueEvaluateTask).toHaveBeenCalledWith(project, scene);});+ it('skips a concurrent duplicate dispatch for the same scene while one is in flight', async () => {+ mocks.listVisionModels.mockResolvedValue([{ providerId: 'ollama', backend: 'ollama', id: 'qwen2.5-vl', vision: true }]);+ mocks.getProviderById.mockImplementation(async (id) => (id === 'ollama' ? OLLAMA : null));+ // Hold the vision call open so the first dispatch keeps its lock.+ let release;+ const pending = new Promise((res) => { release = res; });+ mocks.runPromptThroughProvider.mockReturnValue(pending);++ const first = dispatchSceneEvaluation(project, scene); // acquires the lock synchronously+ const second = await dispatchSceneEvaluation(project, scene); // same scene → skipped+ expect(second).toBeNull();++ release({ text: '{"accepted": true}', model: 'qwen2.5-vl', provider: OLLAMA });+ await first;+ // Exactly one evaluation ran despite two dispatches.+ expect(mocks.runPromptThroughProvider).toHaveBeenCalledTimes(1);+ });+it('falls back to the agent when the vision path is unavailable', async () => {mocks.listVisionModels.mockResolvedValue([]);await dispatchSceneEvaluation(project, scene);