Skip to content

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

feat: surface music-bed output for music commission CD runs (#2772)

[._.]/ Adam Eivy1da6b3cb5357
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index adbd5c4e21..fa99d272b0 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -52,6 +52,8 @@
## Fixed
+- [issue-2772] **A scheduled Music commission now produces a track you can actually play and rate, not just a job id.** When a `music` commission's Creative Director ran, its planner enqueued the audio render but never tagged it for the project — so the finished track was never filed onto the project and the commission's run preview had nothing to show. Planner-enqueued audio jobs are now tagged the same way the first-pass music flow already was, so the durable music-bed hook files the rendered track onto the project the moment it completes (no open browser required), and the commission run preview surfaces it as an inline audio player you can play and thumbs-up/down to steer the next run. Video and image commissions are unchanged.
+
- [issue-2696] **Background jobs that finish your work through git/GitHub/Jira instead of a commit no longer report a permanent 0% success rate.** The branch-reconcile, issue-reconcile, branch-cleanup, and Jira status-report jobs deliver their result as a side effect — a merged PR, a resolved conflict, a deleted branch, a posted report — so they deliberately never make a `task-…` commit of their own. But the success check only knew how to look for that commit, so it scored every *successful* run as a failure and pinned those task types at 0% on the CoS Learning card (which in turn steered the self-improvement loop away from them on evidence that was never true). They're now judged the same way pipeline and media jobs already were — by whether the run itself succeeded — and a one-time migration clears the mis-recorded history on upgrade (and the "Backfill History" button no longer re-poisons it from the old records). This is the same measurement bug already fixed for the Layered Intelligence reasoning run; jobs that genuinely do commit their work — the accessibility audit, the Jira sprint manager, the PLAN.md replan — are unaffected and still judged on their commit, so a real failure there is never masked.
- [issue-2737] **An unattended background AI job that hits a failing provider no longer buries you in a stack of red error toasts.** Jobs that run without you watching — like the weekly goal check-in, which makes one AI call per goal at once — used to fire a separate red error toast for *every* failed call when a provider was down (an expired key, a dead endpoint, a model returning nothing). A seven-goal check-in against a broken provider meant seven stacked toasts you never saw coming. Those background failures now collapse into a single toast per provider that counts them ("Example Provider failed on 5 background AI calls"), with the first one still showing the provider's real reason. AI actions *you* triggered are unchanged: they still report their failure the instant it happens, one toast each, with the provider's actual error — so a failure you're waiting on is never aggregated away.
diff --git a/client/src/components/creative-director/ProjectPreview.jsx b/client/src/components/creative-director/ProjectPreview.jsx
index da94400ccb..28ffa1a7a9 100644
--- a/client/src/components/creative-director/ProjectPreview.jsx
+++ b/client/src/components/creative-director/ProjectPreview.jsx
@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
-import { Play, Film } from 'lucide-react';
+import { Play, Film, Music } from 'lucide-react';
import MediaImage from '../MediaImage.jsx';
import ScenePreview from './ScenePreview.jsx';
import { selectProjectPreview, previewAspectClass } from '../../lib/creativeDirectorPreview.js';
@@ -68,6 +68,34 @@ export default function ProjectPreview({ project, to }) {
);
}
+ // A `music` commission's output is an audio track, not a frame — render a
+ // native <audio controls> so the run is playable/rateable in place (#2772).
+ // The player is interactive, so it sits OUTSIDE the navigation <Link> (same
+ // "no interactive control inside an <a>" rule as the video play button); the
+ // icon + label above it carry the click-to-open target instead.
+ if (preview.kind === 'audio') {
+ const durationSuffix = preview.durationSec ? ` · ${Math.round(preview.durationSec)}s` : '';
+ return (
+ <div className={`relative ${aspectClass} rounded overflow-hidden bg-port-bg border border-port-border flex flex-col items-center justify-center gap-2 p-3`}>
+ <Link
+ to={to}
+ className="flex flex-col items-center gap-1 text-port-text-muted hover:text-white focus:outline-none focus:ring-2 focus:ring-port-accent rounded"
+ aria-label={`Open ${project?.name || 'project'}`}
+ >
+ <Music className="w-6 h-6 text-port-accent" aria-hidden="true" />
+ <span className="text-[10px]">{preview.label}{durationSuffix}</span>
+ </Link>
+ <audio
+ controls
+ preload="none"
+ src={preview.src}
+ aria-label={`${project?.name || 'Project'} — ${preview.label}`}
+ className="w-full max-w-[95%]"
+ />
+ </div>
+ );
+ }
+
return (
<div className={`relative ${aspectClass} rounded overflow-hidden bg-port-bg border border-port-border`}>
<Link to={to} className="block w-full h-full" aria-label={`Open ${project?.name || 'project'}`}>
diff --git a/client/src/components/creative-director/ProjectPreview.test.jsx b/client/src/components/creative-director/ProjectPreview.test.jsx
new file mode 100644
index 0000000000..04ff2e8ef7
--- /dev/null
+++ b/client/src/components/creative-director/ProjectPreview.test.jsx
@@ -0,0 +1,52 @@
+/**
+ * Tests for ProjectPreview's audio branch (#2772): a `music` commission whose
+ * output is a `project.musicBed` track renders a playable <audio> element in the
+ * list card / commission run preview, so the run is rateable in place.
+ */
+import { describe, it, expect, vi } from 'vitest';
+import { render, screen } from '@testing-library/react';
+import { MemoryRouter } from 'react-router-dom';
+
+// The audio branch never touches these, but the module imports them — stub so
+// the test stays a unit of ProjectPreview's own branch selection.
+vi.mock('../MediaImage.jsx', () => ({ default: () => <div data-testid="media-image" /> }));
+vi.mock('./ScenePreview.jsx', () => ({ default: () => <div data-testid="scene-preview" /> }));
+vi.mock('../../services/apiImageVideo.js', () => ({ listVideoHistory: vi.fn(async () => []) }));
+
+import ProjectPreview from './ProjectPreview.jsx';
+
+const renderPreview = (project) =>
+ render(
+ <MemoryRouter>
+ <ProjectPreview project={project} to="/creative-director/cd-music-1" />
+ </MemoryRouter>,
+ );
+
+describe('ProjectPreview audio branch (#2772)', () => {
+ it('renders a playable audio element for a project with a music bed', () => {
+ renderPreview({
+ id: 'cd-music-1',
+ name: 'Example Score',
+ musicBed: { filename: 'music-gen-xyz.wav', durationSec: 30.4, engine: 'musicgen' },
+ });
+ const audio = document.querySelector('audio');
+ expect(audio).toBeTruthy();
+ expect(audio.getAttribute('src')).toBe('/data/music/music-gen-xyz.wav');
+ // Duration is surfaced next to the label so the run reads as a finished asset.
+ expect(screen.getByText(/Music bed · 30s/)).toBeTruthy();
+ // No video play affordance for an audio result.
+ expect(screen.queryByRole('button', { name: /Play/i })).toBeNull();
+ });
+
+ it('links the audio card to the project detail route', () => {
+ renderPreview({ id: 'cd-music-1', name: 'Example Score', musicBed: { filename: 'm.wav' } });
+ const link = screen.getByRole('link', { name: /Open Example Score/i });
+ expect(link.getAttribute('href')).toBe('/creative-director/cd-music-1');
+ });
+
+ it('shows the no-render state when nothing has been produced', () => {
+ renderPreview({ id: 'cd-1', name: 'Empty' });
+ expect(screen.getByText(/no render yet/i)).toBeTruthy();
+ expect(document.querySelector('audio')).toBeNull();
+ });
+});
diff --git a/client/src/lib/README.md b/client/src/lib/README.md
index fb53fe5b3a..6171a86cef 100644
--- a/client/src/lib/README.md
+++ b/client/src/lib/README.md
@@ -39,7 +39,7 @@ grep -i "what you want to do" client/src/lib/README.md
| `bibleLimits.js` | Mirror of `server/lib/storyBible.js` `BIBLE_LIMITS`. |
| `catalogTypes.js` | Client mirror of `server/lib/catalogTypes.js` — catalog ingredient type registry (label, badge color, primary-content key/label, snippet fallback chain, per-type editor field list) for the Catalog list/picker/editor. |
| `creativeDirectorPlan.js` | Pure presentation helpers for the CD studio Plan board (CDO Phase 4) — annotate `plan.steps[]` with tool cost-class/timing/approval flags, cost/status summaries, owning-surface deep links, status/cost badge tone maps. |
-| `creativeDirectorPreview.js` | `selectProjectPreview(project)` → `{ kind: 'video'\|'image'\|'none', jobId?, src?, poster?, label }` — picks a CD project's representative produced asset (finalVideoId → last rendered scene → last done plan video/image step → startingImageFile) for the list cards + Overview tab (#2702). Pure, computed off the already-returned project payload (no fetch). Plus `previewAspectClass(aspectRatio)` (literal Tailwind classes — a computed `aspect-[w/h]` never lands in the build), `startingImageSrc()` (client mirror of `localImageFilename`), and the `videoSrcForJob`/`videoPosterForJob`/`imageSrcForJob` path builders — the one client-side definition of the `<jobId>`-named asset convention, shared with `ScenePreview.jsx`. |
+| `creativeDirectorPreview.js` | `selectProjectPreview(project)` → `{ kind: 'video'\|'image'\|'audio'\|'none', jobId?, src?, poster?, label, durationSec? }` — picks a CD project's representative produced asset (finalVideoId → last rendered scene → last done plan video/image step → `musicBed` audio → startingImageFile) for the list cards + Overview tab (#2702, audio #2772). Pure, computed off the already-returned project payload (no fetch). Plus `previewAspectClass(aspectRatio)` (literal Tailwind classes — a computed `aspect-[w/h]` never lands in the build), `startingImageSrc()` (client mirror of `localImageFilename`), and the `videoSrcForJob`/`videoPosterForJob`/`imageSrcForJob`/`musicBedSrc` path builders — the one client-side definition of the `<jobId>`-named asset convention, shared with `ScenePreview.jsx`. |
| `editorialRoadmap.js` | `projectAnalyzedPoints` (aggregate roadmap → analyzed chart points with arc-position `frac`) + `dominant` (most-frequent string). Shared by EditorialRoadmapPanel and the Reader Map page. |
| `imageCleaners.js` | Mirror of `resolveCleanersFromConfig` from `server/lib/imageClean.js`. Reads `{cleanC2PA, denoise}` off a per-mode settings record. `cleanC2PA` defaults are mode-aware (on for `codex` + `external` — the backends that emit C2PA chunks today — off otherwise, as an allow-list rather than a deny-list); `denoise` defaults off everywhere (lossy, opt-in only). |
| `runnerFamilies.js` | Mirror of `server/lib/runners.js`. |
diff --git a/client/src/lib/creativeDirectorPreview.js b/client/src/lib/creativeDirectorPreview.js
index 4bc0a4c46c..ce8c387dad 100644
--- a/client/src/lib/creativeDirectorPreview.js
+++ b/client/src/lib/creativeDirectorPreview.js
@@ -17,10 +17,13 @@
* on completion (mid-flight commissions).
* 4. last done image-render plan step — a plan that emits images (e.g. a comic)
* rather than video.
- * 5. `startingImageFile` — no render yet, but the project has a
+ * 5. `musicBed` — a `music` commission's produced audio
+ * (or a first-pass bed), filed onto the
+ * project by the durable music-bed hook.
+ * 6. `startingImageFile` — no render yet, but the project has a
* reference image. Labeled distinctly so
* the UI never passes an INPUT off as output.
- * 6. `{ kind: 'none' }` — nothing to show.
+ * 7. `{ kind: 'none' }` — nothing to show.
*
* NOTE ON CAST PORTRAITS: #2702 also floated "first cast portrait" as a fallback.
* A project's `cast[]` member is `{ ingredientId, name, type, role, summary }` —
@@ -38,6 +41,16 @@ export const videoSrcForJob = (jobId) => `/data/videos/${jobId}.mp4`;
export const videoPosterForJob = (jobId) => `/data/video-thumbnails/${jobId}.jpg`;
export const imageSrcForJob = (jobId) => `/data/images/${jobId}.png`;
+// A project's music bed (a `music` commission's produced audio, or a first-pass
+// bed) is stored as `project.musicBed.filename` and served from `/data/music/`
+// (PATHS.music, mounted in server/index.js). generateMusic names the file
+// `music-gen-<uuid>.wav`; the hook stores just that basename, so encode it and
+// prefix the mount.
+export const musicBedSrc = (musicBed) => {
+ const filename = nonEmptyString(musicBed?.filename);
+ return filename ? `/data/music/${encodeURIComponent(filename)}` : null;
+};
+
// The registry tools a plan step uses to render media. Mirrors
// `VIDEO_RENDER_TOOL_NAME` in server/services/creativeDirector/planAdvance.js;
// both settle with a `{ jobId }` result digest.
@@ -176,6 +189,15 @@ export function selectProjectPreview(project) {
return { kind: 'image', jobId: planImageId, src: imageSrcForJob(planImageId), label: 'Produced image' };
}
+ // A `music` commission produces no video/image — its output is the rendered
+ // music bed filed onto `project.musicBed` by the durable music-bed hook
+ // (#2772). Surface it as a playable audio result so the run is rateable.
+ const audio = musicBedSrc(project.musicBed);
+ if (audio) {
+ const durationSec = Number.isFinite(project.musicBed?.durationSec) ? project.musicBed.durationSec : null;
+ return { kind: 'audio', src: audio, label: 'Music bed', durationSec };
+ }
+
// Last resort: the project's own reference image. Distinct label — this is an
// INPUT the user supplied, not something the director produced.
const starting = startingImageSrc(project.startingImageFile);
diff --git a/client/src/lib/creativeDirectorPreview.test.js b/client/src/lib/creativeDirectorPreview.test.js
index 592dbb88f2..f012b24d11 100644
--- a/client/src/lib/creativeDirectorPreview.test.js
+++ b/client/src/lib/creativeDirectorPreview.test.js
@@ -7,6 +7,7 @@ import {
videoSrcForJob,
videoPosterForJob,
imageSrcForJob,
+ musicBedSrc,
} from './creativeDirectorPreview.js';
// Obviously-fake ids/filenames throughout — never real records from an install.
@@ -46,6 +47,18 @@ describe('asset path builders', () => {
expect(videoPosterForJob('job-1')).toBe('/data/video-thumbnails/job-1.jpg');
expect(imageSrcForJob('job-1')).toBe('/data/images/job-1.png');
});
+
+ it('resolves a music bed to its /data/music/ mount, encoding the filename', () => {
+ expect(musicBedSrc({ filename: 'music-gen-abc.wav' })).toBe('/data/music/music-gen-abc.wav');
+ expect(musicBedSrc({ filename: 'a b.wav' })).toBe('/data/music/a%20b.wav');
+ });
+
+ it('returns null for a missing/blank music-bed filename', () => {
+ expect(musicBedSrc(null)).toBeNull();
+ expect(musicBedSrc({})).toBeNull();
+ expect(musicBedSrc({ filename: ' ' })).toBeNull();
+ expect(musicBedSrc({ filename: 42 })).toBeNull();
+ });
});
describe('startingImageSrc', () => {
@@ -228,6 +241,46 @@ describe('selectProjectPreview', () => {
expect(starting.jobId).toBeUndefined();
});
+ it('surfaces a music bed as a playable audio result for a music commission (#2772)', () => {
+ const preview = selectProjectPreview({
+ id: 'cd-music-1',
+ musicBed: { filename: 'music-gen-xyz.wav', durationSec: 30.4, engine: 'musicgen' },
+ });
+ expect(preview).toEqual({
+ kind: 'audio',
+ src: '/data/music/music-gen-xyz.wav',
+ label: 'Music bed',
+ durationSec: 30.4,
+ });
+ });
+
+ it('reports a null durationSec for a music bed missing/invalid duration', () => {
+ const preview = selectProjectPreview({ musicBed: { filename: 'music-gen-xyz.wav' } });
+ expect(preview.kind).toBe('audio');
+ expect(preview.durationSec).toBeNull();
+ });
+
+ it('prefers a produced video/image over a music bed (music-video keeps its video hero)', () => {
+ const preview = selectProjectPreview({
+ finalVideoId: 'final-1',
+ musicBed: { filename: 'music-gen-xyz.wav' },
+ });
+ expect(preview.kind).toBe('video');
+ expect(preview.jobId).toBe('final-1');
+ });
+
+ it('prefers a music bed over a bare starting image (produced output beats an input)', () => {
+ const preview = selectProjectPreview({
+ musicBed: { filename: 'music-gen-xyz.wav' },
+ startingImageFile: 'start.png',
+ });
+ expect(preview.kind).toBe('audio');
+ });
+
+ it('ignores a music bed with no filename', () => {
+ expect(selectProjectPreview({ musicBed: { durationSec: 12 } }).kind).toBe('none');
+ });
+
it('does not use an unservable starting image', () => {
expect(selectProjectPreview({ startingImageFile: 'https://example.com/x.png' }).kind).toBe('none');
});
diff --git a/server/services/creative/toolRegistry.test.js b/server/services/creative/toolRegistry.test.js
index 77fd15350e..c1357ec9b1 100644
--- a/server/services/creative/toolRegistry.test.js
+++ b/server/services/creative/toolRegistry.test.js
@@ -273,6 +273,41 @@ describe('budget charging', () => {
expect(enqueueJob).toHaveBeenCalledWith({ kind: 'video', params: { prompt: 'p', width: 640 }, owner: 'creative' });
});
+ it('tags a planner-enqueued audio job with creativeDirectorMusicBed so the durable hook files it onto the project (#2772)', async () => {
+ setMode('execute');
+ await dispatchCreativeTool(
+ 'media_enqueueAudioJob',
+ { params: { prompt: 'a mournful synth score', engine: 'musicgen' } },
+ { projectId: 'p1' },
+ );
+ const enqueued = enqueueJob.mock.calls.at(-1)[0];
+ expect(enqueued.kind).toBe('audio');
+ // Without this tag, project.musicBed stays null and the run has no surfaced output.
+ expect(enqueued.params.creativeDirectorMusicBed).toEqual({ projectId: 'p1' });
+ // Creative params the planner owns are preserved.
+ expect(enqueued.params.prompt).toBe('a mournful synth score');
+ expect(enqueued.owner).toBe('creative-director:p1');
+ });
+
+ it('leaves audio params untagged when there is no owning project (bare enqueue)', async () => {
+ setMode('execute');
+ await dispatchCreativeTool('media_enqueueAudioJob', { params: { prompt: 'p' } }, {});
+ const enqueued = enqueueJob.mock.calls.at(-1)[0];
+ expect(enqueued.kind).toBe('audio');
+ expect(enqueued.params).not.toHaveProperty('creativeDirectorMusicBed');
+ });
+
+ it('preserves an explicit creativeDirectorMusicBed tag the caller already set', async () => {
+ setMode('execute');
+ await dispatchCreativeTool(
+ 'media_enqueueAudioJob',
+ { params: { prompt: 'p', creativeDirectorMusicBed: { projectId: 'explicit' } } },
+ { projectId: 'p1' },
+ );
+ const enqueued = enqueueJob.mock.calls.at(-1)[0];
+ expect(enqueued.params.creativeDirectorMusicBed).toEqual({ projectId: 'explicit' });
+ });
+
it('does not charge a free tool', async () => {
setMode('execute');
await dispatchCreativeTool('pipeline_createSeries', { name: 'S' });
diff --git a/server/services/creative/tools/media.js b/server/services/creative/tools/media.js
index 825e426880..1875abca8c 100644
--- a/server/services/creative/tools/media.js
+++ b/server/services/creative/tools/media.js
@@ -60,6 +60,27 @@ async function enforceVideoRenderPreset(params, ctx) {
};
}
+/**
+ * Tag a planner-enqueued audio job so the durable `creativeDirectorMusicBedHook`
+ * files the finished track onto the owning project's `musicBed` field (#2772).
+ *
+ * Without this, a `music` commission's plan step enqueues an audio job that
+ * completes with only a job id — `project.musicBed` stays null and the run has
+ * no surfaced, rateable output. The first-pass music flow
+ * (creativeDirector/firstPassMusicGen.js) already stamps this exact tag; the
+ * planner path did not, so the hook never fired for planner-driven audio.
+ *
+ * Only tags inside a CD project context (`ctx.projectId`) — a bare enqueue with
+ * no owning project keeps its params untouched. An explicit
+ * `creativeDirectorMusicBed` already on the params (a caller that set its own
+ * destination) wins and is left as-is.
+ */
+function attachMusicBedTag(params, ctx) {
+ if (!ctx?.projectId) return params;
+ if (params?.creativeDirectorMusicBed) return params;
+ return { ...params, creativeDirectorMusicBed: { projectId: ctx.projectId } };
+}
+
const mediaTool = (kind, label) => ({
name: `media_enqueue${label}Job`,
description: `Enqueue a ${kind} media job. Long-running: returns a job handle; completion arrives via media-job events. Tags the job owner to the calling project.`,
@@ -75,9 +96,9 @@ const mediaTool = (kind, label) => ({
required: ['params'],
},
execute: async (args, ctx) => {
- const params = kind === 'video'
- ? await enforceVideoRenderPreset(args.params || {}, ctx)
- : (args.params || {});
+ let params = args.params || {};
+ if (kind === 'video') params = await enforceVideoRenderPreset(params, ctx);
+ else if (kind === 'audio') params = attachMusicBedTag(params, ctx);
return enqueueJob({ kind, params, owner: resolveOwner(args, ctx) });
},
});