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

refactor: share one status policy across FableLoom media asset planning (#10732)

Adam Eivy67ea9bf935d6
diff --git a/server/lib/fableLoomProduction.js b/server/lib/fableLoomProduction.js
index 0b0900148f..1c07f58af0 100644
--- a/server/lib/fableLoomProduction.js
+++ b/server/lib/fableLoomProduction.js
@@ -540,6 +540,15 @@ export function verifyExactInputProvenance(recordedProvenance, {
* Enumerate and plan all production assets for an episode.
* Pure deterministic preflight and DAG generation.
*/
+// One status policy for the still/entry/hold/exit media assets: an existing asset
+// is reused unless exact_inputs demands a re-render; everything else is ready or
+// blocked. `reuseAllowed` is supplied per asset (it is deliberately not derived
+// from `ready`: an existing still or entry stays reusable without a prompt).
+const plannedMediaAssetStatus = ({ existingAssetId, reuseAllowed, ready, mode }) => {
+ if (existingAssetId && reuseAllowed && mode !== 'exact_inputs') return 'already_rendered';
+ return ready ? 'ready' : 'blocked';
+};
+
export function buildEpisodeProductionPlan({
loom = null,
episode = null,
@@ -753,9 +762,12 @@ export function buildEpisodeProductionPlan({
temporalSourceNodeId,
dependencies: imageDependencies,
existingAssetId: existingStill,
- status: existingStill && nodeBlockers.length === 0 && effectiveMode !== 'exact_inputs'
- ? 'already_rendered'
- : (imageHasPrompt && nodeBlockers.length === 0 ? 'ready' : 'blocked'),
+ status: plannedMediaAssetStatus({
+ existingAssetId: existingStill,
+ reuseAllowed: nodeBlockers.length === 0,
+ ready: imageReady,
+ mode: effectiveMode,
+ }),
readiness: {
ready: imageReady,
reasons: imageBlockers,
@@ -785,9 +797,12 @@ export function buildEpisodeProductionPlan({
cameraMovement: node.cameraMovement || null,
dependencies: [imageAssetId],
existingAssetId: existingEntryVideo,
- status: existingEntryVideo && nodeBlockers.length === 0 && effectiveMode !== 'exact_inputs'
- ? 'already_rendered'
- : (videoReady ? 'ready' : 'blocked'),
+ status: plannedMediaAssetStatus({
+ existingAssetId: existingEntryVideo,
+ reuseAllowed: nodeBlockers.length === 0,
+ ready: videoReady,
+ mode: effectiveMode,
+ }),
readiness: {
ready: videoReady,
reasons: videoBlockers,
@@ -813,6 +828,7 @@ export function buildEpisodeProductionPlan({
}
}
+ const holdReady = videoHasPrompt && holdBlockers.length === 0;
plannedAssets.push({
id: holdAssetId,
nodeId: node.id,
@@ -824,11 +840,14 @@ export function buildEpisodeProductionPlan({
cameraMovement: node.cameraMovement || null,
dependencies: [imageAssetId],
existingAssetId: existingHold,
- status: existingHold && holdBlockers.length === 0 && effectiveMode !== 'exact_inputs'
- ? 'already_rendered'
- : (videoHasPrompt && holdBlockers.length === 0 ? 'ready' : 'blocked'),
+ status: plannedMediaAssetStatus({
+ existingAssetId: existingHold,
+ reuseAllowed: holdBlockers.length === 0,
+ ready: holdReady,
+ mode: effectiveMode,
+ }),
readiness: {
- ready: videoHasPrompt && holdBlockers.length === 0,
+ ready: holdReady,
reasons: videoHasPrompt ? holdBlockers : [...holdBlockers, 'Scene has neither videoPrompt nor prose for video.'],
},
});
@@ -845,6 +864,7 @@ export function buildEpisodeProductionPlan({
if (lockedCanon && !existingExit && node.visualCanon?.storyboardImageApproved !== true) {
exitBlockers.push('Locked canon video requires an author-approved storyboard image.');
}
+ const exitReady = exitHasPrompt && exitBlockers.length === 0;
plannedAssets.push({
id: exitAssetId,
nodeId: node.id,
@@ -857,11 +877,14 @@ export function buildEpisodeProductionPlan({
prompt: tr.description || videoPrompt,
dependencies: [imageAssetId],
existingAssetId: existingExit,
- status: existingExit && exitBlockers.length === 0 && effectiveMode !== 'exact_inputs'
- ? 'already_rendered'
- : (exitHasPrompt && exitBlockers.length === 0 ? 'ready' : 'blocked'),
+ status: plannedMediaAssetStatus({
+ existingAssetId: existingExit,
+ reuseAllowed: exitBlockers.length === 0,
+ ready: exitReady,
+ mode: effectiveMode,
+ }),
readiness: {
- ready: exitHasPrompt && exitBlockers.length === 0,
+ ready: exitReady,
reasons: exitBlockers,
},
});
diff --git a/server/lib/fableLoomProduction.test.js b/server/lib/fableLoomProduction.test.js
index 17cc1b8008..837c2f7aaf 100644
--- a/server/lib/fableLoomProduction.test.js
+++ b/server/lib/fableLoomProduction.test.js
@@ -171,6 +171,118 @@ describe('fableLoomProduction', () => {
expect(videoStage.stageIndex).toBeGreaterThan(stillStage.stageIndex);
});
+ describe('media asset status policy', () => {
+ const NO_APPROVAL = 'Locked canon video requires an author-approved storyboard image.';
+ const NO_VIDEO_PROMPT = 'Scene has neither videoPrompt nor prose for video.';
+ const NO_EXIT_PROMPT = 'Transition has no description or scene video prompt.';
+ const protagonistReason = 'Canonical protagonist "char-x" is not present in the linked Universe.';
+
+ // One scene with a still, an entry clip, a hold loop and a transition exit.
+ const sceneEpisode = ({ node = {}, assets = {}, transition = {} } = {}) => ({
+ id: 'ep-status',
+ startNodeId: 'scene',
+ nodes: [
+ {
+ id: 'scene',
+ title: 'Scene',
+ imagePrompt: 'A still.',
+ videoPrompt: 'A clip.',
+ image: 'still.png',
+ playbackAssets: {
+ entryVideoHistoryId: 'entry-1',
+ holdLoopVideoHistoryIds: ['hold-1'],
+ exitByTransition: { 'tr-exit': 'exit-1' },
+ ...assets,
+ },
+ transitions: [{ id: 'tr-exit', targetNodeId: 'end', description: 'Leave.', ...transition }],
+ ...node,
+ },
+ { id: 'end', title: 'End', prose: 'The end.', isEnding: true, transitions: [] },
+ ],
+ });
+ const noExisting = {
+ entryVideoHistoryId: null, holdLoopVideoHistoryIds: [], exitByTransition: {},
+ };
+ const plan = (episode, options = {}) => buildEpisodeProductionPlan({
+ loom: { id: 'loom-1' }, mode: 'current_canon', episode, ...options,
+ });
+ const sceneStatuses = (result) => Object.fromEntries(result.plannedAssets
+ .filter((asset) => asset.nodeId === 'scene')
+ .map((asset) => [asset.role, [asset.status, asset.readiness.ready, asset.readiness.reasons]]));
+
+ it('reuses every existing asset in current canon and counts them as already rendered', () => {
+ const result = plan(sceneEpisode());
+ expect(sceneStatuses(result)).toEqual({
+ image: ['already_rendered', true, []],
+ entry: ['already_rendered', true, []],
+ hold: ['already_rendered', true, []],
+ exit: ['already_rendered', true, []],
+ });
+ expect(result.plannedAssets.filter((asset) => asset.status === 'already_rendered')).toHaveLength(4);
+ expect(result.isFullyReady).toBe(true);
+ });
+
+ it('regenerates existing assets in exact_inputs mode instead of reusing them', () => {
+ const result = plan(sceneEpisode(), { mode: 'exact_inputs' });
+ expect(sceneStatuses(result)).toEqual({
+ image: ['ready', true, []],
+ entry: ['ready', true, []],
+ hold: ['ready', true, []],
+ exit: ['ready', true, []],
+ });
+ expect(result.plannedAssets.some((asset) => asset.status === 'already_rendered')).toBe(false);
+ });
+
+ it('keeps an existing still, entry and hold reusable without prompts but not an exit', () => {
+ const result = plan(sceneEpisode({
+ node: { imagePrompt: '', videoPrompt: '' },
+ transition: { description: '' },
+ }));
+ expect(sceneStatuses(result)).toEqual({
+ image: ['already_rendered', false, ['Scene has neither imagePrompt nor prose.']],
+ entry: ['already_rendered', false, [NO_VIDEO_PROMPT]],
+ hold: ['already_rendered', false, [NO_VIDEO_PROMPT]],
+ exit: ['blocked', false, [NO_EXIT_PROMPT]],
+ });
+ });
+
+ it('blocks every existing asset on a blocker common to the scene', () => {
+ const result = plan(sceneEpisode(), {
+ loom: { id: 'loom-1', protagonistCharacterId: 'char-x' },
+ universe: { id: 'universe-1', characters: [] },
+ });
+ expect(sceneStatuses(result)).toEqual({
+ image: ['blocked', false, [protagonistReason]],
+ entry: ['blocked', false, [protagonistReason]],
+ hold: ['blocked', false, [protagonistReason]],
+ exit: ['blocked', false, [protagonistReason]],
+ });
+ });
+
+ it('requires an approved storyboard for new locked-canon video but not for existing clips', () => {
+ const universe = { id: 'universe-1', characters: [] };
+ const lockedNode = { visualCanon: { mode: 'locked' } };
+
+ const unapproved = plan(sceneEpisode({ node: { ...lockedNode, image: null }, assets: noExisting }), { universe });
+ expect(sceneStatuses(unapproved)).toEqual({
+ image: ['ready', true, []],
+ entry: ['blocked', false, [NO_APPROVAL]],
+ hold: ['blocked', false, [NO_APPROVAL]],
+ exit: ['blocked', false, [NO_APPROVAL]],
+ });
+
+ const approved = plan(sceneEpisode({
+ node: { visualCanon: { mode: 'locked', storyboardImageApproved: true }, image: null },
+ assets: noExisting,
+ }), { universe });
+ expect(Object.values(sceneStatuses(approved)).map(([status]) => status)).toEqual(['ready', 'ready', 'ready', 'ready']);
+
+ const existing = plan(sceneEpisode({ node: lockedNode }), { universe });
+ expect(Object.values(sceneStatuses(existing)).map(([status]) => status))
+ .toEqual(['already_rendered', 'already_rendered', 'already_rendered', 'already_rendered']);
+ });
+ });
+
it('blocks production when the canonical protagonist cannot resolve in the linked Universe', () => {
const plan = buildEpisodeProductionPlan({
episode: sampleEpisode,