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: detect missing Python modules in BYOV video runtimes + match preview to render aspect

[._.]/ Adam Eivy7c27502ec880
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 9005c4225c..ae78cd355b 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -32,6 +32,9 @@ TBD
## Fixed
+- **Wan 2.2 / HunyuanVideo: detect missing Python modules and surface an actionable install prompt.** Wan 2.2's import probe was checking `import torch, transformers, huggingface_hub` — which passed even though `einops` (imported transitively by `wan/modules/vae2_1.py` but absent from upstream's `pyproject.toml`) was never installed. The install banner stayed hidden and renders failed with an opaque `Exit code 1` over a deep `ModuleNotFoundError` in the server log. Two fixes: the probes now exercise the real import chain (`import wan` for Wan 2.2; `sys.path.insert` + `import hyvideo.inference` for HunyuanVideo) so any transitive dep missing trips the probe and re-surfaces the install banner; and the stderr handler in `server/services/videoGen/local.js` now scans for `ModuleNotFoundError: No module named 'X'`, swapping the generic `Exit code 1` for a runtime-specific message naming the module and the re-install command (`INSTALL_WAN22=1 bash scripts/setup-image-video.sh`). The ready cache is also invalidated on detection so the next status poll re-probes and the install banner re-appears immediately.
+- **Video Gen preview matches the configured render aspect ratio.** The preview pane was hardcoded `aspect-video` (16:9), so a portrait 576×1024 request previewed in a 16:9 letterbox. The container now computes explicit pixel dimensions from the configured `width × height` fit inside a 420×420 budget — landscape, portrait, and square renders all preview in their true ratio.
+
- **HunyuanVideo: pin to fp32 + mark deprecated; fix invisible per-step progress on all BYOV video runtimes.** The hunyuan runner previously defaulted to fp16, which trips an MPS matmul assertion (`MPSNDArrayMatrixMultiplication.mm:5799 failed assertion: Destination NDArray and Accumulator NDArray cannot have different datatype`) within ~2s of `predict()`. Verified bf16 hits the same assertion — only fp32 across DiT + VAE + both text encoders works on Apple Silicon, because MPS matmul kernels always use an fp32 accumulator internally and assert when the output dtype differs. At 576×1024×121 frames × 30 steps fp32 is a 4-8 hr render, so the entry is also flagged `deprecated: true` (lands in the "Legacy" optgroup). Migration `044-hunyuan-fp32-deprecated.js` patches the precision/deprecated/name fields onto existing installs' `data/media-models.json`; fresh installs pick up the shape via the updated `data.reference/media-models.json` and `DEFAULT_REGISTRY` seed. Two adjacent ergonomic fixes also landed in `server/services/videoGen/local.js` that apply to every BYOV video runtime (HunyuanVideo + Wan 2.2 + LTX-2): `PYTHONUNBUFFERED=1` on the spawn env so tqdm + loguru + STAGE: prints flush per-line (previously the UI saw no progress for the entire run because child stdio was line-buffered against a pipe), and `caffeinate -dis` (was `-i`) so display + idle + system sleep are all blocked — fixes a regression where a laptop on battery would sleep mid-render and leave the Python child in uninterruptible-wait until a hard kill. For HunyuanVideo specifically, `scripts/generate_hunyuan.py` monkey-patches `tqdm.tqdm` / `tqdm.auto.tqdm` so each diffusion step emits a `STAGE:inference:step:N:30:` line that `local.js#handleLine` parses into an SSE progress event — without this, even with unbuffered stdio, the pipeline's `tqdm` against a pipe was too sparse for the UI to render a step count. Set `hv.text_encoder_precision_2` alongside `hv.text_encoder_precision` so CLIP-L follows the same dtype as Llama — otherwise CLIP silently loaded at fp16 against an fp32 Llama and tripped the assertion via mixed-dtype embeddings.
- **Scheduled `reference-watch` was silently read-only, breaking weekly PLAN.md updates.** `DEFAULT_TASK_INTERVALS['reference-watch']` in `server/services/taskSchedule.js` carried `taskMetadata: { readOnly: true }`, which `agentPromptBuilder.js` translated into a "## Read-Only Task — Do NOT commit, push, or modify any files" guard at the bottom of the prompt. But the v2 reference-watch prompt (`PROMPT_VERSIONS['reference-watch'] = 2`) explicitly instructs the agent to APPEND slug-tagged `[ref-watch-…]` checklist items to PLAN.md and commit them — the agent (correctly) refused to write any files, defeating the whole flow on every weekly cron firing. The on-commit trigger path in `referenceRepos.js#triggerReferenceAnalysis` was already correct (`readOnly: false`, with an inline comment documenting exactly this pitfall); the scheduled-cron default drifted. Flipped the default to `readOnly: false`, updated the stale comment, and pinned the contract via tests in `taskSchedule.test.js` (default-interval contract) and `referenceRepos.test.js` (trigger-path contract).
diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsx
index 983c9e4d7c..3e557006cb 100644
--- a/client/src/pages/VideoGen.jsx
+++ b/client/src/pages/VideoGen.jsx
@@ -520,6 +520,13 @@ export default function VideoGen() {
const { matched: matchedResolution, label: resolutionLabel } = resolveResolutionLabel(VIDEO_RESOLUTIONS, width, height);
const progressPct = progress?.progress != null ? Math.round(progress.progress * 100) : null;
+ // Explicit px sizing — maxWidth + maxHeight + aspectRatio together resolves
+ // inconsistently across browsers for mixed orientations.
+ const previewBudget = 420;
+ const previewRatio = (width > 0 && height > 0) ? width / height : 16 / 9;
+ const previewWidth = previewRatio >= 1 ? previewBudget : Math.round(previewBudget * previewRatio);
+ const previewHeight = previewRatio >= 1 ? Math.round(previewBudget / previewRatio) : previewBudget;
+
const handleResolutionChange = (e) => {
const r = VIDEO_RESOLUTIONS.find((r) => r.label === e.target.value);
if (r) { setWidth(r.w); setHeight(r.h); }
@@ -1520,7 +1527,10 @@ export default function VideoGen() {
</a>
)}
</div>
- <div className="aspect-video max-w-[420px] mx-auto bg-port-bg border border-port-border rounded-lg overflow-hidden flex items-center justify-center relative">
+ <div
+ className="mx-auto bg-port-bg border border-port-border rounded-lg overflow-hidden flex items-center justify-center relative max-w-full"
+ style={{ width: previewWidth, height: previewHeight }}
+ >
{result ? (
// muted so the clip autoplays under the mobile media-engagement
// policy (iOS/Android block unmuted autoplay outside a user
diff --git a/server/services/videoGen/local.js b/server/services/videoGen/local.js
index 4d97dd7703..3bcf9ac34a 100644
--- a/server/services/videoGen/local.js
+++ b/server/services/videoGen/local.js
@@ -53,6 +53,8 @@ const execFileAsync = promisify(execFile);
const IS_WIN = process.platform === 'win32';
+const MODULE_NOT_FOUND_RE = /ModuleNotFoundError: No module named ['"]([^'"]+)['"]/;
+
// Catalog comes from data/media-models.json (see server/lib/mediaModels.js).
// Cached as a plain object at boot for O(1) lookup by id, matching the prior shape.
export const VIDEO_MODELS = Object.fromEntries(getVideoModels().map((m) => [m.id, m]));
@@ -77,7 +79,9 @@ export const BYOV_RUNTIME_INFO = Object.freeze({
repoDir: HUNYUAN_REPO_DIR,
installEnvVar: 'INSTALL_HUNYUAN',
repoUrl: 'https://github.com/gaurav-nelson/HunyuanVideo_MLX',
- importProbe: 'import torch, huggingface_hub, transformers',
+ // `hyvideo` isn't pip-installed — mirror the runner's sys.path prepend so
+ // the probe walks the same transitive import chain (loguru, diffusers, …).
+ importProbe: `import sys; sys.path.insert(0, ${JSON.stringify(HUNYUAN_REPO_DIR)}); import hyvideo.inference`,
},
wan22: {
id: 'wan22',
@@ -86,7 +90,10 @@ export const BYOV_RUNTIME_INFO = Object.freeze({
repoDir: WAN22_REPO_DIR,
installEnvVar: 'INSTALL_WAN22',
repoUrl: 'https://github.com/osama-ata/Wan2.2-mlx',
- importProbe: 'import torch, transformers, huggingface_hub',
+ // Walks the package's __init__ chain so transitive deps absent from
+ // upstream's pyproject.toml (e.g. einops, imported by wan/modules/vae2_1.py)
+ // fail the probe instead of slipping past a flat torch/transformers check.
+ importProbe: 'import wan',
},
ltx2: {
id: 'ltx2',
@@ -744,6 +751,7 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m
});
let outputBuf = '';
+ let missingPyModule = null;
// Returns true when the line was a known progress/status message (already
// broadcast over SSE) or python-noise — caller should suppress logging.
@@ -822,6 +830,12 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m
proc.stderr.on('data', (chunk) => {
for (const raw of chunk.toString().split(/[\n\r]+/)) {
+ // Record the root-cause module only — downstream imports in the same
+ // traceback raise the same error against later names.
+ if (!missingPyModule) {
+ const m = raw.match(MODULE_NOT_FOUND_RE);
+ if (m) missingPyModule = m[1];
+ }
if (!handleLine(raw)) console.log(`🐍 [${jobId.slice(0, 8)}] ${raw.trim()}`);
}
});
@@ -847,9 +861,25 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m
if (code !== 0) {
job.status = 'error';
- const reason = signal === 'SIGKILL'
- ? 'Process killed (likely out of memory — try a smaller model or resolution)'
- : signal ? `Killed by signal ${signal}` : `Exit code ${code}`;
+ let reason;
+ if (missingPyModule) {
+ const runtimeInfo = BYOV_RUNTIME_INFO[model.runtime];
+ if (runtimeInfo) {
+ // The probe believed the venv was ready but a runtime import
+ // disagreed — drop the cached "ready" so the next /runtime-status
+ // re-probes and the install banner re-appears.
+ invalidateByovReadyCache(runtimeInfo.id);
+ reason = `Python module '${missingPyModule}' is missing from the ${runtimeInfo.label} venv. Re-run the installer via Settings → Video (or \`${runtimeInfo.installEnvVar}=1 bash scripts/setup-image-video.sh\`).`;
+ } else {
+ reason = `Python module '${missingPyModule}' is missing. Install it into the configured Python environment and retry.`;
+ }
+ } else if (signal === 'SIGKILL') {
+ reason = 'Process killed (likely out of memory — try a smaller model or resolution)';
+ } else if (signal) {
+ reason = `Killed by signal ${signal}`;
+ } else {
+ reason = `Exit code ${code}`;
+ }
console.log(`❌ Video generation failed [${jobId.slice(0, 8)}]: ${reason}`);
broadcastSse(job, { type: 'error', error: `Generation failed: ${reason}` });
videoGenEvents.emit('failed', { generationId: jobId, error: reason });