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: cancelling a revision also stops the generation jobs it started (#8987)
[._.]/ Adam Eivy00b200b37de7
diff --git a/client/src/hooks/useMusicVideoRevisions.js b/client/src/hooks/useMusicVideoRevisions.jsindex 1f0151c8db..9aceef8119 100644--- a/client/src/hooks/useMusicVideoRevisions.js+++ b/client/src/hooks/useMusicVideoRevisions.js@@ -89,7 +89,12 @@ export default function useMusicVideoRevisions({ project, replaceProject, sceneM.then((res) => (res?.revision ? resume(res.revision.id) : null));const cancel = (revisionId) => run(() => cancelMusicVideoRevision(projectId, revisionId, { silent: true })- .then((res) => { replaceProject(res.project); return res; }));+ .then((res) => {+ replaceProject(res.project);+ const stopped = res.canceledJobIds?.length || 0;+ toast.info(stopped ? `Revision cancelled — stopped ${plural(stopped, 'generation job')}` : 'Revision cancelled');+ return res;+ }));return { busy, revise, resume, cancel };}diff --git a/server/routes/musicVideoRevision.test.js b/server/routes/musicVideoRevision.test.jsindex 2bc9854baa..00270c0aa7 100644--- a/server/routes/musicVideoRevision.test.js+++ b/server/routes/musicVideoRevision.test.js@@ -35,7 +35,7 @@ const h = vi.hoisted(() => {procs.push(p);return p;};- return { procs, spawn, jobs: [], enqueueJob: vi.fn() };+ return { procs, spawn, jobs: [], enqueueJob: vi.fn(), cancelJob: vi.fn(async () => {}) };});vi.mock('../lib/childProcess.js', async (importOriginal) => ({ ...(await importOriginal()), spawn: h.spawn }));@@ -45,6 +45,7 @@ vi.mock('../services/htmlComposition/encode.js', () => ({ encodeFileContactSheetvi.mock('../services/mediaJobQueue/index.js', () => ({listJobs: vi.fn(({ kind } = {}) => h.jobs.filter((j) => !kind || j.kind === kind)),enqueueJob: h.enqueueJob,+ cancelJob: h.cancelJob,}));// Three 10s sections: footage s1, footage s2, still s3 (a composed render).const CLIPS = [@@ -267,6 +268,23 @@ describe('selective section revision (#8987)', () => {expect(resume.status).toBe(409);});+ it('cancelling an open revision stops the generation it started, and only that', async () => {+ const project = await reviewedProject();+ const earlier = new Date(Date.now() - 60_000).toISOString();+ const { body: { revision } } = await request(app).post(`${base(project.id)}/excerpt/mve-draft/revisions`).send({});+ const tag = (sceneId) => ({ musicVideo: { projectId: project.id, sceneId } });+ const now = new Date().toISOString();+ h.jobs.push(+ { id: 'job-s2', kind: 'video', status: 'running', queuedAt: now, params: tag('s2') },+ { id: 'job-s1', kind: 'video', status: 'queued', queuedAt: now, params: tag('s1') }, // an approved section: not the revision's+ { id: 'job-old', kind: 'video', status: 'running', queuedAt: earlier, params: tag('s2') }, // predates the revision+ );+ const r = await request(app).post(`${base(project.id)}/revisions/${revision.id}/cancel`);+ expect(r.status).toBe(200);+ expect(r.body.canceledJobIds).toEqual(['job-s2']);+ expect(h.cancelJob).toHaveBeenCalledTimes(1);+ });+it('refuses a second open revision, a section outside the draft, and a draft without a section map', async () => {const project = await reviewedProject();const first = await request(app).post(`${base(project.id)}/excerpt/mve-draft/revisions`).send({ sceneIds: ['s1'] });diff --git a/server/services/musicVideo/revision.js b/server/services/musicVideo/revision.jsindex 5a6c163b82..c1455f27ac 100644--- a/server/services/musicVideo/revision.js+++ b/server/services/musicVideo/revision.js@@ -232,6 +232,18 @@ export function resumableRevision(project, revisionId) {return revision;}+/**+ * Pure: the live (queued/running) generation jobs a revision started — tagged+ * for one of its rejected sections and queued since it opened. Cancelling the+ * revision cancels these, so no paid work keeps running for a closed revision.+ */+export function revisionGenerationJobs(project, revision, jobs = []) {+ const rejected = (revision.sections || []).filter((s) => s.verdict === 'rejected');+ return jobs.filter((job) => (job?.status === 'queued' || job?.status === 'running')+ && typeof job.queuedAt === 'string' && job.queuedAt >= revision.createdAt+ && rejected.some((s) => job.kind === s.kind && tagMatches(job, project.id, s.sceneId)));+}+/*** Resume's atomic step (run under the record's write serialization): derive* every section's state and CLAIM the ones about to be handed out fordiff --git a/server/services/musicVideo/revisionService.js b/server/services/musicVideo/revisionService.jsindex 658efc74e4..5557cf2733 100644--- a/server/services/musicVideo/revisionService.js+++ b/server/services/musicVideo/revisionService.js@@ -25,6 +25,7 @@ import {cancelRevisionOnProject,claimRevisionGeneration,projectRevisions,+ revisionGenerationJobs,revisionSectionStates,startRevisionOnProject,} from './revision.js';@@ -57,9 +58,22 @@ export async function resumeRevision(projectId, revisionId) {return { project: fresh, revision: { ...current, sections: revisionSectionStates(fresh, current, jobs) }, needsGeneration: [], generating: [], render };}-/** Cancel a revision; a draft render it started is cancelled too. Returns `{ project, revision }`. */+/**+ * Cancel a revision. Its draft render and any generation job it started that+ * is still queued/running are cancelled too, so a closed revision incurs no+ * further paid work. Returns `{ project, revision, canceledJobIds }`.+ */export async function cancelRevision(projectId, revisionId) {const { project, revision, renderExcerptId } = await mutateProjectRecord(projectId, (current) => cancelRevisionOnProject(current, revisionId));if (renderExcerptId) cancelExcerptRender(renderExcerptId);- return { project, revision };+ const { listJobs, cancelJob } = await import('../mediaJobQueue/index.js');+ const live = revisionGenerationJobs(project, revision, [...listJobs({ kind: 'video' }), ...listJobs({ kind: 'image' })]);+ const canceledJobIds = [];+ for (const job of live) {+ await cancelJob(job.id).then(() => canceledJobIds.push(job.id), (err) => {+ console.error(`❌ Music Video revision ${revisionId.slice(4, 12)} could not cancel generation job ${job.id.slice(0, 8)}: ${err.message}`);+ });+ }+ if (canceledJobIds.length) console.log(`🛑 Music Video revision ${revisionId.slice(4, 12)} cancelled ${canceledJobIds.length} generation job(s)`);+ return { project, revision, canceledJobIds };}