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: recover job completion updates and audio cue busy state (#9941)
[._.]/ Adam Eivyc04462f832f8
diff --git a/client/src/components/pipeline/stages/AudioStage.jsx b/client/src/components/pipeline/stages/AudioStage.jsxindex 99899a3f86..9dd74d8895 100644--- a/client/src/components/pipeline/stages/AudioStage.jsx+++ b/client/src/components/pipeline/stages/AudioStage.jsx@@ -404,18 +404,24 @@ export default function AudioStage({ issue, onStageUpdate }) {// serializing avoids thrashing the single sidecar).const handleRenderAllCues = async () => {setRenderingAllCues(true);- let rendered = 0;- for (let i = 0; i < cues.length; i += 1) {- const effectivePrompt = cuePromptDrafts[i] !== undefined ? cuePromptDrafts[i] : (cues[i]?.prompt || '');- if (!effectivePrompt.trim()) continue;- // Skip cues whose engine isn't installed — the per-cue button would block- // them, so render-all should too rather than firing a doomed request.- if (!engineForCue(cues[i])?.ready) continue;- const ok = await renderOneCue(i, cuePromptDrafts[i]);- if (ok) rendered += 1;+ try {+ let rendered = 0;+ for (let i = 0; i < cues.length; i += 1) {+ const effectivePrompt = cuePromptDrafts[i] !== undefined ? cuePromptDrafts[i] : (cues[i]?.prompt || '');+ if (!effectivePrompt.trim()) continue;+ // Skip cues whose engine isn't installed — the per-cue button would block+ // them, so render-all should too rather than firing a doomed request.+ if (!engineForCue(cues[i])?.ready) continue;+ const ok = await renderOneCue(i, cuePromptDrafts[i]);+ if (ok) rendered += 1;+ }+ if (rendered > 0) toast.success(`Rendered ${rendered} cue${rendered === 1 ? '' : 's'}`);+ } catch (err) {+ console.error(`❌ Render all cues follow-up failed: ${err?.message || 'Unknown error'}`);+ toast.error('Could not finish updating audio cues — reload to see the result');+ } finally {+ setRenderingAllCues(false);}- setRenderingAllCues(false);- if (rendered > 0) toast.success(`Rendered ${rendered} cue${rendered === 1 ? '' : 's'}`);};const loadMusicLibrary = async () => {diff --git a/client/src/components/pipeline/stages/AudioStage.test.jsx b/client/src/components/pipeline/stages/AudioStage.test.jsxindex 079d6b00f0..26de017a8c 100644--- a/client/src/components/pipeline/stages/AudioStage.test.jsx+++ b/client/src/components/pipeline/stages/AudioStage.test.jsx@@ -30,6 +30,7 @@ vi.mock('../../ui/Toast', () => ({vi.mock('../../voice/VoicePicker', () => ({ default: () => null }));import AudioStage from './AudioStage';+import toast from '../../ui/Toast';import {updatePipelineIssue,generatePipelineAudioCues,@@ -160,6 +161,26 @@ describe('AudioStage — whole-episode audio (#863)', () => {));});+ it('releases Render all cues after the stage update callback throws', async () => {+ const cues = [{ id: 'cue-1', label: 'Act I', prompt: 'warm pads' }];+ const issue = makeIssue({ audioMode: 'generated', cues });+ const onStageUpdate = vi.fn(() => { throw new Error('Synthetic update failure'); });+ const log = vi.spyOn(console, 'error').mockImplementation(() => {});+ let finishRender;+ renderPipelineAudioCue.mockImplementationOnce(() => new Promise(resolve => { finishRender = resolve; }));+ render(<AudioStage issue={issue} onStageUpdate={onStageUpdate} />);+ const button = screen.getByRole('button', { name: /Render all cues/i });+ await waitFor(() => expect(button).toBeEnabled());+ await userEvent.click(button);+ expect(button).toBeDisabled();+ await act(async () => { finishRender({ issue, stage: { cues } }); });+ expect(onStageUpdate).toHaveBeenCalledOnce();+ expect(button).toBeEnabled();+ expect(toast.error).toHaveBeenCalledWith('Could not finish updating audio cues — reload to see the result');+ expect(toast.success).not.toHaveBeenCalled();+ log.mockRestore();+ });+it('serializes overlapping cue-prompt saves so neither edit clobbers the other', async () => {const cues = [{ id: 'cue-1', label: 'Act I', prompt: 'a0' },diff --git a/client/src/hooks/useSseJobSlot.js b/client/src/hooks/useSseJobSlot.jsindex e5418a1819..58761f05c2 100644--- a/client/src/hooks/useSseJobSlot.js+++ b/client/src/hooks/useSseJobSlot.js@@ -83,9 +83,19 @@ export default function useSseJobSlot({if (['complete', 'error', 'canceled', 'cancelled'].includes(latest.type)) onSettled?.(latest.type, job.context);if (latest.type === 'complete') {clearJob();- onComplete?.(latest, job.context);- const msg = successToast?.(latest);- if (msg) toast.success(msg);+ // Completion follow-ups may throw synchronously or return a rejected+ // promise. Own both failures after releasing the slot.+ const finish = async () => {+ try {+ await onComplete?.(latest, job.context);+ const msg = successToast?.(latest);+ if (msg) toast.success(msg);+ } catch (err) {+ console.error(`❌ Job completion follow-up failed: ${err?.message || 'Unknown error'}`);+ toast.error('Finished, but the page could not update — reload to see the result');+ }+ };+ void finish();} else if (latest.type === 'error') {clearJob();if (!onErrorFrame?.(latest, job.context)) {diff --git a/client/src/hooks/useSseJobSlot.test.jsx b/client/src/hooks/useSseJobSlot.test.jsxindex 8fa18789bc..7761d4b0fb 100644--- a/client/src/hooks/useSseJobSlot.test.jsx+++ b/client/src/hooks/useSseJobSlot.test.jsx@@ -12,7 +12,7 @@ beforeEach(() => {MockEventSource.reset();vi.stubGlobal('EventSource', MockEventSource);});-afterEach(() => vi.unstubAllGlobals());+afterEach(() => { vi.unstubAllGlobals(); vi.restoreAllMocks(); });// Direct starts in the same React turn uniquely exercise the synchronous guard;// a rendered disabled button cannot cover a retained callback invoked twice.@@ -96,3 +96,28 @@ it.each(['complete', 'error', 'canceled', 'disconnected'])('settles %s once agaiexpect(result.current.active).toBe(false);expect(onSettled).toHaveBeenCalledExactlyOnceWith(reason, 'synthetic-project');});++// A real terminal SSE frame must release the slot without unmounting its+// consumer even when the consumer's completion follow-up fails.+it.each(['throw', 'reject'])('recovers a completion callback %s and accepts the next job', async (failure) => {+ const error = new Error('Synthetic update failure');+ const onComplete = vi.fn(() => {+ if (failure === 'throw') throw error;+ return Promise.reject(error);+ });+ const log = vi.spyOn(console, 'error').mockImplementation(() => {});+ const { result } = renderHook(() => useSseJobSlot({+ eventsUrl: id => `/events/${id}`, onComplete, successToast: () => 'Finished',+ }), { wrapper: StrictMode });+ act(() => result.current.attach('first-job', 'first-target'));+ await act(async () => { lastEventSource().emit({ type: 'complete' }); });+ expect(result.current.active).toBe(false);+ expect(result.current.jobId).toBeNull();+ expect(onComplete).toHaveBeenCalledExactlyOnceWith({ type: 'complete' }, 'first-target');+ expect(log).toHaveBeenCalledWith('❌ Job completion follow-up failed: Synthetic update failure');+ expect(toast.error).toHaveBeenCalledWith('Finished, but the page could not update — reload to see the result');+ expect(toast.success).not.toHaveBeenCalled();+ act(() => { expect(result.current.attach('next-job', 'next-target')).toBe(true); });+ expect(result.current.active).toBe(true);+ expect(lastEventSource().url).toBe('/events/next-job');+});