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 (claude): keep guide picks and loaded guides through edits and failed reloads
[._.]/ Adam Eivyd02eb376848c
diff --git a/client/src/components/musicVideo/SceneCastVariant.jsx b/client/src/components/musicVideo/SceneCastVariant.jsxindex 283e86ecf6..276221e8f1 100644--- a/client/src/components/musicVideo/SceneCastVariant.jsx+++ b/client/src/components/musicVideo/SceneCastVariant.jsx@@ -14,9 +14,12 @@ export default function SceneCastVariant({ project, scene, castMedia = null, onEconst variant = scene.characterVariant || null;const id = (name) => `mv-scene-${scene.sceneId}-cast-${name}`;// A shot's hand-picked references keep their guide ids only for the variant that picked them.+ // A pick of only guides returns to Auto (null), so the new variant's guides lead; [] would send nothing.const save = (next) => {- const patch = Array.isArray(scene.frameReferenceIds)- ? { characterVariant: next, frameReferenceIds: scene.frameReferenceIds.filter((refId) => !refId.startsWith('mvr-guide-')) }+ const picked = scene.frameReferenceIds;+ const kept = Array.isArray(picked) ? picked.filter((refId) => !refId.startsWith('mvr-guide-')) : null;+ const patch = Array.isArray(picked)+ ? { characterVariant: next, frameReferenceIds: kept.length || !picked.length ? kept : null }: { characterVariant: next };onEditLocal(scene.sceneId, patch);onSave(scene.sceneId, patch);diff --git a/client/src/components/musicVideo/SceneCastVariant.test.jsx b/client/src/components/musicVideo/SceneCastVariant.test.jsxindex 4ff806461b..1d061541ec 100644--- a/client/src/components/musicVideo/SceneCastVariant.test.jsx+++ b/client/src/components/musicVideo/SceneCastVariant.test.jsx@@ -41,6 +41,16 @@ describe('a shot\'s Cast guides picker', () => {expect(onSave).toHaveBeenLastCalledWith('s1', { characterVariant: { ingredientId: 'cat-chr-x', era: 'teen' }, frameReferenceIds: ['r1'] });});+ // Uniquely catches a guide-only pick turning into [] (an explicit "send nothing") on a variant change.+ it('returns a guide-only pick to Auto when the variant changes or is cleared', () => {+ const onSave = vi.fn();+ render(<SceneCastVariant project={project} scene={{ sceneId: 's1', characterVariant: { ingredientId: 'cat-chr-x' }, frameReferenceIds: ['mvr-guide-a.png'] }} onEditLocal={vi.fn()} onSave={onSave} />);+ fireEvent.change(screen.getByLabelText('Era'), { target: { value: 'teen' } });+ expect(onSave).toHaveBeenLastCalledWith('s1', { characterVariant: { ingredientId: 'cat-chr-x', era: 'teen' }, frameReferenceIds: null });+ fireEvent.change(screen.getByLabelText('Cast guides'), { target: { value: '' } });+ expect(onSave).toHaveBeenLastCalledWith('s1', { characterVariant: null, frameReferenceIds: null });+ });+it('renders nothing when no subject is saved to Casting', () => {const { container } = render(<SceneCastVariant project={{ concept: { subjects: [project.concept.subjects[1]] } }} scene={{ sceneId: 's1' }} onEditLocal={vi.fn()} onSave={vi.fn()} />);expect(container.firstChild).toBeNull();diff --git a/client/src/components/musicVideo/SceneFrameReferences.jsx b/client/src/components/musicVideo/SceneFrameReferences.jsxindex cd48046bff..8ee866ba35 100644--- a/client/src/components/musicVideo/SceneFrameReferences.jsx+++ b/client/src/components/musicVideo/SceneFrameReferences.jsx@@ -56,7 +56,13 @@ export default function SceneFrameReferences({ project, scene, castMedia = null,// Until the cast member's guides load, an edit would save the row without them.const variantId = scene.characterVariant?.ingredientId;const locked = disabled || Boolean(castMedia && variantId && castMedia[variantId] === undefined);- const set = (next) => { onEditLocal(scene.sceneId, { frameReferenceIds: next }); onSave(scene.sceneId, { frameReferenceIds: next }); };+ // A saved guide id that does not resolve now (its media failed to load) is kept, so an edit cannot drop it.+ const unresolvedGuides = (scene.frameReferenceIds || []).filter((refId) => refId.startsWith('mvr-guide-') && !ids.includes(refId));+ const set = (picked) => {+ const next = picked && [...picked, ...unresolvedGuides].slice(0, MUSIC_VIDEO_MAX_CONDITIONING_REFERENCES);+ onEditLocal(scene.sceneId, { frameReferenceIds: next });+ onSave(scene.sceneId, { frameReferenceIds: next });+ };return (<div role="group" aria-label="References sent with the frames" className="space-y-1">diff --git a/client/src/components/musicVideo/SceneFrameReferences.test.jsx b/client/src/components/musicVideo/SceneFrameReferences.test.jsxindex e2aedfd052..0c342c5ce3 100644--- a/client/src/components/musicVideo/SceneFrameReferences.test.jsx+++ b/client/src/components/musicVideo/SceneFrameReferences.test.jsx@@ -74,3 +74,14 @@ describe('a shot whose Casting guides are still loading', () => {expect(screen.getByRole('button', { name: /Don't send Lead/ }).disabled).toBe(false);});});++describe('a shot whose Casting guides failed to load', () => {+ // Uniquely catches an edit made while guides are unresolved permanently dropping the saved guide ids.+ it('keeps saved guide ids that do not resolve when another reference is taken off', () => {+ const onSave = vi.fn();+ const scene = { sceneId: 's1', characterVariant: { ingredientId: 'cat-chr-x' }, frameReferenceIds: ['r1', 'r2', 'mvr-guide-child.png'] };+ render(<SceneFrameReferences project={project} scene={scene} castMedia={{ 'cat-chr-x': null }} onEditLocal={vi.fn()} onSave={onSave} />);+ fireEvent.click(screen.getByRole('button', { name: /Don't send Lead/ }));+ expect(onSave).toHaveBeenCalledWith('s1', { frameReferenceIds: ['r2', 'mvr-guide-child.png'] });+ });+});diff --git a/client/src/hooks/useMusicVideoSceneMedia.js b/client/src/hooks/useMusicVideoSceneMedia.jsindex 15f25b9e84..952357bbd8 100644--- a/client/src/hooks/useMusicVideoSceneMedia.js+++ b/client/src/hooks/useMusicVideoSceneMedia.js@@ -160,7 +160,7 @@ export default function useMusicVideoSceneMedia({ project, videoSettings, applySreturn () => { live = false; };}, [projectId, restoreFrameJobs, restoreVideoJobs, restoreEndFrameJobs]);// The Casting media of every cast member a shot names in its `characterVariant`- // (#12763), keyed by ingredient id: an array once loaded, null when the load+ // (#12763), keyed by ingredient id: an array once loaded, null when the first load// failed, absent while pending. A shot's frames lead with that member's guides;// without an array the shot uses the automatic set. Casting has no change event,// so the board reloads them when its tab comes back into view.@@ -173,7 +173,8 @@ export default function useMusicVideoSceneMedia({ project, videoSettings, applySlet active = true;Promise.all(castIds.split(',').map((id) => listCatalogIngredientMedia(id, { silent: true }).then((media) => [id, Array.isArray(media) ? media : null], () => [id, null])))- .then((entries) => { if (active) setCastMedia(Object.fromEntries(entries)); });+ // A failed reload keeps the media already loaded; only a never-loaded member is marked failed (null).+ .then((entries) => { if (active) setCastMedia((prev) => Object.fromEntries(entries.map(([id, media]) => [id, media ?? prev[id] ?? null]))); });return () => { active = false; };}, [castIds, castRefresh]);// A render before the shot's cast guides load would silently go out without them.diff --git a/client/src/hooks/useMusicVideoSceneMedia.test.jsx b/client/src/hooks/useMusicVideoSceneMedia.test.jsxindex 8639435b41..1411f50e23 100644--- a/client/src/hooks/useMusicVideoSceneMedia.test.jsx+++ b/client/src/hooks/useMusicVideoSceneMedia.test.jsx@@ -85,7 +85,7 @@ describe('useMusicVideoSceneMedia in-flight restore and failure chip (#10154)',});describe('useMusicVideoSceneMedia Casting guides (#12763)', () => {- beforeEach(() => { handlers.clear(); generateImage.mockClear(); getMusicVideoSceneJobs.mockReset(); getMusicVideoSceneJobs.mockResolvedValue({ jobs: [] }); });+ beforeEach(() => { handlers.clear(); generateImage.mockClear(); getMusicVideoSceneJobs.mockReset(); getMusicVideoSceneJobs.mockResolvedValue({ jobs: [] }); listCatalogIngredientMedia.mockReset(); });afterEach(cleanup);// Uniquely catches a board render sent without the shot's cast guides, before or after they load.@@ -112,4 +112,23 @@ describe('useMusicVideoSceneMedia Casting guides (#12763)', () => {await act(async () => { await result.current.generateFrame(cast.scenes[0]); });expect(generateImage.mock.calls.at(-1)[0].referenceImageFiles).toEqual(['child.png', 'adult.png']);});++ // Uniquely catches a failed reload on tab refocus wiping loaded guides, so renders go out without them.+ it('keeps the loaded guides when a reload on refocus fails', async () => {+ listCatalogIngredientMedia.mockResolvedValueOnce([{ mediaKey: 'child.png', kind: 'reference', library: { variant: { age: 7 }, guide: true } }]);+ const cast = {+ id: 'p3',+ concept: { subjects: [{ id: 'mvc-1', kind: 'character', name: 'Example Lead', ingredientId: 'cat-chr-x' }] },+ scenes: [{ sceneId: 's1', order: 0, label: 'Intro', prompt: 'a lighthouse', referenceImageId: null, takes: [], characterVariant: { ingredientId: 'cat-chr-x', age: 7 } }],+ };+ const { result } = renderHook(() => useMusicVideoSceneMedia({ project: cast, videoSettings: { settings: {} }, applyScenePatch: vi.fn() }));+ await waitFor(() => expect(result.current.castMedia['cat-chr-x']).toHaveLength(1));+ listCatalogIngredientMedia.mockRejectedValueOnce(new Error('offline'));+ await act(async () => { document.dispatchEvent(new Event('visibilitychange')); });+ await waitFor(() => expect(listCatalogIngredientMedia).toHaveBeenCalledTimes(2));+ await act(async () => { await Promise.resolve(); });+ expect(result.current.castMedia['cat-chr-x']).toHaveLength(1);+ await act(async () => { await result.current.generateFrame(cast.scenes[0]); });+ expect(generateImage.mock.calls.at(-1)[0].referenceImageFiles).toEqual(['child.png']);+ });});diff --git a/server/lib/musicVideoConditioning.js b/server/lib/musicVideoConditioning.jsindex 2917366ffe..39f7b9d02e 100644--- a/server/lib/musicVideoConditioning.js+++ b/server/lib/musicVideoConditioning.js@@ -48,6 +48,9 @@ export function sceneCastVariant(scene) {return variant && typeof variant.ingredientId === 'string' && variant.ingredientId ? variant : null;}+// A file a frame render can name as a reference (routes/imageGen.js galleryImageFilenameSchema).+const SENDABLE_REFERENCE_FILE = /^[^/\\]+\.(png|jpe?g|webp)$/i;+/*** The Casting guide images (catalogMediaLibrary.pickGuideMedia) for the cast* member a scene's `characterVariant` names, as visual-spec-shaped references.@@ -60,9 +63,10 @@ export function musicVideoCastGuideReferences(project, scene, castMedia) {const media = variant && castMedia?.[variant.ingredientId];if (!Array.isArray(media)) return [];const name = (project?.concept?.subjects || []).find((s) => s?.ingredientId === variant.ingredientId)?.name || 'Cast guide';- return pickGuideMedia(media, { age: variant.age, era: variant.era, wardrobeId: variant.wardrobeId }, MUSIC_VIDEO_MAX_CONDITIONING_REFERENCES)- // Frame renders name references by basename (routes/imageGen.js), so a nested key cannot be sent.- .filter((m) => typeof m.mediaKey === 'string' && m.mediaKey && !/[/\\]/.test(m.mediaKey))+ // Frame renders accept only a png/jpg/jpeg/webp basename (routes/imageGen.js). Filtering before+ // the pick lets the next candidate take an unsendable file's slot.+ const sendable = media.filter((m) => typeof m?.mediaKey === 'string' && SENDABLE_REFERENCE_FILE.test(m.mediaKey));+ return pickGuideMedia(sendable, { age: variant.age, era: variant.era, wardrobeId: variant.wardrobeId }, MUSIC_VIDEO_MAX_CONDITIONING_REFERENCES).map((m) => {const v = m.library?.variant || {};const detail = v.label || (Number.isInteger(v.age) ? `age ${v.age}` : v.era || '');diff --git a/server/lib/musicVideoConditioning.test.js b/server/lib/musicVideoConditioning.test.jsindex 0a29e4c15e..6a68976578 100644--- a/server/lib/musicVideoConditioning.test.js+++ b/server/lib/musicVideoConditioning.test.js@@ -35,6 +35,13 @@ describe('musicVideoConditioningReferences with Casting guides', () => {.toHaveLength(MUSIC_VIDEO_MAX_CONDITIONING_REFERENCES);});+ // Uniquely catches a guide the image route would reject (400) taking a slot a sendable guide should fill.+ it('skips guides a frame render cannot name, letting the next candidate take the slot', () => {+ const media = { [CAST_ID]: [guide('child.gif', 7), guide('nested/child.png', 7), guide('teen.png', 17)] };+ expect(ids(musicVideoConditioningReferences(project(authored), { characterVariant: { ingredientId: CAST_ID, age: 7 } }, media)))+ .toEqual(['teen.png', 'lead.png', 'set.png']);+ });+it('is unchanged without a variant or before the cast media loads', () => {const today = ids(musicVideoConditioningReferences(project(authored), {}));expect(today).toEqual(['lead.png', 'set.png']);