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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix(image-gen): detect corrupted mflux installs and surface a repair command
Adam Eivy9669115866c0
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 16504cf59d..5d45e67fa9 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -17,6 +17,7 @@## Fixed+- **mflux corrupted-install detection.** When mflux's entry-point shim references `mflux.models.flux.cli.flux_generate` but the importable `mflux/` package on disk is stuck at an older layout (file tree out of sync with the dist-info — easy to hit when `~/.local/lib/python*/site-packages/mflux/` and a conda-env mflux both exist at version 0.12.1 but were installed at different repackaging stages), the runner crashed with bare "Exit code 1" and a Python `ModuleNotFoundError`. PortOS now detects that specific traceback in the runner's stderr and surfaces an actionable message explaining the cause and the exact `pip uninstall -y mflux && pip install --user --force-reinstall --no-cache-dir --no-deps mflux` repair command. `scripts/setup-image-video.sh` also now passes `--force-reinstall --no-deps` on the mflux install so subsequent setup runs flush the package's file tree without re-resolving torch/mlx and friends — heading off the divergence at the source.- **Guidance input hidden for distilled image models; runner stops emitting "Guidance scale X is ignored" warnings.** Step-wise distilled image models (Flux 1 Schnell, FLUX.2 Klein 4B/9B/Int8, Z-Image-Turbo) bake classifier-free guidance internally — any guidance scale > 1.0 is silently dropped by diffusers, which logs a noisy `"Guidance scale 7.0 is ignored for step-wise distilled models."` line on every render. The registry now flags those entries with `cfgDisabled: true` (backfilled on existing installs by id, in `server/lib/mediaModels.js → backfillCfgDisabled`), the Image Gen / World Builder Guidance input is hidden when the selected model has the flag set, and `server/services/imageGen/local.js` pins the resolved guidance to `1.0` for cfgDisabled models so the runner's diffusers call stays quiet and the saved metadata sidecar reflects the value the model actually used. Any user override of `cfgDisabled` (true OR false) on a custom registry entry wins.- **World Builder expansion no longer 0-variations on Codex CLI responses.** The expand-starter step had three failure modes against Codex's CLI provider that all manifested as "Expanded into 0 variations": (1) Codex echoes the user prompt back to stdout before the model's reply, and the prompt itself contains a JSON-shaped *schema example* (`{ "label": string (max 80 chars), "prompt": … }`) — its braces balance but its contents are not valid JSON, so the previous first-balanced-block extractor crashed on it; (2) Codex occasionally emits an orphan `}` between a variation's close-brace and the array's `]` (`…blister"}}]}}}`), making `JSON.parse` throw on otherwise-recoverable output; (3) some prompt variants embed small literal `{ "label": …, "prompt": … }` example variations that parse cleanly but are not the response, so the extractor would happily return the wrong object. `extractJson` now (a) walks every top-level brace-balanced block and tries each in order, (b) prefers a block that has any of `stylePrompt` / `negativePrompt` / `categories` at the top level over an example-shaped one, and (c) attempts cheap repairs for trailing commas and the orphan-brace `}}]` → `}]` corruption before giving up. The expand path also logs the toolkit `runId` plus per-category variation counts so a 0-variation outcome is debuggable from `data/runs/<id>/output.txt`. Four new tests cover the Codex prompt-echo, orphan-brace, trailing-comma, and shape-preference cases.- **CoS review-loop tasks now actually loop until clean and merge the PR.** Previously, scheduled or user tasks running with worktree + openPR + reviewLoop only fired one Copilot review request and stopped — the worktree got cleaned up immediately, the PR sat with whatever feedback Copilot returned, and nothing addressed comments or merged. The fix adds a follow-up internal task that the original cleanup hook spawns once the PR is open and the initial Copilot review has been requested. The follow-up agent attaches a fresh worktree to the PR branch (via a new `existingBranch` option on `createWorktree`), runs the full `/do:rpr`-style poll/fix/push/re-request loop until Copilot returns zero unresolved comments (or hits a 10-iteration guardrail), then merges the PR with `gh pr merge --squash --auto --delete-branch`. The follow-up's own cleanup pass passes `skipMerge: true` so the worktree branch isn't re-merged locally on top of the squash-merge gh just executed. GitLab MRs and other non-GitHub forges still skip the loop entirely (Copilot reviewer is GitHub-only). See `server/services/agentLifecycle.js` (`spawnReviewLoopFollowUp`) and `server/services/agentPromptBuilder.js` (`reviewLoopFollowUpSection`).diff --git a/scripts/setup-image-video.sh b/scripts/setup-image-video.shindex 3b6075bc44..05e539eccb 100755--- a/scripts/setup-image-video.sh+++ b/scripts/setup-image-video.sh@@ -36,9 +36,15 @@ INSTALL_VIDEO="${INSTALL_VIDEO:-$(is_macos && echo 1 || echo 0)}"# Install via pip --user so we don't pollute the system or require a venv.# mflux comes with the mflux-generate CLI which the local image backend# spawns directly. transformers<5 is required for MLX compatibility.+#+# `--force-reinstall --no-deps` on mflux only — earlier setup runs could+# leave the user-site copy at the right version number but with stale file+# layout (we hit this in 0.12.1, where `mflux/models/flux/cli/` was missing+# from a partial reinstall, breaking the entry-point shim). Forcing the+# reinstall flushes the file tree without re-resolving torch/mlx and friends.echo "📦 Installing image generation packages (mflux + deps)..."+"$PYTHON_BIN" -m pip install --upgrade --user --force-reinstall --no-deps mflux"$PYTHON_BIN" -m pip install --upgrade --user \- mflux \"transformers<5" \safetensors \huggingface_hub \diff --git a/server/services/imageGen/local.js b/server/services/imageGen/local.jsindex 31c18c0502..f2cc18d916 100644--- a/server/services/imageGen/local.js+++ b/server/services/imageGen/local.js@@ -444,6 +444,18 @@ export async function generateImage({ pythonPath, prompt, negativePrompt = '', mconst proseIdx = lines.findIndex((l, i) => i > structIdx && l.startsWith('❌'));userMessage = proseIdx >= 0 ? lines[proseIdx].replace(/^❌\s*/, '') : null;}+ // Heuristic detection for non-USER_ERROR failures we can still+ // surface actionably. mflux's entry-point shim breaks when a partial+ // package upgrade leaves user-site at the right version number but+ // with stale file layout — Python imports the wrong `mflux/` first.+ // Easier to spot at the source than to teach the user to read pip diffs.+ if (!userMessage) {+ const mfluxBroken = lines.some((l) => /ModuleNotFoundError: No module named 'mflux\.models\.flux\.cli'/.test(l));+ if (mfluxBroken) {+ userKind = 'mflux_install_corrupted';+ userMessage = 'Your mflux install is corrupted (entry-point shim and package layout out of sync). Repair with: `pip uninstall -y mflux && pip install --user --force-reinstall --no-cache-dir --no-deps mflux`. If you use conda, run the same in your conda env\'s pip.';+ }+ }const tail = lines.slice(-10).join('\n');const errorText = userMessage? `${userMessage}\n\n(diagnostic) ${reason}`