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

fix: show instrumental music caption additions and preserve sent text (#11317)

[._.]/ Adam Eivyc8fd3b270285
diff --git a/client/src/components/music/MusicGenPanel.jsx b/client/src/components/music/MusicGenPanel.jsx
index 430e0e7355..96ace1308a 100644
--- a/client/src/components/music/MusicGenPanel.jsx
+++ b/client/src/components/music/MusicGenPanel.jsx
@@ -23,6 +23,8 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import useMounted from '../../hooks/useMounted';
+import { useModelInputPreview } from '../../hooks/useModelInputPreview';
+import ModelInputPreview from '../media/ModelInputPreview';
import useMediaJobProgress from '../../hooks/useMediaJobProgress';
import { useSocketResource } from '../../hooks/useSocketResource';
import { Loader2, Wand2, Download, X } from 'lucide-react';
@@ -30,7 +32,7 @@ import toast from '../ui/Toast';
import { analyzeMusicLyrics } from '../../lib/musicDuration.js';
import { formatDurationSec } from '../../utils/formatters.js';
import {
- listMusicEngines, generateMusic, installAudioModel, removeAudioModel, getActiveProcessing, getMediaJob, getTrack, cancelMediaJob,
+ listMusicEngines, generateMusic, previewMusicPrompt, installAudioModel, removeAudioModel, getActiveProcessing, getMediaJob, getTrack, cancelMediaJob,
} from '../../services/api';
import { formatDownloadGb } from '../../utils/formatters';
import { useFederatedMediaTarget } from '../../hooks/useFederatedMediaTarget.js';
@@ -275,6 +277,9 @@ export default function MusicGenPanel({ track, title = '', artistId = '', artist
// picked it. Where the peer CAN sing, it is an ordinary choice again.
const forcedInstrumental = isRemote && !remoteLyricsAvailable;
const effectiveInstrumentalOnly = forcedInstrumental || instrumentalOnly;
+ const captionPreview = useModelInputPreview(previewMusicPrompt, {
+ prompt, instrumentalOnly: effectiveInstrumentalOnly,
+ }, { enabled: !isRemote && !!prompt?.trim() });
const lyricsCondition = !isRemote || remoteLyricsAvailable;
const conditioningLyrics = generationEngine?.lyrics && !effectiveInstrumentalOnly && lyricsCondition
? lyrics
@@ -413,7 +418,7 @@ export default function MusicGenPanel({ track, title = '', artistId = '', artist
}
setGenerating(true);
const body = {
- prompt: prompt.trim(),
+ prompt,
engine: generationEngine.id || generationEngine.engine,
modelId: isRemote ? generationEngine.modelId : selectedModelId,
instrumentalOnly: effectiveInstrumentalOnly,
@@ -697,6 +702,8 @@ export default function MusicGenPanel({ track, title = '', artistId = '', artist
</p>
</div>
+ {!isRemote && <ModelInputPreview preview={captionPreview} prompt={prompt} />}
+
<div className="flex items-center gap-2">
<button
type="button"
diff --git a/client/src/components/music/MusicGenPanel.test.jsx b/client/src/components/music/MusicGenPanel.test.jsx
index 95d1eb82a5..325a3da745 100644
--- a/client/src/components/music/MusicGenPanel.test.jsx
+++ b/client/src/components/music/MusicGenPanel.test.jsx
@@ -24,6 +24,7 @@ vi.mock('../../services/api', () => ({
listMusicEngines: vi.fn(),
getInstances: vi.fn(),
generateMusic: vi.fn(),
+ previewMusicPrompt: vi.fn(),
getActiveProcessing: vi.fn(),
getMediaJob: vi.fn(),
getTrack: vi.fn(),
@@ -87,10 +88,30 @@ const minimax = (overrides) => engine({
describe('MusicGenPanel', () => {
beforeEach(() => {
vi.clearAllMocks();
+ api.previewMusicPrompt.mockResolvedValue({});
api.getActiveProcessing.mockResolvedValue({ jobs: [] });
api.getInstances.mockResolvedValue({ peers: [] });
});
+ it('shows the server instrumental addition while submitting the authored caption unchanged', async () => {
+ const prompt = ' **warm** folk\n';
+ api.listMusicEngines.mockResolvedValue({ defaultEngine: 'musicgen', engines: [engine({ ready: true })] });
+ api.previewMusicPrompt.mockImplementation(async (body) => body.instrumentalOnly ? {
+ sentPrompt: `${body.prompt}\n\nNo vocals.`,
+ promptAdditions: [{ id: 'instrumental-only', label: 'Instrumental only', text: 'No vocals.' }],
+ } : { sentPrompt: body.prompt });
+ api.generateMusic.mockResolvedValue({ track: { id: 'track-1' } });
+ render(<MusicGenPanel track={{ id: 'track-1' }} prompt={prompt} />);
+ fireEvent.click(await screen.findByRole('checkbox', { name: /instrumental only/i }));
+ fireEvent.click(await screen.findByRole('button', { name: '+ Instrumental only' }));
+ expect(screen.getByText('No vocals.')).toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: 'Show full prompt' }));
+ expect(screen.getByRole('button', { name: 'Copy full prompt' })).toBeInTheDocument();
+ expect(api.previewMusicPrompt).toHaveBeenCalledWith({ prompt, instrumentalOnly: true }, { silent: true });
+ fireEvent.click(screen.getByRole('button', { name: /^generate$/i }));
+ await waitFor(() => expect(api.generateMusic).toHaveBeenCalledWith(expect.objectContaining({ prompt, instrumentalOnly: true }), { silent: true }));
+ });
+
// `clearAllMocks` resets calls but leaves a spy installed. A test that pins
// Date.now and then fails before restoring it would leave the clock frozen
// for every test after it, turning one failure into a cascade.
diff --git a/client/src/components/music/TrackRenderModal.jsx b/client/src/components/music/TrackRenderModal.jsx
index b6ae667f42..659506b957 100644
--- a/client/src/components/music/TrackRenderModal.jsx
+++ b/client/src/components/music/TrackRenderModal.jsx
@@ -10,6 +10,7 @@
import { Sparkles, CheckCircle2, Download, Trash2, X, Film } from 'lucide-react';
import Modal from '../ui/Modal';
+import SentPromptPanel from '../media/SentPromptPanel';
import { formatTimecode, timeAgo } from '../../utils/formatters';
import { trackAudioUrl } from '../../services/api';
import { renderSourceLabel } from '../../lib/trackProvenance';
@@ -73,6 +74,8 @@ export default function TrackRenderModal({ render, active = false, onClose, onSe
</div>
) : null}
+ <SentPromptPanel prompt={render.authoredPrompt || prompt} sentPrompt={render.sentPrompt} additions={render.promptAdditions || []} />
+
{lyrics ? (
<div>
<div className="text-[10px] uppercase tracking-wider text-gray-500 mb-1">Lyrics (conditioning)</div>
diff --git a/client/src/services/README.md b/client/src/services/README.md
index 2d7a99ec08..ac24a38d28 100644
--- a/client/src/services/README.md
+++ b/client/src/services/README.md
@@ -125,7 +125,7 @@ toasts on throw). **Custom catch ⇒ `silent: true`** — otherwise toasts fire
| `apiAlbums.js` | Music albums (title, artist FK + name, description, genre, release year, cover art, ordered track ids). |
| `apiTracks.js` | Music tracks (title, album/artist FKs, lyrics, prompt, gen metadata, audio-library pointer) + shared music-library list + audio upload/attach + saving drawn-waveform and code-engine takes. |
| `apiVideoDownload.js` | Dev Tools video downloader (#1946): start/cancel a YouTube/x.com full-video download via yt-dlp (SSE progress), list + delete downloaded clips, plus `getYtDlpStatus`/`updateYtDlp` for the in-place yt-dlp update the page offers when a download fails on a stale binary. |
-| `apiMusic.js` | On-device music generation (MusicGen / AudioLDM2 / ACE-Step): list engines (+ readiness), the stepped designer's AI describe/lyrics steps, the drawn-waveform and Strudel-code engines' LLM calls, generate a track from a prompt/lyrics, and the SuperCollider runtime (status, setup, render, cancel). |
+| `apiMusic.js` | On-device music generation (MusicGen / AudioLDM2 / ACE-Step): list engines (+ readiness), the stepped designer's AI describe/lyrics steps, the drawn-waveform and Strudel-code engines' LLM calls, preview the local caption and labeled additions, generate a track from a prompt/lyrics, and the SuperCollider runtime (status, setup, render, cancel). |
| `apiWritersRoom.js` | Writers Room (folders + works + drafts, live continuation + render-preview reservation, scene-image attach). |
| `apiSharing.js` | Share buckets + federation sync. |
| `apiRounds.js` | Rounds workbench CRUD (a cappella round writing + arranging voice layers + learning tracking). |
diff --git a/client/src/services/apiMusic.js b/client/src/services/apiMusic.js
index 4cac3d2124..991dcc208b 100644
--- a/client/src/services/apiMusic.js
+++ b/client/src/services/apiMusic.js
@@ -23,6 +23,11 @@ export const generateMusic = (body, requestOptions = {}) => request('/music/gene
...requestOptions,
});
+// Preview the local audio caption without starting a render.
+export const previewMusicPrompt = (body, options = {}) => request('/music/prompt-preview', {
+ method: 'POST', body: JSON.stringify(body), ...options,
+});
+
// ---- Stepped music designer (#4305) ----
// Both fire one LLM call each and are only ever invoked from an explicit button
// press in the designer wizard. Callers own their loading/error UI, so pass
diff --git a/scripts/generate_acestep.py b/scripts/generate_acestep.py
index 51d0c2333c..0efe91d15a 100644
--- a/scripts/generate_acestep.py
+++ b/scripts/generate_acestep.py
@@ -109,8 +109,8 @@ def main():
parser.add_argument("--guidance", type=float, default=15.0, help="Classifier-free guidance scale")
args = parser.parse_args()
- text = (args.text or "").strip()
- if not text:
+ text = args.text or ""
+ if not text.strip():
print("ERROR: --text is required", file=sys.stderr, flush=True)
return 2
diff --git a/scripts/generate_acestep15.py b/scripts/generate_acestep15.py
index 0d2ee55a8e..2777302b1f 100644
--- a/scripts/generate_acestep15.py
+++ b/scripts/generate_acestep15.py
@@ -51,8 +51,8 @@ def main():
parser.add_argument("--runtime-dir", default="")
args = parser.parse_args()
- text = args.text.strip()
- if not text:
+ text = args.text
+ if not text.strip():
print("ERROR: --text is required", file=sys.stderr, flush=True)
return 2
if args.model != MODEL_ID:
diff --git a/scripts/generate_audioldm2.py b/scripts/generate_audioldm2.py
index 061045c6a7..c68d2e66df 100644
--- a/scripts/generate_audioldm2.py
+++ b/scripts/generate_audioldm2.py
@@ -161,8 +161,8 @@ def main():
help="Classifier-free guidance scale")
args = parser.parse_args()
- text = (args.text or "").strip()
- if not text:
+ text = args.text or ""
+ if not text.strip():
print("ERROR: --text is required", file=sys.stderr, flush=True)
return 2
diff --git a/scripts/generate_musicgen.py b/scripts/generate_musicgen.py
index 59aa59427e..88218ed127 100644
--- a/scripts/generate_musicgen.py
+++ b/scripts/generate_musicgen.py
@@ -103,8 +103,8 @@ def main():
help="Path to the mlx-examples musicgen/ package dir")
args = parser.parse_args()
- text = (args.text or "").strip()
- if not text:
+ text = args.text or ""
+ if not text.strip():
print("ERROR: --text is required", file=sys.stderr, flush=True)
return 2
diff --git a/server/lib/schemaVersions.js b/server/lib/schemaVersions.js
index 79280407b3..226e18923b 100644
--- a/server/lib/schemaVersions.js
+++ b/server/lib/schemaVersions.js
@@ -310,7 +310,10 @@ export const PORTOS_SCHEMA_VERSIONS = Object.freeze({
// server-rendered SuperCollider take). A <=v9 peer's sanitizer would strip it
// and LWW the unreproducible take back. Absent on every older render; nothing
// to migrate.
- tracks: 10,
+ // tracks v11 = exact local audio captions and labeled prompt additions on
+ // takes. Older sanitizers would erase the record of what the model received.
+ // Optional on older takes; no stored records need rewriting.
+ tracks: 11,
// v1 = creative ingredients catalog (Postgres tables: catalog_scraps,
// catalog_ingredients, catalog_ingredient_sources, catalog_ingredient_refs).
// v2 = `catalog_ingredients.search_tsv` expanded to also index the
diff --git a/server/routes/music.js b/server/routes/music.js
index 4253fff86f..cd2bb3fd90 100644
--- a/server/routes/music.js
+++ b/server/routes/music.js
@@ -54,7 +54,7 @@ import { createInstallLogger } from '../lib/installLogger.js';
import { inspectModelCache } from '../lib/hfCache.js';
import { getCudaCapability } from '../lib/cudaCapability.js';
import { federatedMediaAudioProfileSchema } from '../lib/federatedMediaWire.js';
-import { queueMusicGeneration } from '../services/musicGeneration.js';
+import { composeMusicPrompt, queueMusicGeneration } from '../services/musicGeneration.js';
const router = Router();
@@ -391,8 +391,10 @@ router.post('/code', asyncHandler(async (req, res) => {
res.json(await writeMusicCode(body));
}));
+const captionField = z.string().max(8000).refine((value) => value.trim().length > 0, 'prompt is required');
+
const generateSchema = z.object({
- prompt: z.string().trim().min(1, 'prompt is required').max(8000),
+ prompt: captionField,
// No default: distinguish ABSENT (don't touch the track's lyrics) from a
// present '' (the user cleared them and generated without — persist the clear).
lyrics: z.string().trim().max(20000).optional(),
@@ -444,6 +446,15 @@ const generateSchema = z.object({
// The check moved into the handler, below the capability resolve.
});
+// Local caption preview: pure composition, no queue, peer probe or provider work.
+router.post('/prompt-preview', asyncHandler(async (req, res) => {
+ const body = validateRequest(z.object({
+ prompt: captionField,
+ instrumentalOnly: z.boolean().optional().default(false),
+ }), req.body ?? {});
+ res.json(composeMusicPrompt(body));
+}));
+
router.post('/generate', asyncHandler(async (req, res) => {
const body = validateRequest(generateSchema, req.body ?? {});
res.status(202).json(await queueMusicGeneration(body));
diff --git a/server/routes/music.test.js b/server/routes/music.test.js
index fe4e523c36..ff130aef50 100644
--- a/server/routes/music.test.js
+++ b/server/routes/music.test.js
@@ -673,6 +673,35 @@ describe('music routes', () => {
expect(models.remove).toHaveBeenCalledWith({ engine: 'musicgen', id: 'facebook/musicgen-large' });
});
+ it('previews the instrumental caption without queueing and records exactly that caption on submit', async () => {
+ const prompt = ' **warm** `analog` folk\n';
+ const body = { prompt, instrumentalOnly: true };
+ const preview = await request(app).post('/api/music/prompt-preview').send(body);
+ expect(preview.status).toBe(200);
+ expect(mediaQueue.enqueue).not.toHaveBeenCalled();
+ expect(preview.body).toEqual({
+ sentPrompt: `${prompt}\n\nInstrumental only. Do not include sung, spoken, chanted, choir, or background vocals. Carry the lead melody with the described instruments or textures.`,
+ promptAdditions: [{
+ id: 'instrumental-only', label: 'Instrumental only',
+ text: 'Instrumental only. Do not include sung, spoken, chanted, choir, or background vocals. Carry the lead melody with the described instruments or textures.',
+ }],
+ });
+ const submitted = await request(app).post('/api/music/generate').send(body);
+ expect(submitted.status).toBe(202);
+ const params = mediaQueue.enqueue.mock.calls[0][0].params;
+ expect(params.prompt).toBe(preview.body.sentPrompt);
+ expect(params.musicStudio).toMatchObject({ authoredPrompt: prompt, ...preview.body });
+ const { buildSidecarArgs } = await vi.importActual('../services/pipeline/musicGen.js');
+ const { args } = buildSidecarArgs({ engineId: 'musicgen', prompt: params.prompt });
+ expect(args[args.indexOf('--text') + 1]).toBe(preview.body.sentPrompt);
+ });
+
+ it('refuses over-limit caption previews instead of returning a shortened caption', async () => {
+ const preview = await request(app).post('/api/music/prompt-preview').send({ prompt: 'x'.repeat(8001) });
+ expect(preview.status).toBe(400);
+ expect(mediaQueue.enqueue).not.toHaveBeenCalled();
+ });
+
it('POST /generate queues a new track render', async () => {
const r = await request(app).post('/api/music/generate').send({
prompt: 'warm folk', lyrics: '[verse] hi', engine: 'acestep', title: 'My Song',
diff --git a/server/services/musicGeneration.js b/server/services/musicGeneration.js
index 5f940c37d5..13b65ffcd9 100644
--- a/server/services/musicGeneration.js
+++ b/server/services/musicGeneration.js
@@ -23,9 +23,21 @@ import { enqueueJob, listJobs } from './mediaJobQueue/index.js';
import { resolveFederatedMediaProvider } from './federatedMediaConsumer.js';
import { getPeers } from './instances.js';
import * as tracks from './tracks/index.js';
+import { promptAddition, sentPromptRecord } from '../lib/modelInput.js';
const INSTRUMENTAL_ONLY_GUIDANCE = 'Instrumental only. Do not include sung, spoken, chanted, choir, or background vocals. Carry the lead melody with the described instruments or textures.';
+/** The local audio caption, shared by preview and enqueue. Lyrics are separate. */
+export function composeMusicPrompt({ prompt, instrumentalOnly = false }) {
+ const addition = instrumentalOnly && !prompt.includes(INSTRUMENTAL_ONLY_GUIDANCE)
+ ? promptAddition('instrumental-only', 'Instrumental only', INSTRUMENTAL_ONLY_GUIDANCE)
+ : null;
+ return sentPromptRecord({
+ sentPrompt: addition ? `${prompt}\n\n${addition.text}` : prompt,
+ added: [addition],
+ });
+}
+
/** Queue one audio render. Resolves to `{ jobId, position, status }`. */
export async function queueMusicGeneration(input) {
// The route's schema applies these defaults; an in-process caller gets them here.
@@ -161,9 +173,8 @@ export async function queueMusicGeneration(input) {
// dropping lyrics is not enough when the authored caption itself mentions a
// vocalist. Keep it idempotent so remixing an instrumental take does not append
// the same directive repeatedly.
- const usedPrompt = body.instrumentalOnly && !body.prompt.includes(INSTRUMENTAL_ONLY_GUIDANCE)
- ? `${body.prompt}\n\n${INSTRUMENTAL_ONLY_GUIDANCE}`
- : body.prompt;
+ const promptRecord = composeMusicPrompt(body);
+ const usedPrompt = promptRecord.sentPrompt;
const usedLyrics = engine.lyrics && !body.instrumentalOnly ? (body.lyrics ?? '') : '';
if (remoteMedia) {
// Lyrics ride the marker, not the top-level params, for the same reason the
@@ -205,6 +216,7 @@ export async function queueMusicGeneration(input) {
// Keep editable source text distinct from the augmented prompt and
// empty lyric payload that actually condition an instrumental render.
authoredPrompt: body.prompt,
+ ...(!remoteMedia ? promptRecord : {}),
authoredLyrics: engine.lyrics === true ? body.lyrics : undefined,
lyricsEnabled: engine.lyrics === true,
lyricsProvided: engine.lyrics === true && body.lyrics !== undefined,
diff --git a/server/services/musicStudioHook.js b/server/services/musicStudioHook.js
index bfdf36578a..2a2248bd13 100644
--- a/server/services/musicStudioHook.js
+++ b/server/services/musicStudioHook.js
@@ -32,6 +32,7 @@ const hook = createMediaJobImageHook({
executionProfile: typeof job.result?.executionProfile === 'string' ? job.result.executionProfile : null,
prompt: remotePrompt || job.params.prompt,
authoredPrompt,
+ ...(typeof tag.sentPrompt === 'string' ? { sentPrompt: tag.sentPrompt, promptAdditions: tag.promptAdditions } : {}),
lyrics: remotePrompt ? '' : job.params.lyrics,
authoredLyrics,
lyricsEnabled: tag.lyricsEnabled === true,
@@ -43,7 +44,7 @@ const hook = createMediaJobImageHook({
albumId: tag.albumId,
};
},
- attach: async ({ job, trackId, filename, durationSec, engine, modelId, executionProfile, prompt, authoredPrompt, lyrics, authoredLyrics, lyricsEnabled, lyricsProvided, instrumentalOnly, title, artistId, artist, albumId }) => {
+ attach: async ({ job, trackId, filename, durationSec, engine, modelId, executionProfile, prompt, authoredPrompt, sentPrompt, promptAdditions, lyrics, authoredLyrics, lyricsEnabled, lyricsProvided, instrumentalOnly, title, artistId, artist, albumId }) => {
const current = trackId ? await tracks.getTrack(trackId) : null;
// A deleted target is a successful render but no longer an attach target.
if (trackId && !current) return null;
@@ -51,6 +52,8 @@ const hook = createMediaJobImageHook({
audioFilename: filename,
prompt,
authoredPrompt,
+ sentPrompt,
+ promptAdditions,
lyrics: lyricsEnabled ? lyrics : '',
instrumentalOnly,
engine,
diff --git a/server/services/musicStudioHook.test.js b/server/services/musicStudioHook.test.js
index 564e58c3da..7051ad3042 100644
--- a/server/services/musicStudioHook.test.js
+++ b/server/services/musicStudioHook.test.js
@@ -84,6 +84,25 @@ describe('music studio completion hook', () => {
expect(queue.updateJobResult).toHaveBeenCalledWith('job-instrumental', { trackId: 'track-1' });
});
+ it('persists exact caption provenance on the take beyond the authored prompt cap', async () => {
+ const authored = 'x'.repeat(8000);
+ const addition = { id: 'instrumental-only', label: 'Instrumental only', text: 'No vocals.' };
+ const sentPrompt = `${authored}\n\n${addition.text}\n`;
+ trackStore.getTrack.mockResolvedValue({ id: 'track-1', renders: [] });
+ trackStore.buildRenderAppend.mockImplementation((_current, input) => ({ renders: [makeRender(input)] }));
+ queue.events.emit('completed', {
+ id: 'job-provenance', kind: 'audio', queuedAt: new Date().toISOString(),
+ params: { prompt: sentPrompt, musicStudio: {
+ trackId: 'track-1', authoredPrompt: authored, sentPrompt, promptAdditions: [addition], instrumentalOnly: true,
+ } },
+ result: { filename: 'provenance.wav', engine: 'musicgen' },
+ });
+ await new Promise((resolve) => setImmediate(resolve));
+ expect(trackStore.updateTrack.mock.calls[0][1].renders[0]).toMatchObject({
+ sentPrompt, promptAdditions: [addition],
+ });
+ });
+
it('keeps authored lyrics when an instrumental render creates a standalone track', async () => {
queue.events.emit('completed', {
id: 'job-standalone-instrumental', kind: 'audio', queuedAt: new Date().toISOString(),
diff --git a/server/services/pipeline/musicGen.js b/server/services/pipeline/musicGen.js
index 645e40ffb0..31af62ebc5 100644
--- a/server/services/pipeline/musicGen.js
+++ b/server/services/pipeline/musicGen.js
@@ -57,7 +57,6 @@ import {
import { getCudaCapability } from '../../lib/cudaCapability.js';
import { inspectModelCache } from '../../lib/hfCache.js';
import { ServerError } from '../../lib/errorHandler.js';
-import { stripMarkdownEmphasis } from '../../lib/markdownText.js';
import { recommendMinimaxDurationSec } from '../../lib/musicDuration.js';
import { safeChildProcessOptions } from '../../lib/processEnv.js';
import { maintenance } from '../../lib/maintenanceAdmission.js';
@@ -623,11 +622,8 @@ export function buildSidecarArgs({ engineId = DEFAULT_ENGINE_ID, pythonPath, scr
scriptPath ?? engine.scriptPath,
'--model', repo,
...(engine.supportsModelRevision && revision ? ['--revision', revision] : []),
- // Prompts are authored in a plain textarea that many users type markdown
- // into out of habit. Every backend's text encoder tokenizes `**` and `_`
- // as literal content, so the emphasis markers become conditioning noise —
- // strip them and keep the words.
- '--text', stripMarkdownEmphasis(prompt).trim(),
+ // Preserve the caption shown in the server's prompt preview.
+ '--text', prompt,
'--duration', String(seconds),
'--output', outputPath,
'--runtime-dir', runtimeDir ?? engine.runtimeDir,
@@ -684,8 +680,8 @@ export async function generateMusic(options = {}) {
}
async function generateMusicAdmitted({ prompt, lyrics, engine: engineId = DEFAULT_ENGINE_ID, durationSec, durationMode, modelId, repo, provenance, signal, onActivity }) {
- const text = (prompt || '').trim();
- if (!text) {
+ const text = prompt || '';
+ if (!text.trim()) {
throw new ServerError('prompt is required', { status: 400, code: 'PIPELINE_MUSIC_EMPTY_PROMPT' });
}
const engine = getEngine(engineId);
diff --git a/server/services/pipeline/musicGen.test.js b/server/services/pipeline/musicGen.test.js
index 804381ba32..ef0f6908bc 100644
--- a/server/services/pipeline/musicGen.test.js
+++ b/server/services/pipeline/musicGen.test.js
@@ -282,16 +282,15 @@ describe('buildSidecarArgs', () => {
outputPath: '/data/music/music-gen-abc.wav',
};
- it('strips markdown emphasis out of the prompt for every engine', () => {
- // The prompt box is a plain textarea; users type markdown into it out of
- // habit and the text encoders tokenize `**`/`_` as literal content.
+ it('preserves the caption including Markdown and whitespace for every engine', () => {
+ // Regression: the sidecar must receive the caption shown by prompt preview.
const textArg = (args) => args[args.indexOf('--text') + 1];
for (const engineId of Object.keys(ENGINES)) {
const { args } = buildSidecarArgs({
...base, engineId, repo: 'some/repo',
- prompt: 'slow-burning, cinematic instrumental with a **dark** `analog` pulse',
+ prompt: ' slow-burning, cinematic instrumental with a **dark** `analog` pulse\n',
});
- expect(textArg(args), engineId).toBe('slow-burning, cinematic instrumental with a dark analog pulse');
+ expect(textArg(args), engineId).toBe(' slow-burning, cinematic instrumental with a **dark** `analog` pulse\n');
}
});
diff --git a/server/services/tracks/logic.js b/server/services/tracks/logic.js
index 77b12eebcc..e4b6904083 100644
--- a/server/services/tracks/logic.js
+++ b/server/services/tracks/logic.js
@@ -56,6 +56,7 @@ import { compareNewerWins } from '../../lib/lwwTimestamp.js';
import { sanitizeChiptuneScore } from '../../lib/chiptuneScore.js';
import { normalizeWaveSketch } from '../../lib/waveSketch.js';
import { isStr, trimTo } from '../../lib/textUtils.js';
+import { promptAdditionsSchema } from '../../lib/modelInput.js';
import { TITLE_MAX, ALBUM_ID_MAX, ARTIST_ID_MAX, ARTIST_NAME_MAX, CONCEPT_MAX, LYRICS_MAX, PROMPT_MAX, ENGINE_MAX, MODEL_ID_MAX, EXECUTION_PROFILE_MAX, AUDIO_FILENAME_MAX, RENDER_ID_MAX, RENDER_SOURCE_MAX, RENDERS_MAX } from '../../lib/trackLimits.js';
export { TITLE_MAX, ALBUM_ID_MAX, ARTIST_ID_MAX, ARTIST_NAME_MAX, CONCEPT_MAX, LYRICS_MAX, PROMPT_MAX, ENGINE_MAX, MODEL_ID_MAX, EXECUTION_PROFILE_MAX, AUDIO_FILENAME_MAX, RENDER_ID_MAX, RENDER_SOURCE_MAX, RENDERS_MAX };
@@ -137,6 +138,12 @@ export function sanitizeRender(raw) {
if (!audioFilename) return null;
const id = isStr(raw.id) && RENDER_ID_RE.test(raw.id) ? raw.id : legacyRenderId(audioFilename);
const codeProvenance = sanitizeCodeProvenance(raw.codeProvenance);
+ const additions = promptAdditionsSchema.safeParse(raw.promptAdditions);
+ // Optional provenance on new local audio takes. Keep the exact caption,
+ // including whitespace and the directive beyond the authored 8,000-char cap.
+ const sent = typeof raw.sentPrompt === 'string' && raw.sentPrompt.length <= 20000
+ ? { sentPrompt: raw.sentPrompt, ...(additions.success && additions.data ? { promptAdditions: additions.data } : {}) }
+ : {};
return {
id,
audioFilename,
@@ -153,6 +160,7 @@ export function sanitizeRender(raw) {
durationSec: sanitizeDuration(raw.durationSec),
createdAt: isStr(raw.createdAt) && raw.createdAt ? raw.createdAt : new Date().toISOString(),
...(codeProvenance ? { codeProvenance } : {}),
+ ...sent,
};
}
@@ -364,7 +372,17 @@ export function mergeTrackRecord(local, remoteRaw) {
// Same for the drawn wave sketch (#8376): a ≤v6 peer's payload lacks the keys.
if (!('waveSketch' in remoteRaw) && local.waveSketch) carry.waveSketch = local.waveSketch;
if (!('waveSketchPrompt' in remoteRaw) && local.waveSketchPrompt) carry.waveSketchPrompt = local.waveSketchPrompt;
- if (Object.keys(carry).length) next = { ...remote, ...carry };
+ // A sender-behind peer may edit the track while omitting caption
+ // provenance from its existing takes. Carry only matching take ids; never
+ // resurrect a take that the incoming record deliberately deleted.
+ const localTakes = new Map((local.renders || []).map((take) => [take.id, take]));
+ carry.renders = remote.renders.map((take) => {
+ const previous = localTakes.get(take.id);
+ return !('sentPrompt' in take) && typeof previous?.sentPrompt === 'string'
+ ? { ...take, sentPrompt: previous.sentPrompt, ...(previous.promptAdditions ? { promptAdditions: previous.promptAdditions } : {}) }
+ : take;
+ });
+ next = { ...remote, ...carry };
}
const changed = JSON.stringify(next) !== JSON.stringify(local);
return { next, inserted: false, remoteWins, changed };
diff --git a/server/services/tracks/logic.test.js b/server/services/tracks/logic.test.js
index 9bcec7384e..7a528dcbb5 100644
--- a/server/services/tracks/logic.test.js
+++ b/server/services/tracks/logic.test.js
@@ -72,6 +72,21 @@ describe('tracks logic', () => {
expect(mergeTrackRecord(local, { ...local, title: 'Old', updatedAt: '2000-01-01T00:00:00.000Z' }).remoteWins).toBe(false);
});
+ it('keeps exact caption provenance from a sender-behind track edit without restoring deleted takes', () => {
+ const addition = { id: 'instrumental-only', label: 'Instrumental only', text: 'No vocals.' };
+ const local = buildTrackRecord({ title: 'Local', renders: [
+ { id: 'r-kept', audioFilename: 'kept.wav', sentPrompt: ' **folk**\nNo vocals.\n', promptAdditions: [addition] },
+ { id: 'r-deleted', audioFilename: 'deleted.wav', sentPrompt: 'deleted' },
+ ] }, { id: 'track-1', now: '2026-06-01T00:00:00.000Z' });
+ const remote = { ...local, title: 'Remote edit', updatedAt: '2099-01-01T00:00:00.000Z', renders: [
+ { id: 'r-kept', audioFilename: 'kept.wav' },
+ ] };
+ const merged = mergeTrackRecord(local, remote).next;
+ expect(merged.renders).toHaveLength(1);
+ expect(merged.renders[0]).toMatchObject({ sentPrompt: local.renders[0].sentPrompt, promptAdditions: [addition] });
+ expect(sanitizeTrack(merged).renders[0]).toEqual(merged.renders[0]);
+ });
+
it('preserves a local concept when an older peer omits the additive field', () => {
const authored = buildTrackRecord({ title: 'Local', concept: 'A dusk-time pulse' }, { id: 'track-1', now: '2026-06-01T00:00:00.000Z' });
const remote = { ...authored, title: 'Remote', updatedAt: '2099-01-01T00:00:00.000Z' };