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

fix: harden FableLoom playback continuity

Adam Eivy3c656224a676
diff --git a/client/src/components/fableloom/LoomPlayPanel.jsx b/client/src/components/fableloom/LoomPlayPanel.jsx
index d9cd70aa81..000b0a65c6 100644
--- a/client/src/components/fableloom/LoomPlayPanel.jsx
+++ b/client/src/components/fableloom/LoomPlayPanel.jsx
@@ -21,6 +21,7 @@ import { playLoomTurn } from '../../services/api';
import { sceneProseClass } from './fieldStyles';
const findNode = (episode, id) => episode?.nodes.find((n) => n.id === id) || null;
+const hasPlayableStart = (episode) => !!findNode(episode, episode?.startNodeId);
// Reader-facing projection of an authored node — the OPENING scene only, which
// the panel shows before any turn has been taken. Every later scene arrives
@@ -41,7 +42,10 @@ export default function LoomPlayPanel({ loom, episode: initialEpisode }) {
const [playEpisodeId, setPlayEpisodeId] = useState(initialEpisode.id);
const episode = loom.episodes?.find((item) => item.id === playEpisodeId) || initialEpisode;
const episodeIndex = loom.episodes?.findIndex((item) => item.id === episode.id) ?? -1;
- const nextEpisode = episodeIndex >= 0 ? loom.episodes?.[episodeIndex + 1] : null;
+ const nextEpisodeIndex = episodeIndex >= 0
+ ? (loom.episodes || []).findIndex((item, index) => index > episodeIndex && hasPlayableStart(item))
+ : -1;
+ const nextEpisode = nextEpisodeIndex >= 0 ? loom.episodes[nextEpisodeIndex] : null;
// Anchored on scalars so an authoring echo elsewhere in the loom (a node
// PATCH, a drag) doesn't mint a new `start` identity and wipe an
// in-progress read-through. The trade: mid-session edits to the opening
@@ -51,19 +55,21 @@ export default function LoomPlayPanel({ loom, episode: initialEpisode }) {
[episode.id, episode.startNodeId],
);
const [scene, setScene] = useState(start);
- const [transcript, setTranscript] = useState([]);
+ const [transcript, setTranscript] = useState(() => (start ? [{ role: 'scene', node: start }] : []));
const [message, setMessage] = useState('');
const [previewMode, setPreviewMode] = useState('text');
+ const [failedVideoId, setFailedVideoId] = useState(null);
const scrollRef = useRef(null);
// Mirrors the server's terminal rule: an ending, or a dead-end scene with
// no paths out, ends the read-through.
const ended = !!scene && (scene.isEnding || !scene.choices?.length);
- const automaticCut = !!scene && scene.playbackMode === 'cut' && scene.choices?.length === 1;
+ const automaticCut = !!scene && !scene.isEnding && scene.playbackMode === 'cut' && scene.choices?.length === 1;
const restart = () => {
setScene(start);
- setTranscript([]);
+ setTranscript(start ? [{ role: 'scene', node: start }] : []);
setMessage('');
+ setFailedVideoId(null);
};
useEffect(() => { setPlayEpisodeId(initialEpisode.id); }, [initialEpisode.id]);
@@ -130,6 +136,11 @@ export default function LoomPlayPanel({ loom, episode: initialEpisode }) {
runTurn({ message: text }, history);
};
+ const latestSceneTurnIndex = transcript.reduce(
+ (latest, turn, index) => (turn.role === 'scene' ? index : latest),
+ -1,
+ );
+
if (!start) {
return (
<p className="p-4 text-sm text-port-text-muted">
@@ -158,7 +169,21 @@ export default function LoomPlayPanel({ loom, episode: initialEpisode }) {
</div>
<div ref={scrollRef} className="flex-1 overflow-y-auto p-4 space-y-4">
{transcript.map((turn, i) => {
- if (turn.role === 'scene') return null;
+ if (turn.role === 'scene') {
+ if (previewMode === 'video' || i === latestSceneTurnIndex) return null;
+ const historicalCut = !turn.node.isEnding
+ && turn.node.playbackMode === 'cut'
+ && turn.node.choices?.length === 1;
+ return (
+ <SceneCard
+ key={i}
+ node={turn.node}
+ format={loom.format}
+ previewMode={previewMode}
+ automaticCut={historicalCut}
+ />
+ );
+ }
return (
<div key={i} className={turn.role === 'reader' ? 'text-right' : ''}>
<div
@@ -180,6 +205,8 @@ export default function LoomPlayPanel({ loom, episode: initialEpisode }) {
previewMode={previewMode}
onCutEnded={advanceCut}
automaticCut={automaticCut}
+ videoFailed={failedVideoId === scene.videoHistoryId}
+ onVideoError={() => setFailedVideoId(scene.videoHistoryId)}
/>
{ended && (
<div className="flex items-center gap-2 justify-center text-port-success text-sm font-medium py-2">
@@ -205,14 +232,27 @@ export default function LoomPlayPanel({ loom, episode: initialEpisode }) {
</div>
)}
{automaticCut && (
- <button
- type="button"
- onClick={advanceCut}
- disabled={sending || (previewMode === 'video' && !!scene.videoHistoryId)}
- className="w-full px-3 py-2 rounded bg-port-accent text-white text-sm disabled:opacity-50"
- >
- {sending ? 'Loading next cut…' : previewMode === 'video' && scene.videoHistoryId ? 'Video advances automatically' : 'Next cut'}
- </button>
+ <div className="flex gap-2">
+ <button
+ type="button"
+ onClick={advanceCut}
+ disabled={sending || (previewMode === 'video' && !!scene.videoHistoryId && failedVideoId !== scene.videoHistoryId)}
+ className="flex-1 px-3 py-2 rounded bg-port-accent text-white text-sm disabled:opacity-50"
+ >
+ {sending
+ ? 'Loading next cut…'
+ : previewMode === 'video' && scene.videoHistoryId && failedVideoId !== scene.videoHistoryId
+ ? 'Video advances automatically'
+ : 'Next cut'}
+ </button>
+ <button
+ type="button"
+ onClick={restart}
+ className="px-3 py-2 rounded bg-port-accent/15 text-port-accent text-sm"
+ >
+ <RotateCcw size={14} className="inline mr-1" /> Restart
+ </button>
+ </div>
)}
{!automaticCut && <div className="flex gap-2">
<input
@@ -230,7 +270,7 @@ export default function LoomPlayPanel({ loom, episode: initialEpisode }) {
onClick={() => (nextEpisode ? setPlayEpisodeId(nextEpisode.id) : restart())}
className="flex items-center gap-1.5 px-3 py-2 rounded bg-port-accent/15 text-port-accent text-sm"
>
- <RotateCcw size={14} /> {nextEpisode ? `Next: Episode ${nextEpisode.number || episodeIndex + 2}` : 'Play again'}
+ <RotateCcw size={14} /> {nextEpisode ? `Next: Episode ${nextEpisode.number || nextEpisodeIndex + 1}` : 'Play again'}
</button>
) : (
<button
@@ -249,9 +289,12 @@ export default function LoomPlayPanel({ loom, episode: initialEpisode }) {
);
}
-function SceneCard({ node, isOpening = false, format, previewMode, onCutEnded, automaticCut }) {
+function SceneCard({
+ node, isOpening = false, format, previewMode, onCutEnded, automaticCut,
+ videoFailed = false, onVideoError,
+}) {
if (!node) return null;
- const showVideo = previewMode === 'video' && node.videoHistoryId;
+ const showVideo = previewMode === 'video' && node.videoHistoryId && !videoFailed;
const showImage = previewMode === 'image' && node.image;
return (
<div className="border border-port-border rounded-lg overflow-hidden bg-port-card">
@@ -264,6 +307,7 @@ function SceneCard({ node, isOpening = false, format, previewMode, onCutEnded, a
playsInline
loop={!automaticCut && !node.isEnding}
onEnded={automaticCut ? onCutEnded : undefined}
+ onError={onVideoError}
src={`/data/videos/${encodeURIComponent(node.videoHistoryId)}.mp4`}
aria-label={node.title || 'Scene video'}
className="w-full max-h-[60vh] bg-black object-contain"
@@ -278,7 +322,11 @@ function SceneCard({ node, isOpening = false, format, previewMode, onCutEnded, a
</div>
{previewMode === 'text' && <p className={sceneProseClass(format)}>{node.prose}</p>}
{previewMode === 'image' && !node.image && <p className="text-sm text-port-text-muted">No storyboard image rendered for this cut yet.</p>}
- {previewMode === 'video' && !node.videoHistoryId && <p className="text-sm text-port-text-muted">No video rendered for this cut yet.</p>}
+ {previewMode === 'video' && (!node.videoHistoryId || videoFailed) && (
+ <p className="text-sm text-port-text-muted">
+ {videoFailed ? 'The rendered video is unavailable; advance manually or retry after rendering.' : 'No video rendered for this cut yet.'}
+ </p>
+ )}
{!node.isEnding && (
<p className="mt-2 text-xs text-port-text-muted">
{automaticCut ? 'Automatic cut' : 'Decision loop — waits for viewer input'}
diff --git a/client/src/components/fableloom/LoomPlayPanel.test.jsx b/client/src/components/fableloom/LoomPlayPanel.test.jsx
index 4070d1ac97..b100f297d4 100644
--- a/client/src/components/fableloom/LoomPlayPanel.test.jsx
+++ b/client/src/components/fableloom/LoomPlayPanel.test.jsx
@@ -56,6 +56,8 @@ describe('LoomPlayPanel', () => {
expect(payload.message).toBeUndefined();
// The reader's choice reads back in the transcript, and the scene advanced.
expect(screen.getByText('enter the gate')).toBeInTheDocument();
+ expect(screen.getByText('You stand before it.')).toBeInTheDocument();
+ expect(screen.getByText('Torchlight.')).toBeInTheDocument();
await waitFor(() => expect(screen.getByRole('button', { name: 'Take path: retreat' })).toBeInTheDocument());
});
@@ -160,4 +162,53 @@ describe('LoomPlayPanel', () => {
expect(screen.getByLabelText('Guard patrol')).toHaveProperty('loop', true);
expect(screen.getByRole('button', { name: 'Take path: cross now' })).toBeInTheDocument();
});
+
+ it('restores manual cut controls when a rendered video cannot load', async () => {
+ const cutEpisode = {
+ id: 'ep-cut', startNodeId: 'cut-1', nodes: [{
+ id: 'cut-1', title: 'Setup', prose: 'A door opens.', playbackMode: 'cut', videoHistoryId: 'missing-video',
+ transitions: [{ id: 'continue-1', targetNodeId: 'next', intent: 'Continue' }],
+ }, { id: 'next', isEnding: true, transitions: [] }],
+ };
+ const user = userEvent.setup();
+ render(<LoomPlayPanel loom={{ ...loom, episodes: [cutEpisode] }} episode={cutEpisode} />);
+ await user.selectOptions(screen.getByLabelText('Preview stage'), 'video');
+
+ fireEvent.error(screen.getByLabelText('Setup'));
+
+ expect(await screen.findByText('The rendered video is unavailable; advance manually or retry after rendering.')).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Next cut' })).toBeEnabled();
+ expect(screen.getByRole('button', { name: 'Restart' })).toBeEnabled();
+ });
+
+ it('continues to the next playable episode and resets the transcript', async () => {
+ const first = {
+ id: 'ep-1', number: 1, title: 'One', startNodeId: 'end-1',
+ nodes: [{ id: 'end-1', title: 'First ending', prose: 'Episode one ends.', isEnding: true, transitions: [] }],
+ };
+ const second = {
+ id: 'ep-2', number: 2, title: 'Two', startNodeId: 'start-2',
+ nodes: [{ id: 'start-2', title: 'Second opening', prose: 'Episode two begins.', transitions: [{ id: 'wait', targetNodeId: 'start-2', intent: 'wait' }] }],
+ };
+ const user = userEvent.setup();
+ render(<LoomPlayPanel loom={{ ...loom, episodes: [first, second] }} episode={first} />);
+
+ await user.click(screen.getByRole('button', { name: 'Next: Episode 2' }));
+
+ expect(await screen.findByText('Episode two begins.')).toBeInTheDocument();
+ expect(screen.queryByText('Episode one ends.')).not.toBeInTheDocument();
+ });
+
+ it('does not offer an unplayable empty episode', () => {
+ const first = {
+ id: 'ep-1', number: 1, startNodeId: 'end-1',
+ nodes: [{ id: 'end-1', prose: 'Done.', isEnding: true, transitions: [] }],
+ };
+ const empty = { id: 'ep-2', number: 2, startNodeId: null, nodes: [] };
+
+ render(<LoomPlayPanel loom={{ ...loom, episodes: [first, empty] }} episode={first} />);
+
+ expect(screen.getByRole('button', { name: 'Play again' })).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Next: Episode 2' })).not.toBeInTheDocument();
+ });
});
diff --git a/server/services/fableLoom/weave.js b/server/services/fableLoom/weave.js
index 9cef9a8596..b966495ad9 100644
--- a/server/services/fableLoom/weave.js
+++ b/server/services/fableLoom/weave.js
@@ -19,7 +19,11 @@ import { isStr, trimTo } from '../../lib/storyBible.js';
import { resolveLlmRoutePin } from '../../lib/llmRoutePin.js';
import { renderCanonForPrompt } from '../../lib/universePromptRenderers.js';
import { analyzeEpisodeGraph, describeGraphForPrompt } from '../../lib/fableLoomGraph.js';
-import { fableLoomCameraMovementCatalogForPrompt } from '../../lib/fableLoomCameraMovements.js';
+import {
+ FABLELOOM_CAMERA_MOVEMENT_VALUES,
+ fableLoomCameraMovementCatalogForPrompt,
+ normalizeFableLoomCameraMovement,
+} from '../../lib/fableLoomCameraMovements.js';
import { isFableLoomPlaybackMode } from '../../lib/fableLoomPlayback.js';
import { getUniverse } from '../universeBuilder.js';
import { LOOM_LIMITS, findEpisode, findNode, getLoom, mutateLoom } from './records.js';
@@ -308,7 +312,7 @@ export async function reviewEpisode(loomId, episodeId, { providerId, model, effo
const FEEDBACK_NODE_FIELDS = ['title', 'prose', 'imagePrompt', 'videoPrompt', 'cameraMovement', 'playbackMode', 'isEnding', 'endingLabel'];
const FEEDBACK_TRANSITION_FIELDS = ['targetNodeId', 'intent', 'triggers', 'description'];
-const FEEDBACK_STRING_NODE_FIELDS = new Set(['title', 'prose', 'imagePrompt', 'videoPrompt', 'cameraMovement', 'endingLabel']);
+const FEEDBACK_STRING_NODE_FIELDS = new Set(['title', 'prose', 'imagePrompt', 'videoPrompt', 'endingLabel']);
const hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
@@ -336,6 +340,9 @@ const normalizeFeedbackPatch = (content, episode) => {
if (!hasOwn(rawScene, key)) continue;
if (FEEDBACK_STRING_NODE_FIELDS.has(key) && typeof value === 'string') {
nodePatch[key] = value;
+ } else if (key === 'cameraMovement' && typeof value === 'string') {
+ const movement = normalizeFableLoomCameraMovement(value);
+ if (!movement || FABLELOOM_CAMERA_MOVEMENT_VALUES.includes(movement)) nodePatch[key] = movement;
} else if (key === 'playbackMode' && isFableLoomPlaybackMode(value)) {
nodePatch[key] = value;
} else if (key === 'isEnding' && typeof value === 'boolean') {
diff --git a/server/services/fableLoom/weave.test.js b/server/services/fableLoom/weave.test.js
index 18cf42acea..58c322e39b 100644
--- a/server/services/fableLoom/weave.test.js
+++ b/server/services/fableLoom/weave.test.js
@@ -244,15 +244,24 @@ describe('feedbackEpisode', () => {
it('preserves playback mode when feedback returns an invalid placeholder', async () => {
const { loomId, episodeId } = await setup();
- const withNode = await addNode(loomId, episodeId, { title: 'Opening', playbackMode: 'cut' });
+ const withNode = await addNode(loomId, episodeId, {
+ title: 'Opening', playbackMode: 'cut', cameraMovement: 'slow-dolly-in',
+ });
const nodeId = withNode.episodes[0].nodes[0].id;
runStagedLLM.mockResolvedValue({
- content: { scenes: [{ id: nodeId, playbackMode: 'cut or decision, only when changed', title: 'Revised' }] },
+ content: { scenes: [{
+ id: nodeId,
+ playbackMode: 'cut or decision, only when changed',
+ cameraMovement: 'slow-dolly-in, only when changed',
+ title: 'Revised',
+ }] },
});
const result = await feedbackEpisode(loomId, episodeId, { feedback: 'Revise the title.' });
- expect(result.loom.episodes[0].nodes[0]).toMatchObject({ title: 'Revised', playbackMode: 'cut' });
+ expect(result.loom.episodes[0].nodes[0]).toMatchObject({
+ title: 'Revised', playbackMode: 'cut', cameraMovement: 'slow-dolly-in',
+ });
});
});