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(video-gen): safer Windows faststart replace + clear gallery pick on upload

Adam Eivyaafbf52c92ff
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index fbe4d9f9b8..5551fecae1 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -27,7 +27,7 @@
- **Last-frame extraction now caches** to `data/images/lastframe-<videoId>.png` — repeated "Continue" clicks reuse the cached PNG instead of re-spawning ffmpeg. Cuts ~1–2s per click.
- **Delete operations now log** for both image (`🗑️ Deleted image: <filename>`) and video (`🗑️ Deleted video: <filename>`) gallery actions. Previously delete was silent, making it impossible to confirm from the server logs that the click hit the backend.
- **Media model registry tolerates partial user edits.** `loadMediaModels()` now merges parsed `data/media-models.json` over the built-in defaults so a registry missing top-level keys (e.g. `{}` or no `video`) doesn't crash server boot at module import. The loader also catches read errors (permissions, broken symlink) — not just JSON parse — falling back to defaults so a registry I/O problem can't take down startup. `getDefaultVideoModelId()` validates the configured default against the platform's available list — typos or `broken`-flagged ids fall back to the first available model with a warning instead of surfacing as "Unknown video model" in the UI. `getTextEncoderRepo()` validates that the resolved entry has a non-empty repo string before passing it to mlx_video. macOS video gen now also validates `model.repo` exists before spawning, surfacing a 500 with a clear error rather than passing `undefined` into spawn args.
-- **Faststart remux works on Windows.** `optimizeForStreaming()` did an in-place `fs.rename(tmpPath, videoPath)` which fails on Windows when the destination already exists, so every successful render would log a warning and skip the optimization. Now unlinks the destination first on Windows (non-atomic, but preserves faststart) and keeps the single-syscall atomic replace on POSIX.
+- **Faststart remux works on Windows without risking the rendered video.** `optimizeForStreaming()` did an in-place `fs.rename(tmpPath, videoPath)` which fails on Windows when the destination already exists. The Windows replace strategy now moves the original aside to a `.bak.<uuid>` first, installs the optimized file, and restores the backup on any failure — so a transient rename failure (file lock, AV scan, permissions) skips faststart instead of destroying the rendered video. POSIX still uses the single-syscall atomic replace.
- **`caffeinate` sleep-prevention is now strictly macOS-only.** Previous gate (`!IS_WIN`) would also fire on Linux and emit a pointless ENOENT every render. Tightened to `process.platform === 'darwin'`.
- **`scripts/setup-image-video.sh` removes the wrong package before install.** The PyPI package `mlx_video` (unrelated video-loading utility) shadows the LTX backend's `import mlx_video` if previously installed. The script now `pip uninstall --yes mlx_video` before installing `mlx-video-with-audio>=0.1.35`, so upgraders aren't left in an ambiguous state.
- **Form fields stay editable during a video render.** Previously every input was `disabled={generating}`, blocking the user from queueing a different config while a render was in flight. The queue worker captures payloads at enqueue time, so live editing is safe.
diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsx
index eecc9cf166..468d80aafb 100644
--- a/client/src/pages/VideoGen.jsx
+++ b/client/src/pages/VideoGen.jsx
@@ -650,7 +650,16 @@ export default function VideoGen() {
<input
type="file"
accept="image/*"
- onChange={(e) => setSourceImageUpload(e.target.files?.[0] || null)}
+ onChange={(e) => {
+ const file = e.target.files?.[0] || null;
+ // Clear any gallery pick + URL param when an upload is
+ // chosen — otherwise the preview keeps rendering the
+ // old gallery image (src prefers sourceImageFile) while
+ // the POST sends `req.file` from the upload, which
+ // looks like the wrong image was used.
+ if (file && (sourceImageFile || incomingSourceImage)) clearSourceImage();
+ setSourceImageUpload(file);
+ }}
className="hidden"
/>
</label>
diff --git a/server/services/videoGen/local.js b/server/services/videoGen/local.js
index 5d78a8eddd..011e7ece0b 100644
--- a/server/services/videoGen/local.js
+++ b/server/services/videoGen/local.js
@@ -127,15 +127,25 @@ const optimizeForStreaming = async (videoPath) => {
});
if (!ok) { await unlink(tmpPath).catch(() => {}); return; }
// POSIX rename atomically replaces an existing dest in one syscall. On
- // Windows, fs.rename fails when the destination already exists, so every
- // successful render would log a warning and skip faststart. Unlink first
- // there — non-atomic (brief window with no file) but preserves the
- // optimization. If the eventual rename still fails, clean up the tmp file
- // so we don't slowly fill data/videos with .fs.mp4 leaks.
+ // Windows, fs.rename fails when the destination already exists — but a
+ // simple unlink-first would destroy the rendered video if the subsequent
+ // rename failed (locked file, AV scan, transient permissions). Move the
+ // original aside to a .bak first, then install the optimized file, and
+ // restore the backup on any failure so the worst case is "faststart
+ // skipped", not "rendered video lost".
+ let backupPath = null;
try {
- if (IS_WIN) await unlink(videoPath).catch((err) => { if (err?.code !== 'ENOENT') throw err; });
+ if (IS_WIN) {
+ backupPath = `${videoPath}.bak.${randomUUID()}`;
+ await rename(videoPath, backupPath).catch((err) => {
+ if (err?.code === 'ENOENT') { backupPath = null; return; }
+ throw err;
+ });
+ }
await rename(tmpPath, videoPath);
+ if (backupPath) await unlink(backupPath).catch(() => {});
} catch (err) {
+ if (backupPath) await rename(backupPath, videoPath).catch(() => {});
await unlink(tmpPath).catch(() => {});
console.log(`⚠️ Failed to install streaming-optimized video at ${videoPath}: ${err.message}`);
}