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: drop late image-prompt responses after reindex via generation counter (#904)

Adam Eivya6b08388ad38
diff --git a/client/src/components/pipeline/stages/ComicPagesStage.jsx b/client/src/components/pipeline/stages/ComicPagesStage.jsx
index 89ff3187b8..e2c9fbe36a 100644
--- a/client/src/components/pipeline/stages/ComicPagesStage.jsx
+++ b/client/src/components/pipeline/stages/ComicPagesStage.jsx
@@ -33,6 +33,11 @@ export default function ComicPagesStage({ issue, onStageUpdate, actionsGated = f
const [panelCandidates, setPanelCandidates] = useState({});
const [promptCount, setPromptCount] = useState(IMAGE_PROMPT_COUNT_DEFAULT);
const [applyingCandidate, setApplyingCandidate] = useState(null);
+ // Bumped whenever the page/panel tree reindexes (remove / extract). A
+ // generate request captures it before its await and drops a late response
+ // whose generation is stale, so an in-flight result can't repopulate
+ // candidates under a `${pi}:${ni}` key now owned by a different panel.
+ const candidateGenRef = useRef(0);
// Per-page in-flight state. Codex can render multiple pages in parallel, so
// tracking a single index would flip the spinner off the wrong button when
// the first request finished while a second was still pending.
@@ -64,12 +69,15 @@ export default function ComicPagesStage({ issue, onStageUpdate, actionsGated = f
persist(next);
};
// Removing a page or panel reindexes the `${pi}:${ni}`-keyed candidates after
- // it, so any open candidate list would point at the wrong panel — drop them.
+ // it, so any open candidate list would point at the wrong panel — drop them
+ // and invalidate any in-flight generate so its late response can't reappear.
const removePage = (pi) => {
+ candidateGenRef.current += 1;
setPanelCandidates({});
persist(pages.filter((_, i) => i !== pi));
};
const removePanel = (pi, ni) => {
+ candidateGenRef.current += 1;
setPanelCandidates({});
const next = pages.map((p, i) => i === pi
? { ...p, panels: (p.panels || []).filter((_, j) => j !== ni) }
@@ -100,7 +108,8 @@ export default function ComicPagesStage({ issue, onStageUpdate, actionsGated = f
if (!result) return;
setPages(result.stage?.pages || []);
// Extraction replaces the whole page/panel tree — stale candidates would
- // now belong to different panels.
+ // now belong to different panels; invalidate in-flight generates too.
+ candidateGenRef.current += 1;
setPanelCandidates({});
onStageUpdate?.('comicPages', result.stage, result.issue);
toast.success(`Extracted ${result.pageCount} page${result.pageCount === 1 ? '' : 's'} / ${result.panelCount} panel${result.panelCount === 1 ? '' : 's'}`);
@@ -183,6 +192,7 @@ export default function ComicPagesStage({ issue, onStageUpdate, actionsGated = f
// Flush any pending textarea edit before the server reads the panel
// description (it builds the prompt from the persisted text). pagesRef
// holds the latest keystroke that onBlur may not have committed yet.
+ const gen = candidateGenRef.current;
await persist(pagesRef.current);
const result = await generatePipelineComicPanelImagePrompts(
issue.id, pi, ni, { count: promptCount, ...genConfigToRefineOptions(genConfig) },
@@ -192,6 +202,9 @@ export default function ComicPagesStage({ issue, onStageUpdate, actionsGated = f
});
setPromptingKey(null);
if (!result) return;
+ // Page/panel tree reindexed (remove / extract) while we were generating —
+ // `${pi}:${ni}` no longer means the same panel, so discard the result.
+ if (gen !== candidateGenRef.current) return;
setPanelCandidates((prev) => ({ ...prev, [key]: result.candidates }));
toast.success(`Generated ${result.candidates.length} prompt${result.candidates.length === 1 ? '' : 's'} for panel ${pi + 1}.${ni + 1}`);
};
diff --git a/client/src/components/pipeline/stages/StoryboardsStage.jsx b/client/src/components/pipeline/stages/StoryboardsStage.jsx
index f7d51d8f60..79ec1e11b3 100644
--- a/client/src/components/pipeline/stages/StoryboardsStage.jsx
+++ b/client/src/components/pipeline/stages/StoryboardsStage.jsx
@@ -49,6 +49,11 @@ export default function StoryboardsStage({ issue, series, onStageUpdate, actions
const [sceneCandidates, setSceneCandidates] = useState({});
const [promptCount, setPromptCount] = useState(IMAGE_PROMPT_COUNT_DEFAULT);
const [applyingCandidate, setApplyingCandidate] = useState(null);
+ // Bumped whenever the scene list reindexes (remove / extract). A generate
+ // request captures it before its await and drops a late response whose
+ // generation is stale — otherwise an in-flight result could repopulate
+ // candidates under an index now owned by a different scene.
+ const candidateGenRef = useRef(0);
// Active per-shot renders keyed by `${sceneIdx}:${shotIdx}` so multiple
// shots can render concurrently with independent spinners. A single ref
// would race when the user starts a second render before the first settles.
@@ -93,7 +98,9 @@ export default function StoryboardsStage({ issue, series, onStageUpdate, actions
const addScene = () => persist([...scenes, { slugline: '', description: '', imageJobId: null }]);
const removeScene = (i) => {
// Removing a scene reindexes everything after it, so any index-keyed
- // candidate state would now point at the wrong scene — drop it all.
+ // candidate state would now point at the wrong scene — drop it all and
+ // invalidate any in-flight generate so its late response can't reappear.
+ candidateGenRef.current += 1;
setSceneCandidates({});
persist(scenes.filter((_, j) => j !== i));
};
@@ -203,7 +210,8 @@ export default function StoryboardsStage({ issue, series, onStageUpdate, actions
const next = result.stage?.scenes || [];
setScenes(next);
// Extraction replaces the whole scene list — stale index-keyed candidates
- // would now belong to different scenes.
+ // would now belong to different scenes; invalidate in-flight generates too.
+ candidateGenRef.current += 1;
setSceneCandidates({});
onStageUpdate?.('storyboards', result.stage, result.issue);
toast.success(`Extracted ${result.sceneCount} scene${result.sceneCount === 1 ? '' : 's'}`);
@@ -273,6 +281,7 @@ export default function StoryboardsStage({ issue, series, onStageUpdate, actions
// Flush any pending textarea edit before the server reads scene.description
// (the server builds the prompt from the persisted text). Same guard the
// shot-render path uses against the blur-save race.
+ const gen = candidateGenRef.current;
await persist(scenes);
const result = await generatePipelineSceneImagePrompts(
issue.id, i, { count: promptCount, ...genConfigToRefineOptions(genConfig) },
@@ -282,6 +291,9 @@ export default function StoryboardsStage({ issue, series, onStageUpdate, actions
});
setPromptingIdx(null);
if (!result) return;
+ // Scene list reindexed (remove / extract) while we were generating — index
+ // `i` no longer means the same scene, so discard the now-orphaned result.
+ if (gen !== candidateGenRef.current) return;
setSceneCandidates((prev) => ({ ...prev, [i]: result.candidates }));
toast.success(`Generated ${result.candidates.length} prompt${result.candidates.length === 1 ? '' : 's'} for scene ${i + 1}`);
};