Suno-style web UI for a self-hosted MiniMax-Music3 inference server
TypeScript ai-musicdiffusersdockerexpressminimaxminimax-musicmusic-generationreactself-hostedsgl-omnisunotailwindcsstext-to-musictypescriptvite
feat: re-queue pending renders after a UI server restart
Adam Benhassen2f58c72326a0
diff --git a/server/src/index.ts b/server/src/index.tsindex f28eac3..16f5123 100644--- a/server/src/index.ts+++ b/server/src/index.ts@@ -20,7 +20,7 @@ const effective = settings.effective();const upstream = new UpstreamClient(effective.musicApi, effective.apiKey);const queue = new RenderQueue(library, upstream, tracksDir);-const orphaned = await queue.failOrphans();+const recovered = await queue.recover();const here = path.dirname(fileURLToPath(import.meta.url));const defaultStatic = path.resolve(here, '../../web/dist');@@ -33,7 +33,8 @@ app.listen(config.port, () => {console.log(` upstream: ${effective.musicApi} [${effective.source.musicApi}]${effective.apiKey ? ` (bearer set [${effective.source.apiKey}])` : ''}`);console.log(` data: ${config.dataDir}`);console.log(` static: ${staticDir ?? '(none — run web dev server)'}`);- if (orphaned) console.log(` marked ${orphaned} interrupted render(s) as error`);+ if (recovered.failed) console.log(` marked ${recovered.failed} interrupted render(s) as error`);+ if (recovered.resumed) console.log(` re-queued ${recovered.resumed} pending render(s)`);});for (const sig of ['SIGINT', 'SIGTERM'] as const) {diff --git a/server/src/upstream.ts b/server/src/upstream.tsindex 8ac198f..f7e8cb6 100644--- a/server/src/upstream.ts+++ b/server/src/upstream.ts@@ -253,13 +253,17 @@ export class RenderQueue {return false;}- /** On boot: anything left queued/running by a previous process can't be resumed. */- async failOrphans(): Promise<number> {- const orphans = this.library.all().filter((t) => t.status === 'queued' || t.status === 'running');- for (const t of orphans) {+ /** On boot: a render that was in flight can't be reattached (the upstream call is gone), so it fails;+ * tracks that were still queued are re-enqueued in their original order. */+ async recover(): Promise<{ failed: number; resumed: number }> {+ const all = this.library.all();+ const running = all.filter((t) => t.status === 'running');+ for (const t of running) {await this.library.update(t.id, { status: 'error', stage: 'error', error: 'interrupted by UI server restart', finishedAt: new Date().toISOString() });}- return orphans.length;+ const queued = all.filter((t) => t.status === 'queued').sort((a, b) => a.createdAt.localeCompare(b.createdAt));+ for (const t of queued) this.enqueue(t.id);+ return { failed: running.length, resumed: queued.length };}private async pump(): Promise<void> {diff --git a/server/test/app.test.ts b/server/test/app.test.tsindex 50f5f99..6b15d09 100644--- a/server/test/app.test.ts+++ b/server/test/app.test.ts@@ -154,11 +154,16 @@ describe('app', () => {await expect(fs.access(path.join(tracksDir, `${id}.wav`))).rejects.toThrow();});- it('failOrphans marks leftover renders after a restart', async () => {+ it('recover fails a running render after a restart and re-enqueues queued ones in order', async () => {const { lib, queue } = await setup();- await lib.add({ id: 'o1', groupId: 'g', takeIndex: 0, title: 'T', prompt: 'p', lyrics: '[Instrumental]', duration: 10, seed: null, format: 'wav', status: 'running', progress: 0.3, stage: 'rendering', eta: null, error: null, file: null, createdAt: new Date().toISOString(), finishedAt: null });- expect(await queue.failOrphans()).toBe(1);+ const base = { groupId: 'g', takeIndex: 0, title: 'T', prompt: 'p', lyrics: '[Instrumental]', duration: 10, seed: null, format: 'wav', progress: 0, eta: null, error: null, file: null, finishedAt: null };+ await lib.add({ ...base, id: 'o1', status: 'running', progress: 0.3, stage: 'rendering', createdAt: '2026-01-01T00:00:00.000Z' });+ await lib.add({ ...base, id: 'q2', status: 'queued', stage: 'queued', createdAt: '2026-01-01T00:00:02.000Z' });+ await lib.add({ ...base, id: 'q1', status: 'queued', stage: 'queued', createdAt: '2026-01-01T00:00:01.000Z' });+ expect(await queue.recover()).toEqual({ failed: 1, resumed: 2 });expect(lib.get('o1')).toMatchObject({ status: 'error', error: /restart/ });+ await until(() => lib.get('q1')?.status === 'done' && lib.get('q2')?.status === 'done');+ expect(Date.parse(lib.get('q1')!.finishedAt!)).toBeLessThanOrEqual(Date.parse(lib.get('q2')!.finishedAt!));});it('uses the given title when present, random otherwise', async () => {