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
fix: move the revision-open check to right before the queue write (#9011)
[._.]/ Adam Eivy2aa320c890ed
diff --git a/server/routes/imageGen.js b/server/routes/imageGen.jsindex f3631a211a..fddcc669a9 100644--- a/server/routes/imageGen.js+++ b/server/routes/imageGen.js@@ -60,6 +60,16 @@ const routeSource = (req) => ({ route: `${req.baseUrl}${req.route?.path ?? ''}`,// Event-only pointer: job id in `target`, never the generation prompt (#5596).async function enqueueLoggedImage(req, job) {+ // Selective section revision (#9011): checked as the LAST step before the+ // actual queue write — every branch that reaches this helper has already+ // done its own staging/provider resolution, so this is as close to the+ // cancel/kickoff race as a request can get. A no-op when the tag carries no+ // revisionId; deferred import since only this rare path needs the revision+ // service's closure.+ if (job.params?.musicVideo?.revisionId) {+ const { assertRevisionOpen } = await import('../services/musicVideo/revisionService.js');+ await assertRevisionOpen(job.params.musicVideo.projectId, job.params.musicVideo.revisionId);+ }const queued = await enqueueJob(job);try {const happenedAt = new Date().toISOString();@@ -544,16 +554,6 @@ router.post('/generate', imageGenUploads, asyncHandler(async (req, res) => {});}- // Selective section revision (#9011): a kickoff tagged for a revision that- // has since closed is refused before any provider dispatch, closing the- // cancel/kickoff race server-side. No-op when the tag carries no- // revisionId; `res.on('close')` above already covers any staged uploads.- // Deferred import since only this rare path needs the revision service.- if (params.musicVideo?.revisionId) {- const { assertRevisionOpen } = await import('../services/musicVideo/revisionService.js');- await assertRevisionOpen(params.musicVideo.projectId, params.musicVideo.revisionId);- }-// Local + codex both go through mediaJobQueue (separate lanes — codex// doesn't share MLX). External SD-API stays synchronous: it's a remote// call with no local single-flight constraint to absorb. `settings` anddiff --git a/server/services/videoGen/submitJob.js b/server/services/videoGen/submitJob.jsindex 4be3a3beb8..8bc366c861 100644--- a/server/services/videoGen/submitJob.js+++ b/server/services/videoGen/submitJob.js@@ -32,16 +32,6 @@ import {import { VIDEO_GEN_LOCAL_ONLY_FIELD_NAMES } from './requestFields.js';const submitValidatedVideoGenJob = async (body, uploads) => {- // Selective section revision (#9011): a kickoff tagged for a revision that- // has since closed (cancelled, or already resolved by another resume) is- // refused before any staging happens, closing the cancel/kickoff race- // server-side rather than relying on the client to have seen the cancel in- // time. A no-op when the tag carries no revisionId — deferred import since- // only this rare path needs the revision service's closure.- if (body.musicVideo?.revisionId) {- const { assertRevisionOpen } = await import('../musicVideo/revisionService.js');- await assertRevisionOpen(body.musicVideo.projectId, body.musicVideo.revisionId);- }let fableLoomRenderSettings = null;if (body.fableLoom) {const taggedLoom = await getLoom(body.fableLoom.loomId);@@ -203,7 +193,19 @@ const submitValidatedVideoGenJob = async (body, uploads) => {if (performance) await unlink(performance.audioFilePath).catch(() => {});await cleanupStaged();},- () => enqueueJob({ kind: 'video', params }),+ async () => {+ // Selective section revision (#9011): checked as the LAST step before the+ // actual queue write (staging, FableLoom compilation and the performance-+ // shot audio slice above can all take real time), so a revision closed+ // mid-submission is caught as close to the cancel/kickoff race as this+ // request can get. A no-op when the tag carries no revisionId; deferred+ // import since only this rare path needs the revision service's closure.+ if (body.musicVideo?.revisionId) {+ const { assertRevisionOpen } = await import('../musicVideo/revisionService.js');+ await assertRevisionOpen(body.musicVideo.projectId, body.musicVideo.revisionId);+ }+ return enqueueJob({ kind: 'video', params });+ },);const hosted = HOSTED_VIDEO_SUBMISSIONS[backend];diff --git a/server/services/videoGen/submitJob.test.js b/server/services/videoGen/submitJob.test.jsindex 3814b240df..cea166c202 100644--- a/server/services/videoGen/submitJob.test.js+++ b/server/services/videoGen/submitJob.test.js@@ -230,14 +230,20 @@ describe('submitVideoGenJob', () => {expect(mocks.enqueueJob).not.toHaveBeenCalled();});- it('refuses a kickoff tagged for a revision that has since closed, before any staging (#9011)', async () => {+ it('refuses a kickoff tagged for a revision that has since closed, as the last step before the queue write (#9011)', async () => {const closed = Object.assign(new Error('This revision is already canceled'), { status: 409, code: 'REVISION_CLOSED' });mocks.assertRevisionOpen.mockRejectedValueOnce(closed);const tagged = { ...musicVideo, revisionId: 'mvr-1' };+ const prepared = falPrepared();+ mocks.prepareVideoGenParams.mockResolvedValue(prepared);await expect(submitVideoGenJob({ prompt: 'singer', backend: 'fal', musicVideo: tagged }, {})).rejects.toBe(closed);expect(mocks.assertRevisionOpen).toHaveBeenCalledWith('mv-1', 'mvr-1');- expect(mocks.prepareVideoGenParams).not.toHaveBeenCalled();+ // The check runs immediately before enqueueJob — after staging, not before+ // it — so the race window against a concurrent cancel is as small as this+ // request can make it; a refusal there still rolls back what was staged.+ expect(mocks.prepareVideoGenParams).toHaveBeenCalledTimes(1);+ expect(prepared.cleanupStaged).toHaveBeenCalledTimes(1);expect(mocks.enqueueJob).not.toHaveBeenCalled();});