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: muted autoplay baseline and retryable filename lookup for card playback (#2702)

[._.]/ Adam Eivyac9431dac7bb
diff --git a/client/src/components/creative-director/OverviewTab.jsx b/client/src/components/creative-director/OverviewTab.jsx
index ddebd0da4f..71b268088d 100644
--- a/client/src/components/creative-director/OverviewTab.jsx
+++ b/client/src/components/creative-director/OverviewTab.jsx
@@ -179,7 +179,7 @@ export default function OverviewTab({ project, onProjectUpdate, onAsyncWorkQueue
const inlineImage = !project.finalVideoId && preview.kind === 'image' && preview.jobId ? preview : null;
// The id→file mismatch: a stitched final is `timeline-*.mp4` behind a UUID.
// The idle player is `preload="none"`, so a late resolve can't be raced here.
- const { src: finalVideoSrc } = useVideoFileSrc(project.finalVideoId, {
+ const { src: finalVideoSrc, retry: retryFinalVideo } = useVideoFileSrc(project.finalVideoId, {
enabled: Boolean(project.finalVideoId),
});
@@ -192,7 +192,7 @@ export default function OverviewTab({ project, onProjectUpdate, onAsyncWorkQueue
</h2>
<div className={`${aspectClass} ${maxWidthClass} w-full mx-auto rounded overflow-hidden bg-port-bg`}>
{project.finalVideoId
- ? <ScenePreview jobId={project.finalVideoId} src={finalVideoSrc} label="Final video" aspectClass={aspectClass} />
+ ? <ScenePreview jobId={project.finalVideoId} src={finalVideoSrc} onRetry={retryFinalVideo} label="Final video" aspectClass={aspectClass} />
: (
<MediaImage
src={inlineImage.src}
diff --git a/client/src/components/creative-director/ProjectPreview.jsx b/client/src/components/creative-director/ProjectPreview.jsx
index b3d29d0278..4d5b9dd9f6 100644
--- a/client/src/components/creative-director/ProjectPreview.jsx
+++ b/client/src/components/creative-director/ProjectPreview.jsx
@@ -45,7 +45,7 @@ export default function ProjectPreview({ project, to }) {
// `timeline-*.mp4` behind a UUID), so resolve the real file before playing.
// `enabled` keeps the grid light: this fires only once the user presses play,
// never for the N cards sitting idle on the page.
- const { src: resolvedSrc, resolving } = useVideoFileSrc(preview.jobId, {
+ const { src: resolvedSrc, resolving, retry: retryResolve } = useVideoFileSrc(preview.jobId, {
enabled: playing && preview.kind === 'video',
});
@@ -63,6 +63,7 @@ export default function ProjectPreview({ project, to }) {
<ScenePreview
jobId={preview.jobId}
src={resolvedSrc}
+ onRetry={retryResolve}
label={`${project?.name || 'Project'} — ${preview.label}`}
aspectClass={aspectClass}
autoPlay
@@ -85,11 +86,12 @@ export default function ProjectPreview({ project, to }) {
src={preview.poster}
alt={`${preview.label} — ${project?.name || 'project'}`}
loading="lazy"
- // A stitched final has no generated thumbnail today (#2702 leaves
- // that out of scope), so a 404 here is expected, not exceptional —
- // degrade to the placeholder rather than a broken-image icon. The
- // play affordance stays either way: the mp4 can be fine even when
- // its poster isn't.
+ // Every render path DOES write a `<jobId>.jpg` thumbnail — clips via
+ // videoGen, stitched finals via the timeline renderer — so a 404 here
+ // means the poster was deleted out from under us (history prune), not
+ // that this project type lacks one. Degrade to the placeholder rather
+ // than a broken-image icon; the play affordance stays either way,
+ // since the mp4 can be fine even when its poster isn't.
onError={() => setPosterMissing(true)}
className="w-full h-full object-cover"
/>
diff --git a/client/src/components/creative-director/ScenePreview.jsx b/client/src/components/creative-director/ScenePreview.jsx
index 27211ea540..a82c85f5ff 100644
--- a/client/src/components/creative-director/ScenePreview.jsx
+++ b/client/src/components/creative-director/ScenePreview.jsx
@@ -1,4 +1,4 @@
-import { useState, useEffect } from 'react';
+import { useState, useEffect, useRef } from 'react';
import { ExternalLink } from 'lucide-react';
import { videoSrcForJob, videoPosterForJob } from '../../lib/creativeDirectorPreview.js';
@@ -30,7 +30,18 @@ import { videoSrcForJob, videoPosterForJob } from '../../lib/creativeDirectorPre
* expressed intent, so a second click on the native controls
* would be redundant. Off by default — the grid must never
* fetch mp4s on its own (`preload="none"` only holds while
- * this is false).
+ * this is false). Autoplay follows the same mobile contract as
+ * MediaLightbox: `muted` is the BASELINE (iOS/Android block
+ * unmuted autoplay not fired from a direct gesture — and the
+ * card's src resolution is async, so the click's transient
+ * activation may well have expired by mount), then the effect
+ * below upgrades to audible when allowed and falls back to
+ * muted playback rather than a dead paused player.
+ * onRetry? — invoked by the Retry button alongside the cache-bust, so a
+ * caller whose `src` came from a FAILED async lookup can redo
+ * it. Without this, Retry would only re-request the same wrong
+ * URL forever (the reconstructed guess) and the video would
+ * stay unreachable until a remount/reload.
* src? — explicit video URL, overriding the `<jobId>.mp4` guess below.
* Required whenever the id is NOT the filename stem: the
* timeline renderer (a CD project's stitched final cut) mints
@@ -40,9 +51,10 @@ import { videoSrcForJob, videoPosterForJob } from '../../lib/creativeDirectorPre
* derived from `jobId` — `generateThumbnail` always writes
* `<jobId>.jpg`, on both the clip and timeline paths.
*/
-export default function ScenePreview({ jobId, label, aspectClass = 'aspect-video', autoPlay = false, src = null }) {
+export default function ScenePreview({ jobId, label, aspectClass = 'aspect-video', autoPlay = false, src = null, onRetry = null }) {
const [missing, setMissing] = useState(false);
const [attempt, setAttempt] = useState(0);
+ const videoRef = useRef(null);
// Reset on `src` too, not just `jobId`: a caller resolving the real filename
// asynchronously renders once with src=null (the reconstructed guess) and
// again once it lands. Without this, an error recorded against the guess
@@ -52,6 +64,21 @@ export default function ScenePreview({ jobId, label, aspectClass = 'aspect-video
setAttempt(0);
}, [jobId, src]);
+ // Upgrade the muted autoplay baseline to audible when the browser allows it
+ // (mirrors MediaLightbox). Re-runs per `attempt` because the Retry button
+ // remounts the element via `key`. Promise.resolve() normalizes both a real
+ // play() promise and the undefined some environments return.
+ useEffect(() => {
+ if (!autoPlay) return;
+ const v = videoRef.current;
+ if (!v) return;
+ v.muted = false;
+ Promise.resolve(v.play()).catch(() => {
+ v.muted = true;
+ Promise.resolve(v.play()).catch(() => {});
+ });
+ }, [autoPlay, src, jobId, attempt]);
+
if (!jobId) {
return <div className={`bg-port-bg ${aspectClass} flex items-center justify-center text-port-text-muted text-xs`}>no render yet</div>;
}
@@ -64,7 +91,7 @@ export default function ScenePreview({ jobId, label, aspectClass = 'aspect-video
<span>media missing</span>
<button
type="button"
- onClick={() => { setMissing(false); setAttempt((a) => a + 1); }}
+ onClick={() => { setMissing(false); setAttempt((a) => a + 1); onRetry?.(); }}
className="px-2 py-0.5 rounded border border-port-border hover:bg-port-card text-port-text"
>
Retry
@@ -76,11 +103,13 @@ export default function ScenePreview({ jobId, label, aspectClass = 'aspect-video
<div className={`relative bg-port-bg ${aspectClass}`}>
<video
key={attempt}
+ ref={videoRef}
src={videoSrc}
poster={posterSrc}
controls
preload={autoPlay ? 'metadata' : 'none'}
autoPlay={autoPlay}
+ muted={autoPlay}
playsInline
aria-label={label}
onError={() => setMissing(true)}
diff --git a/client/src/hooks/useVideoFileSrc.js b/client/src/hooks/useVideoFileSrc.js
index 68273cbd39..b949651ce5 100644
--- a/client/src/hooks/useVideoFileSrc.js
+++ b/client/src/hooks/useVideoFileSrc.js
@@ -1,4 +1,4 @@
-import { useEffect, useState } from 'react';
+import { useCallback, useEffect, useState } from 'react';
import { listVideoHistory } from '../services/apiImageVideo.js';
/**
@@ -31,15 +31,16 @@ import { listVideoHistory } from '../services/apiImageVideo.js';
* so a card resolves only once the user actually presses play.
*/
export function useVideoFileSrc(jobId, { enabled = true } = {}) {
- // Keyed by the id it was resolved FOR, so `resolving` can be derived
+ // Keyed by the id + attempt it was resolved FOR, so `resolving` can be derived
// synchronously rather than set from an effect. An effect-set flag would
// still be false for the first render after `enabled` flips true (effects run
// after commit) — long enough for a caller gating autoplay to mount a player
// against the unresolved fallback path, fire a doomed request, and flash
// "media missing" before the real src lands.
- const [resolved, setResolved] = useState({ jobId: null, src: null });
+ const [attempt, setAttempt] = useState(0);
+ const [resolved, setResolved] = useState({ jobId: null, attempt: -1, src: null });
const active = Boolean(enabled && jobId);
- const settled = resolved.jobId === jobId;
+ const settled = resolved.jobId === jobId && resolved.attempt === attempt;
const resolving = active && !settled;
useEffect(() => {
@@ -48,18 +49,25 @@ export function useVideoFileSrc(jobId, { enabled = true } = {}) {
// Silent: a failed lookup is not a user-facing error — ScenePreview's
// reconstruction fallback (and its own missing-media UI) covers it, so a
// toast here would be noise on a page that already degrades gracefully.
- // Both paths settle on THIS jobId so `resolving` can never latch on.
+ // Both paths settle on THIS jobId+attempt so `resolving` can never latch on.
listVideoHistory({ silent: true })
.then((entries) => {
if (cancelled) return;
const list = Array.isArray(entries) ? entries : [];
const entry = list.find((e) => e?.id === jobId);
const filename = typeof entry?.filename === 'string' ? entry.filename.trim() : '';
- setResolved({ jobId, src: filename ? `/data/videos/${filename}` : null });
+ setResolved({ jobId, attempt, src: filename ? `/data/videos/${filename}` : null });
})
- .catch(() => { if (!cancelled) setResolved({ jobId, src: null }); });
+ .catch(() => { if (!cancelled) setResolved({ jobId, attempt, src: null }); });
return () => { cancelled = true; };
- }, [jobId, active, settled]);
+ }, [jobId, active, settled, attempt]);
- return { src: settled ? resolved.src : null, resolving };
+ // Redo a settled lookup. A transient 5xx on the history call would otherwise
+ // strand a timeline final forever: `src` stays null, the caller falls back to
+ // the reconstructed `<jobId>.mp4` that cannot exist for it, and ScenePreview's
+ // own Retry only re-requests that same wrong URL. Wire this to that Retry
+ // (`<ScenePreview onRetry={retry}>`) so one button recovers both layers.
+ const retry = useCallback(() => setAttempt((a) => a + 1), []);
+
+ return { src: settled ? resolved.src : null, resolving, retry };
}
diff --git a/client/src/hooks/useVideoFileSrc.test.js b/client/src/hooks/useVideoFileSrc.test.js
index 1cc4114c43..ddf0bdc644 100644
--- a/client/src/hooks/useVideoFileSrc.test.js
+++ b/client/src/hooks/useVideoFileSrc.test.js
@@ -98,6 +98,30 @@ describe('useVideoFileSrc', () => {
await waitFor(() => expect(result.current.src).toBe('/data/videos/scene-1.mp4'));
});
+ it('recovers a transiently-failed lookup via retry()', async () => {
+ // The regression: a settled failure used to be permanent, so a 5xx blip
+ // stranded a timeline final on the reconstructed URL that cannot exist for
+ // it — and ScenePreview's Retry only re-requested that same wrong URL.
+ listVideoHistory.mockRejectedValueOnce(new Error('transient 503'));
+ const { result } = renderHook(() => useVideoFileSrc('final-1'));
+ await waitFor(() => expect(result.current.resolving).toBe(false));
+ expect(result.current.src).toBeNull();
+
+ act(() => { result.current.retry(); });
+ expect(result.current.resolving).toBe(true); // synchronously re-armed
+ await waitFor(() => expect(result.current.resolving).toBe(false));
+ expect(result.current.src).toBe('/data/videos/timeline-abcd1234-1700000000000.mp4');
+ expect(listVideoHistory).toHaveBeenCalledTimes(2);
+ });
+
+ it('keeps retry() stable across renders', async () => {
+ const { result, rerender } = renderHook(() => useVideoFileSrc('final-1'));
+ await waitFor(() => expect(result.current.resolving).toBe(false));
+ const first = result.current.retry;
+ rerender();
+ expect(result.current.retry).toBe(first);
+ });
+
it('requests silently — the caller owns the failure UI', async () => {
const { result } = renderHook(() => useVideoFileSrc('final-1'));
await waitFor(() => expect(result.current.resolving).toBe(false));