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

address review (codex): honest render lyrics snapshot + append onto fresh track state

[._.]/ Adam Eivy712ceacf21a6
diff --git a/server/routes/music.js b/server/routes/music.js
index 3861601b4b..a3c2b86f3d 100644
--- a/server/routes/music.js
+++ b/server/routes/music.js
@@ -278,13 +278,19 @@ router.post('/generate', asyncHandler(async (req, res) => {
if (picked.userAdded) repo = picked.repo || picked.id;
}
+ // The lyrics that actually CONDITION this render: what the caller sent for a
+ // lyric-aware engine ('' = render without lyrics), nothing for a non-lyric
+ // engine. The same value drives the generation call AND the render snapshot,
+ // so a render card can never claim conditioning text the audio wasn't built
+ // from (an absent-lyrics lyric render is genuinely un-conditioned, not "the
+ // track's old words").
+ const usedLyrics = engine.lyrics ? (body.lyrics ?? '') : '';
+
// generateMusic throws a typed ServerError (503 venv-missing / 500 sidecar
- // failure) that asyncHandler maps verbatim — no need to re-wrap here. A
- // lyric-aware engine renders with the provided lyrics ('' = no lyrics); a
- // non-lyric engine ignores the flag entirely.
+ // failure) that asyncHandler maps verbatim — no need to re-wrap here.
const result = await generateMusic({
prompt: body.prompt,
- lyrics: engine.lyrics ? (body.lyrics ?? '') : '',
+ lyrics: usedLyrics,
engine: engine.id,
modelId: body.modelId,
repo,
@@ -297,17 +303,16 @@ router.post('/generate', asyncHandler(async (req, res) => {
// but an ABSENT lyrics field leaves the track's lyrics untouched. A non-lyric
// engine never writes lyrics (it can't erase a song's words by adding a bed).
const durationSec = Math.round(result.durationSec);
- // The lyrics actually used for THIS render (snapshotted onto the render card):
- // what the caller sent for a lyric-aware engine, else the track's saved lyrics.
- const renderLyrics = engine.lyrics
- ? (body.lyrics ?? existing?.lyrics ?? '')
- : (existing?.lyrics ?? '');
- // Append to the existing history (sanitizeTrack de-dups + caps); a new track
- // seeds the array with this first render.
- const { renders } = tracks.buildRenderAppend(existing, {
+ // Re-read the track AFTER the (minutes-long) render so the append lands on the
+ // FRESHEST persisted history — a render uploaded/generated to this same track
+ // while this generation was running isn't dropped by writing back a stale
+ // pre-render array. (The sub-millisecond getTrack→updateTrack window is a
+ // single-user request race we intentionally don't lock against — trust model.)
+ const current = existing ? ((await tracks.getTrack(body.trackId)) ?? existing) : null;
+ const { renders } = tracks.buildRenderAppend(current, {
audioFilename: result.filename,
prompt: body.prompt,
- lyrics: renderLyrics,
+ lyrics: usedLyrics,
engine: result.engine,
modelId: result.modelId,
durationSec,
diff --git a/server/routes/music.test.js b/server/routes/music.test.js
index a7de48ba74..b06b6aa12b 100644
--- a/server/routes/music.test.js
+++ b/server/routes/music.test.js
@@ -247,6 +247,23 @@ describe('music routes', () => {
expect(patch).not.toHaveProperty('lyrics');
// The sidecar still renders (with empty lyrics) — engine.lyrics coalesces to ''.
expect(gen.generateMusic).toHaveBeenCalledWith(expect.objectContaining({ lyrics: '' }));
+ // The render SNAPSHOT records the lyrics that actually conditioned it ('' —
+ // generated without lyrics), NOT the track's stale saved lyrics. Otherwise
+ // the card would falsely advertise conditioning text the audio wasn't built from.
+ expect(tracks.buildRenderAppend).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ lyrics: '' }));
+ });
+
+ it('POST /generate appends the render onto the FRESHEST track state (re-reads after the render)', async () => {
+ // A render added to the same track WHILE this multi-minute generation ran
+ // must not be dropped: the append must use the post-render track, not the
+ // pre-render snapshot.
+ const stale = { id: 'track-1', title: 'S', renders: [{ id: 'r-old', audioFilename: 'old.wav' }] };
+ const fresh = { id: 'track-1', title: 'S', renders: [{ id: 'r-old', audioFilename: 'old.wav' }, { id: 'r-concurrent', audioFilename: 'concurrent.wav' }] };
+ tracks.getTrack.mockResolvedValueOnce(stale).mockResolvedValueOnce(fresh);
+ gen.generateMusic.mockResolvedValueOnce({ filename: 'm.wav', durationSec: 12, engine: 'musicgen', modelId: 'm' });
+ await request(app).post('/api/music/generate').send({ prompt: 'beat', engine: 'musicgen', trackId: 'track-1' });
+ expect(tracks.getTrack).toHaveBeenCalledTimes(2); // validate, then re-read after the render
+ expect(tracks.buildRenderAppend).toHaveBeenCalledWith(fresh, expect.objectContaining({ audioFilename: 'm.wav' }));
});
it('POST /generate on a lyric engine with an EXPLICIT empty lyrics persists the clear', async () => {