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
address review (codex): reconcile a running-cancel so scene UIs don't show failure (#1796)
[._.]/ Adam Eivy633b911f5158
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex a9643448a7..63670d1269 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -27,7 +27,7 @@## Scene image rendering-- **[issue-1791] Canceling a scene render now clears its spinner immediately, and a late older render can't overwrite a newer frame.** Two long-standing rough edges in the background scene-image renderers — storyboard scenes in Writers' Room, catalog portraits, and the Music Video director board — are fixed together. First: canceling a render that was still **queued** (e.g. from the Media Jobs queue) used to leave its "Rendering…" spinner stuck until you reloaded the page, because a queued-then-canceled job never produced a client event; the cancellation now reaches the UI and clears the spinner right away, with no error toast, everywhere a scene spinner appears. Second: if you regenerated a scene frame and an **older** render happened to finish *after* the newer one, it could quietly revert the scene to the stale image — the storyboard and catalog now drop the out-of-order older render (matching the behavior the Music Video board already had), so the newest frame you asked for is the one that sticks (a stale catalog portrait is kept as a reference instead of being lost). Internally the four near-identical media-job completion hooks were consolidated behind one shared tag-dispatch mechanism so this guarantee stays uniform as new render targets are added. (Closes #1791)+- **[issue-1791] Canceling a scene render now clears its spinner cleanly, and a late older render can't overwrite a newer frame.** Two long-standing rough edges in the background scene-image renderers — storyboard scenes in Writers' Room, catalog portraits, and the Music Video director board — are fixed together. First: canceling a render used to leave its "Rendering…" spinner stuck (when the job was still **queued**, which produced no client event at all) or surface a misleading failure (when canceled **while running**, which the generator reported as a failure). Now a cancellation reaches the UI and clears the spinner right away — with no error toast and no error state — everywhere a scene spinner appears, whether the render was queued or already running. Second: if you regenerated a scene frame and an **older** render happened to finish *after* the newer one, it could quietly revert the scene to the stale image — the storyboard and catalog now drop the out-of-order older render (matching the behavior the Music Video board already had), so the newest frame you asked for is the one that sticks (a stale catalog portrait is kept as a reference instead of being lost). Internally the four near-identical media-job completion hooks were consolidated behind one shared tag-dispatch mechanism so this guarantee stays uniform as new render targets are added. (Closes #1791, #1796)## Devtoolsdiff --git a/client/src/components/writers-room/SceneCard.jsx b/client/src/components/writers-room/SceneCard.jsxindex b73005f150..6b60b5e35c 100644--- a/client/src/components/writers-room/SceneCard.jsx+++ b/client/src/components/writers-room/SceneCard.jsx@@ -70,6 +70,11 @@ const SceneCard = forwardRef(function SceneCard({const [progress, setProgress] = useState(null);const [showDebugMenu, setShowDebugMenu] = useState(false);const jobIdRef = useRef(null);+ // The jobId a just-fired `onFailed` cleared, kept so a cancel that arrives+ // immediately after (a running render canceled from the queue emits+ // image-gen:failed THEN image-gen:canceled) can still reconcile to a clean+ // cancel instead of leaving the card stuck in the error state (#1791/#1796).+ const recentlyFailedRef = useRef(null);const debugMenuRef = useRef(null);// Sync local image state when parent reloads analyses (e.g. post-re-Adapt)@@ -120,18 +125,26 @@ const SceneCard = forwardRef(function SceneCard({};const onFailed = (data) => {if (!jobIdRef.current || data.generationId !== jobIdRef.current) return;+ // Remember the job so a cancel arriving right after (running-cancel) can+ // override the error below; cleared on the next render start (see generate).+ recentlyFailedRef.current = data.generationId;setError(data.error || data.message || 'Generation failed');setGenStatus('error');setProgress(null);jobIdRef.current = null;};- // A canceled render (e.g. dropped from the Media Jobs queue) is not an- // error — roll back to idle / the prior image so the spinner clears instead- // of sticking until remount (#1791). The `*-gen:canceled` event is bridged- // from mediaJobEvents, keyed by the same generationId as completed/failed.+ // A canceled render (dropped while queued, OR canceled while running — which+ // reaches us as image-gen:failed first, then this) is not an error: roll back+ // to idle / the prior image so the spinner clears and any error state shown by+ // a preceding onFailed is retracted, instead of sticking until remount+ // (#1791). The `*-gen:canceled` event is bridged from mediaJobEvents, keyed by+ // the same generationId as completed/failed.const onCanceled = (data) => {- if (!jobIdRef.current || data.generationId !== jobIdRef.current) return;+ const isActive = jobIdRef.current && data.generationId === jobIdRef.current;+ const isJustFailed = data.generationId === recentlyFailedRef.current;+ if (!isActive && !isJustFailed) return;jobIdRef.current = null;+ recentlyFailedRef.current = null;setProgress(null);setError(null);setGenerated(initialImage@@ -163,6 +176,9 @@ const SceneCard = forwardRef(function SceneCard({setError(null);setProgress(null);setGenerated(null);+ // A new render supersedes any prior failure — drop the stale correlation so a+ // late cancel for the old job can't retract this render's state.+ recentlyFailedRef.current = null;const prompt = buildScenePrompt(workTitle, scene, matchedCharacters, imageStyle?.prompt || '', matchedPlace);const res = await generateImage(buildSceneRenderPayload({prompt,diff --git a/client/src/pages/MusicVideo.jsx b/client/src/pages/MusicVideo.jsxindex 75424d0f30..babfb40268 100644--- a/client/src/pages/MusicVideo.jsx+++ b/client/src/pages/MusicVideo.jsx@@ -14,6 +14,7 @@ import {} from '../services/apiMusicVideo.js';import { generateImage } from '../services/apiSystem.js';import { listTracks } from '../services/apiTracks.js';+import { getMediaJob } from '../services/apiMediaJobs.js';import socket from '../services/socket.js';import { formatDurationSec } from '../utils/formatters.js';@@ -99,7 +100,18 @@ export default function MusicVideo() {if (failed) toast.error('Frame render failed');};const onCompleted = (data) => settle(data, false);- const onFailed = (data) => settle(data, true);+ // A render canceled WHILE RUNNING reaches us as image-gen:failed (SIGTERM)+ // just before image-gen:canceled, so confirm via the authoritative job status+ // before showing a failure toast — a user cancel must not toast "render+ // failed" (#1791/#1796). A real failure still toasts. The queued-cancel case+ // never emits failed and is handled by onCanceled below.+ const onFailed = (data) => {+ const jobId = data?.generationId || data?.jobId;+ if (!jobId) { settle(data, true); return; }+ getMediaJob(jobId)+ .then((job) => settle(data, job?.status !== 'canceled'))+ .catch(() => settle(data, true));+ };socket.on('music-video:scene-image', onSceneImage);socket.on('image-gen:completed', onCompleted);socket.on('image-gen:failed', onFailed);