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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: retain preview look and title edits made during worker startup
[._.]/ Adam Eivy71b485558e68
diff --git a/client/src/components/musicVideo/CompositionPreviewPlayer.test.jsx b/client/src/components/musicVideo/CompositionPreviewPlayer.test.jsxindex 9d02750022..25b2eff73a 100644--- a/client/src/components/musicVideo/CompositionPreviewPlayer.test.jsx+++ b/client/src/components/musicVideo/CompositionPreviewPlayer.test.jsx@@ -127,10 +127,52 @@ describe('CompositionPreviewPlayer', () => {expect(document.querySelector('iframe')).toBeNull();});+ it('applies film look and title-card edits made while the isolated worker is opening', async () => {+ socket.emit.mockImplementation(() => {});+ const look = { version: 1, preset: 'custom', grain: 0.4 };+ const card = { enabled: true, title: 'Opening title', startSec: 2, endSec: 8 };+ const { rerender } = render(<CompositionPreviewPlayer project={{ ...project, filmLook: look, titleCard: card }} audioUrl={null} />);+ const open = opens()[0][1];+ const nextLook = { ...look, grain: 0.9 };+ const nextCard = { ...card, title: 'Edited title' };+ rerender(<CompositionPreviewPlayer project={{ ...project, filmLook: nextLook, titleCard: nextCard }} audioUrl={null} />);+ expect(socket.emit.mock.calls.filter(([event]) => event === 'generated-preview:command')).toHaveLength(0);++ act(() => socket.reply('generated-preview:open', open));+ await waitFor(() => expect(socket.emit).toHaveBeenCalledWith('generated-preview:command', expect.objectContaining({+ requestId: open.requestId, action: 'film-look', look: nextLook,+ })));+ expect(socket.emit).toHaveBeenCalledWith('generated-preview:command', expect.objectContaining({+ requestId: open.requestId, action: 'title-card', card: expect.objectContaining({ title: 'Edited title' }),+ }));+ expect(opens()).toHaveLength(1);+ });++ it('reconciles controls only for the new session after reopening and ignores the old reply', async () => {+ const look = { version: 1, preset: 'custom', grain: 0.4 };+ const { rerender } = render(<CompositionPreviewPlayer project={{ ...project, filmLook: look }} audioUrl={null} />);+ const oldOpen = opens()[0][1];+ socket.emit.mockImplementation(() => {});+ const nextProject = { ...project, filmLook: { ...look, grain: 0.6 }, composition: { ...project.composition,+ document: { ...DOCUMENT, updatedAt: '2026-02-02T00:00:00.000Z' } } };+ rerender(<CompositionPreviewPlayer project={nextProject} audioUrl={null} />);+ const nextOpen = opens()[1][1];+ const latestLook = { ...look, grain: 0.9 };+ rerender(<CompositionPreviewPlayer project={{ ...nextProject, filmLook: latestLook }} audioUrl={null} />);+ act(() => socket.reply('generated-preview:open', oldOpen));+ expect(socket.emit.mock.calls.filter(([event]) => event === 'generated-preview:command')).toHaveLength(0);+ act(() => socket.reply('generated-preview:open', nextOpen));+ await waitFor(() => expect(socket.emit).toHaveBeenCalledWith('generated-preview:command', expect.objectContaining({+ requestId: nextOpen.requestId, action: 'film-look', look: latestLook,+ })));+ expect(socket.emit.mock.calls.filter(([event]) => event === 'generated-preview:command')).toHaveLength(1);+ });+it('sends the film look with the open and again when it changes, without reopening', async () => {const look = { version: 1, preset: 'custom', grain: 0.4 };const { rerender } = render(<CompositionPreviewPlayer project={{ ...project, filmLook: look }} audioUrl={null} />);await waitFor(() => expect(opens()[0][1].look).toEqual(look));+ expect(socket.emit.mock.calls.filter(([event]) => event === 'generated-preview:command')).toHaveLength(0);const next = { ...look, grain: 0.9 };rerender(<CompositionPreviewPlayer project={{ ...project, filmLook: next }} audioUrl={null} />);await waitFor(() => expect(socket.emit).toHaveBeenCalledWith('generated-preview:command', expect.objectContaining({ action: 'film-look', look: next })));diff --git a/client/src/hooks/useGeneratedPreview.js b/client/src/hooks/useGeneratedPreview.jsindex e340be6665..f25e24b383 100644--- a/client/src/hooks/useGeneratedPreview.js+++ b/client/src/hooks/useGeneratedPreview.js@@ -39,7 +39,6 @@ export default function useGeneratedPreview({ active, request, controls = null }const recordingUrl = useRef('');const controlsRef = useRef(controls);controlsRef.current = controls;- const sentControls = useRef(null);const [state, setState] = useState(EMPTY);const requestKey = active && request ? JSON.stringify(request) : '';@@ -68,22 +67,6 @@ export default function useGeneratedPreview({ active, request, controls = null }});}, []);- useEffect(() => {- sentControls.current = null;- }, [requestKey]);-- useEffect(() => {- if (state.status !== 'ready' || !pending.current?.sessionId) return undefined;- const key = JSON.stringify(controls ?? null);- if (sentControls.current === key) return undefined;- const first = sentControls.current == null;- sentControls.current = key;- if (first || !controls) return undefined;- if ('look' in controls) command('film-look', { look: controls.look ?? null });- if ('card' in controls) command('title-card', { card: controls.card ?? null });- return undefined;- }, [controls, state.status, command, requestKey]);-useEffect(() => {if (!requestKey) {const current = pending.current;@@ -98,13 +81,14 @@ export default function useGeneratedPreview({ active, request, controls = null }return undefined;}const requestId = newRequestId();- pending.current = { requestId, sessionId: null, generation: 0 };+ const openControls = { look: controlsRef.current?.look ?? null, card: controlsRef.current?.card ?? null };+ pending.current = { requestId, sessionId: null, generation: 0, controls: openControls };if (mounted.current) setState((prev) => ({ ...prev, status: 'opening', ready: false, reason: '', lastEvent: null }));const mine = (payload) => payload?.requestId === requestId && pending.current?.requestId === requestId;const onOpened = (payload) => {if (!mine(payload)) return;- pending.current = { requestId, sessionId: payload.sessionId, generation: 0 };+ pending.current = { ...pending.current, sessionId: payload.sessionId };if (!mounted.current) return;setState((prev) => ({...prev,@@ -182,7 +166,6 @@ export default function useGeneratedPreview({ active, request, controls = null }socket.on('generated-preview:event', onEvent);socket.on('generated-preview:recording', onRecording);socket.on('generated-preview:closed', onClosed);- const openControls = controlsRef.current || {};socket.emit('generated-preview:open', {requestId,...request,@@ -209,6 +192,19 @@ export default function useGeneratedPreview({ active, request, controls = null }// eslint-disable-next-line react-hooks/exhaustive-deps}, [requestKey, mounted]);+ // Reconcile against what this session actually received. Controls can change+ // while its open request is in flight; readiness must not mark those edits sent.+ // This effect follows session setup so a reopen never targets the old session.+ useEffect(() => {+ const current = pending.current;+ if (state.status !== 'ready' || !current?.sessionId) return;+ const next = { look: controls?.look ?? null, card: controls?.card ?? null };+ const previous = current.controls;+ current.controls = next;+ if (JSON.stringify(previous.look) !== JSON.stringify(next.look)) command('film-look', { look: next.look });+ if (JSON.stringify(previous.card) !== JSON.stringify(next.card)) command('title-card', { card: next.card });+ }, [controls, state.status, command, requestKey]);+useEffect(() => () => {if (frameUrl.current) URL.revokeObjectURL(frameUrl.current);if (recordingUrl.current) URL.revokeObjectURL(recordingUrl.current);