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: cancel a local song render queued after the run was stopped (#9473)

Adam Eivyd6839e22268a
diff --git a/server/services/musicVideo/autonomousService.js b/server/services/musicVideo/autonomousService.js
index 3dd73199f5..8fcf1351b1 100644
--- a/server/services/musicVideo/autonomousService.js
+++ b/server/services/musicVideo/autonomousService.js
@@ -141,7 +141,15 @@ async function localSong({ project, run, save }) {
}
await deps.generateLocalSong({
trackId, title, prompt, lyrics, instrumental: run.brief.instrumental, jobId: run.output.localSongJobId,
- onSubmitted: (jobId) => save({ output: { localSongJobId: jobId } }),
+ onSubmitted: async (jobId) => {
+ await save({ output: { localSongJobId: jobId } });
+ // Stop/cancel cancel the job they find on the record; one that landed
+ // before this id was stored never saw it, so settle that race here.
+ const latest = projectAutonomousRun(await getProject(project.id));
+ if (latest?.status === 'running' && latest.processId === PROCESS_ID) return;
+ await deps.cancelLocalSong(jobId).catch(() => {});
+ throw runError(409, 'NOT_RUNNING', 'The run was stopped before its song render started');
+ },
});
// Linking the track seeds the project's timed lyric cues from the track lyrics.
await deps.updateProject(project.id, { trackId });
@@ -386,6 +394,11 @@ export async function resumeAutonomousVideo(projectId, edits = {}) {
return { project: out.project, run: presentAutonomousRun(out.run) };
}
+// Read from the freshly patched record, so a job id stored a moment before the status flipped is seen.
+const cancelLocalSongJob = (run) => (run.stage === 'song' && run.output.localSongJobId
+ ? deps.cancelLocalSong(run.output.localSongJobId).catch(() => {})
+ : null);
+
export async function stopAutonomousVideo(projectId) {
const { run } = await requireRun(projectId);
if (!['running', 'awaiting-approval', 'needs-human'].includes(run.status)) throw runError(409, 'NOT_RUNNING', `A ${run.status} run cannot be stopped`);
@@ -394,7 +407,7 @@ export async function stopAutonomousVideo(projectId) {
const { stopProduction } = await import('./productionService.js');
await stopProduction(projectId, run.output.productionRunId).catch(() => {});
}
- if (run.stage === 'song' && run.output.localSongJobId) await deps.cancelLocalSong(run.output.localSongJobId).catch(() => {});
+ await cancelLocalSongJob(out.run);
return { project: out.project, run: presentAutonomousRun(out.run) };
}
@@ -406,7 +419,7 @@ export async function cancelAutonomousVideo(projectId) {
const { cancelProduction } = await import('./productionService.js');
await cancelProduction(projectId, run.output.productionRunId).catch(() => {});
}
- if (run.stage === 'song' && run.output.localSongJobId) await deps.cancelLocalSong(run.output.localSongJobId).catch(() => {});
+ await cancelLocalSongJob(out.run);
return { project: out.project, run: presentAutonomousRun(out.run) };
}
diff --git a/server/services/musicVideo/autonomousService.test.js b/server/services/musicVideo/autonomousService.test.js
index b3fb891989..e0c5f04af9 100644
--- a/server/services/musicVideo/autonomousService.test.js
+++ b/server/services/musicVideo/autonomousService.test.js
@@ -279,6 +279,24 @@ describe('local song source (#9473)', () => {
expect(runOf()).toMatchObject({ status: 'stopped', stage: 'song' });
expect(runOf().stages.song.status).toBe('running');
});
+
+ it('cancels a render queued after the run was already stopped, so no orphan job keeps the GPU busy', async () => {
+ let queued;
+ doubles.generateLocalSong.mockImplementationOnce(async ({ onSubmitted }) => {
+ await new Promise((resolve) => { queued = resolve; }); // engine pick / enqueue still in flight
+ await onSubmitted('job-late');
+ return { filename: 'song.wav' };
+ });
+ await service.startAutonomousVideo({ prompt: 'p', songSource: 'local' });
+ await vi.waitFor(() => expect(queued).toBeTypeOf('function'));
+ await service.stopAutonomousVideo('mv-auto');
+ expect(doubles.cancelLocalSong).not.toHaveBeenCalled(); // nothing was queued yet
+ queued();
+ await vi.waitFor(() => expect(doubles.cancelLocalSong).toHaveBeenCalledWith('job-late'));
+ await new Promise((resolve) => setTimeout(resolve, 20));
+ expect(runOf()).toMatchObject({ status: 'stopped', stage: 'song' });
+ expect(calls).not.toContain('analyze');
+ });
});
describe('events and process pinning', () => {