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: stop unchanged terminal production retries (#9351)

[._.]/ Adam Eivy757125d4b716
diff --git a/client/src/components/musicVideo/AutopilotPanel.jsx b/client/src/components/musicVideo/AutopilotPanel.jsx
index dba90ce511..b463ed6ed8 100644
--- a/client/src/components/musicVideo/AutopilotPanel.jsx
+++ b/client/src/components/musicVideo/AutopilotPanel.jsx
@@ -80,6 +80,7 @@ function RunView({ run, production, codeFirst }) {
}).join(' · ')}. Reviewer calls use the separate review limit and may also cost money.</p>}
<p className="text-port-text-muted">Allowed: {(run.pool || []).map(routeLabel).join(', ')}</p>
{hint && <p className="text-port-warning break-words">{hint}</p>}
+ {steps.some((step) => step.retryBlocked) && <p className="text-port-warning">Terminal refusal recorded: unchanged inputs will not be submitted again on Resume. Repair the shot or cancel and choose another supported route. No new spend is reserved while blocked.</p>}
{run.error && <p role="status" className="text-port-error break-words">{run.error}</p>}
{failures.length > 0 && <p className="text-port-error">{failures.length} step{failures.length === 1 ? '' : 's'} failed — see the list below.</p>}
{steps.length > 0 && (
diff --git a/client/src/components/musicVideo/AutopilotPanel.test.jsx b/client/src/components/musicVideo/AutopilotPanel.test.jsx
index 9438e572d8..b06139503d 100644
--- a/client/src/components/musicVideo/AutopilotPanel.test.jsx
+++ b/client/src/components/musicVideo/AutopilotPanel.test.jsx
@@ -226,6 +226,17 @@ describe('AutopilotPanel production run', () => {
expect(await screen.findByText('Running')).toBeTruthy();
});
+ it('explains a terminal refusal without hiding the stop and recovery controls', () => {
+ render(<ProductionHarness initial={{ id: 'p1', productionRuns: [run({
+ status: 'blocked', steps: [{ key: 'frame:a:base:1', kind: 'frame', route: { kind: 'image', mode: 'local' },
+ status: 'refused', error: 'Unsupported request', retryBlocked: true }],
+ })] }} />);
+ expect(screen.getByText(/unchanged inputs will not be submitted again/)).toBeTruthy();
+ expect(screen.getByText(/No new spend is reserved while blocked/)).toBeTruthy();
+ expect(screen.getByRole('button', { name: /Cancel/ })).toBeTruthy();
+ expect(api.resumeMusicVideoProduction).not.toHaveBeenCalled();
+ });
+
it('shows an interrupted run and resumes it only on request; pushed projects update it', async () => {
api.resumeMusicVideoProduction.mockResolvedValue({ project: { id: 'p1', productionRuns: [run()] }, run: run() });
render(<ProductionHarness initial={{ id: 'p1', productionRuns: [run({ interrupted: true })] }} />);
diff --git a/server/services/musicVideo/production.js b/server/services/musicVideo/production.js
index 0ca42ae491..07593b180d 100644
--- a/server/services/musicVideo/production.js
+++ b/server/services/musicVideo/production.js
@@ -62,8 +62,6 @@ const PRODUCTION_STATUSES = Object.freeze([
const RESUMABLE = new Set(['running', 'stopped', 'limit-reached', 'blocked', 'needs-replan']);
const LIVE_STEP = new Set(['reserved', 'queued']);
const LIVE_JOB = new Set(['queued', 'running']);
-// A scene slot whose generation failed this many times needs a director.
-const MAX_SLOT_FAILURES = 2;
// A reserved step whose job never showed up in the queue after this long did
// not reach it (enqueue persists synchronously before returning).
const RESERVATION_LEASE_MS = 60_000;
@@ -287,6 +285,37 @@ const productionSceneBasis = (project, sceneId) => canonicalSnapshotChecksum({
videoSettings: project.videoSettings || null,
});
+// A retry is a new provider operation only when its actual inputs changed.
+// Take history, review timestamps and UI labels must not clear a terminal refusal.
+const productionRetryBasis = (project, sceneId, kind) => {
+ const scene = (project.scenes || []).find((entry) => entry.sceneId === sceneId) || {};
+ return canonicalSnapshotChecksum({
+ kind,
+ framePrompt: scene.framePrompt ?? null,
+ prompt: scene.prompt ?? null,
+ direction: scene.direction ?? null,
+ shotMode: scene.shotMode ?? null,
+ startSec: scene.startSec ?? null,
+ endSec: scene.endSec ?? null,
+ ...(kind === 'clip' ? { referenceImageId: scene.referenceImageId ?? null } : {}),
+ concept: project.concept ?? null,
+ treatment: project.treatment ?? null,
+ sectionIndex: scene.sectionIndex ?? null,
+ visualSpec: project.visualSpec ?? null,
+ castAndSets: project.castAndSets?.direction?.songMap ?? null,
+ lyricCues: kind === 'clip' ? project.lyricCues ?? null : null,
+ phrases: kind === 'clip' ? project.phrases ?? null : null,
+ audioAnalysis: kind === 'clip' ? project.audioAnalysis ?? null : null,
+ styleReferences: project.styleReferences ?? null,
+ videoSettings: project.videoSettings ?? null,
+ });
+};
+
+const terminalRefusal = (project, run, sceneId, kind, route = null) =>
+ run.steps.find((step) => step.sceneId === sceneId && step.kind === kind && step.retryBlocked
+ && step.retryBasis === productionRetryBasis(project, sceneId, kind)
+ && (!route || routeKey(step.route) === routeKey(route)));
+
/** All code-first work stays tied to the process and approved plan that reserved it. */
export function assertProductionActive(project, runId, processId) {
const run = findProductionRun(project, runId);
@@ -393,12 +422,12 @@ export function nextProductionStep(project, run, { jobs = [], processId = null }
if (stepKind === 'clip' && !scene.referenceImageId) { waiting = true; continue; }
const steps = slotSteps(run, scene.sceneId, stepKind);
if (steps.some((s) => LIVE_STEP.has(s.status)) || liveSlotJob(jobs, project.id, scene.sceneId, stepKind)) { waiting = true; continue; }
- // Failures since the last Start/Resume: a resume retries the slot, and a
- // job cancelled by Stop is not a failure of the route.
- const failures = steps.filter((s) => s.status === 'failed' && (s.settledAt || '') >= (run.resumedAt || '')).length;
- if (failures >= MAX_SLOT_FAILURES) {
- return { type: 'halt', status: 'blocked', reason: `"${scene.label || scene.sceneId}" failed to generate its ${stepKind} ${failures} times — generate it by hand, or resume to try again` };
- }
+ const refused = terminalRefusal(project, run, scene.sceneId, stepKind);
+ if (refused) return { type: 'halt', status: 'blocked', reason: `"${scene.label || scene.sceneId}" has a terminal ${stepKind} refusal (${refused.errorCode}). Change its inputs or start a new run with another supported route; Resume will not repeat it.` };
+ // A paid failure is not evidence that the same operation will work next
+ // time. Pause before another charge; explicit Resume permits a transient retry.
+ const failed = steps.find((s) => s.status === 'failed' && !(run.retryAcknowledged || []).includes(s.key));
+ if (failed) return { type: 'halt', status: 'blocked', reason: `"${scene.label || scene.sceneId}" failed to generate its ${stepKind}. Inspect the failure and repair its inputs, or resume explicitly to retry.` };
return { type: 'dispatch', kind: stepKind, sceneId: scene.sceneId };
}
}
@@ -460,6 +489,7 @@ export function reserveProductionStep(project, runId, {
const medium = project.treatment?.shotDirections?.find((d) => d.sceneId === sceneId)?.medium;
if ((kind === 'clip' && medium !== 'generated-footage') || (kind === 'frame' && !['still', 'generated-footage'].includes(medium))) throw productionError(409, 'PRODUCTION_MEDIUM_CONFLICT', 'This shot does not permit the requested generation');
}
+ if (terminalRefusal(project, run, sceneId, kind, route)) throw productionError(409, 'PRODUCTION_TERMINAL_REFUSAL', 'This route already refused these inputs; repair them or start a run with a supported route');
const existing = slotSteps(run, sceneId, kind, revisionId);
if (existing.some((s) => LIVE_STEP.has(s.status))) {
throw productionError(409, 'PRODUCTION_STEP_IN_FLIGHT', 'This scene is already generating for the production run', { sceneId });
@@ -487,6 +517,7 @@ export function reserveProductionStep(project, runId, {
route: { kind: route.kind, mode: route.mode, model: route.model || null },
rationale: trimTo(rationale, MAX_ERROR_LEN) || '',
costUsd,
+ ...(['frame', 'clip'].includes(kind) ? { retryBasis: productionRetryBasis(project, sceneId, kind) } : {}),
...(kind === 'clip' && scene?.direction?.actionContract ? { plateAdmission: { assetId: scene.referenceImageId, basis: plateRequirementBasis(scene) } } : {}),
...(plateRepairBasis ? { plateRepairBasis } : {}),
...(run.authoring && !author ? { submissionBasis: productionSceneBasis(project, sceneId) } : {}),
@@ -519,7 +550,7 @@ const refund = (run, step) => ({
* refused — a charge whose job reached the queue stays spent.
* Returns `{ project, run, step, changed }`.
*/
-export function settleProductionStep(project, runId, stepKey, { status, jobId = null, error = null }, now = new Date().toISOString()) {
+export function settleProductionStep(project, runId, stepKey, { status, jobId = null, error = null, errorCode = null, retryBlocked = false }, now = new Date().toISOString()) {
const run = findProductionRun(project, runId);
const step = run.steps.find((s) => s.key === stepKey);
if (!step) return { project, run, step: null, changed: false };
@@ -532,6 +563,8 @@ export function settleProductionStep(project, runId, stepKey, { status, jobId =
status,
jobId: jobId || step.jobId,
error: error ? trimTo(String(error), MAX_ERROR_LEN) : step.error,
+ ...(errorCode ? { errorCode: trimTo(String(errorCode), 100) } : {}),
+ ...(status === 'refused' && retryBlocked ? { retryBlocked: true } : {}),
settledAt: status === 'queued' ? null : now,
};
const out = mutateRun(project, runId, (r) => ({
@@ -657,6 +690,7 @@ export function resumeProductionOnProject(project, runId, { limits, acceptBasis
limits: nextLimits,
processId,
resumedAt: now,
+ retryAcknowledged: run.steps.filter((step) => step.status === 'failed').map((step) => step.key),
stopReason: null,
error: null,
...(run.finalRender?.status === 'failed' || (run.finalRender && run.processId !== processId) ? { finalRender: null } : {}),
diff --git a/server/services/musicVideo/productionService.js b/server/services/musicVideo/productionService.js
index ff1e67d73b..c2e371737a 100644
--- a/server/services/musicVideo/productionService.js
+++ b/server/services/musicVideo/productionService.js
@@ -260,7 +260,12 @@ async function dispatchSlot(projectId, runId, { stepKind, sceneId, revisionId =
const sent = await deps.dispatch({ stepKind, project: reserved.project, scene: reserved.project.scenes.find((s) => s.sceneId === sceneId), route: choice.route, tag, settings: env.settings })
.catch((err) => ({ error: err }));
if (sent.error) {
- await mutateProjectRecord(projectId, (current) => settleProductionStep(current, runId, step.key, { status: 'refused', error: sent.error.message }));
+ await mutateProjectRecord(projectId, (current) => settleProductionStep(current, runId, step.key, { status: 'refused', error: sent.error.message,
+ errorCode: sent.error.code || 'PRODUCTION_INVALID_REQUEST',
+ // Invalid input/capability refusals cannot heal by repeating the request.
+ // Availability and transport errors remain explicitly resumable.
+ retryBlocked: [400, 422].includes(sent.error.status) || /(?:UNSUPPORTED|INCAPABLE)$/.test(sent.error.code || ''),
+ }));
if (revisionId) await deps.releaseRevisionSection(projectId, revisionId, sceneId).catch(() => {});
console.warn(`⚠️ Music Video production ${short(runId)} ${stepKind} for ${sceneId} refused: ${sent.error.message}`);
return { halt: { status: 'blocked', reason: `The ${stepKind} for "${scene.label || sceneId}" was refused: ${sent.error.message}` } };
diff --git a/server/services/musicVideo/productionService.test.js b/server/services/musicVideo/productionService.test.js
index b0d109fa25..7f8bacc83a 100644
--- a/server/services/musicVideo/productionService.test.js
+++ b/server/services/musicVideo/productionService.test.js
@@ -336,12 +336,13 @@ describe('music video production run (#9066)', () => {
mediaJobEvents.emit('failed', job);
await settle();
const steps = theRun().steps.filter((s) => s.sceneId === 'mvs-a');
- expect(steps.map((s) => s.status)).toEqual(['failed', 'queued']);
- // One retry for the failed slot, not one per duplicate event.
- expect(dispatch.mock.calls.filter(([a]) => a.scene.sceneId === 'mvs-a')).toHaveLength(2);
+ expect(steps.map((s) => s.status)).toEqual(['failed']);
+ // Duplicate failure events cannot authorize another paid operation.
+ expect(dispatch.mock.calls.filter(([a]) => a.scene.sceneId === 'mvs-a')).toHaveLength(1);
+ expect(theRun().status).toBe('blocked');
});
- it('halts a slot that keeps failing, and a resume retries it', async () => {
+ it('pauses after a paid failure and retries only on explicit Resume, including a second failure', async () => {
seedProject();
await start();
const fail = (id) => {
@@ -351,13 +352,52 @@ describe('music video production run (#9066)', () => {
};
fail('job-1');
await settle();
+ expect(theRun()).toMatchObject({ status: 'blocked', usage: { generations: 2 } });
+ expect(dispatch).toHaveBeenCalledTimes(2);
+ await service.resumeProduction('mv-example', theRun().id);
+ await settle();
+ expect(dispatch.mock.calls.slice(2).map(([a]) => a.scene.sceneId)).toEqual(['mvs-a']);
fail('job-3');
await settle();
- expect(theRun()).toMatchObject({ status: 'blocked', stopReason: expect.stringMatching(/"A" failed to generate its frame 2 times/) });
- const before = dispatch.mock.calls.length;
+ expect(theRun()).toMatchObject({ status: 'blocked', usage: { generations: 3 } });
+ expect(dispatch).toHaveBeenCalledTimes(3);
+ });
+
+ it('persists terminal refusal across Resume and incidental edits, but admits repaired inputs', async () => {
+ seedProject();
+ dispatch.mockRejectedValueOnce(Object.assign(new Error('Unsupported request'), { status: 422, code: 'VIDEO_MODE_UNSUPPORTED' }));
+ await start();
+ const refused = theRun().steps[0];
+ expect(refused).toMatchObject({ status: 'refused', retryBlocked: true, errorCode: 'VIDEO_MODE_UNSUPPORTED' });
+ expect(theRun().usage.generations).toBe(0);
+ expect(() => reserveProductionStep(current(), theRun().id, {
+ kind: 'frame', sceneId: 'mvs-a', revisionId: 'mvr-new', route: refused.route, processId: theRun().processId,
+ })).toThrow();
+ store.get('mv-example').scenes[0].label = 'Renamed';
+ store.get('mv-example').scenes[0].takes.push({ id: 'take-example', status: 'rejected' });
+ for (let i = 0; i < 2; i += 1) {
+ await service.resumeProduction('mv-example', theRun().id);
+ await settle();
+ }
+ expect(dispatch).toHaveBeenCalledTimes(1);
+ expect(theRun()).toMatchObject({ status: 'blocked', usage: { generations: 0 } });
+ store.get('mv-example').scenes[0].framePrompt = 'a repaired frame';
+ await service.resumeProduction('mv-example', theRun().id);
+ await settle();
+ expect(dispatch).toHaveBeenCalledTimes(3);
+ expect(theRun().usage.generations).toBe(2);
+ });
+
+ it('allows explicit Resume after a transient submission failure without spending on the refusal', async () => {
+ seedProject();
+ dispatch.mockRejectedValueOnce(Object.assign(new Error('Provider temporarily unavailable'), { status: 503 }));
+ await start();
+ expect(theRun().steps[0]).not.toHaveProperty('retryBlocked');
+ expect(theRun().usage.generations).toBe(0);
await service.resumeProduction('mv-example', theRun().id);
await settle();
- expect(dispatch.mock.calls.slice(before).map(([a]) => a.scene.sceneId)).toEqual(['mvs-a']);
+ expect(dispatch).toHaveBeenCalledTimes(3);
+ expect(theRun().usage.generations).toBe(2);
});
it('coalesces concurrent advances so each slot is dispatched once', async () => {
@@ -801,6 +841,8 @@ it('charges a selected performance retry by its actual padded provider duration
try {
await start({ pool: [{ kind: 'video', mode: 'fal' }], authoring: AUTHORING, limits: { ...LIMITS, spendCapUsd: 1.7 } });
const job = jobs[0]; job.status = 'failed'; mediaJobEvents.emit('failed', job); await settle();
+ expect(theRun().status).toBe('blocked');
+ await service.resumeProduction('mv-example', theRun().id); await settle();
const clips = theRun().steps.filter((step) => step.kind === 'clip');
expect(clips).toHaveLength(2);
expect(clips.map((step) => step.costUsd)).toEqual([0.808, 0.808]);