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: mint a stable id per pulled visual-spec reference

[._.]/ Adam Eivy0160871cf558
diff --git a/client/src/lib/musicVideoUniverseRefs.js b/client/src/lib/musicVideoUniverseRefs.js
index d4d4fd0939..c281d2ba15 100644
--- a/client/src/lib/musicVideoUniverseRefs.js
+++ b/client/src/lib/musicVideoUniverseRefs.js
@@ -1,12 +1,15 @@
// Map a linked universe's canon (characters/places/objects) onto a music
// video project's visual-spec references (#8978 "Pull from universe"). Pure
-// and read-only: the caller owns persisting the result via the ordinary
-// visualSpec PATCH (see VisualSpecPanel.jsx).
+// (aside from minting reference ids) and read-only: the caller owns
+// persisting the result via the ordinary visualSpec PATCH (see
+// VisualSpecPanel.jsx).
//
// Mirrors the server's 24-reference cap
// (server/lib/musicVideoValidation.js musicVideoVisualSpecSchema) so a pull
// can never produce a spec the server would reject.
+import { uuidv4 } from './uuid.js';
+
export const MUSIC_VIDEO_MAX_REFERENCES = 24;
// Canon kind → visual-spec reference role (server/lib/musicVideoValidation.js
@@ -50,7 +53,13 @@ export function pullUniverseCanonReferences(universe, existingReferences = []) {
if (!imageId) { skippedNoImage += 1; continue; }
if (existingIds.has(imageId)) { skippedDuplicate += 1; continue; }
existingIds.add(imageId); // two canon entries sharing one image only add it once
- candidates.push({ imageId, role, label: (entry.name || '').slice(0, 120), condition: false });
+ // Mint a client-side id per addition (the server also mints one on
+ // save, but VisualSpecPanel's row edit/remove handlers match by `r.id`
+ // against the LOCAL, optimistic list — pulling several references at
+ // once with no id would make every one of them share the same
+ // `undefined` id and collapse into a single editable/removable row
+ // until the PATCH response lands).
+ candidates.push({ id: `mvr-pull-${uuidv4()}`, imageId, role, label: (entry.name || '').slice(0, 120), condition: false });
}
}
const room = Math.max(0, MUSIC_VIDEO_MAX_REFERENCES - existingReferences.length);
diff --git a/client/src/lib/musicVideoUniverseRefs.test.js b/client/src/lib/musicVideoUniverseRefs.test.js
index f103798fae..e8eb2d3b3f 100644
--- a/client/src/lib/musicVideoUniverseRefs.test.js
+++ b/client/src/lib/musicVideoUniverseRefs.test.js
@@ -15,10 +15,14 @@ describe('pullUniverseCanonReferences', () => {
expect(added).toBe(3);
expect(skipped).toBe(1); // 'No Image' has neither primaryImageRef nor imageRefs
expect(next).toEqual([
- { imageId: 'nyra-primary.png', role: 'character', label: 'Nyra', condition: false },
- { imageId: 'harbor.png', role: 'set', label: 'Harbor', condition: false },
- { imageId: 'lantern.png', role: 'prop', label: 'Lantern', condition: false },
+ { id: expect.any(String), imageId: 'nyra-primary.png', role: 'character', label: 'Nyra', condition: false },
+ { id: expect.any(String), imageId: 'harbor.png', role: 'set', label: 'Harbor', condition: false },
+ { id: expect.any(String), imageId: 'lantern.png', role: 'prop', label: 'Lantern', condition: false },
]);
+ // Every pulled reference gets its OWN id — sharing one (e.g. all
+ // `undefined`) would make VisualSpecPanel's by-id edit/remove handlers
+ // treat several rows as a single one until the server round-trips ids.
+ expect(new Set(next.map((r) => r.id)).size).toBe(3);
});
it('is idempotent: an image already present as a reference is skipped, not duplicated', () => {
diff --git a/client/src/pages/MusicVideo.test.jsx b/client/src/pages/MusicVideo.test.jsx
index 830070d86b..eae5646181 100644
--- a/client/src/pages/MusicVideo.test.jsx
+++ b/client/src/pages/MusicVideo.test.jsx
@@ -1175,7 +1175,9 @@ describe('MusicVideo pull references from universe (#8978)', () => {
'mv-universe',
{ visualSpec: { references: [
{ id: 'r0', imageId: 'harbor.png', role: 'mood', condition: false },
- { imageId: 'nyra.png', role: 'character', label: 'Nyra', condition: false },
+ // Pulled references get their own client-minted id (not the server's
+ // stable one yet) so multiple additions never collide on `undefined`.
+ { id: expect.any(String), imageId: 'nyra.png', role: 'character', label: 'Nyra', condition: false },
] } },
{ silent: true },
));