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: auto-review never hands out work for a paused run and never refunds a queued job (#8988)

[._.]/ Adam Eivyae20fa8b43ed
diff --git a/client/src/components/musicVideo/AutoReviewPanel.jsx b/client/src/components/musicVideo/AutoReviewPanel.jsx
index 18f8c51821..4529fcd0ba 100644
--- a/client/src/components/musicVideo/AutoReviewPanel.jsx
+++ b/client/src/components/musicVideo/AutoReviewPanel.jsx
@@ -13,7 +13,7 @@ const STATUS_TONES = {
'needs-human': 'text-port-warning', failed: 'text-port-error', canceled: 'text-port-text-muted',
};
const CHECK_TONES = { pass: 'bg-port-success/20 text-port-success', fail: 'bg-port-error/20 text-port-error', unverified: 'bg-port-border text-port-text-muted' };
-const CHECK_LABELS = { composition: 'Composition', continuity: 'Continuity', motion: 'Motion', audioSync: 'Audio sync' };
+const CHECK_LABELS = { composition: 'Composition', continuity: 'Continuity', motion: 'Motion', audioSync: 'Audio sync (stream parity)' };
const ACTION_LABELS = {
wait: (a) => (a.on === 'generation' ? 'Waiting for the revised sections to generate…' : 'Rendering the draft…'),
reviewing: () => 'Reviewing the draft (frames + continuous excerpt)…',
diff --git a/client/src/hooks/useMusicVideoAutoReview.js b/client/src/hooks/useMusicVideoAutoReview.js
index c3389b301a..ef7c99bb19 100644
--- a/client/src/hooks/useMusicVideoAutoReview.js
+++ b/client/src/hooks/useMusicVideoAutoReview.js
@@ -47,7 +47,8 @@ export default function useMusicVideoAutoReview({ project, replaceProject, submi
const { replaceProject: replace, submitSections: submit } = handlers.current;
if (data.project) replace?.(data.project);
setAction(data.action || null);
- if (data.action?.type === 'generate' && data.action.sections?.length && submit) {
+ // Only a RUNNING run's hand-out is submitted — never one that raced a pause.
+ if (data.action?.type === 'generate' && data.run?.status === 'running' && data.action.sections?.length && submit) {
submit(data.project, data.action.sections, data.action.revisionId).then((n) => {
if (n) toast.info(`Auto-review: generating ${n} revised section${n === 1 ? '' : 's'}`);
});
diff --git a/server/routes/musicVideoAutoReview.test.js b/server/routes/musicVideoAutoReview.test.js
index aebd3a8511..b01fd9e0df 100644
--- a/server/routes/musicVideoAutoReview.test.js
+++ b/server/routes/musicVideoAutoReview.test.js
@@ -277,6 +277,10 @@ describe('opt-in automatic review/retries (#8988)', () => {
expect(run(current).stopReason).toMatch(/generation failed: provider error/);
expect(run(current).usage.generations).toBe(1);
expect(current.revisions.find((rv) => rv.id === revisionId).sections.find((s) => s.sceneId === 's2').claimedAt).toBeNull();
+ // That job DID reach the queue, so a later release never refunds it.
+ h.jobs.push(job);
+ await request(app).post(`${base(p.id)}/revisions/${revisionId}/release`).send({ sceneId: 's2' });
+ expect(run(await projects.getProject(p.id)).usage.generations).toBe(1);
});
it('stops before handing out a revision the remaining spend cannot cover', async () => {
diff --git a/server/services/musicVideo/autoReview.js b/server/services/musicVideo/autoReview.js
index a5c286e42b..320b127ad9 100644
--- a/server/services/musicVideo/autoReview.js
+++ b/server/services/musicVideo/autoReview.js
@@ -71,8 +71,16 @@ export const projectAutoReviews = (project) => (Array.isArray(project?.autoRevie
const activeAutoReview = (project) => projectAutoReviews(project).find((r) => ACTIVE.has(r.status)) || null;
const currentAttempt = (run) => run.attempts[run.attempts.length - 1];
-const liveReservations = (run, nowMs) => (Array.isArray(run.reservations) ? run.reservations : [])
- .filter((r) => Number.isFinite(nowMs) && nowMs - Date.parse(r.at) < RESERVATION_LEASE_MS);
+// A reservation is live until its lease lapses or a job for its section
+// reaches the queue (from then on the job itself is the in-flight evidence,
+// and the charge is spent for good — it can never be refunded).
+const reachedQueue = (r, jobs) => jobs.some((job) => {
+ const tag = job?.params?.musicVideo;
+ return tag?.revisionId === r.revisionId && tag?.sceneId === r.sceneId
+ && (!r.kind || job.kind === r.kind) && typeof job.queuedAt === 'string' && job.queuedAt >= r.at;
+});
+const liveReservations = (run, nowMs, jobs = []) => (Array.isArray(run.reservations) ? run.reservations : [])
+ .filter((r) => Number.isFinite(nowMs) && nowMs - Date.parse(r.at) < RESERVATION_LEASE_MS && !reachedQueue(r, jobs));
function findRun(project, runId) {
const run = projectAutoReviews(project).find((r) => r.id === runId);
@@ -336,11 +344,10 @@ export function cancelAutoReviewOnProject(project, runId, now = new Date().toISO
* Returns `{ project, run }` — `run` null (and the project untouched) when no
* running run owns the revision.
*/
-export function chargeAutoReviewGeneration(project, revisionId, { sceneId = null, kind = null } = {}, now = new Date().toISOString()) {
+export function chargeAutoReviewGeneration(project, revisionId, { sceneId = null, kind = null, jobs = [] } = {}, now = new Date().toISOString()) {
const run = runOwningRevision(project, revisionId);
if (!run) return { project, run: null };
- const nowMs = Date.parse(now);
- const reservations = liveReservations(run, nowMs);
+ const reservations = liveReservations(run, Date.parse(now), jobs);
// A charge RESERVES its section until the job reaches the queue (where the
// caller's live-job check takes over), so two overlapping submissions of the
// same section can never both be paid for.
@@ -360,12 +367,13 @@ export function chargeAutoReviewGeneration(project, revisionId, { sceneId = null
* Refund a charge whose submission never reached the queue (the board reports
* a failed kickoff by releasing the section's claim): the reservation is
* dropped and its generation returned to the budget. A no-op when there is no
- * live reservation for the section — a job that was queued stays charged.
+ * live reservation for the section — a charge whose job reached the queue
+ * (`jobs`, the queue's list incl. its recent archive) stays spent.
*/
-export function refundAutoReviewGeneration(project, revisionId, sceneId, now = new Date().toISOString()) {
+export function refundAutoReviewGeneration(project, revisionId, sceneId, jobs = [], now = new Date().toISOString()) {
const run = projectAutoReviews(project).find((r) => RESUMABLE.has(r.status) && currentAttempt(r).revisionId === revisionId);
if (!run) return { project, run: null };
- const reservations = liveReservations(run, Date.parse(now));
+ const reservations = liveReservations(run, Date.parse(now), jobs);
const idx = reservations.findIndex((r) => r.revisionId === revisionId && r.sceneId === sceneId);
if (idx === -1) return { project, run: null };
return mutateRun(project, run.id, (r) => ({
diff --git a/server/services/musicVideo/autoReviewJudge.js b/server/services/musicVideo/autoReviewJudge.js
index 083a705cc1..7a4ca4176b 100644
--- a/server/services/musicVideo/autoReviewJudge.js
+++ b/server/services/musicVideo/autoReviewJudge.js
@@ -11,6 +11,14 @@
* audio/video stream-length parity that shows the song ran under the whole
* cut without being clipped or padded.
*
+ * What `audioSync` can and cannot prove: the render maps the master song on
+ * the same timebase as the cut and never re-cuts it (render.js), and a
+ * lip-synced performance take of a stale song interval is refused before the
+ * render (performanceShot.js), so the one way picture and song drift apart is
+ * a stream that ends early or runs long — which the parity check measures. It
+ * does not listen to the content; a problem only a listener would hear is a
+ * director's call, and the UI labels the check as stream parity.
+ *
* A vision model cannot hear, and a set of stills cannot show motion, so the
* gate never lets frames alone pass `motion` or `audioSync`: without a
* successful continuous analysis both stay `unverified`, and a review with any
diff --git a/server/services/musicVideo/autoReviewService.js b/server/services/musicVideo/autoReviewService.js
index 060a8e2aa6..534d6b2cd7 100644
--- a/server/services/musicVideo/autoReviewService.js
+++ b/server/services/musicVideo/autoReviewService.js
@@ -258,6 +258,8 @@ async function takeSteps(projectId, runId) {
if (resumed.render) continue;
const fresh = await requireProject(projectId);
const current = findRun(fresh, runId);
+ // Paused or cancelled while the revision resumed: hand nothing out.
+ if (current.status !== 'running') return { project: fresh, run: current, action: { type: 'idle' } };
if (resumed.needsGeneration.length) {
return { project: fresh, run: current, action: { type: 'generate', revisionId: step.revisionId, sections: resumed.needsGeneration } };
}
diff --git a/server/services/musicVideo/revisionService.js b/server/services/musicVideo/revisionService.js
index 2b116f86ca..07902e0b3b 100644
--- a/server/services/musicVideo/revisionService.js
+++ b/server/services/musicVideo/revisionService.js
@@ -68,7 +68,7 @@ export async function assertRevisionOpen(projectId, revisionId, { sceneId = null
if (inFlight) {
throw new ServerError('This section is already generating for the auto-review run', { status: 409, code: 'AUTO_REVIEW_SECTION_IN_FLIGHT', context: { sceneId } });
}
- return chargeAutoReviewGeneration(current, revisionId, { sceneId, kind });
+ return chargeAutoReviewGeneration(current, revisionId, { sceneId, kind, jobs });
});
}
@@ -79,10 +79,12 @@ export async function assertRevisionOpen(projectId, revisionId, { sceneId = null
*/
export async function releaseRevisionSection(projectId, revisionId, sceneId) {
// #8988: a kickoff that never reached the queue also returns its charge to
- // the owning auto-review run's spend budget.
+ // the owning auto-review run's spend budget (never one whose job did).
+ const { listJobs } = await import('../mediaJobQueue/index.js');
+ const jobs = [...listJobs({ kind: 'video' }), ...listJobs({ kind: 'image' })];
return mutateProjectRecord(projectId, (current) => {
const released = releaseRevisionClaim(current, revisionId, sceneId);
- return { ...released, project: refundAutoReviewGeneration(released.project, revisionId, sceneId).project };
+ return { ...released, project: refundAutoReviewGeneration(released.project, revisionId, sceneId, jobs).project };
});
}