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

refactor: resolve the image model once per flux2 status request and reuse queryString

Adam Eivy6a2d1168b41c
diff --git a/client/src/components/imageGen/Flux2InstallModal.jsx b/client/src/components/imageGen/Flux2InstallModal.jsx
index f9369be65b..1624eba88f 100644
--- a/client/src/components/imageGen/Flux2InstallModal.jsx
+++ b/client/src/components/imageGen/Flux2InstallModal.jsx
@@ -13,6 +13,7 @@
import { useEffect, useState } from 'react';
import { CheckCircle2, Loader2, AlertCircle, Download, X } from 'lucide-react';
import { useInstallStream } from '../../hooks/useInstallStream';
+import { queryString } from '../../services/apiCore';
import InstallErrorFooter from '../install/InstallErrorFooter';
import Modal from '../ui/Modal';
@@ -34,14 +35,12 @@ const STAGE_INDEX = Object.fromEntries(STAGES.map((s, i) => [s.id, i]));
*/
export default function Flux2InstallModal({ open, onClose, onComplete, modelId = null }) {
const [confirmingCancel, setConfirmingCancel] = useState(false);
+ const installUrl = `/api/image-gen/setup/flux2-install${queryString({ modelId })}`;
// The shared install-stream hook owns the fetch-stream lifecycle, log
// accumulation, stage tracking, connection-lost handling and auto-scroll.
// onComplete is ref-stashed inside the hook so ImageGen's frequent state
// churn (gallery, generating, localProgress) can't kill the install
// mid-stream by re-running the effect.
- const installUrl = modelId
- ? `/api/image-gen/setup/flux2-install?modelId=${encodeURIComponent(modelId)}`
- : '/api/image-gen/setup/flux2-install';
const { logs, currentStage, done, error, logsEndRef, close } = useInstallStream(
installUrl,
{ enabled: open, onComplete, method: 'POST' },
diff --git a/server/lib/pythonSetup.js b/server/lib/pythonSetup.js
index 5e04321ae3..ff36f8fb84 100644
--- a/server/lib/pythonSetup.js
+++ b/server/lib/pythonSetup.js
@@ -393,9 +393,16 @@ async function probeFlux2Venv(pipelineClass) {
.catch(() => false)
: false;
}
-// Pipeline classes the installer's verify stage guarantees, newest first-class
-// family last. The readiness GATE in front of the installer must require all of
-// them: gating on the base `Flux2KleinPipeline` alone let a venv built before a
+// Pipeline classes the installer's verify stage guarantees. Membership rule:
+// the base FLUX.2 pipeline, plus the NEWEST diffusers pipeline PortOS ships a
+// model for — together they date the venv's diffusers snapshot, which is the
+// only thing the verify stage can assert without a model download. Per-model
+// classes are not listed here; the gate takes the selected model's own
+// `pipelineClass` as an argument instead, so the registry stays the one place
+// a new family is declared.
+//
+// The readiness GATE in front of the installer must require all of them:
+// gating on the base `Flux2KleinPipeline` alone let a venv built before a
// newer pipeline landed report "already installed" while the per-model verdict
// (which probes that model's own `pipelineClass`) said unavailable — the user
// saw an Install button that answered "nothing to do".
diff --git a/server/routes/imageGenSetup.js b/server/routes/imageGenSetup.js
index 77f644fe8d..167d4c4a1d 100644
--- a/server/routes/imageGenSetup.js
+++ b/server/routes/imageGenSetup.js
@@ -47,20 +47,26 @@ router.get('/python', asyncHandler(async (_req, res) => {
// gate the second click — the first install hasn't created the python yet.
let flux2InstallInFlight = null;
+// The model the caller named, resolved ONCE per request — `getImageModels()`
+// re-derives hardware compatibility for the whole registry on every call, and
+// these endpoints are polled by the Image Gen page.
+function requestedModel(req) {
+ const modelId = typeof req.query?.modelId === 'string' ? req.query.modelId : '';
+ if (!modelId) return null;
+ return getImageModels().find((candidate) => candidate.id === modelId) || null;
+}
+
// The pipeline class the caller's model needs, so every readiness answer here
// matches the per-model verdict `diagnoseLocalRuntime` showed the user. Without
// it a venv whose diffusers predates that class reads as installed.
-function requestedPipelineClass(req) {
- const modelId = typeof req.query?.modelId === 'string' ? req.query.modelId : '';
- if (!modelId) return '';
- const model = getImageModels().find((candidate) => candidate.id === modelId);
- return typeof model?.pipelineClass === 'string' ? model.pipelineClass : '';
-}
+const pipelineClassOf = (model) =>
+ (typeof model?.pipelineClass === 'string' ? model.pipelineClass : '');
async function flux2Status(req) {
+ const model = requestedModel(req);
const [token, healthy] = await Promise.all([
getHfToken(),
- isFlux2InstallSatisfied(requestedPipelineClass(req)),
+ isFlux2InstallSatisfied(pipelineClassOf(model)),
]);
const venvPython = resolveFlux2Python();
// The 9B (bf16) and 4B variants ship as separately-gated repos with
@@ -68,13 +74,9 @@ async function flux2Status(req) {
// client supplies a `modelId`; fall back to the 4B URL for callers that
// pre-date the multi-variant registry.
const FLUX2_DEFAULT_LICENSE = 'https://huggingface.co/black-forest-labs/FLUX.2-klein-4B';
- let licenseUrl = FLUX2_DEFAULT_LICENSE;
- if (typeof req.query?.modelId === 'string' && req.query.modelId.length > 0) {
- const model = getImageModels().find((candidate) => candidate.id === req.query.modelId);
- if (isFlux2(model) && typeof model?.licenseUrl === 'string' && model.licenseUrl.length > 0) {
- licenseUrl = model.licenseUrl;
- }
- }
+ const licenseUrl = (isFlux2(model) && typeof model?.licenseUrl === 'string' && model.licenseUrl.length > 0)
+ ? model.licenseUrl
+ : FLUX2_DEFAULT_LICENSE;
return {
hfTokenPresent: !!token,
venvInstalled: healthy,
@@ -110,7 +112,7 @@ router.post('/flux2-install', asyncHandler(async (req, res) => {
// model's own class must all import. A half-broken venv (binary present,
// packages missing from a killed mid-install) or one whose diffusers predates
// the selected model's pipeline needs the install, not "nothing to do".
- if (await isFlux2InstallSatisfied(requestedPipelineClass(req))) {
+ if (await isFlux2InstallSatisfied(pipelineClassOf(requestedModel(req)))) {
send({ type: 'stage', stage: 'verify', message: 'FLUX.2 venv already installed.' });
send({ type: 'complete', message: 'Already installed — nothing to do.' });
return safeEnd();
diff --git a/server/services/imageGen/localRuntime.js b/server/services/imageGen/localRuntime.js
index 12993f4519..0c924530ce 100644
--- a/server/services/imageGen/localRuntime.js
+++ b/server/services/imageGen/localRuntime.js
@@ -92,9 +92,7 @@ export async function diagnoseLocalRuntime({ modelId: requestedModelId, settings
// model's pipeline" — both need the same installer run, but the second
// read as a contradiction ("install" → "already installed") while the
// copy claimed nothing was installed.
- const baseHealthy = model.pipelineClass
- ? await isFlux2VenvHealthy().then((value) => value).catch(() => false)
- : false;
+ const baseHealthy = !!model.pipelineClass && await isFlux2VenvHealthy().catch(() => false);
return verdict({
readiness: UNAVAILABLE,
reason: baseHealthy