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): rewind the clip transport when a refinement rewrites the open clip (#4542)

[._.]/ Adam Eivy4a001cd324a2
diff --git a/client/src/components/threejsModels/ThreejsModelPreview.jsx b/client/src/components/threejsModels/ThreejsModelPreview.jsx
index 18b73316e7..d9532594bf 100644
--- a/client/src/components/threejsModels/ThreejsModelPreview.jsx
+++ b/client/src/components/threejsModels/ThreejsModelPreview.jsx
@@ -346,7 +346,6 @@ function useClipPlayback({ clip, cuesById, onCue }) {
const timeRef = useRef(0);
const onCueRef = useRef(onCue);
const duration = getThreejsClipDuration(clip);
- const clipId = clip?.id || null;
const setPlayhead = useCallback((value) => {
timeRef.current = value;
@@ -355,10 +354,19 @@ function useClipPlayback({ clip, cuesById, onCue }) {
// A different clip starts at its own beginning, stopped — carrying a playhead
// across clips would drop the model into a pose the new clip never authored.
+ //
+ // Keyed on the clip's CONTENT, not its id: a refinement can hand back a
+ // rewritten `deploy` whose sequences and duration are new, and evaluating that
+ // at the old playhead would pose the model mid-nowhere and fire the new clip's
+ // cues from the middle. The detail page re-fetches the record every 2s while a
+ // generation runs, so an equivalent snapshot must NOT reset it — which is why
+ // this compares the content rather than the object identity, the same way the
+ // part and model signatures above do.
+ const clipSignature = useMemo(() => JSON.stringify(clip ?? null), [clip]);
useEffect(() => {
setPlaying(false);
setPlayhead(0);
- }, [clipId, setPlayhead]);
+ }, [clipSignature, setPlayhead]);
// Held in a ref so a caller passing an inline handler cannot restart the loop
// on every render.
diff --git a/client/src/components/threejsModels/ThreejsModelPreview.test.jsx b/client/src/components/threejsModels/ThreejsModelPreview.test.jsx
index edc7b5984c..a6067f7151 100644
--- a/client/src/components/threejsModels/ThreejsModelPreview.test.jsx
+++ b/client/src/components/threejsModels/ThreejsModelPreview.test.jsx
@@ -694,3 +694,25 @@ describe('ThreejsModelPreview clip framing and looping', () => {
expect(onCue).toHaveBeenCalledTimes(2);
});
});
+
+describe('ThreejsModelPreview clip refresh', () => {
+ it('rewinds and stops when a refinement rewrites the open clip under the same id', () => {
+ const { rerender } = renderPreview(<ThreejsModelPreview spec={clipSpec()} />);
+ scrub(1.2);
+ expect(screen.getByText('1.20/2.00s')).toBeInTheDocument();
+
+ // The detail page re-fetches every 2s while a generation runs: an equivalent
+ // snapshot must not throw away where the user scrubbed to.
+ rerender(<ThreejsModelPreview spec={clipSpec()} />);
+ expect(screen.getByText('1.20/2.00s')).toBeInTheDocument();
+
+ // A refinement that hands back a rewritten `deploy` is a different clip
+ // wearing the same id — evaluating it at the old playhead would pose the
+ // model somewhere the new clip never authored.
+ const refined = clipSpec();
+ refined.animation.clips[0].durationSeconds = 5;
+ refined.animation.clips[0].sequences[0].endSeconds = 3;
+ rerender(<ThreejsModelPreview spec={refined} />);
+ expect(screen.getByText('0.00/5.00s')).toBeInTheDocument();
+ });
+});