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
address review (self): fix ensureClosingSection guarantee + reindent
[._.]/ Adam Eivy6482b2742e88
diff --git a/client/src/components/music/MusicGenPanel.jsx b/client/src/components/music/MusicGenPanel.jsxindex 24f45faed9..0a72c2d69a 100644--- a/client/src/components/music/MusicGenPanel.jsx+++ b/client/src/components/music/MusicGenPanel.jsx@@ -637,7 +637,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. Auto leaves extra room, but an explicit [outro] marker gives the ending clearer structure.</p>+ <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>) : 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>diff --git a/server/services/pipeline/musicGen.js b/server/services/pipeline/musicGen.jsindex c43675df7e..021fba0984 100644--- a/server/services/pipeline/musicGen.js+++ b/server/services/pipeline/musicGen.js@@ -311,20 +311,21 @@ export const ENGINES = Object.freeze({// documented section tags. Engines without this field (ACE-Step) accept an// empty string and render an instrumental themselves.//- // The sheet is built per-render rather than fixed, because `audio_duration`- // is only a CEILING for this engine — see buildMinimaxInstrumentalLyrics.- instrumentalLyrics: buildMinimaxInstrumentalLyrics,- // Guarantee a closing section on the sheet (see ensureClosingSection) so the- // model resolves its ending instead of cutting off mid-phrase at an- // arbitrary time. Applied only to this engine — it is the one whose- // resolution point is an end-token the user's draft may not cue.- ensureOutro: true,- // Auto mode sizes that ceiling from lyric words/sections and leaves room- // for an ending. MiniMax may still stop earlier by design.- autoDuration: true,- customModels: false,- fixedModelInstall: true,- cudaRequired: true,+ // The sheet is built per-render rather than fixed, because `audio_duration`+ // is only a CEILING for this engine — see buildMinimaxInstrumentalLyrics.+ instrumentalLyrics: buildMinimaxInstrumentalLyrics,+ // Guarantee a closing section on the sheet (see ensureClosingSection) so the+ // model resolves its ending instead of cutting off mid-phrase at an+ // arbitrary time. Applied to both MiniMax Music 3 variants below (not+ // ACE-Step) — MiniMax is the one whose resolution point is an end-token+ // the user's draft may not cue.+ ensureOutro: true,+ // Auto mode sizes that ceiling from lyric words/sections and leaves room+ // for an ending. MiniMax may still stop earlier by design.+ autoDuration: true,+ customModels: false,+ fixedModelInstall: true,+ cudaRequired: true,executionProfile: 'cuda-bf16-auto-experimental',vramProfiles: MINIMAX_MUSIC3_VRAM_PROFILES,benchmarkGuide: MUSIC_RENDERER_BENCHMARK_GUIDE,@@ -343,7 +344,7 @@ export const ENGINES = Object.freeze({resolvePython: resolveMinimaxMusic3MlxPython,venvDefault: MINIMAX_MUSIC3_MLX_VENV_DEFAULT,installEnv: 'INSTALL_MINIMAX_MUSIC3_MLX',- healthProbe: 'import mlx; from mlx_audio.music import load',+ healthProbe: 'import mlx; from mlx_audio.music import load',lyrics: true,instrumentalLyrics: buildMinimaxInstrumentalLyrics,ensureOutro: true,@@ -583,17 +584,18 @@ const MINIMAX_OUTRO_TAG = /^outro\b/i;* abruptly, no conclusion" report. Appending an explicit `[outro]` hands the* model a closing structure without touching any section the user wrote.*- * Idempotent: a sheet that already carries an outro tag is returned unchanged, so- * the instrumental fallback (which already closes with `[outro]`) is untouched and- * a user's own `[outro]` is never duplicated.+ * Idempotent: a sheet whose LAST section already carries an outro tag is returned+ * unchanged, so the instrumental fallback (which already closes with `[outro]`)+ * is untouched and a user's own closing `[outro]` is never duplicated.*/export function ensureClosingSection(lyrics) {const text = typeof lyrics === 'string' ? lyrics : '';- const hasOutro = text.split(/\r?\n/).some((raw) => {- const tag = MINIMAX_LEADING_TAG.exec(raw.trim());- return tag && MINIMAX_OUTRO_TAG.test(tag[1]);- });- if (hasOutro) return text;+ const lastTag = text+ .split(/\r?\n/)+ .map((raw) => MINIMAX_LEADING_TAG.exec(raw.trim()))+ .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]';}@@ -626,20 +628,20 @@ export function buildSidecarArgs({ engineId = DEFAULT_ENGINE_ID, pythonPath, scr'--runtime-dir', runtimeDir ?? engine.runtimeDir,];if (engine.lyrics) {- // Preserve the caller's string verbatim 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.+ // 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;- // For engines whose resolution point is an end-token the draft may not cue- // (see ensureClosingSection), guarantee a closing section on whatever sheet- // reaches the model — a caller's or the fallback's — idempotently.+ ? 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);- }+ }return { bin: pythonPath, args };}diff --git a/server/services/pipeline/musicGen.test.js b/server/services/pipeline/musicGen.test.jsindex 5d04bf94b2..a069f5d24b 100644--- a/server/services/pipeline/musicGen.test.js+++ b/server/services/pipeline/musicGen.test.js@@ -241,11 +241,11 @@ describe('buildSidecarArgs', () => {});expect(args).toContain('MiniMaxAI/MiniMax-Music3');expect(args.slice(args.indexOf('--duration'), args.indexOf('--duration') + 2)).toEqual(['--duration', '300']);- // A sheet with no closing section gets an [outro] cue appended so the model- // resolves its ending; the caller's words still lead the sheet.+ // A sheet with no closing section gets an [outro] cue appended so the model+ // resolves its ending; the caller's words still lead the sheet.expect(args.slice(args.indexOf('--lyrics'), args.indexOf('--lyrics') + 2))- .toEqual(['--lyrics', 'Example lyrics\n[outro]']);- });+ .toEqual(['--lyrics', 'Example lyrics\n[outro]']);+ });it('pins the selected MLX checkpoint revision in the sidecar args', () => {const { args } = buildSidecarArgs({@@ -257,7 +257,10 @@ describe('buildSidecarArgs', () => {'--revision', '10aa4ca578d04c6f5256c1bc22fc8405a09602b5',]);expect(args[0]).toMatch(/generate_minimax_music3_mlx\.py$/);- expect(args).toContain('--lyrics');+ // MLX carries ensureOutro too — confirm the flag isn't scoped to the CUDA+ // engine only, not just that a --lyrics flag exists.+ expect(args.slice(args.indexOf('--lyrics'), args.indexOf('--lyrics') + 2))+ .toEqual(['--lyrics', '[verse] Example\n[outro]']);});const base = {pythonPath: '/venv/bin/python3',@@ -770,30 +773,33 @@ describe('instrumental lyrics fallback', () => {});it('preserves the caller\'s words but guarantees a closing section', () => {- // A caller sheet that resolves mid-phrase would make the model end abruptly;- // append the [outro] cue without disturbing any content the caller wrote.+ // A caller sheet that resolves mid-phrase would make the model end abruptly;+ // append the [outro] cue without disturbing any content the caller wrote.const words = '[verse]\nExample words here';const { args } = buildSidecarArgs({ ...base, engineId: 'minimax-music3', repo: 'MiniMaxAI/MiniMax-Music3', lyrics: words });- const sheet = lyricsArg(args);- expect(sheet).toBe(`${words}\n[outro]`);- // The user's text is preserved verbatim as the leading content, and the- // cue sits on its own closing line.- expect(sheet.startsWith(words)).toBe(true);- expect(sheet.split('\n').at(-1)).toBe('[outro]');- });+ expect(lyricsArg(args)).toBe(`${words}\n[outro]`);+ });it('does not duplicate a closing section the caller already supplied', () => {- // The cue is idempotent — a sheet that already ends on [outro] is untouched.+ // The cue is idempotent — a sheet that already ends on [outro] is untouched.const words = '[intro]\n[verse]\nsing\n[outro]';const { args } = buildSidecarArgs({ ...base, engineId: 'minimax-music3', repo: 'MiniMaxAI/MiniMax-Music3', lyrics: words });expect(lyricsArg(args)).toBe(words);- });+ });++ it('still guarantees a closing section when the caller\'s outro is not the last one', () => {+ // The failure mode this PR exists to fix: an outro earlier in the sheet is+ // not a CLOSING section, so the model still resolves on the trailing content.+ const words = '[outro]\n[chorus]\nbig finish';+ const { args } = buildSidecarArgs({ ...base, engineId: 'minimax-music3', repo: 'MiniMaxAI/MiniMax-Music3', lyrics: words });+ expect(lyricsArg(args)).toBe(`${words}\n[outro]`);+ });it('leaves ACE-Step empty — it renders an instrumental from empty lyrics itself', () => {expect(ENGINES.acestep.instrumentalLyrics).toBeUndefined();const { args } = buildSidecarArgs({ ...base, engineId: 'acestep', repo: 'ACE-Step/ACE-Step-v1-3.5B', lyrics: '' });expect(lyricsArg(args)).toBe('');- });+ });});describe('buildMinimaxInstrumentalLyrics', () => {@@ -838,43 +844,53 @@ describe('buildMinimaxInstrumentalLyrics', () => {});it('caps the sheet so a 5-minute render does not emit an unbounded tag wall', () => {- expect(tags(buildMinimaxInstrumentalLyrics(300)).length).toBeLessThanOrEqual(14);- });+ expect(tags(buildMinimaxInstrumentalLyrics(300)).length).toBeLessThanOrEqual(14);+ });});describe('ensureClosingSection', () => {it('appends an [outro] cue to a sheet that has no closing section', () => {- expect(ensureClosingSection('[verse]\nhello world')).toBe('[verse]\nhello world\n[outro]');- });+ expect(ensureClosingSection('[verse]\nhello world')).toBe('[verse]\nhello world\n[outro]');+ });it('returns a sheet that already closes on [outro] unchanged (idempotent)', () => {- const withOutro = '[intro]\n[verse]\nsing\n[outro]';- expect(ensureClosingSection(withOutro)).toBe(withOutro);- });+ const withOutro = '[intro]\n[verse]\nsing\n[outro]';+ expect(ensureClosingSection(withOutro)).toBe(withOutro);+ });++ it('still appends a cue when an outro tag exists but is not the last section', () => {+ // Only the LAST section counts as a closing section — an outro earlier in+ // the sheet does not guarantee the model resolves there.+ expect(ensureClosingSection('[outro]\n[chorus]\nbig finish')).toBe('[outro]\n[chorus]\nbig finish\n[outro]');+ });it('matches a closing section case-insensitively on the tag name', () => {- expect(ensureClosingSection('[VERSE]\n[OUTRO]')).toBe('[VERSE]\n[OUTRO]');- });+ expect(ensureClosingSection('[VERSE]\n[OUTRO]')).toBe('[VERSE]\n[OUTRO]');+ });it('treats an outro with trailing words as a closing section', () => {- expect(ensureClosingSection('[verse]\nfinal\n[outro fade out]')).toBe('[verse]\nfinal\n[outro fade out]');- });+ expect(ensureClosingSection('[verse]\nfinal\n[outro fade out]')).toBe('[verse]\nfinal\n[outro fade out]');+ });++ it('treats a padded tag as a closing section, matching the hasOutro parity in server/lib/musicDuration.js', () => {+ expect(ensureClosingSection('[verse]\nfinal\n[ outro ]')).toBe('[verse]\nfinal\n[ outro ]');+ });it('does not treat a non-boundary lookalike as a closing section', () => {- // "outroduction" has no word boundary after "outro", so it is a different- // tag — matching the hasOutro detection in server/lib/musicDuration.js.- expect(ensureClosingSection('[outroduction]')).toBe('[outroduction]\n[outro]');- expect(ensureClosingSection('\n[final-outro]')).toBe('\n[final-outro]\n[outro]');- });+ // "outroduction" has no word boundary after "outro", so it is a different+ // tag — matching the hasOutro detection in server/lib/musicDuration.js.+ expect(ensureClosingSection('[outroduction]')).toBe('[outroduction]\n[outro]');+ expect(ensureClosingSection('\n[final-outro]')).toBe('\n[final-outro]\n[outro]');+ });- it('recognizes an inline outro tag and a bare word', () => {- expect(ensureClosingSection('no tags at all\n[outro]')).toBe('no tags at all\n[outro]');- expect(ensureClosingSection('outro')).toBe('outro\n[outro]');- });+ it('treats a leading bracketed tag as a closing section but not a bare unbracketed word', () => {+ expect(ensureClosingSection('no tags at all\n[outro]')).toBe('no tags at all\n[outro]');+ 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]');- expect(ensureClosingSection('')).toBe('[outro]');- expect(ensureClosingSection(' \n ')).toBe('[outro]');- });+ expect(ensureClosingSection('[verse]\nsing\n\n ')).toBe('[verse]\nsing\n[outro]');+ expect(ensureClosingSection('')).toBe('[outro]');+ expect(ensureClosingSection(' \n ')).toBe('[outro]');+ });});