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

address review: mode-gated FFLF, cancel settles run promise, accurate STATUS log, skip wasted resize, assert lastImagePath plumbing

Adam Eivy3ddf6d7a6546
diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsx
index 8cf1efa79c..5d11f03c34 100644
--- a/client/src/pages/VideoGen.jsx
+++ b/client/src/pages/VideoGen.jsx
@@ -167,6 +167,11 @@ export default function VideoGen() {
const [result, setResult] = useState(null);
const [error, setError] = useState(null);
const eventSourceRef = useRef(null);
+ // Hold the reject() of the in-flight runGeneration Promise so cancel can
+ // settle it. Without this, handleCancel() closes the EventSource but the
+ // outstanding Promise dangles forever — and the queue worker's .finally()
+ // never runs, leaving runningQueueId stuck and freezing further dequeue.
+ const runRejectRef = useRef(null);
// Batch queue. Each item snapshots the params at enqueue time so the user
// can keep editing the form while jobs are in flight without affecting the
@@ -273,8 +278,8 @@ export default function VideoGen() {
});
// Run a single payload through the SSE pipeline. Returns a promise that
- // resolves when the job completes (or rejects on error). Shared by the
- // inline submit and the queue worker.
+ // resolves when the job completes (or rejects on error / cancel). Shared
+ // by the inline submit and the queue worker.
const runGeneration = (payload) => new Promise((resolve, reject) => {
setGenerating(true);
setProgress({ progress: 0 });
@@ -282,6 +287,13 @@ export default function VideoGen() {
setResult(null);
setError(null);
+ // Wrap settle so the cancel ref is cleared exactly once when the Promise
+ // transitions to a final state — guarantees the queue worker's .finally()
+ // always runs and stale rejects can't fire after a successful complete.
+ const settleResolve = (value) => { runRejectRef.current = null; resolve(value); };
+ const settleReject = (err) => { runRejectRef.current = null; reject(err); };
+ runRejectRef.current = settleReject;
+
generateVideo(payload).then((data) => {
const jobId = data.jobId || data.generationId;
const es = new EventSource(`/api/video-gen/${jobId}/events`);
@@ -303,27 +315,27 @@ export default function VideoGen() {
es.close();
toast.success('Video generated');
refreshHistory();
- resolve(msg.result);
+ settleResolve(msg.result);
}
if (msg.type === 'error') {
setError(msg.error);
setGenerating(false);
es.close();
toast.error(msg.error);
- reject(new Error(msg.error));
+ settleReject(new Error(msg.error));
}
};
es.onerror = () => {
setError('Lost connection to server');
setGenerating(false);
es.close();
- reject(new Error('Lost connection to server'));
+ settleReject(new Error('Lost connection to server'));
};
}).catch((err) => {
setError(err.message || 'Video generation failed');
setGenerating(false);
toast.error(err.message || 'Video generation failed');
- reject(err);
+ settleReject(err);
});
});
@@ -383,6 +395,14 @@ export default function VideoGen() {
await cancelVideoGen().catch(() => {});
setGenerating(false);
setStatusMsg('Cancelled');
+ // Settle the in-flight runGeneration Promise so the queue worker's
+ // .finally() releases runningQueueId and the next pending item can run.
+ // Without this the Promise would dangle and the worker would stay parked.
+ if (runRejectRef.current) {
+ const reject = runRejectRef.current;
+ runRejectRef.current = null;
+ reject(new Error('Cancelled'));
+ }
if (runningQueueId) {
setQueue((q) => q.map((item) => item.id === runningQueueId ? { ...item, status: 'error', error: 'Cancelled' } : item));
setRunningQueueId(null);
diff --git a/scripts/generate_win.py b/scripts/generate_win.py
index b514346e3d..5fb81f0d02 100644
--- a/scripts/generate_win.py
+++ b/scripts/generate_win.py
@@ -74,8 +74,23 @@ def main():
'consume two keyframes; flag is accepted for forward '
'compatibility with multi-keyframe pipelines.')
args = p.parse_args()
+ # The current LTX-Video 0.9.5 diffusers pipelines only accept a single
+ # conditioning image, so --last-image is forward-compat only. Tailor the
+ # STATUS log to the actual branch the script will take based on whether
+ # --image was also provided, so users/logs aren't misled into thinking we
+ # ran an I2V flow when we're really running T2V.
if args.last_image:
- log(f'STATUS:Last-frame image supplied ({args.last_image}) — currently advisory; falling back to single-image I2V')
+ if args.image:
+ log(
+ f'STATUS:Last-frame image supplied ({args.last_image}) — '
+ 'currently advisory; using single-image I2V with --image as '
+ 'the only conditioning frame'
+ )
+ else:
+ log(
+ f'STATUS:Last-frame image supplied ({args.last_image}) without --image — '
+ 'currently advisory and ignored for mode selection; continuing with T2V'
+ )
dtype = torch.bfloat16
generator = torch.Generator('cuda').manual_seed(args.seed) if args.seed is not None else None
diff --git a/server/routes/videoGen.test.js b/server/routes/videoGen.test.js
index aab04aec19..93d83ebe78 100644
--- a/server/routes/videoGen.test.js
+++ b/server/routes/videoGen.test.js
@@ -123,8 +123,14 @@ describe('videoGen routes', () => {
mode: 'fflf',
});
expect(r.status).toBe(200);
+ // Locks in the new request-field plumbing: lastImageFile becomes
+ // lastImagePath resolved under PATHS.images, and the mode hint flows
+ // through to the service. existsSync + PATHS.images are mocked so the
+ // resolver returns deterministic paths.
expect(videoGenService.generateVideo).toHaveBeenCalledWith(expect.objectContaining({
prompt: 'morph between two scenes',
+ sourceImagePath: '/mock/images/first.png',
+ lastImagePath: '/mock/images/last.png',
mode: 'fflf',
}));
});
diff --git a/server/services/videoGen/local.js b/server/services/videoGen/local.js
index 4651994382..5be21a2be9 100644
--- a/server/services/videoGen/local.js
+++ b/server/services/videoGen/local.js
@@ -119,7 +119,7 @@ const generateThumbnail = async (videoPath, jobId) => {
export const loadHistory = () => readJSONFile(HISTORY_FILE, []);
export const saveHistory = (h) => atomicWrite(HISTORY_FILE, h);
-const buildArgs = ({ pythonPath, modelId, model, prompt, negativePrompt, width, height, numFrames, fps, steps, guidance, seed, tiling, disableAudio, sourceImagePath, lastImagePath, outputPath }) => {
+const buildArgs = ({ pythonPath, modelId, model, prompt, negativePrompt, width, height, numFrames, fps, steps, guidance, seed, tiling, disableAudio, sourceImagePath, lastImagePath, mode, outputPath }) => {
if (IS_WIN) {
const scriptPath = join(PATHS.root, 'scripts', 'generate_win.py');
const args = [scriptPath, '--model', modelId, '--prompt', prompt, '--height', String(height), '--width', String(width), '--num-frames', String(numFrames), '--fps', String(fps), '--steps', String(steps), '--guidance', String(guidance), '--seed', String(seed), '--output', outputPath];
@@ -148,13 +148,14 @@ const buildArgs = ({ pythonPath, modelId, model, prompt, negativePrompt, width,
if (sourceImagePath) args.push('--image', sourceImagePath);
// mlx_video.generate_av exposes only single-image conditioning at a chosen
// frame index (--image-frame-idx). True FFLF (two keyframes) requires the
- // wrapper script to support multi-frame conditioning. For now we surface
- // the limitation: if the caller requested FFLF, we condition on the LAST
- // image at the final frame index — gives a "video ends here" feel even
- // without the start-frame keyframe. UI labels this clearly.
- if (lastImagePath && !sourceImagePath) {
+ // wrapper script to support multi-frame conditioning. We only opt into the
+ // last-frame-as-end-frame fallback when the caller explicitly asked for
+ // FFLF and supplied ONLY a last image (no source) — gating on `mode`
+ // matches the comment and avoids accidentally triggering the fallback for
+ // an i2v request that happened to send a `lastImagePath`.
+ if (mode === 'fflf' && lastImagePath && !sourceImagePath) {
args.push('--image', lastImagePath, '--image-frame-idx', String(Math.max(0, numFrames - 1)));
- } else if (lastImagePath && sourceImagePath) {
+ } else if (mode === 'fflf' && lastImagePath && sourceImagePath) {
// Both frames provided. mlx_video CLI can't currently consume both —
// log so the user knows their last image is advisory.
console.log(`⚠️ FFLF requested but mlx_video CLI only supports single-frame conditioning — last image ignored`);
@@ -190,7 +191,15 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m
// exact dimensions (it doesn't auto-pad), and pixie-forge learned the
// hard way that letting the model upscale a portrait reference makes
// garbled output.
- const ffmpeg = (sourceImagePath || lastImagePath) ? await findFfmpeg() : null;
+ //
+ // Skip the last-image resize when buildArgs would discard it anyway:
+ // - On macOS/mlx_video the FFLF fallback only triggers when no source
+ // image is also provided (single conditioning frame only).
+ // - On Windows we always forward --last-image to generate_win.py so it can
+ // log status, but the diffusers pipeline still consumes only --image —
+ // the resize is needed there because the script reads the file.
+ const lastImageWillBeUsed = !!lastImagePath && (IS_WIN || !sourceImagePath);
+ const ffmpeg = (sourceImagePath || lastImageWillBeUsed) ? await findFfmpeg() : null;
const resizeImage = async (srcPath, tag) => {
if (!srcPath || !ffmpeg) return { resolved: srcPath, tempPath: null };
const resizedPath = join(tmpdir(), `resized-${tag}-${jobId}.png`);
@@ -207,13 +216,15 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m
return { resolved: resizedPath, tempPath: resizedPath };
};
const { resolved: resolvedSourceImage, tempPath: resizedSrcTempPath } = await resizeImage(sourceImagePath, 'src');
- const { resolved: resolvedLastImage, tempPath: resizedLastTempPath } = await resizeImage(lastImagePath, 'last');
+ const { resolved: resolvedLastImage, tempPath: resizedLastTempPath } = lastImageWillBeUsed
+ ? await resizeImage(lastImagePath, 'last')
+ : { resolved: lastImagePath, tempPath: null };
const meta = { id: jobId, prompt, negativePrompt, modelId, seed: actualSeed, width: w, height: h, numFrames: parsedNumFrames, fps: parsedFps, filename, createdAt: new Date().toISOString(), mode: mode || (sourceImagePath ? 'image' : 'text') };
const job = { ...meta, clients: [], status: 'running' };
jobs.set(jobId, job);
- const { bin, args } = buildArgs({ pythonPath, modelId, model, prompt, negativePrompt, width: w, height: h, numFrames: parsedNumFrames, fps: parsedFps, steps: actualSteps, guidance: actualGuidance, seed: actualSeed, tiling, disableAudio, sourceImagePath: resolvedSourceImage, lastImagePath: resolvedLastImage, outputPath });
+ const { bin, args } = buildArgs({ pythonPath, modelId, model, prompt, negativePrompt, width: w, height: h, numFrames: parsedNumFrames, fps: parsedFps, steps: actualSteps, guidance: actualGuidance, seed: actualSeed, tiling, disableAudio, sourceImagePath: resolvedSourceImage, lastImagePath: resolvedLastImage, mode, outputPath });
console.log(`🎬 Generating video [${jobId.slice(0, 8)}]: ${modelId} ${w}x${h} frames=${parsedNumFrames} steps=${actualSteps}`);
videoGenEvents.emit('started', { generationId: jobId, totalSteps: actualSteps, ...meta });