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: show exact local music lyric inputs and preserve authored spacing (#11317)
[._.]/ Adam Eivy0ab6e9532c90
diff --git a/client/src/components/music/MusicDesigner.jsx b/client/src/components/music/MusicDesigner.jsxindex bd3cd8ac31..a607ef5751 100644--- a/client/src/components/music/MusicDesigner.jsx+++ b/client/src/components/music/MusicDesigner.jsx@@ -551,7 +551,7 @@ export default function MusicDesigner() {id="music-designer-lyrics"value={lyrics}onChange={(event) => setLyrics(event.target.value)}- onBlur={() => saveDraft({ lyrics: lyrics.trim() })}+ onBlur={() => saveDraft({ lyrics })}disabled={draftLoading}rows={10}maxLength={20000}@@ -565,7 +565,7 @@ export default function MusicDesigner() {<SentPromptPanel sentPrompt={lyricsSent.sentPrompt} additions={lyricsSent.additions} /></div>)}- <button type="button" onClick={() => { saveDraft({ prompt: description.trim(), lyrics: lyrics.trim() }); goTo('render'); }} disabled={busy || !draftReady} className={PRIMARY_BTN}>+ <button type="button" onClick={() => { saveDraft({ prompt: description.trim(), lyrics }); goTo('render'); }} disabled={busy || !draftReady} className={PRIMARY_BTN}>{lyrics.trim() ? 'Next: render' : 'Continue without lyrics'}</button>{!lyrics.trim() && (diff --git a/client/src/components/music/MusicDesigner.test.jsx b/client/src/components/music/MusicDesigner.test.jsxindex 3a4bc3f262..ef9b6b1c56 100644--- a/client/src/components/music/MusicDesigner.test.jsx+++ b/client/src/components/music/MusicDesigner.test.jsx@@ -163,6 +163,17 @@ describe('<MusicDesigner>', () => {expect(window.localStorage.getItem('portos.musicDesigner.activeDraft')).toBe('track-draft');});+ it('saves the lyric editor exactly as authored before proceeding to render', async () => {+ const lyrics = ' [verse]\nKeep these spaces \n';+ api.getTrack.mockResolvedValue({ id: 'track-saved', title: 'Named Track', concept: '', prompt: 'folk', lyrics: '' });+ renderAt('/music/generate/lyrics?trackId=track-saved');+ const editor = await findEnabledByLabelText('Lyrics');+ fireEvent.change(editor, { target: { value: lyrics } });+ fireEvent.blur(editor);+ await waitFor(() => expect(api.updateTrack).toHaveBeenCalledWith('track-saved', { lyrics }, { silent: true }));+ expect(editor).toHaveValue(lyrics);+ });+it('keeps the render prompt visible and editable for a saved draft', async () => {api.getTrack.mockResolvedValue({id: 'track-saved', title: 'Named Track', concept: 'A dusk-time pulse',diff --git a/client/src/components/music/MusicGenPanel.jsx b/client/src/components/music/MusicGenPanel.jsxindex 96ace1308a..07e308da51 100644--- a/client/src/components/music/MusicGenPanel.jsx+++ b/client/src/components/music/MusicGenPanel.jsx@@ -25,6 +25,7 @@ import { useEffect, useMemo, useRef, useState } from 'react';import useMounted from '../../hooks/useMounted';import { useModelInputPreview } from '../../hooks/useModelInputPreview';import ModelInputPreview from '../media/ModelInputPreview';+import SentPromptPanel from '../media/SentPromptPanel';import useMediaJobProgress from '../../hooks/useMediaJobProgress';import { useSocketResource } from '../../hooks/useSocketResource';import { Loader2, Wand2, Download, X } from 'lucide-react';@@ -278,7 +279,9 @@ export default function MusicGenPanel({ track, title = '', artistId = '', artistconst forcedInstrumental = isRemote && !remoteLyricsAvailable;const effectiveInstrumentalOnly = forcedInstrumental || instrumentalOnly;const captionPreview = useModelInputPreview(previewMusicPrompt, {- prompt, instrumentalOnly: effectiveInstrumentalOnly,+ prompt, lyrics, engine: engine?.id, instrumentalOnly: effectiveInstrumentalOnly,+ durationSec: Number.isFinite(durationSec) ? durationSec : undefined,+ durationMode: autoDurationAvailable ? durationMode : 'manual',}, { enabled: !isRemote && !!prompt?.trim() });const lyricsCondition = !isRemote || remoteLyricsAvailable;const conditioningLyrics = generationEngine?.lyrics && !effectiveInstrumentalOnly && lyricsCondition@@ -639,7 +642,7 @@ export default function MusicGenPanel({ track, title = '', artistId = '', artist<p className="mt-1 text-gray-500">No structured lyric sections detected. Add tags such as [intro], [verse], [chorus], and [outro] so MiniMax can pace the composition more reliably.</p>) : null}{lyricDuration.sectionCount > 0 && !lyricDuration.hasOutro && lyricDuration.hasLyrics ? (- <p className="mt-1 text-gray-500">No [outro] section detected. PortOS appends a closing cue for you, but adding your own [outro] marker gives you control over exactly where the ending lands.</p>+ <p className="mt-1 text-gray-500">No [outro] section detected. The closing cue is shown below; adding your own [outro] marker gives you control over exactly where the ending lands.</p>) : null}{lyricDuration.isCapped ? (<p className="mt-1 text-port-warning">These lyrics estimate beyond MiniMax’s five-minute limit, so the final lines may still need to be shortened or split into another render.</p>@@ -703,6 +706,16 @@ export default function MusicGenPanel({ track, title = '', artistId = '', artist</div>{!isRemote && <ModelInputPreview preview={captionPreview} prompt={prompt} />}+ {!isRemote && typeof captionPreview.preview?.sentLyrics === 'string' && (+ <section aria-label="Lyrics sent to the model" className="text-xs space-y-1">+ <p className="text-gray-500">Lyrics sent to the model</p>+ <SentPromptPanel+ prompt={effectiveInstrumentalOnly ? '' : lyrics || ''}+ sentPrompt={captionPreview.preview.sentLyrics}+ additions={captionPreview.preview.lyricAdditions || []}+ />+ </section>+ )}<div className="flex items-center gap-2"><buttondiff --git a/client/src/components/music/MusicGenPanel.test.jsx b/client/src/components/music/MusicGenPanel.test.jsxindex 325a3da745..6c5db3a444 100644--- a/client/src/components/music/MusicGenPanel.test.jsx+++ b/client/src/components/music/MusicGenPanel.test.jsx@@ -1,6 +1,6 @@import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';import { StrictMode } from 'react';-import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';+import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react';import MusicGenPanel from './MusicGenPanel';import * as api from '../../services/api';import toast from '../ui/Toast';@@ -107,11 +107,32 @@ describe('MusicGenPanel', () => {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 });+ expect(api.previewMusicPrompt).toHaveBeenCalledWith(expect.objectContaining({ 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 }));});+ it('shows lyric additions from the server and submits the authored sheet without trimming it', async () => {+ const lyrics = ' [verse]\nKeep these spaces \n';+ const sentLyrics = `${lyrics}\n[outro]`;+ api.listMusicEngines.mockResolvedValue({ defaultEngine: 'minimax-music3', engines: [minimax({ ready: true, modelReady: true })] });+ api.previewMusicPrompt.mockResolvedValue({+ sentPrompt: 'folk', sentLyrics,+ lyricAdditions: [{ id: 'closing-section', label: 'Closing section', text: '[outro]' }],+ });+ api.generateMusic.mockResolvedValue({ track: { id: 'track-1' } });+ render(<MusicGenPanel track={{ id: 'track-1' }} prompt="folk" lyrics={lyrics} />);+ const region = await screen.findByRole('region', { name: 'Lyrics sent to the model' });+ fireEvent.click(within(region).getByRole('button', { name: '+ Closing section' }));+ expect(within(region).getByText('[outro]')).toBeInTheDocument();+ fireEvent.click(within(region).getByRole('button', { name: 'Show full prompt' }));+ expect(region.querySelector('pre').textContent).toBe(sentLyrics);+ expect(within(region).getByRole('button', { name: 'Copy full prompt' })).toBeInTheDocument();+ expect(api.previewMusicPrompt).toHaveBeenCalledWith(expect.objectContaining({ lyrics, engine: 'minimax-music3' }), { silent: true });+ fireEvent.click(screen.getByRole('button', { name: /^generate$/i }));+ await waitFor(() => expect(api.generateMusic).toHaveBeenCalledWith(expect.objectContaining({ lyrics }), { 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.jsxindex 659506b957..26319f8c62 100644--- a/client/src/components/music/TrackRenderModal.jsx+++ b/client/src/components/music/TrackRenderModal.jsx@@ -76,6 +76,13 @@ export default function TrackRenderModal({ render, active = false, onClose, onSe<SentPromptPanel prompt={render.authoredPrompt || prompt} sentPrompt={render.sentPrompt} additions={render.promptAdditions || []} />+ {typeof render.sentLyrics === 'string' && (+ <section aria-label="Lyrics sent to the model" className="text-xs space-y-1">+ <p className="text-gray-500">Lyrics sent to the model</p>+ <SentPromptPanel prompt={lyrics} sentPrompt={render.sentLyrics} additions={render.lyricAdditions || []} />+ </section>+ )}+{lyrics ? (<div><div className="text-[10px] uppercase tracking-wider text-gray-500 mb-1">Lyrics (conditioning)</div>diff --git a/client/src/components/music/TrackRenderModal.test.jsx b/client/src/components/music/TrackRenderModal.test.jsxnew file mode 100644index 0000000000..36e9419a1f--- /dev/null+++ b/client/src/components/music/TrackRenderModal.test.jsx@@ -0,0 +1,23 @@+import { describe, it, expect, vi } from 'vitest';+import { fireEvent, render, screen, within } from '@testing-library/react';+import TrackRenderModal from './TrackRenderModal';+import { copyToClipboard } from '../../lib/clipboard';++vi.mock('../../lib/clipboard', () => ({ copyToClipboard: vi.fn() }));++describe('TrackRenderModal lyric provenance', () => {+ it('shows and copies the exact lyric sheet that conditioned a completed instrumental take', () => {+ const sentLyrics = '[intro]\n[instrumental]\n[outro]';+ render(<TrackRenderModal render={{+ id: 'take-1', audioFilename: 'take.wav', engine: 'minimax-music3', lyrics: '',+ sentLyrics, lyricAdditions: [{ id: 'instrumental-sections', label: 'Instrumental sections', text: sentLyrics }],+ }} onClose={vi.fn()} />);+ const region = screen.getByRole('region', { name: 'Lyrics sent to the model' });+ fireEvent.click(within(region).getByRole('button', { name: '+ Instrumental sections' }));+ expect(region.querySelector('p.whitespace-pre-wrap').textContent).toBe(sentLyrics);+ fireEvent.click(within(region).getByRole('button', { name: 'Show full prompt' }));+ expect(region.querySelector('pre').textContent).toBe(sentLyrics);+ fireEvent.click(within(region).getByRole('button', { name: 'Copy full prompt' }));+ expect(copyToClipboard).toHaveBeenCalledWith(sentLyrics, 'Full prompt copied');+ });+});diff --git a/scripts/generate_acestep15.py b/scripts/generate_acestep15.pyindex 2777302b1f..a83cc10a5c 100644--- a/scripts/generate_acestep15.py+++ b/scripts/generate_acestep15.py@@ -91,7 +91,7 @@ def main():output_dir = os.path.dirname(os.path.abspath(args.output))os.makedirs(output_dir, exist_ok=True)- lyrics = args.lyrics.strip() or "[Instrumental]"+ lyrics = args.lyrics if args.lyrics.strip() else "[Instrumental]"params = GenerationParams(task_type="text2music",caption=text,diff --git a/server/routes/music.js b/server/routes/music.jsindex 6d1e127dc7..9c428561d9 100644--- a/server/routes/music.js+++ b/server/routes/music.js@@ -38,7 +38,7 @@ import { validateRequest } from '../lib/validation.js';import { createLineReader } from '../lib/streamLines.js';import { SETUP_IMAGE_VIDEO_SCRIPT, spawnSetupScript, stopSetupScript } from '../lib/setupScriptRunner.js';import {- ENGINES, isEngineHealthy, isEnginePlatformSupported,+ ENGINES, composeMusicLyrics, isEngineHealthy, isEnginePlatformSupported,enginePlatformLabel, resolveEngineVramReadiness, MUSIC_VRAM_READINESS,formatEngineVramReadinessMessage,} from '../services/pipeline/musicGen.js';@@ -397,7 +397,7 @@ const generateSchema = z.object({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(),+ lyrics: z.string().max(20000).optional(),// A render-level override: ignore even supplied lyrics without clearing the// track's saved lyric field when the completed audio is attached.instrumentalOnly: z.boolean().optional().default(false),@@ -448,11 +448,14 @@ const generateSchema = z.object({// 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));+ const body = validateRequest(generateSchema, req.body ?? {});+ if (body.engine !== undefined && !ENGINES[body.engine]) {+ throw new ServerError(`Unknown audio engine: ${body.engine}`, { status: 400, code: 'PIPELINE_MUSIC_UNKNOWN_ENGINE' });+ }+ res.json({+ ...composeMusicPrompt(body),+ ...composeMusicLyrics({ ...body, lyrics: body.instrumentalOnly ? '' : body.lyrics }),+ });}));router.post('/generate', asyncHandler(async (req, res) => {diff --git a/server/routes/music.test.js b/server/routes/music.test.jsindex ff130aef50..1afb3ae31c 100644--- a/server/routes/music.test.js+++ b/server/routes/music.test.js@@ -18,7 +18,8 @@ const cuda = vi.hoisted(() => ({ status: 'available', maxVramGb: 40 }));vi.mock('../lib/cudaCapability.js', () => ({getCudaCapability: vi.fn(async () => ({ status: cuda.status, gpus: [], maxVramGb: cuda.maxVramGb, error: null })),}));-vi.mock('../services/pipeline/musicGen.js', () => {+vi.mock('../services/pipeline/musicGen.js', async () => {+ const actual = await vi.importActual('../services/pipeline/musicGen.js');const ENGINES = {musicgen: { id: 'musicgen', name: 'MusicGen', models: [{ id: 'm', name: 'M' }], defaultModelId: 'm', minDurationSec: 1, maxDurationSec: 30, defaultDurationSec: 12, installEnv: 'INSTALL_MUSICGEN', venvDefault: '/v/mg', resolvePython: () => (gen.ready ? '/v/mg/bin/python3' : null), customModels: true },acestep: { id: 'acestep', name: 'ACE-Step', models: [{ id: 'a', name: 'A' }], defaultModelId: 'a', minDurationSec: 1, maxDurationSec: 240, defaultDurationSec: 60, installEnv: 'INSTALL_ACESTEP', venvDefault: '/v/ace', resolvePython: () => (gen.ready ? '/v/ace/bin/python3' : null), lyrics: true, customModels: false },@@ -30,6 +31,7 @@ vi.mock('../services/pipeline/musicGen.js', () => {], defaultModelId: 'minimax-music3-mlx-8bit', minDurationSec: 1, maxDurationSec: 300, defaultDurationSec: 60, installEnv: 'INSTALL_MINIMAX_MUSIC3_MLX', venvDefault: '/v/minimax-mlx', resolvePython: () => (gen.ready ? '/v/minimax-mlx/bin/python3' : null), lyrics: true, customModels: false, fixedModelInstall: true, autoDuration: true },};return {+ composeMusicLyrics: actual.composeMusicLyrics,ENGINES,DEFAULT_ENGINE_ID: 'musicgen',getEngine: (id) => ENGINES[id] || ENGINES.musicgen,@@ -696,6 +698,40 @@ describe('music routes', () => {expect(args[args.indexOf('--text') + 1]).toBe(preview.body.sentPrompt);});+ it('previews exact lyric bytes and additions that the sidecar sends, without changing the authored sheet', async () => {+ const actual = await vi.importActual('../services/pipeline/musicGen.js');+ for (const body of [+ { prompt: 'folk', engine: 'minimax-music3', lyrics: ' [verse]\nKeep these words\n \t', durationMode: 'auto' },+ { prompt: 'folk', engine: 'minimax-music3-mlx', lyrics: '', durationSec: 180, instrumentalOnly: true },+ { prompt: 'folk', engine: 'acestep15', lyrics: ' [verse]\nKeep the ending \n', durationSec: 60 },+ { prompt: 'folk', engine: 'acestep15', lyrics: ' \n', durationSec: 60 },+ ]) {+ mediaQueue.enqueue.mockClear();+ const preview = await request(app).post('/api/music/prompt-preview').send(body);+ expect(preview.status).toBe(200);+ expect(mediaQueue.enqueue).not.toHaveBeenCalled();+ 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.musicStudio.authoredLyrics).toBe(body.lyrics);+ expect(params.musicStudio.sentLyrics).toBe(preview.body.sentLyrics);+ expect(params.musicStudio.lyricAdditions).toEqual(preview.body.lyricAdditions);+ const { args } = actual.buildSidecarArgs({+ engineId: params.engine, prompt: params.prompt, lyrics: params.lyrics,+ durationSec: body.durationSec ?? 60,+ });+ expect(args[args.indexOf('--lyrics') + 1]).toBe(preview.body.sentLyrics);+ if (!body.instrumentalOnly) expect(preview.body.sentLyrics.startsWith(body.lyrics)).toBe(true);+ }+ });++ it('refuses lyrics beyond the authored cap before preview or queueing', async () => {+ const body = { prompt: 'folk', engine: 'minimax-music3', lyrics: ' '.repeat(20001) };+ expect((await request(app).post('/api/music/prompt-preview').send(body)).status).toBe(400);+ expect((await request(app).post('/api/music/generate').send(body)).status).toBe(400);+ expect(mediaQueue.enqueue).not.toHaveBeenCalled();+ });+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);diff --git a/server/routes/tracks.js b/server/routes/tracks.jsindex b51046f571..b6d456a95d 100644--- a/server/routes/tracks.js+++ b/server/routes/tracks.js@@ -73,7 +73,7 @@ const albumIdField = z.string().trim().max(tracks.ALBUM_ID_MAX);const artistIdField = z.string().trim().max(tracks.ARTIST_ID_MAX);const artistNameField = z.string().trim().max(tracks.ARTIST_NAME_MAX);const conceptField = z.string().trim().max(tracks.CONCEPT_MAX);-const lyricsField = z.string().trim().max(tracks.LYRICS_MAX);+const lyricsField = z.string().max(tracks.LYRICS_MAX);const promptField = z.string().trim().max(tracks.PROMPT_MAX);const engineField = z.string().trim().max(tracks.ENGINE_MAX);const modelIdField = z.string().trim().max(tracks.MODEL_ID_MAX);diff --git a/server/routes/tracks.test.js b/server/routes/tracks.test.jsindex ca477a0f44..fecfcb476b 100644--- a/server/routes/tracks.test.js+++ b/server/routes/tracks.test.js@@ -240,9 +240,9 @@ describe('tracks routes', () => {});it('POST / creates a track', async () => {- const r = await request(app).post('/api/tracks').send({ title: 'Intro', engine: 'acestep' });+ const r = await request(app).post('/api/tracks').send({ title: 'Intro', engine: 'acestep', lyrics: ' [verse]\nKeep the spaces \n' });expect(r.status).toBe(201);- expect(tracks.createTrack).toHaveBeenCalledWith(expect.objectContaining({ title: 'Intro', engine: 'acestep' }));+ expect(tracks.createTrack).toHaveBeenCalledWith(expect.objectContaining({ title: 'Intro', engine: 'acestep', lyrics: ' [verse]\nKeep the spaces \n' }));expect(r.body.id).toBe('track-new');});diff --git a/server/services/musicGeneration.js b/server/services/musicGeneration.jsindex 13b65ffcd9..67d59950b3 100644--- a/server/services/musicGeneration.js+++ b/server/services/musicGeneration.js@@ -12,7 +12,7 @@*/import { ServerError } from '../lib/errorHandler.js';-import { ENGINES, getEngine } from './pipeline/musicGen.js';+import { ENGINES, getEngine, composeMusicLyrics } from './pipeline/musicGen.js';import { listEngineModels } from './audioModels.js';import {FEDERATED_MEDIA_WIRE_VERSION,@@ -176,6 +176,7 @@ export async function queueMusicGeneration(input) {const promptRecord = composeMusicPrompt(body);const usedPrompt = promptRecord.sentPrompt;const usedLyrics = engine.lyrics && !body.instrumentalOnly ? (body.lyrics ?? '') : '';+ const lyricRecord = !remoteMedia ? composeMusicLyrics({ ...body, engine: engine.id, lyrics: usedLyrics }) : {};if (remoteMedia) {// Lyrics ride the marker, not the top-level params, for the same reason the// profile does: `params.lyrics` stays blank so a build rolled back past@@ -216,7 +217,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 : {}),+ ...(!remoteMedia ? { ...promptRecord, ...lyricRecord } : {}),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.jsindex 2a2248bd13..4c62b4b8d6 100644--- a/server/services/musicStudioHook.js+++ b/server/services/musicStudioHook.js@@ -35,6 +35,7 @@ const hook = createMediaJobImageHook({...(typeof tag.sentPrompt === 'string' ? { sentPrompt: tag.sentPrompt, promptAdditions: tag.promptAdditions } : {}),lyrics: remotePrompt ? '' : job.params.lyrics,authoredLyrics,+ ...(typeof tag.sentLyrics === 'string' ? { sentLyrics: tag.sentLyrics, lyricAdditions: tag.lyricAdditions } : {}),lyricsEnabled: tag.lyricsEnabled === true,lyricsProvided: tag.lyricsProvided === true,instrumentalOnly: typeof tag.instrumentalOnly === 'boolean' ? tag.instrumentalOnly : null,@@ -44,7 +45,7 @@ const hook = createMediaJobImageHook({albumId: tag.albumId,};},- attach: async ({ job, trackId, filename, durationSec, engine, modelId, executionProfile, prompt, authoredPrompt, sentPrompt, promptAdditions, lyrics, authoredLyrics, lyricsEnabled, lyricsProvided, instrumentalOnly, title, artistId, artist, albumId }) => {+ attach: async ({ job, trackId, filename, durationSec, engine, modelId, executionProfile, prompt, authoredPrompt, sentPrompt, promptAdditions, sentLyrics, lyricAdditions, 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;@@ -54,6 +55,8 @@ const hook = createMediaJobImageHook({authoredPrompt,sentPrompt,promptAdditions,+ sentLyrics,+ lyricAdditions,lyrics: lyricsEnabled ? lyrics : '',instrumentalOnly,engine,diff --git a/server/services/musicStudioHook.test.js b/server/services/musicStudioHook.test.jsindex 7051ad3042..d18cf19902 100644--- a/server/services/musicStudioHook.test.js+++ b/server/services/musicStudioHook.test.js@@ -84,22 +84,26 @@ 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 () => {+ it('persists exact caption and lyric provenance on the take beyond the authored caps', 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`;+ const sentLyrics = `${'x'.repeat(20000)}\n[outro]`;+ const lyricAdditions = [{ id: 'closing-section', label: 'Closing section', text: '[outro]' }];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,+ sentLyrics, lyricAdditions,} },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],+ sentLyrics, lyricAdditions,});});diff --git a/server/services/pipeline/musicGen.js b/server/services/pipeline/musicGen.jsindex 31af62ebc5..2a145af0d7 100644--- a/server/services/pipeline/musicGen.js+++ b/server/services/pipeline/musicGen.js@@ -60,6 +60,7 @@ import { ServerError } from '../../lib/errorHandler.js';import { recommendMinimaxDurationSec } from '../../lib/musicDuration.js';import { safeChildProcessOptions } from '../../lib/processEnv.js';import { maintenance } from '../../lib/maintenanceAdmission.js';+import { promptAddition } from '../../lib/modelInput.js';const execFileAsync = promisify(execFile);@@ -290,6 +291,8 @@ export const ENGINES = Object.freeze({// "runtime not found" 503.healthProbe: 'import torch; from transformers import AutoModel; from acestep.handler import AceStepHandler; from acestep.inference import GenerationConfig, GenerationParams, generate_music',lyrics: true,+ // Keep the sidecar's required instrumental marker visible in the preview.+ instrumentalLyrics: '[Instrumental]',customModels: false,fixedModelInstall: true,},@@ -600,8 +603,43 @@ export function ensureClosingSection(lyrics) {.filter(Boolean).at(-1);if (lastTag && MINIMAX_OUTRO_TAG.test(lastTag[1].trim())) return text;- const trimmed = text.replace(/\s+$/, '');- return trimmed ? `${trimmed}\n[outro]` : '[outro]';+ return text ? `${text}\n[outro]` : '[outro]';+}++/** Resolve the same duration ceiling for preview, lyric composition and render. */+function resolveMusicDuration({ engine: engineId = DEFAULT_ENGINE_ID, lyrics, durationSec, durationMode }) {+ const engine = getEngine(engineId);+ return durationMode === 'auto' && engine.autoDuration+ ? recommendMinimaxDurationSec(lyrics, {+ minDurationSec: engine.defaultDurationSec,+ maxDurationSec: engine.maxDurationSec,+ })+ : durationSec ?? engine.defaultDurationSec;+}++/** Exact lyric-side input, shared by the studio preview, snapshot and sidecar. */+export function composeMusicLyrics(input) {+ const engine = getEngine(input.engine);+ if (!engine.lyrics) return {};+ const provided = typeof input.lyrics === 'string' ? input.lyrics : '';+ const seconds = clampDuration(resolveMusicDuration(input), engine.id);+ const fallback = typeof engine.instrumentalLyrics === 'function'+ ? engine.instrumentalLyrics(seconds)+ : (engine.instrumentalLyrics || '');+ // A whitespace-only authored input remains intact; the required section+ // sheet is appended as an inspectable addition instead of replacing it.+ const fallbackAddition = !provided.trim() && fallback+ ? promptAddition('instrumental-sections', 'Instrumental sections', fallback)+ : null;+ const sheet = fallbackAddition ? `${provided}${provided ? '\n' : ''}${fallbackAddition.text}` : provided;+ const sentLyrics = engine.ensureOutro ? ensureClosingSection(sheet) : sheet;+ const outroAddition = sentLyrics !== sheet+ ? promptAddition('closing-section', 'Closing section', '[outro]')+ : null;+ return {+ sentLyrics,+ lyricAdditions: [fallbackAddition, outroAddition].filter(Boolean),+ };}/**@@ -629,19 +667,7 @@ export function buildSidecarArgs({ engineId = DEFAULT_ENGINE_ID, pythonPath, scr'--runtime-dir', runtimeDir ?? engine.runtimeDir,];if (engine.lyrics) {- // Preserve the caller's string when they supplied one; substitute only when- // it is absent or whitespace, and only for an engine that cannot accept- // empty lyrics (see instrumentalLyrics). The substitute may be a builder- // that sizes the sheet to the render length. `ensureOutro` engines may- // still append a closing section to either sheet below.- const provided = typeof lyrics === 'string' ? lyrics : '';- const fallback = typeof engine.instrumentalLyrics === 'function'- ? engine.instrumentalLyrics(seconds)- : (engine.instrumentalLyrics || '');- const sheet = provided.trim() ? provided : fallback;- // ensureOutro engines resolve on an end-token the draft may not cue —- // guarantee one on whatever sheet reaches the model, idempotently.- args.push('--lyrics', engine.ensureOutro ? ensureClosingSection(sheet) : sheet);+ args.push('--lyrics', composeMusicLyrics({ engine: engine.id, lyrics, durationSec: seconds }).sentLyrics);}return { bin: pythonPath, args };}@@ -694,12 +720,7 @@ async function generateMusicAdmitted({ prompt, lyrics, engine: engineId = DEFAULconst model = repo? { id: modelId || repo, repo, name: modelId || repo }: shippedModel;- const resolvedDuration = durationMode === 'auto' && engine.autoDuration- ? recommendMinimaxDurationSec(lyrics, {- minDurationSec: engine.defaultDurationSec,- maxDurationSec: engine.maxDurationSec,- })- : durationSec ?? engine.defaultDurationSec;+ const resolvedDuration = resolveMusicDuration({ engine: engine.id, lyrics, durationSec, durationMode });const pythonPath = engine.resolvePython();if (engine.cudaRequired) {const cuda = await getCudaCapability();diff --git a/server/services/pipeline/musicGen.test.js b/server/services/pipeline/musicGen.test.jsindex ef0f6908bc..f64c6dd36f 100644--- a/server/services/pipeline/musicGen.test.js+++ b/server/services/pipeline/musicGen.test.js@@ -831,13 +831,13 @@ describe('instrumental lyrics fallback', () => {const base = { pythonPath: '/venv/bin/python3', prompt: 'cinematic electronic instrumental', durationSec: 60, outputPath: '/tmp/out.wav' };const lyricsArg = (args) => args[args.indexOf('--lyrics') + 1];- it('substitutes a documented structure-tag sheet when MiniMax Music 3 gets no lyrics', () => {+ it('adds a documented structure-tag sheet while preserving whitespace-only MiniMax input', () => {// The checkpoint's tokenize step raises on an empty string, so an// instrumental prompt used to die with "`lyrics` must be a non-empty// string" after the model had already loaded.for (const lyrics of [undefined, '', ' ', '\n\t ']) {const { args } = buildSidecarArgs({ ...base, engineId: 'minimax-music3', repo: 'MiniMaxAI/MiniMax-Music3', lyrics });- expect(lyricsArg(args), `lyrics=${JSON.stringify(lyrics)}`).toBe(buildMinimaxInstrumentalLyrics(60));+ expect(lyricsArg(args), `lyrics=${JSON.stringify(lyrics)}`).toBe(`${lyrics || ''}${lyrics ? '\n' : ''}${buildMinimaxInstrumentalLyrics(60)}`);}});@@ -969,9 +969,9 @@ describe('ensureClosingSection', () => {expect(ensureClosingSection('outro')).toBe('outro\n[outro]');});- it('trims trailing whitespace before appending and emits a single cue', () => {- expect(ensureClosingSection('[verse]\nsing\n\n ')).toBe('[verse]\nsing\n[outro]');+ it('preserves authored whitespace before appending the closing cue', () => {+ expect(ensureClosingSection('[verse]\nsing\n\n ')).toBe('[verse]\nsing\n\n \n[outro]');expect(ensureClosingSection('')).toBe('[outro]');- expect(ensureClosingSection(' \n ')).toBe('[outro]');+ expect(ensureClosingSection(' \n ')).toBe(' \n \n[outro]');});});diff --git a/server/services/tracks/logic.js b/server/services/tracks/logic.jsindex e4b6904083..1461f85fa8 100644--- a/server/services/tracks/logic.js+++ b/server/services/tracks/logic.js@@ -139,6 +139,10 @@ export function sanitizeRender(raw) {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);+ const lyricAdditions = promptAdditionsSchema.safeParse(raw.lyricAdditions);+ const sentLyrics = typeof raw.sentLyrics === 'string' && raw.sentLyrics.length <= LYRICS_MAX + 1000+ ? { sentLyrics: raw.sentLyrics, ...(lyricAdditions.success && lyricAdditions.data ? { lyricAdditions: lyricAdditions.data } : {}) }+ : {};// 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@@ -149,7 +153,7 @@ export function sanitizeRender(raw) {audioFilename,prompt: trimTo(raw.prompt, PROMPT_MAX),authoredPrompt: trimTo(raw.authoredPrompt, PROMPT_MAX),- lyrics: trimTo(raw.lyrics, LYRICS_MAX),+ lyrics: isStr(raw.lyrics) ? raw.lyrics.slice(0, LYRICS_MAX) : '',// null means a legacy/uploaded render never recorded the choice. Preserve// that sentinel so remixing cannot infer vocal intent from empty lyrics.instrumentalOnly: typeof raw.instrumentalOnly === 'boolean' ? raw.instrumentalOnly : null,@@ -161,6 +165,7 @@ export function sanitizeRender(raw) {createdAt: isStr(raw.createdAt) && raw.createdAt ? raw.createdAt : new Date().toISOString(),...(codeProvenance ? { codeProvenance } : {}),...sent,+ ...sentLyrics,};}@@ -189,7 +194,7 @@ export function sanitizeTrack(raw) {const createdAt = isStr(raw.createdAt) ? raw.createdAt : new Date().toISOString();const updatedAt = isStr(raw.updatedAt) ? raw.updatedAt : createdAt;const deleted = raw.deleted === true;- const lyrics = trimTo(raw.lyrics, LYRICS_MAX);+ const lyrics = isStr(raw.lyrics) ? raw.lyrics.slice(0, LYRICS_MAX) : '';const prompt = trimTo(raw.prompt, PROMPT_MAX);const engine = trimTo(raw.engine, ENGINE_MAX);const modelId = trimTo(raw.modelId, MODEL_ID_MAX);@@ -378,9 +383,13 @@ export function mergeTrackRecord(local, remoteRaw) {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;+ return {+ ...take,+ ...(!('sentPrompt' in take) && typeof previous?.sentPrompt === 'string'+ ? { sentPrompt: previous.sentPrompt, ...(previous.promptAdditions ? { promptAdditions: previous.promptAdditions } : {}) } : {}),+ ...(!('sentLyrics' in take) && typeof previous?.sentLyrics === 'string'+ ? { sentLyrics: previous.sentLyrics, ...(previous.lyricAdditions ? { lyricAdditions: previous.lyricAdditions } : {}) } : {}),+ };});next = { ...remote, ...carry };}diff --git a/server/services/tracks/logic.test.js b/server/services/tracks/logic.test.jsindex 7a528dcbb5..817b2d85df 100644--- a/server/services/tracks/logic.test.js+++ b/server/services/tracks/logic.test.js@@ -74,16 +74,17 @@ describe('tracks logic', () => {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] },+ const local = buildTrackRecord({ title: 'Local', lyrics: ' [verse]\nKeep the spaces \n', renders: [+ { id: 'r-kept', audioFilename: 'kept.wav', sentPrompt: ' **folk**\nNo vocals.\n', promptAdditions: [addition], sentLyrics: ' [verse]\nKeep spaces \n[outro]', lyricAdditions: [{ id: 'closing-section', label: 'Closing section', text: '[outro]' }] },{ 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.lyrics).toBe(' [verse]\nKeep the spaces \n');expect(merged.renders).toHaveLength(1);- expect(merged.renders[0]).toMatchObject({ sentPrompt: local.renders[0].sentPrompt, promptAdditions: [addition] });+ expect(merged.renders[0]).toMatchObject({ sentPrompt: local.renders[0].sentPrompt, promptAdditions: [addition], sentLyrics: local.renders[0].sentLyrics, lyricAdditions: local.renders[0].lyricAdditions });expect(sanitizeTrack(merged).renders[0]).toEqual(merged.renders[0]);});