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 (claude): persist generateFirstPass independent of compose; skip continuation scenes

[._.]/ Adam Eivy159b7ba93727
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 4477fbabdd..4dc4e9ca24 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -17,7 +17,7 @@
## Creative Director
-- **[issue-1867] Auto-cast first-pass scene reference frames.** Extends the opt-in first-pass gen step from #1818 (catalog portraits) one stage later: once auto-compose writes a treatment, the director seeds a first reference frame per scene the same way it already seeds cast portraits — one image-gen job per scene, enqueued onto the durable media-job queue and filed onto `scene.sourceImageFile` (the same field a manual reference image or i2v-continuation source already populates) by a new `creativeDirectorSceneImageHook`, so the render lands even with no client mounted. Idempotent (a scene that already has a reference frame is left alone) and only fires for queue-backed image-gen modes (local/Codex), mirroring the portrait path's graceful skip for external mode. The two remaining downstream modalities #1818 named — first-pass scene clips (image-to-video) and a first-pass music bed — are genuinely separate pipelines and are tracked as their own follow-up issues (#1927, #1928) rather than folded into this slice. (`server/services/creativeDirector/firstPassGen.js`, `server/services/creativeDirectorSceneImageHook.js`)
+- **[issue-1867] Auto-cast first-pass scene reference frames.** Extends the opt-in first-pass gen step from #1818 (catalog portraits) one stage later: once a treatment exists (via auto-compose, or a later `/:id/start`), the director seeds a first reference frame per scene the same way it already seeds cast portraits — one image-gen job per scene, rendered at the project's locked-in aspect ratio, enqueued onto the durable media-job queue and filed onto `scene.sourceImageFile` (the same field a manual reference image or i2v-continuation source already populates) by a new `creativeDirectorSceneImageHook`, so the render lands even with no client mounted. The user's opt-in is persisted on the project independent of the compose toggle (the OverviewTab checkboxes are independent, and a project can be started later without re-composing in the same request). Idempotent (a scene that already has a reference frame is left alone), skips `useContinuationFromPrior` scenes (their actual source is the prior scene's extracted last frame at render time, so a seeded frame there would just be discarded), and only fires for queue-backed image-gen modes (local/Codex), mirroring the portrait path's graceful skip for external mode. The two remaining downstream modalities #1818 named — first-pass scene clips (image-to-video) and a first-pass music bed — are genuinely separate pipelines and are tracked as their own follow-up issues (#1927, #1928) rather than folded into this slice. (`server/services/creativeDirector/firstPassGen.js`, `server/services/creativeDirectorSceneImageHook.js`)
## Architecture
diff --git a/server/routes/creativeDirector.js b/server/routes/creativeDirector.js
index 5d70cd5334..803244db86 100644
--- a/server/routes/creativeDirector.js
+++ b/server/routes/creativeDirector.js
@@ -119,18 +119,23 @@ router.post('/:id/auto-cast', asyncHandler(async (req, res) => {
// treatment path — so we simply skip those statuses.
const composable = project && project.status !== 'paused' && project.status !== 'failed';
const composing = Boolean(compose) && composable && Array.isArray(cast) && cast.length > 0 && !project.treatment;
+ // Scene reference frames (#1867) depend on a treatment existing, which may
+ // land well after THIS request — either because `compose` kicks it off
+ // asynchronously below, or because the user opted into `generateFirstPass`
+ // without `compose` and only starts the project later via a separate
+ // `/:id/start` call (the OverviewTab toggles are independent, per its own
+ // "Independent of the treatment toggle" copy). Persist the user's opt-in on
+ // the project record unconditionally — NOT gated on `composing` — so the
+ // `/:id/treatment` handler (the only place the agent's scene plan actually
+ // lands) can find it regardless of which path triggered composition.
+ // Awaited (rather than fired alongside startCreativeDirectorProject) so
+ // there is no ordering ambiguity between this write and a same-request
+ // compose's first read.
+ if (generateFirstPass) {
+ await updateProject(req.params.id, { generateFirstPass: true })
+ .catch((e) => console.log(`⚠️ CD persist generateFirstPass flag failed: ${e.message}`));
+ }
if (composing) {
- // Scene reference frames (#1867) depend on a treatment existing, which
- // auto-compose only writes asynchronously below. Persist the user's
- // opt-in on the project record BEFORE kicking off the compose chain —
- // there is no other durable hand-off point between this request and the
- // agent's much-later `/:id/treatment` write, and awaiting it here (rather
- // than firing it alongside startCreativeDirectorProject) rules out any
- // ordering ambiguity between the write and the orchestrator's first read.
- if (generateFirstPass) {
- await updateProject(req.params.id, { generateFirstPass: true })
- .catch((e) => console.log(`⚠️ CD persist generateFirstPass flag failed: ${e.message}`));
- }
startCreativeDirectorProject(req.params.id).catch((e) => console.log(`⚠️ CD auto-compose failed: ${e.message}`));
}
// First-pass gen (#1818): when opted in, kick off a catalog portrait render
diff --git a/server/routes/creativeDirector.test.js b/server/routes/creativeDirector.test.js
index cff43704a3..5c15da0f0c 100644
--- a/server/routes/creativeDirector.test.js
+++ b/server/routes/creativeDirector.test.js
@@ -391,12 +391,22 @@ describe('creativeDirector routes', () => {
expect(cdService.updateProject).toHaveBeenCalledWith('cd-1', { generateFirstPass: true });
});
- it('does not persist generateFirstPass when not composing', async () => {
+ it('persists generateFirstPass even when not composing this request (#1867) — the toggles are independent, and the project may only be started later via /:id/start', async () => {
autoCast.applyAutoCastToProject.mockResolvedValue({
project: { id: 'cd-1', cast: [{ ingredientId: 'p1' }] }, added: [{ ingredientId: 'p1' }], suggestions: [],
});
const r = await request(app).post('/api/creative-director/cd-1/auto-cast').send({ generateFirstPass: true });
expect(r.status).toBe(200);
+ expect(cdService.updateProject).toHaveBeenCalledWith('cd-1', { generateFirstPass: true });
+ expect(hook.startCreativeDirectorProject).not.toHaveBeenCalled();
+ });
+
+ it('does not persist generateFirstPass when the flag is omitted', async () => {
+ autoCast.applyAutoCastToProject.mockResolvedValue({
+ project: { id: 'cd-1', cast: [{ ingredientId: 'p1' }] }, added: [{ ingredientId: 'p1' }], suggestions: [],
+ });
+ const r = await request(app).post('/api/creative-director/cd-1/auto-cast').send({ compose: true });
+ expect(r.status).toBe(200);
expect(cdService.updateProject).not.toHaveBeenCalledWith('cd-1', { generateFirstPass: true });
});
});
diff --git a/server/services/creativeDirector/firstPassGen.js b/server/services/creativeDirector/firstPassGen.js
index a9b3ba89cb..4bc6aea8c0 100644
--- a/server/services/creativeDirector/firstPassGen.js
+++ b/server/services/creativeDirector/firstPassGen.js
@@ -194,6 +194,11 @@ export async function enqueueFirstPassPortraits(members = []) {
* image to at actual render time — an unscaled square seed would have its
* edges cropped away to fit a 16:9/9:16 target.
*
+ * Skips `useContinuationFromPrior` scenes: sceneRunner.js overwrites their
+ * `sourceImageFile` with the prior scene's extracted last frame whenever
+ * extraction succeeds, so a seeded frame there is generated and then
+ * silently discarded in the common case — not worth the render-queue cost.
+ *
* Returns `{ mode, enqueued: [{ sceneId, jobId }], skipped: [{ sceneId, reason }], reason? }`.
*/
export async function enqueueFirstPassSceneFrames(project) {
@@ -225,6 +230,18 @@ export async function enqueueFirstPassSceneFrames(project) {
skipped.push({ sceneId: scene.sceneId, reason: 'has-reference' });
continue;
}
+ // A continuation scene's actual render source is the PRIOR scene's
+ // extracted last frame (sceneRunner.js overwrites sourceImageFile with it
+ // whenever extraction succeeds), so a seeded reference frame here is
+ // generated and then silently discarded the moment the chain advances
+ // normally — wasted render-queue/GPU time for the common case. It would
+ // still help as a fallback if continuation extraction ever fails, but
+ // that failure path is the exception, not the case first-pass gen should
+ // spend renders optimizing for.
+ if (scene.useContinuationFromPrior) {
+ skipped.push({ sceneId: scene.sceneId, reason: 'continuation' });
+ continue;
+ }
const prompt = typeof scene.prompt === 'string' ? scene.prompt.trim() : '';
if (!prompt) {
skipped.push({ sceneId: scene.sceneId, reason: 'no-prompt' });
diff --git a/server/services/creativeDirector/firstPassGen.test.js b/server/services/creativeDirector/firstPassGen.test.js
index 110830fb2e..0d063605c6 100644
--- a/server/services/creativeDirector/firstPassGen.test.js
+++ b/server/services/creativeDirector/firstPassGen.test.js
@@ -192,6 +192,20 @@ describe('enqueueFirstPassSceneFrames (#1867)', () => {
expect(enqueueJob.mock.calls[0][0].params.height).toBeUndefined();
});
+ it('skips a continuation scene — its source comes from the prior scene\'s extracted last frame, not a seeded frame (#1867 fix)', async () => {
+ const project = {
+ id: 'cd-1',
+ treatment: { scenes: [
+ scene({ sceneId: 's1' }),
+ scene({ sceneId: 's2', useContinuationFromPrior: true }),
+ ] },
+ };
+ const out = await enqueueFirstPassSceneFrames(project);
+ expect(out.enqueued).toEqual([{ sceneId: 's1', jobId: 'job-1' }]);
+ expect(out.skipped).toEqual([{ sceneId: 's2', reason: 'continuation' }]);
+ expect(enqueueJob).toHaveBeenCalledTimes(1);
+ });
+
it('skips a scene that already has a reference frame (idempotent re-run)', async () => {
const project = {
id: 'cd-1',