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): also invalidate stale comicPages art on beat rewrite

Adam Eivybb06eb99e378
diff --git a/server/services/pipeline/arcPlanner/beatContinuity.js b/server/services/pipeline/arcPlanner/beatContinuity.js
index 378541d814..82f4991ca8 100644
--- a/server/services/pipeline/arcPlanner/beatContinuity.js
+++ b/server/services/pipeline/arcPlanner/beatContinuity.js
@@ -36,10 +36,23 @@ import {
shapeBeatResolutions,
} from './context.js';
-// Text stages generated FROM the beats — stale once the beats are rewritten, so
-// a beat correction must clear them for regeneration. `idea` (which holds the
-// beats) is excluded; the rest of the text chain (prose → scripts) is downstream.
-const DOWNSTREAM_TEXT_STAGES = TEXT_STAGE_IDS.filter((s) => s !== 'idea');
+// Stages the Series Autopilot generates FROM the beats — all stale once the
+// beats are rewritten, so a beat correction must clear them for regeneration.
+// `idea` (which holds the beats) is the root and is excluded; the rest of the
+// chain the conductor produces is beats → prose → scripts → comicPages art. Only
+// `comicPages` is included from the visual group: it's the one visual stage the
+// autopilot's visualDraft step produces, so it's the only one the autopilot
+// could finish with stale (storyboards/episodeVideo/audio are manual stages the
+// conductor never generates, so it can't leave them stale).
+const DOWNSTREAM_STAGES = [...TEXT_STAGE_IDS.filter((s) => s !== 'idea'), 'comicPages'];
+
+// A downstream stage carries derived content worth clearing when it has text
+// output (prose/scripts) OR rendered comic art (comicPages pages / cover slots).
+const stageHasDerivedContent = (st) => !!(
+ (st?.output && st.output.trim())
+ || (Array.isArray(st?.pages) && st.pages.length)
+ || st?.cover || st?.backCover
+);
// Cross-issue BEAT continuity pass over the whole series. Read-only — returns
// `{ issues }` shaped like verifyArc. Issues without beats are reviewed at
@@ -170,21 +183,26 @@ export async function applyBeatResolutions(seriesId, series, episodes) {
})).catch((err) => {
console.log(`⚠️ beat-continuity: episode ${edit.episodeNumber} beat edit failed: ${err.message}`);
});
- // The beats just changed, so any already-generated prose/scripts derived from
- // them are stale. Clear the unlocked downstream text stages so the conductor's
- // textStages step regenerates them from the corrected beats — otherwise
- // `textReady` sees the old scripts as ready and the run finishes with scripts
- // that contradict the fixed beats. In the normal forward flow these stages are
- // still empty (beat continuity runs before textStages), so this only bites on a
- // re-run / resume over already-drafted issues. Mirrors how applyEpisodeResolutions
- // clears beats when it rewrites a synopsis. A locked downstream stage is the
- // user's frozen work — leave it untouched.
+ // The beats just changed, so every already-generated stage derived from them
+ // is stale: prose + scripts (textReady) AND the comicPages art (visualReady).
+ // Clear the unlocked ones so the conductor's textStages / visualDraft steps
+ // regenerate from the corrected beats — otherwise those gates see the old
+ // outputs as ready and the run finishes with scripts/art that contradict the
+ // fixed beats. In the normal forward flow these stages are still empty (beat
+ // continuity runs before textStages), so this only bites on a re-run / resume
+ // over already-drafted issues. Mirrors how applyEpisodeResolutions clears beats
+ // when it rewrites a synopsis. A locked stage is the user's frozen work — leave
+ // it untouched. One uniform reset partial works for both shapes: text
+ // sanitizers ignore the pages/cover fields, the comicPages sanitizer ignores
+ // `output`.
const clearedStages = [];
- for (const stageId of DOWNSTREAM_TEXT_STAGES) {
+ for (const stageId of DOWNSTREAM_STAGES) {
const st = issue.stages?.[stageId];
if (!st || st.locked === true) continue;
- if (!(st.output && st.output.trim())) continue; // nothing generated → nothing to clear
- await updateStageWithLatest(issue.id, stageId, () => ({ status: 'empty', output: '', errorMessage: '' })).catch((err) => {
+ if (!stageHasDerivedContent(st)) continue; // nothing generated → nothing to clear
+ await updateStageWithLatest(issue.id, stageId, () => ({
+ status: 'empty', output: '', pages: [], cover: null, backCover: null, errorMessage: '',
+ })).catch((err) => {
console.log(`⚠️ beat-continuity: clear ${stageId} for episode ${edit.episodeNumber} failed: ${err.message}`);
});
clearedStages.push(stageId);
diff --git a/server/services/pipeline/seriesAutopilot.test.js b/server/services/pipeline/seriesAutopilot.test.js
index 19e0e12515..92399a41ad 100644
--- a/server/services/pipeline/seriesAutopilot.test.js
+++ b/server/services/pipeline/seriesAutopilot.test.js
@@ -912,18 +912,28 @@ describe('beat-continuity resolve (#1510)', () => {
expect(issue.stages.idea.status).toBe('ready');
});
- it('clears stale downstream prose/scripts so they regenerate from the corrected beats', async () => {
+ it('clears stale downstream prose/scripts AND comicPages art so they regenerate from the corrected beats', async () => {
const { series, issueId } = await seedIssueWithBeats();
- // Pre-existing downstream drafts (the re-run / resume case): prose + comicScript
- // were generated from the OLD beats.
+ // Pre-existing downstream drafts (the re-run / resume case): prose, comicScript,
+ // and rendered comic art were all generated from the OLD beats.
await issuesSvc.updateStage(issueId, 'prose', { status: 'ready', output: 'old prose' });
await issuesSvc.updateStage(issueId, 'comicScript', { status: 'ready', output: 'old script' });
+ await issuesSvc.updateStage(issueId, 'comicPages', {
+ status: 'ready',
+ pages: [{ panels: [{ description: 'p' }], proofImage: { jobId: 'pg0' } }],
+ cover: { proofImage: { jobId: 'cov' } },
+ backCover: { proofImage: { jobId: 'bc' } },
+ });
+ // Sanity: art reads as fully drafted before the beat fix.
+ expect(autopilot.visualReady(await issuesSvc.getIssue(issueId))).toBe(true);
+
const applied = await applyBeatResolutions(series.id, series, [{ seasonNumber: 1, episodeNumber: 1, beats: 'corrected beats' }]);
- expect(applied[0].clearedStages).toEqual(expect.arrayContaining(['prose', 'comicScript']));
+ expect(applied[0].clearedStages).toEqual(expect.arrayContaining(['prose', 'comicScript', 'comicPages']));
const issue = await issuesSvc.getIssue(issueId);
expect(issue.stages.idea.output).toBe('corrected beats'); // new beats applied
- expect(issuesSvc.isStageReady(issue.stages.prose)).toBe(false); // stale → cleared
- expect(issuesSvc.isStageReady(issue.stages.comicScript)).toBe(false); // stale → cleared
+ expect(issuesSvc.isStageReady(issue.stages.prose)).toBe(false); // stale text → cleared
+ expect(issuesSvc.isStageReady(issue.stages.comicScript)).toBe(false); // stale script → cleared
+ expect(autopilot.visualReady(issue)).toBe(false); // stale art → re-draw forced
});
it('does NOT clear a locked downstream stage when rewriting beats', async () => {