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 (codex): fix lyric erasure, user-model rendering, fast-fail + album sync
[._.]/ Adam Eivy8f6517c4dbd9
diff --git a/client/src/components/music/MusicGenPanel.jsx b/client/src/components/music/MusicGenPanel.jsxindex ce901cf9d2..787308b7ba 100644--- a/client/src/components/music/MusicGenPanel.jsx+++ b/client/src/components/music/MusicGenPanel.jsx@@ -87,15 +87,20 @@ export default function MusicGenPanel({ track, prompt, lyrics, onGenerated }) {if (!repo || !engine) return;setInstalling(true);setInstallProgress({ message: `Starting ${repo}…` });+ // Track failure across the stream: an `error` frame OR a thrown request+ // (e.g. a 400 invalid-repo) means the install did NOT succeed, so we must+ // not then clear the field / select the repo / report "Installed".+ let failed = false;await installAudioModel({ engine: engine.id, repo }, (ev) => {if (!mountedRef.current) return;if (ev.type === 'progress') setInstallProgress({ message: `${ev.file || 'downloading'} — ${Math.round((ev.progress || 0) * 100)}%`, progress: ev.progress });else if (ev.type === 'stage') setInstallProgress({ message: ev.stage });- else if (ev.type === 'error') { toast.error(ev.message || 'Download failed'); }- }).catch((err) => { if (mountedRef.current) toast.error(err.message || 'Install failed'); });+ else if (ev.type === 'error') { failed = true; toast.error(ev.message || 'Download failed'); }+ }).catch((err) => { failed = true; if (mountedRef.current) toast.error(err.message || 'Install failed'); });if (!mountedRef.current) return;setInstalling(false);setInstallProgress(null);+ if (failed) return; // leave the repo field intact so the user can retry/fixsetInstallRepo('');await loadEngines(); // refresh model list (the new repo is now registered)setModelId(repo);diff --git a/server/routes/music.js b/server/routes/music.jsindex 99d869240e..e259efd2ef 100644--- a/server/routes/music.js+++ b/server/routes/music.js@@ -24,6 +24,7 @@ import { ENGINES, DEFAULT_ENGINE_ID, getEngine, isEngineReady, generateMusic } fimport { listEngineModels, addAudioModel, removeAudioModel, isValidRepoId } from '../services/audioModels.js';import { startHfDownloadStream } from '../lib/sseDownload.js';import * as tracks from '../services/tracks/index.js';+import * as albums from '../services/albums/index.js';const router = Router();@@ -115,6 +116,24 @@ router.post('/generate', asyncHandler(async (req, res) => {const body = validateRequest(generateSchema, req.body ?? {});const engine = getEngine(body.engine);+ // Validate the target track BEFORE the (minutes-long) render so a stale/+ // deleted trackId fails fast instead of wasting a render + orphaning a WAV.+ let existing = null;+ if (body.trackId) {+ existing = await tracks.getTrack(body.trackId);+ if (!existing) throw new ServerError('Track not found', { status: 404, code: 'NOT_FOUND' });+ }++ // Resolve a USER-INSTALLED model id to its HF repo so the sidecar renders with+ // the installed checkpoint instead of falling back to the engine default. A+ // shipped model id leaves `repo` undefined (generateMusic uses the registry).+ let repo;+ if (body.modelId) {+ const merged = await listEngineModels(engine.id);+ const picked = merged.find((m) => m.id === body.modelId);+ if (picked?.userAdded) repo = picked.repo || picked.id;+ }+// generateMusic throws a typed ServerError (503 venv-missing / 500 sidecar// failure) that asyncHandler maps verbatim — no need to re-wrap here.const result = await generateMusic({@@ -122,22 +141,24 @@ router.post('/generate', asyncHandler(async (req, res) => {lyrics: body.lyrics,engine: engine.id,modelId: body.modelId,+ repo,durationSec: body.durationSec,});- // Persist the audio onto a track: update the named one, or create a new one.+ // Persist the audio + gen metadata. Lyrics: only write them when the engine is+ // lyric-aware AND the caller sent some — otherwise a non-lyric render (or an+ // engine that sends lyrics:'') would silently erase a track's existing lyrics.const meta = {audioFilename: result.filename,engine: result.engine,modelId: result.modelId,durationSec: Math.round(result.durationSec),prompt: body.prompt,- lyrics: body.lyrics,};+ if (engine.lyrics && body.lyrics) meta.lyrics = body.lyrics;+let track;- if (body.trackId) {- track = await tracks.getTrack(body.trackId);- if (!track) throw new ServerError('Track not found', { status: 404, code: 'NOT_FOUND' });+ if (existing) {track = await tracks.updateTrack(body.trackId, meta);} else {track = await tracks.createTrack({@@ -145,8 +166,17 @@ router.post('/generate', asyncHandler(async (req, res) => {artistId: body.artistId,artist: body.artist,albumId: body.albumId,+ ...(engine.lyrics && body.lyrics ? { lyrics: body.lyrics } : {}),...meta,});+ // Mirror the /api/tracks create path: a new track with an albumId must be+ // appended to that album's ordered trackIds so album views show it.+ if (track.albumId) {+ const album = await albums.getAlbum(track.albumId).catch(() => null);+ if (album && !(album.trackIds || []).includes(track.id)) {+ await albums.updateAlbum(track.albumId, { trackIds: [...(album.trackIds || []), track.id] }).catch(() => {});+ }+ }}res.status(body.trackId ? 200 : 201).json({diff --git a/server/routes/music.test.js b/server/routes/music.test.jsindex a88287ea2c..bf6a84b7d2 100644--- a/server/routes/music.test.js+++ b/server/routes/music.test.js@@ -40,7 +40,13 @@ vi.mock('../services/audioModels.js', () => ({const sse = vi.hoisted(() => ({ run: vi.fn(async ({ res }) => { res.writeHead(200, { 'Content-Type': 'text/event-stream' }); res.end('data: {"type":"complete"}\n\n'); }) }));vi.mock('../lib/sseDownload.js', () => ({ startHfDownloadStream: (args) => sse.run(args) }));+vi.mock('../services/albums/index.js', () => ({+ getAlbum: vi.fn(async () => null),+ updateAlbum: vi.fn(async (id, patch) => ({ id, ...patch })),+}));+import * as tracks from '../services/tracks/index.js';+import * as albums from '../services/albums/index.js';import { errorMiddleware } from '../lib/errorHandler.js';import musicRoutes from './music.js';@@ -56,7 +62,19 @@ describe('music routes', () => {let app;beforeEach(() => {app = makeApp();- vi.clearAllMocks();+ // mockReset clears queued *Once implementations too (clearAllMocks only+ // clears call history) — otherwise an unconsumed mockResolvedValueOnce on+ // generateMusic leaks into the next test.+ gen.generateMusic.mockReset();+ models.list.mockReset();+ models.add.mockReset();+ models.remove.mockReset();+ tracks.getTrack.mockReset();+ tracks.createTrack.mockReset().mockImplementation(async (input) => ({ id: 'track-new', ...input }));+ tracks.updateTrack.mockReset().mockImplementation(async (id, patch) => ({ id, ...patch }));+ albums.getAlbum.mockReset().mockResolvedValue(null);+ albums.updateAlbum.mockReset().mockImplementation(async (id, patch) => ({ id, ...patch }));+ sse.run.mockReset().mockImplementation(async ({ res }) => { res.writeHead(200, { 'Content-Type': 'text/event-stream' }); res.end('data: {"type":"complete"}\n\n'); });gen.ready = true;models.list.mockResolvedValue([{ id: 'm', name: 'M', userAdded: false }]);});@@ -125,6 +143,40 @@ describe('music routes', () => {expect(tracks.createTrack).not.toHaveBeenCalled();});+ it('POST /generate on a non-lyric engine does NOT write lyrics (no erasure)', async () => {+ tracks.getTrack.mockResolvedValueOnce({ id: 'track-1', title: 'Has Lyrics', lyrics: 'keep me' });+ gen.generateMusic.mockResolvedValueOnce({ filename: 'm.wav', durationSec: 12, engine: 'musicgen', modelId: 'm' });+ // MusicGen is not lyric-aware; even if the client sends lyrics:'' the update must omit lyrics.+ await request(app).post('/api/music/generate').send({ prompt: 'bed', lyrics: '', engine: 'musicgen', trackId: 'track-1' });+ const patch = tracks.updateTrack.mock.calls[0][1];+ expect(patch).not.toHaveProperty('lyrics');+ });++ it('POST /generate validates trackId BEFORE rendering (no wasted render)', async () => {+ tracks.getTrack.mockResolvedValueOnce(null);+ const r = await request(app).post('/api/music/generate').send({ prompt: 'x', trackId: 'gone' });+ expect(r.status).toBe(404);+ expect(gen.generateMusic).not.toHaveBeenCalled(); // render never started+ });++ it('POST /generate resolves a USER-INSTALLED model id to its repo for the sidecar', async () => {+ models.list.mockResolvedValueOnce([+ { id: 'm', name: 'M', userAdded: false },+ { id: 'someorg/big-musicgen', name: 'Big', repo: 'someorg/big-musicgen', userAdded: true },+ ]);+ gen.generateMusic.mockResolvedValueOnce({ filename: 'm.wav', durationSec: 12, engine: 'musicgen', modelId: 'someorg/big-musicgen' });+ await request(app).post('/api/music/generate').send({ prompt: 'x', engine: 'musicgen', modelId: 'someorg/big-musicgen' });+ expect(gen.generateMusic).toHaveBeenCalledWith(expect.objectContaining({ repo: 'someorg/big-musicgen', modelId: 'someorg/big-musicgen' }));+ });++ it('POST /generate creating a track with albumId appends it to the album tracklist', async () => {+ albums.getAlbum.mockResolvedValueOnce({ id: 'album-1', trackIds: ['track-0'] });+ tracks.createTrack.mockResolvedValueOnce({ id: 'track-gen', title: 'x', albumId: 'album-1' });+ gen.generateMusic.mockResolvedValueOnce({ filename: 'm.wav', durationSec: 12, engine: 'musicgen', modelId: 'm' });+ await request(app).post('/api/music/generate').send({ prompt: 'x', engine: 'musicgen', albumId: 'album-1' });+ expect(albums.updateAlbum).toHaveBeenCalledWith('album-1', { trackIds: ['track-0', 'track-gen'] });+ });+it('POST /generate with an unknown trackId 404s and does not create', async () => {tracks.getTrack.mockResolvedValueOnce(null);gen.generateMusic.mockResolvedValueOnce({ filename: 'm.wav', durationSec: 10, engine: 'musicgen', modelId: 'm' });diff --git a/server/services/pipeline/musicGen.js b/server/services/pipeline/musicGen.jsindex 6f0a15295a..36bccde3ac 100644--- a/server/services/pipeline/musicGen.js+++ b/server/services/pipeline/musicGen.js@@ -251,13 +251,21 @@ function parseResultLine(stdout) {* engines ignore it. `signal` (optional AbortSignal) SIGTERMs the child — wired* through so a cancel button can abort a long render.*/-export async function generateMusic({ prompt, lyrics, engine: engineId = DEFAULT_ENGINE_ID, durationSec, modelId, signal } = {}) {+export async function generateMusic({ prompt, lyrics, engine: engineId = DEFAULT_ENGINE_ID, durationSec, modelId, repo, signal } = {}) {const text = (prompt || '').trim();if (!text) {throw new ServerError('prompt is required', { status: 400, code: 'PIPELINE_MUSIC_EMPTY_PROMPT' });}const engine = getEngine(engineId);- const model = getEngineModel(engine.id, modelId) || getEngineModel(engine.id, engine.defaultModelId);+ // `repo` (when given) is an explicit HF checkpoint — used for USER-INSTALLED+ // models that aren't in the shipped ENGINES registry (the caller resolved it+ // from the audio-models registry). It overrides the registry lookup so an+ // installed model actually renders instead of silently falling back to the+ // engine default. `modelId` is still reported for metadata.+ const shippedModel = getEngineModel(engine.id, modelId) || getEngineModel(engine.id, engine.defaultModelId);+ const model = repo+ ? { id: modelId || repo, repo, name: modelId || repo }+ : shippedModel;const resolvedDuration = durationSec ?? engine.defaultDurationSec;const pythonPath = engine.resolvePython();if (!pythonPath) {