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
serialize timeline project writes, and fix a Creative Director retry the new guard broke
[._.]/ Adam Eivy279707626783
diff --git a/client/src/components/media/VideoTimelineLanes.jsx b/client/src/components/media/VideoTimelineLanes.jsxindex 618ea5ac29..bf1479d170 100644--- a/client/src/components/media/VideoTimelineLanes.jsx+++ b/client/src/components/media/VideoTimelineLanes.jsx@@ -8,7 +8,7 @@* would re-render (and, in the video lane, re-run `useSortable`) 60×/s.*/-import { memo } from 'react';+import { memo, useEffect, useRef } from 'react';import { useSortable } from '@dnd-kit/sortable';import { X, Film, Plus, Music } from 'lucide-react';import { dndTransformToCss } from '../../lib/dndTransform';@@ -265,3 +265,30 @@ export const AudioRow = memo(function AudioRow({ track, onAdd }) {</div>);});++/**+ * One hidden `<audio>` element for a bed track, registered in the editor's+ * playback registry for as long as it is mounted.+ *+ * A component rather than an inline `ref` callback so the registration is tied+ * to the element's LIFETIME, not to render identity: an inline+ * `ref={(el) => ...}` is a fresh function every render, so React detaches and+ * re-attaches it on each frame of playback — and its `el === null` call, which+ * is also how a genuine removal arrives, can't tell the two apart. Unmount is+ * unambiguous, so this is where a removed bed gets paused; a detached but still+ * playing `<audio>` keeps producing sound in some browsers.+ */+export function BedAudio({ trackKey, src, registry }) {+ const elRef = useRef(null);+ useEffect(() => {+ const el = elRef.current;+ if (!el) return undefined;+ registry.set(trackKey, el);+ return () => {+ el.pause();+ registry.delete(trackKey);+ };+ }, [trackKey, registry]);+ if (!src) return null;+ return <audio ref={elRef} src={src} preload="auto" className="hidden" />;+}diff --git a/client/src/components/media/VideoTimelineLanes.test.jsx b/client/src/components/media/VideoTimelineLanes.test.jsxindex 21d7099cd7..eae715c5cf 100644--- a/client/src/components/media/VideoTimelineLanes.test.jsx+++ b/client/src/components/media/VideoTimelineLanes.test.jsx@@ -18,7 +18,7 @@ vi.mock('@dnd-kit/sortable', async () => {};});-import { TimelineBlock, LaneBlock, FloatingLane } from './VideoTimelineLanes';+import { TimelineBlock, LaneBlock, FloatingLane, BedAudio } from './VideoTimelineLanes';const clip = { _key: 'clip-key', clipId: 'clip-1', inSec: 0, outSec: 2 };const clipMeta = { prompt: 'A dramatic sunrise' };@@ -221,3 +221,33 @@ describe('FloatingLane', () => {expect(screen.getByText('logo.png').closest('div').className).not.toContain('bg-port-accent/20');});});++describe('BedAudio — registration is tied to the element lifetime', () => {+ it('registers on mount and pauses + deregisters on unmount', () => {+ const registry = new Map();+ const { unmount, rerender } = render(<BedAudio trackKey="bed-1" src="/data/music/bed.mp3" registry={registry} />);++ const el = registry.get('bed-1');+ expect(el).toBeInstanceOf(HTMLAudioElement);+ const pause = vi.spyOn(el, 'pause');++ // A re-render (which happens every animation frame during playback) must+ // NOT be mistaken for a removal.+ rerender(<BedAudio trackKey="bed-1" src="/data/music/bed.mp3" registry={registry} />);+ expect(registry.get('bed-1')).toBe(el);+ expect(pause).not.toHaveBeenCalled();++ // Removing the bed is what stops it — a detached but still-playing+ // <audio> keeps producing sound in some browsers.+ unmount();+ expect(pause).toHaveBeenCalled();+ expect(registry.has('bed-1')).toBe(false);+ });++ it('renders nothing for an unresolvable asset', () => {+ const registry = new Map();+ const { container } = render(<BedAudio trackKey="bed-1" src={null} registry={registry} />);+ expect(container.querySelector('audio')).toBeNull();+ expect(registry.size).toBe(0);+ });+});diff --git a/client/src/pages/VideoTimelineEditor.jsx b/client/src/pages/VideoTimelineEditor.jsxindex 7a48483d27..81193f5964 100644--- a/client/src/pages/VideoTimelineEditor.jsx+++ b/client/src/pages/VideoTimelineEditor.jsx@@ -21,7 +21,7 @@ import * as api from '../services/api';import { formatTimecode, clamp } from '../utils/formatters';import { useSseProgress, isTerminalSseFrame } from '../hooks/useSseProgress';import {- TimelineBlock, FloatingLane, LibraryTile, StillTile, AudioRow,+ TimelineBlock, FloatingLane, LibraryTile, StillTile, AudioRow, BedAudio,} from '../components/media/VideoTimelineLanes';import { NumberField, FadeFields, RemoveButton } from '../components/media/VideoTimelineInspector';import {@@ -471,10 +471,6 @@ export default function VideoTimelineEditor() {// Drive the bed <audio> elements from the same playhead the export mixes// against, so what the user hears while scrubbing is what amix will produce.- const setBedRef = useCallback((key) => (el) => {- if (el) bedRefs.current.set(key, el);- else bedRefs.current.delete(key);- }, []);useEffect(() => {for (const track of audio.tracks) {const el = bedRefs.current.get(track._key);@@ -781,6 +777,18 @@ export default function VideoTimelineEditor() {{activeStillSrc && (<img src={activeStillSrc} alt="" className="absolute inset-0 w-full h-full object-contain" />)}+ {/* The segment fade scrim sits UNDER the overlay lane, matching the+ export: ffmpeg fades each segment before concat and composites+ overlays afterwards, so a fade dims the base video and leaves+ the overlay at its own opacity. */}+ {activeFadeScrim > 0 && (+ <div+ data-testid="fade-scrim"+ aria-hidden="true"+ style={{ opacity: activeFadeScrim }}+ className="absolute inset-0 bg-black pointer-events-none"+ />+ )}{/* Overlay lane, composited exactly as ffmpeg will: normalizedposition/width against the canvas, alpha from the same ramp.Every overlay stays MOUNTED and rides its opacity to zero —@@ -796,14 +804,6 @@ export default function VideoTimelineEditor() {className="absolute pointer-events-none"/>) : null))}- {activeFadeScrim > 0 && (- <div- data-testid="fade-scrim"- aria-hidden="true"- style={{ opacity: activeFadeScrim }}- className="absolute inset-0 bg-black pointer-events-none"- />- )}{segments.length === 0 && (<div className="absolute inset-0 flex items-center justify-center text-gray-500 text-sm">Add clips to start@@ -812,19 +812,14 @@ export default function VideoTimelineEditor() {</div>{/* Bed playback elements. Hidden — the timeline lane is the UI. */}- {audio.tracks.map((track) => {- const src = assetUrl(track.assetKind, track.assetFile);- if (!src) return null;- return (- <audio- key={track._key}- ref={setBedRef(track._key)}- src={src}- preload="auto"- className="hidden"- />- );- })}+ {audio.tracks.map((track) => (+ <BedAudio+ key={track._key}+ trackKey={track._key}+ src={assetUrl(track.assetKind, track.assetFile)}+ registry={bedRefs.current}+ />+ ))}<div className="flex items-center gap-2 text-xs text-gray-400"><buttondiff --git a/server/services/creativeDirector/stitchRunner.js b/server/services/creativeDirector/stitchRunner.jsindex 2b93d5eb0e..4492fbbe1c 100644--- a/server/services/creativeDirector/stitchRunner.js+++ b/server/services/creativeDirector/stitchRunner.js@@ -70,7 +70,12 @@ export async function runStitch(projectId) {timeline = await createTimelineProject(`${project.name} — Final Cut`);await updateProject(projectId, { timelineProjectId: timeline.id });}- await updateTimelineProject(timeline.id, { clips });+ // Send the v2 video lane, not the legacy `clips` mirror: a reused timeline+ // the user has since layered (a still, a fade, a clip volume) refuses a+ // clips-only save with SCHEMA_TOO_NEW, which would fail the whole retry.+ // The accepted scenes ARE the cut, so the lane is replaced wholesale — but+ // as clip segments, which can carry those fields.+ await updateTimelineProject(timeline.id, { segments: clips.map((c) => ({ type: 'clip', ...c })) });const { jobId } = await renderTimelineProject(timeline.id);diff --git a/server/services/videoTimeline/local.js b/server/services/videoTimeline/local.jsindex 95989199cc..0e75cfa5f9 100644--- a/server/services/videoTimeline/local.js+++ b/server/services/videoTimeline/local.js@@ -28,6 +28,7 @@ import { safeChildProcessOptions } from '../../lib/processEnv.js';import { killWithEscalation } from '../../lib/killWithEscalation.js';import { attachFfmpegRenderGuard } from '../../lib/ffmpegRenderGuard.js';import { mapWithConcurrency } from '../../lib/mapWithConcurrency.js';+import { createFileWriteQueue } from '../../lib/fileWriteQueue.js';import { loadHistory, mutateVideoHistory } from '../videoGen/local.js';import {TIMELINE_SCHEMA_VERSION,@@ -98,6 +99,14 @@ export const loadProjects = async () => {// migration missed (a restored backup, a hand-edited file) working anyway.return (await loadRawProjects()).map(normalizeProject);};+// Every mutator read-modify-writes ONE shared file, so they share ONE tail:+// each waits for the previous to settle before it reads, and therefore merges+// against the freshest persisted state. Without it two concurrent PATCHes — a+// debounced lane save and the flush Render issues — can both read the same+// `updatedAt`, both pass the conflict check, and the later write silently+// erases the earlier one's lane (server/AGENTS.md, "write serialization").+const queueProjectWrite = createFileWriteQueue();+const saveProjects = async (projects) => {// First write on a fresh install lands before PATHS.data is created by any// other service — without ensureDir it would ENOENT on the temp-file write@@ -115,7 +124,9 @@ export async function getProject(id) {return project ? normalizeProject(project) : null;}-export async function createProject(name) {+export const createProject = (name) => queueProjectWrite(() => createProjectNow(name));++async function createProjectNow(name) {const trimmed = (name || '').trim();if (!trimmed) throw new ServerError('Project name required', { status: 400, code: 'VALIDATION_ERROR' });const projects = await loadProjects();@@ -143,7 +154,11 @@ export async function createProject(name) {// client-supplied numFrames/fps here either; those come from the history// entry at render time.-export async function updateProject(id, patch, expectedUpdatedAt) {+export const updateProject = (id, patch, expectedUpdatedAt) => queueProjectWrite(+ () => updateProjectNow(id, patch, expectedUpdatedAt),+);++async function updateProjectNow(id, patch, expectedUpdatedAt) {const projects = await loadProjects();const idx = projects.findIndex((p) => p.id === id);if (idx === -1) throw new ServerError('Project not found', { status: 404, code: 'NOT_FOUND' });@@ -203,7 +218,9 @@ export async function updateProject(id, patch, expectedUpdatedAt) {return project;}-export async function deleteProject(id) {+export const deleteProject = (id) => queueProjectWrite(() => deleteProjectNow(id));++async function deleteProjectNow(id) {// Only ids are compared here — nothing to normalize.const projects = await loadRawProjects();const filtered = projects.filter((p) => p.id !== id);