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
fix: serialize linked storyboard updates and preserve active issue edits
[._.]/ Adam Eivy3ec21d1189d6
diff --git a/client/src/components/pipeline/stages/StoryboardsStage.jsx b/client/src/components/pipeline/stages/StoryboardsStage.jsxindex 06be38a447..cf770e44c5 100644--- a/client/src/components/pipeline/stages/StoryboardsStage.jsx+++ b/client/src/components/pipeline/stages/StoryboardsStage.jsx@@ -49,6 +49,16 @@ const STORYBOARD_CHANGE_EVENTS = ['storyboard:changed'];export default function StoryboardsStage({ issue, series, onStageUpdate, actionsGated = false }) {const navigate = useNavigate();+ const mounted = useMounted();+ // A new scope also invalidates requests when leaving and returning to the same issue.+ const requestScope = useRef({ issueId: issue.id });+ if (requestScope.current.issueId !== issue.id) requestScope.current = { issueId: issue.id };+ const boardOpenRef = useRef(null);+ const boardUpdateRef = useRef(null);+ const [boardOpen, setBoardOpen] = useState(null);+ const [boardUpdate, setBoardUpdate] = useState(null);+ const openingBoard = boardOpen?.scope === requestScope.current;+ const updatingFromBoard = boardUpdate?.scope === requestScope.current ? boardUpdate.shotId : null;const stage = issue.stages?.storyboards || { status: 'empty', scenes: [] };const [scenes, setScenes] = useState(stage.scenes || []);// Scene index currently minting a blank sketch (so its button shows a spinner@@ -115,6 +125,7 @@ export default function StoryboardsStage({ issue, series, onStageUpdate, actionsconst extractInFlight = !!extractingFrom;const persist = async (nextScenes) => {+ if (boardUpdateRef.current?.scope === requestScope.current) return false;setScenes(nextScenes);// Keep the ref coherent for every write path (not just the ones that set it// explicitly), so a discrete pick fired between a persist and the next@@ -133,11 +144,15 @@ export default function StoryboardsStage({ issue, series, onStageUpdate, actions// Open in storyboard editor: the issue's linked board in Create › Storyboards// (made from these scenes the first time), where recipes make panel art.- const [openingBoard, setOpeningBoard] = useState(false);const openBoard = async () => {- setOpeningBoard(true);+ if (boardOpenRef.current?.scope === requestScope.current) return;+ const request = { scope: requestScope.current };+ boardOpenRef.current = request;+ setBoardOpen(request);const res = await openStoryboardForPipelineIssue(issue.id).catch(() => null);- setOpeningBoard(false);+ if (!mounted.current || requestScope.current !== request.scope || boardOpenRef.current !== request) return;+ boardOpenRef.current = null;+ setBoardOpen(null);if (res?.boardId) navigate(`/storyboards/${encodeURIComponent(res.boardId)}`);};@@ -150,24 +165,16 @@ export default function StoryboardsStage({ issue, series, onStageUpdate, actionsmatchesEvent: event => !boardChanges?.boardId || event?.id === boardChanges.boardId,},);- const mounted = useMounted();- const boardUpdateRef = useRef({ issueId: issue.id, generation: 0, pending: false });- if (boardUpdateRef.current.issueId !== issue.id) {- boardUpdateRef.current = { issueId: issue.id, generation: boardUpdateRef.current.generation + 1, pending: false };- }- const [boardUpdate, setBoardUpdate] = useState(null);- const updatingFromBoard = boardUpdate?.issueId === issue.id && boardUpdate.generation === boardUpdateRef.current.generation- ? boardUpdate.shotId : null;const changedShots = useMemo(() => new Map((boardChanges?.changed || []).map((c) => [c.shotId, c])), [boardChanges]);const boardLocked = stage.locked === true;const updateFromBoard = async (shotId = null) => {- if (boardUpdateRef.current.pending) return;- const request = { issueId: issue.id, generation: boardUpdateRef.current.generation + 1, pending: true };+ if (boardUpdateRef.current?.scope === requestScope.current) return;+ const request = { scope: requestScope.current, shotId: shotId || 'all' };boardUpdateRef.current = request;- setBoardUpdate({ ...request, shotId: shotId || 'all' });+ setBoardUpdate(request);const res = await updatePipelineShotsFromBoard(issue.id, shotId).catch(() => null);- if (!mounted.current || boardUpdateRef.current !== request) return;- boardUpdateRef.current = { ...request, pending: false };+ if (!mounted.current || requestScope.current !== request.scope || boardUpdateRef.current !== request) return;+ boardUpdateRef.current = null;setBoardUpdate(null);if (!res) return;const { updated, issue: saved, ...changes } = res;@@ -503,7 +510,7 @@ export default function StoryboardsStage({ issue, series, onStageUpdate, actions};return (- <div className="space-y-4">+ <fieldset disabled={!!updatingFromBoard} className="min-w-0 space-y-4"><div className="flex items-center justify-between gap-3 flex-wrap"><div><h2 className="text-lg font-semibold text-white">Storyboards</h2>@@ -744,7 +751,7 @@ export default function StoryboardsStage({ issue, series, onStageUpdate, actions))}</ul>)}- </div>+ </fieldset>);}diff --git a/client/src/components/pipeline/stages/StoryboardsStage.test.jsx b/client/src/components/pipeline/stages/StoryboardsStage.test.jsxindex e2e477d25c..4379cdcbc0 100644--- a/client/src/components/pipeline/stages/StoryboardsStage.test.jsx+++ b/client/src/components/pipeline/stages/StoryboardsStage.test.jsx@@ -6,10 +6,11 @@ const api = vi.hoisted(() => ({openStoryboardForPipelineIssue: vi.fn(),getPipelineStoryboardChanges: vi.fn(async () => ({ boardId: null, locked: false, changed: [] })),updatePipelineShotsFromBoard: vi.fn(),+ updatePipelineIssue: vi.fn(),}));vi.mock('../../../services/api', () => {const rest = ['generatePipelineVisualImage', 'generatePipelineSceneVideo', 'generatePipelineShotStartFrame',- 'refinePipelineSceneImagePrompt', 'generatePipelineSceneImagePrompts', 'updatePipelineIssue',+ 'refinePipelineSceneImagePrompt', 'generatePipelineSceneImagePrompts','extractPipelineStoryboardScenes', 'createBlankSketch'];return { ...api, ...Object.fromEntries(rest.map((name) => [name, vi.fn()])) };});@@ -106,4 +107,39 @@ describe('StoryboardsStage', () => {await act(async () => { finishUpdate({ updated: 1, issue: withShot, boardId: 'sb-1', locked: false, changed: [] }); });expect(onStageUpdate).not.toHaveBeenCalled();});++ it('holds scene edits and saves while a storyboard update is pending', async () => {+ const withShot = { ...issue, stages: { storyboards: { status: 'edited', scenes: [{ ...issue.stages.storyboards.scenes[0], shots: [{ id: 'shot-01', description: 'Wide of the lab', durationSeconds: 5 }] }] } } };+ api.getPipelineStoryboardChanges.mockResolvedValueOnce({ boardId: 'sb-1', locked: false,+ changed: [{ sceneId: 'scene-01', shotId: 'shot-01', panelId: 'panel-1', fields: ['description'] }] });+ let finishUpdate;+ api.updatePipelineShotsFromBoard.mockImplementationOnce(() => new Promise(resolve => { finishUpdate = resolve; }));+ render(<MemoryRouter><StoryboardsStage issue={withShot} series={null} onStageUpdate={vi.fn()} /></MemoryRouter>);+ fireEvent.click(await screen.findByRole('button', { name: 'Update' }));+ try {+ expect(screen.getByDisplayValue('Wide of the lab')).toBeDisabled();+ expect(screen.getByLabelText('Scene 1 slugline')).toBeDisabled();+ expect(screen.getByRole('button', { name: 'Add scene' })).toBeDisabled();+ fireEvent.blur(screen.getByDisplayValue('Wide of the lab'));+ expect(api.updatePipelineIssue).not.toHaveBeenCalled();+ } finally {+ await act(async () => { finishUpdate({ updated: 1, issue: withShot, boardId: 'sb-1', locked: false, changed: [] }); });+ }+ expect(screen.getByDisplayValue('Wide of the lab')).toBeEnabled();+ });++ it('does not leave the newly selected issue when an earlier Open request finishes', async () => {+ let finishOpen;+ api.openStoryboardForPipelineIssue.mockImplementationOnce(() => new Promise(resolve => { finishOpen = resolve; }));+ const element = selectedIssue => <MemoryRouter><Routes>+ <Route path="/" element={<StoryboardsStage issue={selectedIssue} series={null} onStageUpdate={vi.fn()} />} />+ <Route path="/storyboards/:id" element={<p>Earlier issue storyboard</p>} />+ </Routes></MemoryRouter>;+ const view = render(element(issue));+ fireEvent.click(screen.getByRole('button', { name: /Open in storyboard editor/ }));+ view.rerender(element({ ...issue, id: 'iss-2' }));+ await act(async () => { finishOpen({ boardId: 'sb-earlier', created: true }); });+ expect(screen.queryByText('Earlier issue storyboard')).not.toBeInTheDocument();+ expect(screen.getByRole('button', { name: /Open in storyboard editor/ })).toBeInTheDocument();+ });});diff --git a/server/services/storyboards/fromPipeline.js b/server/services/storyboards/fromPipeline.jsindex 88ec4d1b07..bfb85a363a 100644--- a/server/services/storyboards/fromPipeline.js+++ b/server/services/storyboards/fromPipeline.js@@ -18,12 +18,14 @@ import { ServerError } from '../../lib/errorHandler.js';import { STORYBOARD_LIMITS as L, STORYBOARD_PANEL_FRAMINGS } from '../../lib/storyboardVocabulary.js';import { trimTo } from '../../lib/textUtils.js';import { storyboardRev } from '../../lib/storyboardFit.js';+import { createRecordWriteQueue } from '../../lib/fileWriteQueue.js';import { createStoryboard, getStoryboard, listStoryboards, mutateStoryboard } from './index.js';const FRAMINGS = new Set(STORYBOARD_PANEL_FRAMINGS);const SKETCH_KEY = /^sketch:[A-Za-z0-9-]{1,80}$/;const SHOT_SECONDS_MAX = 30;+const queueBoardOpen = createRecordWriteQueue();const panelRev = (panel) => storyboardRev([panel.action, panel.framing, panel.seconds]);@@ -66,6 +68,10 @@ async function linkedBoardId(issueId) {}export async function openStoryboardForPipelineIssue(issueId) {+ return queueBoardOpen(issueId, () => openLinkedStoryboard(issueId));+}++async function openLinkedStoryboard(issueId) {const { getIssue } = await import('../pipeline/issues.js');const issue = await getIssue(issueId);const linked = await linkedBoardId(issue.id);@@ -164,29 +170,33 @@ export async function updatePipelineShotsFromBoard(issueId, { shotId = null } =.filter((panel) => (!shotId || panel.sourceShotId === shotId) && editedOnBoard(panel)).map((panel) => [shotKey(panel.sourceSceneId, panel.sourceShotId), panel]));let taken = new Map();+ let updated = 0;const { issue: saved } = await updateStageWithLatest(issue.id, 'storyboards', (stage) => {assertStageUnlocked({ stages: { storyboards: stage } }, 'storyboards');taken = new Map();+ updated = 0;const scenes = (Array.isArray(stage?.scenes) ? stage.scenes : []).map((scene) => {if (!Array.isArray(scene?.shots)) return scene;return {...scene,shots: scene.shots.map((shot) => {const panel = panels.get(shotKey(scene.id, shot?.id));- const patch = panel ? panelShotPatch(panel, shot) : {};- if (!Object.keys(patch).length) return shot;+ if (!panel) return shot;taken.set(panel.id, panelRev(panel));+ const patch = panelShotPatch(panel, shot);+ if (!Object.keys(patch).length) return shot;+ updated++;return { ...shot, ...patch };}),};});- return taken.size ? { scenes } : {};+ return updated ? { scenes } : {};});if (taken.size) {await mutateStoryboard(boardId, (draft) => {for (const panel of shotPanels(draft)) if (taken.has(panel.id)) panel.sourceRev = taken.get(panel.id);});- console.log(`🎬 Pipeline issue ${issue.id}: ${taken.size} shot(s) updated from storyboard ${boardId}`);+ console.log(`🎬 Pipeline issue ${issue.id}: ${updated} shot(s) updated from storyboard ${boardId}`);}- return { updated: taken.size, issue: saved, ...(await pipelineStoryboardChanges(issue.id)) };+ return { updated, issue: saved, ...(await pipelineStoryboardChanges(issue.id)) };}diff --git a/server/services/storyboards/fromPipeline.test.js b/server/services/storyboards/fromPipeline.test.jsindex 3f7500a7cd..8bae7087a9 100644--- a/server/services/storyboards/fromPipeline.test.js+++ b/server/services/storyboards/fromPipeline.test.js@@ -120,4 +120,29 @@ describe('storyboard from a pipeline issue', () => {const res = await request(app).post('/api/storyboards/from-pipeline/iss-empty');expect([res.status, res.body.code]).toEqual([400, 'NO_SCENES']);});++ it('acknowledges an edited panel already matching its shot before later stage edits', async () => {+ seed('iss-equal', { scenes: [{ id: 'scene-equal', shots: [+ { id: 'shot-equal', description: 'Original action', shotType: 'wide', durationSeconds: 5 },+ ] }] });+ const { boardId } = (await request(app).post('/api/storyboards/from-pipeline/iss-equal')).body;+ const board = (await request(app).get(`/api/storyboards/${boardId}`)).body;+ const panelId = board.beats[0].panels[0].id;+ await request(app).patch(`/api/storyboards/${boardId}/panels/${panelId}`).send({ action: 'Matching edit' });+ const shot = issues.get('iss-equal').stages.storyboards.scenes[0].shots[0];+ shot.description = 'Matching edit';+ const update = await request(app).post('/api/storyboards/pipeline/iss-equal/update-from-board').send({ shotId: shot.id });+ expect(update.body).toMatchObject({ updated: 0, changed: [] });+ shot.description = 'A newer stage edit';+ const changes = await request(app).get('/api/storyboards/pipeline/iss-equal/changes');+ expect(changes.body.changed).toEqual([]);+ });++ it('returns one linked board for simultaneous opens of the same issue', async () => {+ seed('iss-concurrent', { scenes: [{ id: 'scene-concurrent', description: 'One scene' }] });+ const opened = await Promise.all(Array.from({ length: 4 }, () => request(app).post('/api/storyboards/from-pipeline/iss-concurrent')));+ expect(new Set(opened.map(result => result.body.boardId)).size).toBe(1);+ expect(opened.filter(result => result.body.created)).toHaveLength(1);+ expect(opened.map(result => result.status).sort()).toEqual([200, 200, 200, 201]);+ });});