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: log cast and sets failure-recording errors (#11452)
[._.]/ Adam Eivy2857cb7a99b7
diff --git a/server/services/musicVideo/castAndSetsBackground.test.js b/server/services/musicVideo/castAndSetsBackground.test.jsnew file mode 100644index 0000000000..1f0fc7a28a--- /dev/null+++ b/server/services/musicVideo/castAndSetsBackground.test.js@@ -0,0 +1,63 @@+/**+ * Cast & Sets background failure reporting — when a background stage throws and+ * the failure cannot be recorded on the project either, the operator still gets+ * an error line naming the project, the stage and the secondary error, while the+ * original failure line stays intact.+ */++import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';++vi.mock('./projects.js', async (importOriginal) => ({+ ...(await importOriginal()),+ getProject: vi.fn(),+ mutateProjectRecord: vi.fn(),+}));++const projects = await import('./projects.js');+const service = await import('./castAndSetsService.js');++const PROJECT_ID = 'mv-0123456789abcdef';+const project = { id: PROJECT_ID, audioAnalysis: { sections: [{ start: 0, end: 10 }] } };++describe('Cast & Sets background failure reporting', () => {+ let errorSpy;++ beforeEach(() => {+ errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});+ vi.spyOn(console, 'log').mockImplementation(() => {});+ });++ afterEach(async () => {+ await service.__settleCastAndSetsForTests();+ vi.restoreAllMocks();+ projects.getProject.mockReset();+ projects.mutateProjectRecord.mockReset();+ });++ it('logs the secondary error when recording a background failure also rejects', async () => {+ // startCastAndSets: the project loads, the start transition persists.+ projects.getProject.mockResolvedValueOnce(project);+ projects.mutateProjectRecord.mockResolvedValueOnce({+ project,+ stage: { revision: 1, status: 'directing' },+ });+ // The background direction pass fails to load the project...+ projects.getProject.mockRejectedValueOnce(new Error('project store offline'));+ // ...and then the failure record cannot be written either.+ projects.mutateProjectRecord.mockRejectedValueOnce(new Error('record write refused'));++ await service.startCastAndSets(PROJECT_ID, {});+ await service.__settleCastAndSetsForTests();++ const lines = errorSpy.mock.calls.map(([line]) => String(line));+ const original = lines.find((l) => l.includes('The creative direction failed: project store offline'));+ const secondary = lines.find((l) => l.includes('could not be recorded'));++ expect(original).toBeDefined();+ expect(secondary).toBe(+ `❌ Music Video Cast & Sets ${PROJECT_ID} The creative direction failed and its failure could not be recorded: record write refused`,+ );+ // Single-line, emoji-prefixed, on the stderr stream.+ expect(secondary.includes('\n')).toBe(false);+ });+});diff --git a/server/services/musicVideo/castAndSetsService.js b/server/services/musicVideo/castAndSetsService.jsindex 66c381fb31..b57f800ecf 100644--- a/server/services/musicVideo/castAndSetsService.js+++ b/server/services/musicVideo/castAndSetsService.js@@ -485,7 +485,7 @@ async function advanceOnce(projectId) {function inBackground(label, projectId, fn) {const work = Promise.resolve().then(fn).catch(async (err) => {console.error(`❌ Music Video Cast & Sets ${short(projectId)} ${label} failed: ${err.message}`);- await fail(projectId, `${label} failed: ${err.message}`).catch(() => {});+ await fail(projectId, `${label} failed: ${err.message}`).catch((recordErr) => console.error(`❌ Music Video Cast & Sets ${projectId} ${label} failed and its failure could not be recorded: ${recordErr.message}`));}).finally(() => backgroundWork.delete(work));backgroundWork.add(work);}