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
Reserve publishing kit builds before asynchronous setup to reject overlapping requests
[._.]/ Adam Eivydd8a809501bd
diff --git a/server/services/musicVideo/publishKit.js b/server/services/musicVideo/publishKit.jsindex bf24320a16..e9849228b5 100644--- a/server/services/musicVideo/publishKit.js+++ b/server/services/musicVideo/publishKit.js@@ -85,16 +85,27 @@ async function releaseKitFiles(filenames, keep) {* record carries the result.*/export async function startPublishKitBuild(projectId) {- const project = await requireProject(projectId);if (projectBuilds.has(projectId)) throw kitError(409, 'PUBLISH_KIT_BUILD_IN_PROGRESS', 'A publishing kit build is already running for this project');+ const jobId = `mvpk-${randomUUID()}`;+ // Reserve synchronously: final-render lookup and ffmpeg probing can overlap+ // another request before there is a background job to put in the registry.+ projectBuilds.set(projectId, jobId);+ try {+ return await beginPublishKitBuild(projectId, jobId);+ } catch (error) {+ projectBuilds.delete(projectId);+ throw error;+ }+}++async function beginPublishKitBuild(projectId, jobId) {+ const project = await requireProject(projectId);const { entry, path: masterPath } = await finalRenderFile(project);const { findFfmpeg, runFfmpegProcess, probeVideoDuration } = await import('../../lib/ffmpeg.js');const ffmpeg = await findFfmpeg();if (!ffmpeg) throw kitError(500, 'FFMPEG_MISSING', 'ffmpeg not found on PATH');- const jobId = `mvpk-${randomUUID()}`;const job = { id: jobId, projectId, status: 'running', clients: [], abort: new AbortController() };jobs.set(jobId, job);- projectBuilds.set(projectId, jobId);const tag = jobId.slice(5, 13);console.log(`📦 Building music-video publishing kit [${tag}]: project=${projectId.slice(0, 8)}`);diff --git a/server/services/musicVideo/publishKit.test.js b/server/services/musicVideo/publishKit.test.jsindex 7aeb2d3aef..9f31bda56e 100644--- a/server/services/musicVideo/publishKit.test.js+++ b/server/services/musicVideo/publishKit.test.js@@ -16,7 +16,8 @@ vi.mock('../../lib/paths.js', async (importOriginal) => makePathsProxy(await imp}));const { PATHS } = await import('../../lib/paths.js');-const { findFfmpeg, runFfmpegProcess } = await import('../../lib/ffmpeg.js');+const ffmpegService = await import('../../lib/ffmpeg.js');+const { findFfmpeg, runFfmpegProcess } = ffmpegService;const projects = await import('./projects.js');const { saveHistory } = await import('../videoGen/history.js');const kit = await import('./publishKit.js');@@ -52,6 +53,33 @@ describe('publishing kit build (#9281)', () => {await expect(kit.startPublishKitBuild(id)).rejects.toMatchObject({ status: 409, code: 'NO_FINAL_RENDER' });});+ it('reserves a build before async prerequisites and releases the reservation after setup fails', async () => {+ const { id } = await projects.createProject({ name: 'Example Concurrent Build' });+ await mkdir(PATHS.videos, { recursive: true });+ await writeFile(join(PATHS.videos, 'concurrent-master.mp4'), 'placeholder; never encoded');+ await saveHistory([{ id: 'concurrent-render', filename: 'concurrent-master.mp4', durationSec: 36 }]);+ await projects.mutateProjectRecord(id, current => ({ project: { ...current, renderHistoryId: 'concurrent-render' } }));+ let releasePrerequisite;+ const pendingPrerequisite = new Promise(resolve => { releasePrerequisite = resolve; });+ const probe = vi.spyOn(ffmpegService, 'findFfmpeg').mockReturnValue(pendingPrerequisite);+ try {+ const first = kit.startPublishKitBuild(id);+ const firstFailure = first.catch(error => error);+ await vi.waitFor(() => expect(probe).toHaveBeenCalledTimes(1));+ const overlap = kit.startPublishKitBuild(id);+ releasePrerequisite(null);+ await expect(overlap).rejects.toMatchObject({ status: 409, code: 'PUBLISH_KIT_BUILD_IN_PROGRESS' });+ expect(await firstFailure).toMatchObject({ code: 'FFMPEG_MISSING' });+ expect(probe).toHaveBeenCalledTimes(1);+ // A failed setup must leave the project available for the next attempt.+ await expect(kit.startPublishKitBuild(id)).rejects.toMatchObject({ code: 'FFMPEG_MISSING' });+ expect(probe).toHaveBeenCalledTimes(2);+ } finally {+ releasePrerequisite(null);+ probe.mockRestore();+ }+ });+it.skipIf(!ffmpeg)('turns the final render into encodes, thumbnails, captions and chapters, and frees a rebuilt kit\'s old files', { timeout: 120000 }, async () => {const id = await renderedProject();await kit.startPublishKitBuild(id);