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: wire first-pass music-bed flag through to the client, and close a cancel-before-spawn race
[._.]/ Adam Eivycf1d32e5e902
diff --git a/client/src/components/creative-director/OverviewTab.jsx b/client/src/components/creative-director/OverviewTab.jsxindex b7429ae51e..cacafe0e96 100644--- a/client/src/components/creative-director/OverviewTab.jsx+++ b/client/src/components/creative-director/OverviewTab.jsx@@ -17,6 +17,11 @@ export default function OverviewTab({ project, onProjectUpdate }) {// on-model. Off by default — opt into the autonomy. Independent of compose:// portraits are useful with or without an auto-written treatment.const [generateFirstPass, setGenerateFirstPass] = useState(false);+ // First-pass music bed (#1928, split from #1867): when checked, auto-cast+ // also enqueues a background music-bed render for the project itself. Off by+ // default — opt into the autonomy. Independent of the other toggles: there's+ // no "newly-cast member" requirement, so it's offered even on a re-cast.+ const [generateFirstPassMusicBed, setGenerateFirstPassMusicBed] = useState(false);// Track the project id this tab is currently mounted for. If the user// toggles audio and navigates to a different CD project before the PATCH// resolves, the late `.then()` would otherwise call onProjectUpdate on@@ -43,6 +48,8 @@ export default function OverviewTab({ project, onProjectUpdate }) {setComposeAfter(false);// First-pass toggle is per-project intent too — reset on switch.setGenerateFirstPass(false);+ // First-pass music-bed toggle is per-project intent too — reset on switch.+ setGenerateFirstPassMusicBed(false);}, [project.id]);useEffect(() => {if (!savingRef.current) {@@ -90,6 +97,7 @@ export default function OverviewTab({ project, onProjectUpdate }) {{...(wantCompose ? { compose: true } : {}),...(generateFirstPass ? { generateFirstPass: true } : {}),+ ...(generateFirstPassMusicBed ? { generateFirstPassMusicBed: true } : {}),},{ silent: true },)@@ -98,6 +106,7 @@ export default function OverviewTab({ project, onProjectUpdate }) {const added = result?.added?.length || 0;const composing = Boolean(result?.composing);const firstPassQueued = result?.firstPass?.enqueued?.length || 0;+ const musicBedQueued = Boolean(result?.firstPassMusicBed?.enqueued);// When the director starts composing, optimistically flip the status to// 'planning' as well — the detail page disables polling for 'draft'// projects, so without this the treatment + runs the agent produces stay@@ -106,15 +115,19 @@ export default function OverviewTab({ project, onProjectUpdate }) {cast: result?.project?.cast || [],...(composing ? { status: 'planning' } : {}),});- // Suffix the portrait-gen count onto whichever success toast fires, so a- // user who opted into first-pass gen sees it kicked off in one place.+ // Suffix the portrait-gen count + music-bed status onto whichever+ // success toast fires, so a user who opted into either first-pass gen+ // sees it kicked off in one place.const portraitSuffix = firstPassQueued > 0? ` — rendering ${firstPassQueued} first-pass portrait${firstPassQueued === 1 ? '' : 's'}`: '';+ const musicBedSuffix = musicBedQueued ? ' + a first-pass music bed' : '';if (composing) {- toast.success(`Auto-cast added ${added} ingredient${added === 1 ? '' : 's'} — director is composing the treatment…${portraitSuffix}`);+ toast.success(`Auto-cast added ${added} ingredient${added === 1 ? '' : 's'} — director is composing the treatment…${portraitSuffix}${musicBedSuffix}`);} else if (added > 0) {- toast.success(`Auto-cast added ${added} ingredient${added === 1 ? '' : 's'}${portraitSuffix}`);+ toast.success(`Auto-cast added ${added} ingredient${added === 1 ? '' : 's'}${portraitSuffix}${musicBedSuffix}`);+ } else if (musicBedQueued) {+ toast.success(`Auto-cast found no new catalog matches for this brief${musicBedSuffix}`);} else {toast.info('Auto-cast found no new catalog matches for this brief');}@@ -158,6 +171,12 @@ export default function OverviewTab({ project, onProjectUpdate }) {</div></div><Field label="Collection" value={project.collectionId ? <Link to={collectionLink} className="text-port-accent">{project.collectionId}</Link> : <span className="text-port-text-muted">—</span>} />+ {project.musicBed?.filename && (+ <Field+ label="Music bed"+ value={`${project.musicBed.filename}${project.musicBed.durationSec ? ` (${Math.round(project.musicBed.durationSec)}s, ${project.musicBed.engine || 'audio-gen'})` : ''}`}+ />+ )}<Field label="Final video" value={final} />{project.timelineProjectId && (<Field label="Timeline" value={<Link to={`/media/timeline/${project.timelineProjectId}`} className="text-port-accent">{project.timelineProjectId}</Link>} />@@ -223,6 +242,25 @@ export default function OverviewTab({ project, onProjectUpdate }) {/><span>+ portraits</span></label>+ {/* First-pass music bed (#1928, split from #1867): enqueue a+ background music-bed render for the project itself. No+ catalog ingredient to attach to, so the result lands on+ project.musicBed via a durable server-side hook instead. */}+ <label+ htmlFor="cd-first-pass-music-bed"+ className="flex items-center gap-1 text-xs text-port-text-muted cursor-pointer"+ title="After seeding the cast, queue a first-pass music-bed render for the project (local audio-gen only)"+ >+ <input+ id="cd-first-pass-music-bed"+ type="checkbox"+ checked={generateFirstPassMusicBed}+ onChange={(e) => setGenerateFirstPassMusicBed(e.target.checked)}+ disabled={autoCasting}+ className="accent-port-accent"+ />+ <span>+ music bed</span>+ </label><buttontype="button"onClick={handleAutoCast}diff --git a/client/src/components/creative-director/OverviewTab.test.jsx b/client/src/components/creative-director/OverviewTab.test.jsxindex b203ae320b..90f7a99000 100644--- a/client/src/components/creative-director/OverviewTab.test.jsx+++ b/client/src/components/creative-director/OverviewTab.test.jsx@@ -193,3 +193,78 @@ describe('OverviewTab first-pass gen (#1818)', () => {expect(toast.success).toHaveBeenCalledWith(expect.not.stringMatching(/first-pass portrait/i));});});++describe('OverviewTab first-pass music bed (#1928)', () => {+ it('offers the +music bed toggle independent of cast/treatment state', () => {+ renderTab(baseProject);+ expect(screen.getByLabelText(/\+ music bed/i)).toBeTruthy();+ });++ it('passes generateFirstPassMusicBed:true when the toggle is checked', async () => {+ applyCreativeDirectorAutoCast.mockResolvedValue({ project: { id: 'cd-1', cast: [] }, added: [], suggestions: [] });+ renderTab(baseProject);+ fireEvent.click(screen.getByLabelText(/\+ music bed/i));+ fireEvent.click(screen.getByRole('button', { name: /^Auto-cast$/i }));+ await waitFor(() => expect(applyCreativeDirectorAutoCast).toHaveBeenCalledWith('cd-1', { generateFirstPassMusicBed: true }, { silent: true }));+ });++ it('combines portraits + music bed when both toggles are checked', async () => {+ applyCreativeDirectorAutoCast.mockResolvedValue({ project: { id: 'cd-1', cast: [] }, added: [], suggestions: [] });+ renderTab(baseProject);+ fireEvent.click(screen.getByLabelText(/\+ portraits/i));+ fireEvent.click(screen.getByLabelText(/\+ music bed/i));+ fireEvent.click(screen.getByRole('button', { name: /^Auto-cast$/i }));+ await waitFor(() => expect(applyCreativeDirectorAutoCast).toHaveBeenCalledWith(+ 'cd-1', { generateFirstPass: true, generateFirstPassMusicBed: true }, { silent: true },+ ));+ });++ it('suffixes the music-bed status onto the success toast when it enqueued', async () => {+ applyCreativeDirectorAutoCast.mockResolvedValue({+ project: { id: 'cd-1', cast: [{ ingredientId: 'p1', name: 'The Spire' }] },+ added: [{ ingredientId: 'p1', name: 'The Spire' }],+ suggestions: [],+ firstPassMusicBed: { mode: 'musicgen', enqueued: true, jobId: 'job-1' },+ });+ renderTab(baseProject);+ fireEvent.click(screen.getByLabelText(/\+ music bed/i));+ fireEvent.click(screen.getByRole('button', { name: /^Auto-cast$/i }));+ await waitFor(() => expect(toast.success).toHaveBeenCalledWith(expect.stringMatching(/first-pass music bed/i)));+ });++ it('omits the flag and music-bed suffix when the toggle is unchecked', async () => {+ applyCreativeDirectorAutoCast.mockResolvedValue({+ project: { id: 'cd-1', cast: [{ ingredientId: 'p1', name: 'The Spire' }] },+ added: [{ ingredientId: 'p1', name: 'The Spire' }],+ suggestions: [],+ });+ renderTab(baseProject);+ fireEvent.click(screen.getByRole('button', { name: /^Auto-cast$/i }));+ await waitFor(() => expect(applyCreativeDirectorAutoCast).toHaveBeenCalledWith('cd-1', {}, { silent: true }));+ expect(toast.success).toHaveBeenCalledWith(expect.not.stringMatching(/music bed/i));+ });++ it('resets the toggle when the project switches', () => {+ const { rerender } = renderTab(baseProject);+ fireEvent.click(screen.getByLabelText(/\+ music bed/i));+ expect(screen.getByLabelText(/\+ music bed/i)).toHaveProperty('checked', true);+ rerender(<MemoryRouter><OverviewTab project={{ ...baseProject, id: 'cd-2' }} onProjectUpdate={() => {}} /></MemoryRouter>);+ expect(screen.getByLabelText(/\+ music bed/i)).toHaveProperty('checked', false);+ });+});++describe('OverviewTab music bed field display (#1928)', () => {+ it('shows nothing when the project has no music bed yet', () => {+ renderTab(baseProject);+ expect(screen.queryByText('Music bed')).toBeNull();+ });++ it('shows the filename + duration + engine once the durable hook attaches one', () => {+ renderTab({+ ...baseProject,+ musicBed: { filename: 'music-gen-abc.wav', durationSec: 12.4, engine: 'musicgen', modelId: 'musicgen-medium' },+ });+ expect(screen.getByText('Music bed')).toBeTruthy();+ expect(screen.getByText(/music-gen-abc\.wav \(12s, musicgen\)/)).toBeTruthy();+ });+});diff --git a/client/src/services/apiCreativeDirector.js b/client/src/services/apiCreativeDirector.jsindex 36f8e90910..ea5aaac694 100644--- a/client/src/services/apiCreativeDirector.js+++ b/client/src/services/apiCreativeDirector.js@@ -48,7 +48,10 @@ export const suggestCreativeDirectorAutoCast = (brief, { types, limit } = {}, op// `generateFirstPass: true` (#1818) additionally enqueues a catalog portrait// render for each newly-cast member lacking one — the response carries a// `firstPass: { mode, enqueued, skipped }` summary when it ran.-export const applyCreativeDirectorAutoCast = (id, { brief, types, limit, compose, generateFirstPass } = {}, options = {}) =>+// `generateFirstPassMusicBed: true` (#1928) additionally enqueues a background+// music-bed render for the project itself — the response carries a+// `firstPassMusicBed: { mode, enqueued, jobId?, reason? }` summary when it ran.+export const applyCreativeDirectorAutoCast = (id, { brief, types, limit, compose, generateFirstPass, generateFirstPassMusicBed } = {}, options = {}) =>request(`/creative-director/${encodeURIComponent(id)}/auto-cast`, {method: 'POST',body: JSON.stringify({@@ -57,6 +60,7 @@ export const applyCreativeDirectorAutoCast = (id, { brief, types, limit, compose...(limit ? { limit } : {}),...(compose ? { compose: true } : {}),...(generateFirstPass ? { generateFirstPass: true } : {}),+ ...(generateFirstPassMusicBed ? { generateFirstPassMusicBed: true } : {}),}),...options,});diff --git a/server/services/pipeline/musicGen.js b/server/services/pipeline/musicGen.jsindex 44e2db95d8..44e713085b 100644--- a/server/services/pipeline/musicGen.js+++ b/server/services/pipeline/musicGen.js@@ -335,6 +335,17 @@ export async function generateMusic({ prompt, lyrics, engine: engineId = DEFAULT// lifecycle), so they resolve a structured result instead.function runSidecarProcess({ bin, args, env, signal, engineId = DEFAULT_ENGINE_ID, onActivity }) {return new Promise((resolve) => {+ // A cancel arriving between the caller awaiting up to here and this Promise+ // executor running (e.g. the audio job-kind adapter's controller is aborted+ // in the same tick it was created) would otherwise be silently missed —+ // the 'abort' listener below is only attached AFTER spawn, so an+ // already-aborted signal would let the sidecar spawn, run to completion,+ // and report success despite the cancel. Check synchronously before+ // spawning anything.+ if (signal?.aborted) {+ resolve({ ok: false, reason: 'cancelled (aborted before spawn)', stdout: '' });+ return;+ }const proc = spawn(bin, args, { env, stdio: ['ignore', 'pipe', 'pipe'] });let stdout = '';let stderrTail = '';diff --git a/server/services/pipeline/musicGen.test.js b/server/services/pipeline/musicGen.test.jsindex bb736b7825..7e5d5e660e 100644--- a/server/services/pipeline/musicGen.test.js+++ b/server/services/pipeline/musicGen.test.js@@ -392,6 +392,14 @@ describe('generateMusic backend selection', () => {await expect(generateMusic({ prompt: 'x' })).rejects.toMatchObject({ status: 500, code: 'PIPELINE_MUSIC_GEN_FAILED' });});++ it('never spawns when the signal is already aborted (cancel raced the call)', async () => {+ const controller = new AbortController();+ controller.abort();+ await expect(generateMusic({ prompt: 'x', signal: controller.signal }))+ .rejects.toMatchObject({ status: 500, code: 'PIPELINE_MUSIC_GEN_FAILED' });+ expect(spawnCalls).toHaveLength(0);+ });});describe('isEngineReady', () => {