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: only advertise a publishing kit build once its SSE job exists (#9942)

Adam Eivy9f6235487b91
diff --git a/server/routes/musicVideoPublishKitReattach.test.js b/server/routes/musicVideoPublishKitReattach.test.js
index d63d2cc00e..3bd36c1f47 100644
--- a/server/routes/musicVideoPublishKitReattach.test.js
+++ b/server/routes/musicVideoPublishKitReattach.test.js
@@ -36,7 +36,9 @@ describe('publishing kit build reattach (#9942)', () => {
await projects.mutateProjectRecord(id, (current) => ({ project: { ...current, renderHistoryId: 'reattach-render' } }));
let release;
const gate = new Promise((resolve) => { release = resolve; });
- const probe = vi.spyOn(ffmpegLib, 'findFfmpeg').mockReturnValue(gate);
+ vi.spyOn(ffmpegLib, 'findFfmpeg').mockResolvedValue('ffmpeg');
+ // The job exists (and is attachable) once the first encode is in flight.
+ const probe = vi.spyOn(ffmpegLib, 'runFfmpegProcess').mockReturnValue(gate.then(() => ({ ok: false, reason: 'test stop' })));
try {
const first = request(app).post(`/api/music-video/${id}/publish-kit/build`).then((r) => r);
await vi.waitFor(() => expect(probe).toHaveBeenCalled());
@@ -48,11 +50,12 @@ describe('publishing kit build reattach (#9942)', () => {
expect(read.body.activePublishKitBuild).toEqual(second.body.context);
release(null);
await first;
+ await vi.waitFor(async () => expect((await request(app).get(`/api/music-video/${id}`)).body.activePublishKitBuild).toBeUndefined());
const after = await request(app).get(`/api/music-video/${id}`);
expect(after.body.activePublishKitBuild).toBeUndefined();
} finally {
release(null);
- probe.mockRestore();
+ vi.restoreAllMocks();
}
});
});
diff --git a/server/services/musicVideo/publishKit.js b/server/services/musicVideo/publishKit.js
index a24a51628c..9fb3d51575 100644
--- a/server/services/musicVideo/publishKit.js
+++ b/server/services/musicVideo/publishKit.js
@@ -36,10 +36,14 @@ export const projectPublishKit = (project) => (project?.publishKit && typeof pro
const kitError = (status, code, message, context) => new ServerError(message, { status, code, ...(context ? { context } : {}) });
-/** The build currently running for a project (`{ jobId, status }`), so a reloaded page can reattach. */
+/**
+ * The build running for a project (`{ jobId, status }`), so a reloaded page can
+ * reattach. Only once its SSE job exists: during the prerequisite lookup the
+ * reservation holds the slot but there is nothing to attach to yet.
+ */
export const getActivePublishKitBuild = (projectId) => {
const jobId = projectBuilds.get(projectId);
- return jobId ? { jobId, status: 'running' } : null;
+ return jobId && jobs.get(jobId)?.status === 'running' ? { jobId, status: 'running' } : null;
};
async function requireProject(projectId) {
@@ -91,8 +95,7 @@ async function releaseKitFiles(filenames, keep) {
* record carries the result.
*/
export async function startPublishKitBuild(projectId) {
- const running = getActivePublishKitBuild(projectId);
- if (running) throw kitError(409, 'PUBLISH_KIT_BUILD_IN_PROGRESS', 'A publishing kit build is already running for this project', running);
+ if (projectBuilds.has(projectId)) throw kitError(409, 'PUBLISH_KIT_BUILD_IN_PROGRESS', 'A publishing kit build is already running for this project', getActivePublishKitBuild(projectId) || undefined);
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.
diff --git a/server/services/musicVideo/publishKit.test.js b/server/services/musicVideo/publishKit.test.js
index 0f0022639a..3cb1d1652d 100644
--- a/server/services/musicVideo/publishKit.test.js
+++ b/server/services/musicVideo/publishKit.test.js
@@ -68,8 +68,9 @@ describe('publishing kit build (#9281)', () => {
await vi.waitFor(() => expect(probe).toHaveBeenCalledTimes(1));
const overlap = kit.startPublishKitBuild(id);
releasePrerequisite(null);
- expect(kit.getActivePublishKitBuild(id)).toMatchObject({ status: 'running', jobId: expect.stringMatching(/^mvpk-/) });
- await expect(overlap).rejects.toMatchObject({ status: 409, code: 'PUBLISH_KIT_BUILD_IN_PROGRESS', context: { jobId: kit.getActivePublishKitBuild(id).jobId, status: 'running' } });
+ // No SSE job exists yet, so nothing is advertised as attachable.
+ expect(kit.getActivePublishKitBuild(id)).toBeNull();
+ 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.