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: music video stages derive from server-provided readiness, no more 'not done' flicker (#10136)
Adam Eivydde50072de59
diff --git a/client/src/hooks/useMusicVideoProductionReview.js b/client/src/hooks/useMusicVideoProductionReview.jsindex a88c59bbca..c59abdc67f 100644--- a/client/src/hooks/useMusicVideoProductionReview.js+++ b/client/src/hooks/useMusicVideoProductionReview.js@@ -4,7 +4,12 @@ import { reverifyMusicVideoAlignment, importMusicVideoDocumentShots, getMusicVidcancelMusicVideoExcerptRender, importMusicVideoProductionPlanning, bindMusicVideoProductionShot, addMusicVideoProductionFeedback, resolveMusicVideoProductionFeedback, reviseMusicVideoProductionFromFeedback } from '../services/apiMusicVideo.js';import useSseJobSlot from './useSseJobSlot.js';-/** Server-authoritative approvals; changing any project input hides stale readiness immediately. */+/**+ * Server-authoritative approvals. A read response carries `productionReadiness`; a mutation response+ * does not, so the last readiness for the same project stays in place (never a flash of "not done")+ * while one review fetch refreshes it. Approvals still bind to the server-issued basis, so a stale+ * basis is refused rather than honoured.+ */export default function useMusicVideoProductionReview({ project, replaceProject }) {const latest = useRef(project);latest.current = project;@@ -12,11 +17,13 @@ export default function useMusicVideoProductionReview({ project, replaceProjectconst [state, setState] = useState(null);const [busy, setBusy] = useState(false);const [error, setError] = useState(null);+ const [readinessError, setReadinessError] = useState(null);useEffect(() => {let active = true;- if (project?.id) getMusicVideoProductionReview(project.id, { silent: true })- .then(result => { if (active) setState({ owner: project, readiness: result.readiness }); })- .catch(err => { if (active) setError(err.message); });+ if (project?.productionReadiness) setState({ id: project.id, readiness: project.productionReadiness });+ else if (project?.id) getMusicVideoProductionReview(project.id, { silent: true })+ .then(result => { if (active) { setState({ id: project.id, readiness: result.readiness }); setReadinessError(null); } })+ .catch(err => { if (active) setReadinessError(err.message); });return () => { active = false; };}, [project]);const refresh = async id => {@@ -49,18 +56,19 @@ export default function useMusicVideoProductionReview({ project, replaceProject} catch (err) { if (latest.current === owner) setError(err.message); return null; }finally { setBusy(false); }};- return { readiness: state?.owner === project ? state.readiness : null, busy, error, proof: { ...proof, occupied: proof.active, active: proof.active && proof.context === project?.id },- feedback: body => call(() => addMusicVideoProductionFeedback(project.id, { ...body, basis: state?.readiness.basis[body.stage] }, { silent: true })),+ const readiness = project?.productionReadiness || (state?.id === project?.id ? state.readiness : null);+ return { readiness, readinessError: readiness ? null : readinessError, busy, error, proof: { ...proof, occupied: proof.active, active: proof.active && proof.context === project?.id },+ feedback: body => call(() => addMusicVideoProductionFeedback(project.id, { ...body, basis: readiness?.basis[body.stage] }, { silent: true })),resolveFeedback: (feedbackId, resolution) => call(() => resolveMusicVideoProductionFeedback(project.id, { feedbackId, resolution }, { silent: true })),revise: stage => call(() => reviseMusicVideoProductionFromFeedback(project.id, { stage }, { silent: true })),importDocumentShots: body => call(() => importMusicVideoDocumentShots(project.id, body, { silent: true })),importPlanning: source => call(() => importMusicVideoProductionPlanning(project.id, source, { silent: true })),bindShot: shotId => call(() => bindMusicVideoProductionShot(project.id, shotId, { silent: true })),- reverifyAlignment: notes => call(() => reverifyMusicVideoAlignment(project.id, { basis: state?.readiness.alignment.basis, notes }, { silent: true })),+ reverifyAlignment: notes => call(() => reverifyMusicVideoAlignment(project.id, { basis: readiness?.alignment.basis, notes }, { silent: true })),save: draft => call(() => saveMusicVideoProductionDraft(project.id, draft, { silent: true })),prepare: () => call(() => prepareMusicVideoProductionReview(project.id, {}, { silent: true })),approve: (stage, proofReview) => call(() => approveMusicVideoProductionReview(project.id,- { stage, basis: state?.readiness.basis[stage], ...(stage === 'proof' ? { proofReview } : {}) }, { silent: true })),+ { stage, basis: readiness?.basis[stage], ...(stage === 'proof' ? { proofReview } : {}) }, { silent: true })),renderProof: window => proof.start({ id: project.id, window }, project.id),};}diff --git a/client/src/hooks/useMusicVideoProductionReview.test.jsx b/client/src/hooks/useMusicVideoProductionReview.test.jsxnew file mode 100644index 0000000000..23d8ea487d--- /dev/null+++ b/client/src/hooks/useMusicVideoProductionReview.test.jsx@@ -0,0 +1,42 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';+import { renderHook, waitFor } from '@testing-library/react';+import useMusicVideoProductionReview from './useMusicVideoProductionReview.js';++const api = vi.hoisted(() => ({+ getMusicVideoProductionReview: vi.fn(),+ reverifyMusicVideoAlignment: vi.fn(), importMusicVideoDocumentShots: vi.fn(), saveMusicVideoProductionDraft: vi.fn(),+ prepareMusicVideoProductionReview: vi.fn(), approveMusicVideoProductionReview: vi.fn(), renderMusicVideoProductionProof: vi.fn(),+ musicVideoExcerptRenderEventsUrl: vi.fn(), cancelMusicVideoExcerptRender: vi.fn(), importMusicVideoProductionPlanning: vi.fn(),+ bindMusicVideoProductionShot: vi.fn(), addMusicVideoProductionFeedback: vi.fn(), resolveMusicVideoProductionFeedback: vi.fn(),+ reviseMusicVideoProductionFromFeedback: vi.fn(),+}));+vi.mock('../services/apiMusicVideo.js', () => api);++const readiness = { art: { approved: true }, basis: {} };+const run = (project) => renderHook(({ p }) => useMusicVideoProductionReview({ project: p, replaceProject: vi.fn() }), { initialProps: { p: project } });++beforeEach(() => { vi.clearAllMocks(); api.getMusicVideoProductionReview.mockResolvedValue({ readiness }); });++describe('useMusicVideoProductionReview readiness source (#10136)', () => {+ it('uses the readiness on the read response without another request, and keeps it across a mutation response', async () => {+ const { result, rerender } = run({ id: 'a', productionReadiness: readiness });+ expect(result.current.readiness).toBe(readiness);+ rerender({ p: { id: 'a' } }); // mutation response: no readiness field+ expect(result.current.readiness).toBe(readiness);+ await waitFor(() => expect(api.getMusicVideoProductionReview).toHaveBeenCalledTimes(1));+ });++ it('never shows another project\'s readiness', async () => {+ api.getMusicVideoProductionReview.mockReturnValue(new Promise(() => {}));+ const { result, rerender } = run({ id: 'a', productionReadiness: readiness });+ rerender({ p: { id: 'b' } });+ expect(result.current.readiness).toBeNull();+ });++ it('surfaces a failed readiness fetch instead of silently reading not done', async () => {+ api.getMusicVideoProductionReview.mockRejectedValue(new Error('boom'));+ const { result } = run({ id: 'a' });+ await waitFor(() => expect(result.current.readinessError).toBe('boom'));+ expect(result.current.readiness).toBeNull();+ });+});diff --git a/client/src/pages/MusicVideo.jsx b/client/src/pages/MusicVideo.jsxindex 4f0944318c..a94a5187d6 100644--- a/client/src/pages/MusicVideo.jsx+++ b/client/src/pages/MusicVideo.jsx@@ -262,7 +262,9 @@ export default function MusicVideo() {};const progress = deriveStages(selected, productionReview.readiness, publish);const [openedStage, setOpenedStage] = useState({ id: null, stage: null });- if (selected && openedStage.id !== selected.id) setOpenedStage({ id: selected.id, stage: progress.current });+ // The opened stage waits for readiness (or its failure) so a done project never pins to Cast & Sets.+ const statusKnown = !!productionReview.readiness || !!productionReview.readinessError;+ if (selected && statusKnown && openedStage.id !== selected.id) setOpenedStage({ id: selected.id, stage: progress.current });const pinnedStage = openedStage.id === selected?.id ? openedStage.stage : null;const activeStage = resolveStageParam(routeStage) || (routeSceneId ? 'board' : (pinnedStage || progress.current));@@ -1383,7 +1385,11 @@ export default function MusicVideo() {nextAction={compositionSavePending > 0 && nextAction ? { ...nextAction, disabled: true, reason: 'Saving composition…' } : nextAction}onNextAction={runNextAction}spend={projectSpend(selected)}- status={describeProjectStatus(selected, { progress, nextAction, readiness: productionReview.readiness })}+ status={statusKnown && productionReview.readiness+ ? describeProjectStatus(selected, { progress, nextAction, readiness: productionReview.readiness })+ : statusKnown+ ? { headline: `Status unavailable: ${productionReview.readinessError}`, tone: 'warn', facts: [] }+ : { headline: 'Loading status…', tone: 'muted', facts: [] }}attention={(<NeedsAttentionBanneritems={attentionItems}diff --git a/server/routes/musicVideo.js b/server/routes/musicVideo.jsindex 92833c5436..a7b32a334c 100644--- a/server/routes/musicVideo.js+++ b/server/routes/musicVideo.js@@ -209,14 +209,20 @@ const projectUpdateSchema = musicVideoProjectUpdateSchema.extend(recordRenderPin// newest first, with a `nextCursor` — for the project index and header picker, so// they never load every project's scenes, runs and reviews.// Both pins are process-local, so only the server can say which stages a restart orphaned.-const presentProjectForRead = (project) => presentProjectAutonomousRun(presentProjectCastAndSets(project));+// Approvals decide stage completion and only the server computes them (#10136), so the read+// response carries `productionReadiness` — stages derive from one record, never "not done" while a+// second request is in flight. GET /:id/production-review still serves the full review payload.+const presentProjectForRead = (project) => {+ const presented = presentProjectAutonomousRun(presentProjectCastAndSets(project));+ return { ...presented, productionReadiness: productionReadiness(presented) };+};router.get('/', asyncHandler(async (req, res) => {const query = validateRequest(musicVideoProjectListQuerySchema, req.query);const projects = (await listProjects()).map(presentProjectForRead);if (query.summary === '1' || query.summary === 'true') {const summaries = projects.sort(compareMusicVideoProjectsNewestFirst)- .map((project) => summarizeMusicVideoProject(project, productionReadiness(project)));+ .map((project) => summarizeMusicVideoProject(project, project.productionReadiness));// The cursor is the next page's offset; `cursor` wins over `offset`.const cursor = parseInt(query.cursor, 10);const page = paginateArray(summaries, Number.isInteger(cursor) && cursor >= 0 ? { ...query, offset: String(cursor) } : query,diff --git a/server/routes/musicVideo.test.js b/server/routes/musicVideo.test.jsindex fb4e991504..834c461aaa 100644--- a/server/routes/musicVideo.test.js+++ b/server/routes/musicVideo.test.js@@ -108,7 +108,18 @@ describe('musicVideo routes', () => {it('GET / lists projects', async () => {const r = await request(app).get('/api/music-video');expect(r.status).toBe(200);- expect(r.body).toEqual([{ id: 'mv-1', name: 'A' }]);+ expect(r.body).toHaveLength(1);+ expect(r.body[0]).toMatchObject({ id: 'mv-1', name: 'A' });+ expect(r.body[0].productionReadiness).toMatchObject({ readyForProduction: false, art: { approved: false } });+ });++ it('GET /:id carries server-computed productionReadiness so stages derive from one record (#10136)', async () => {+ svc.getProject.mockResolvedValue({ id: 'mv-1', name: 'A' });+ const r = await request(app).get('/api/music-video/mv-1');+ expect(r.status).toBe(200);+ expect(r.body.productionReadiness).toMatchObject({+ art: { approved: false }, storyboard: { approved: false }, proof: { approved: false },+ });});it('GET /midi-sources returns only the newest transcription per track, trimmed (#10203)', async () => {