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(music-video): allow Retake song when the run is stopped or failed inside the song stage

Claude355589272cbb
diff --git a/server/services/musicVideo/autonomousService.js b/server/services/musicVideo/autonomousService.js
index 44334a41f5..2416f2c4fb 100644
--- a/server/services/musicVideo/autonomousService.js
+++ b/server/services/musicVideo/autonomousService.js
@@ -436,10 +436,14 @@ const assertResumable = (run) => {
if (run.status === 'running' && run.processId === PROCESS_ID) throw runError(409, 'ALREADY_RUNNING', 'This run is already running');
};
-// A retake is only meaningful while the run is parked on the song it would replace.
+// A retake is only meaningful while the run sits on the song it would replace: parked for
+// approval of it, or stopped / failed inside the song stage (a Suno request whose rows
+// vanished leaves ids no export can find — the retake discards them and submits afresh).
const assertAtSongCheckpoint = (run) => {
- if (run.status !== 'awaiting-approval' || run.awaiting !== 'song') {
- throw runError(409, 'NOT_AT_SONG_CHECKPOINT', 'A song can only be retaken while the run is waiting for approval of its song');
+ const parkedOnSong = run.status === 'awaiting-approval' && run.awaiting === 'song';
+ const stuckInSong = run.stage === 'song' && ['stopped', 'failed', 'needs-human'].includes(run.status);
+ if (!parkedOnSong && !stuckInSong) {
+ throw runError(409, 'NOT_AT_SONG_CHECKPOINT', 'A song can only be retaken while the run is waiting for approval of its song, or is stopped or failed in the song stage');
}
};
diff --git a/server/services/musicVideo/autonomousService.test.js b/server/services/musicVideo/autonomousService.test.js
index 15f8d09250..5b3cea1d0e 100644
--- a/server/services/musicVideo/autonomousService.test.js
+++ b/server/services/musicVideo/autonomousService.test.js
@@ -311,6 +311,33 @@ describe('retaking the song at the song checkpoint', () => {
expect(calls).not.toContain('suno');
});
+ it('retakes a song whose export never finished: a run stopped in the song stage discards the dead ids and submits afresh', async () => {
+ let release;
+ doubles.generateSunoSong.mockImplementationOnce(async (_fields, opts) => {
+ await opts.onSubmitted(['song-dead-a', 'song-dead-b']);
+ opts.onProgress('exporting');
+ // Suno dropped the rows: the export hangs until the director stops the run.
+ await new Promise((resolve) => { release = resolve; });
+ throw Object.assign(new Error('cancelled'), { code: 'SUNO_AUDIO_CANCELLED' });
+ });
+ await service.startAutonomousVideo({ prompt: 'p', checkpoints: ['song'] });
+ await vi.waitFor(() => expect(runOf().output.sunoSongIds).toEqual(['song-dead-a', 'song-dead-b']));
+ await service.stopAutonomousVideo('mv-auto');
+ release();
+ await vi.waitFor(() => expect(runOf().status).toBe('stopped'));
+ expect(runOf().stage).toBe('song');
+
+ doubles.generateSunoSong.mockImplementationOnce(async (_fields, opts) => {
+ expect(opts.songIds).toBeNull();
+ await opts.onSubmitted(['song-e', 'song-f']);
+ return { songId: 'song-f', songIds: ['song-e', 'song-f'], filename: 'music-song-f.m4a' };
+ });
+ const { run } = await service.resumeAutonomousVideo('mv-auto', { retakeSong: true, style: 'industrial electro' });
+ expect(run).toMatchObject({ status: 'running', stage: 'song', output: { sunoSongIds: null, sunoStyle: 'industrial electro' } });
+ await settled('awaiting-approval');
+ expect(runOf()).toMatchObject({ awaiting: 'song', output: { sunoSongIds: ['song-e', 'song-f'] } });
+ });
+
it('applies a Suno options patch on a plain approval too', async () => {
await service.startAutonomousVideo({ prompt: 'p', checkpoints: ['lyrics'], suno: { excludeStyles: 'metal', model: 'v5' } });
await settled('awaiting-approval');