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: make the FLUX.2 install button repair a venv that predates a model's pipeline

Adam Eivya800aa58edb1
diff --git a/client/src/components/imageGen/Flux2InstallModal.jsx b/client/src/components/imageGen/Flux2InstallModal.jsx
index 60c675d4bf..f9369be65b 100644
--- a/client/src/components/imageGen/Flux2InstallModal.jsx
+++ b/client/src/components/imageGen/Flux2InstallModal.jsx
@@ -26,15 +26,24 @@ const STAGES = [
const STAGE_INDEX = Object.fromEntries(STAGES.map((s, i) => [s.id, i]));
-export default function Flux2InstallModal({ open, onClose, onComplete }) {
+/**
+ * `modelId` scopes the server's "already installed?" gate to the model the user
+ * is trying to render with. Omitting it gates on the base FLUX.2 pipeline only,
+ * which reports "nothing to do" for a venv whose diffusers predates a newer
+ * model's pipeline class — the install button that did nothing.
+ */
+export default function Flux2InstallModal({ open, onClose, onComplete, modelId = null }) {
const [confirmingCancel, setConfirmingCancel] = useState(false);
// 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(
- '/api/image-gen/setup/flux2-install',
+ installUrl,
{ enabled: open, onComplete, method: 'POST' },
);
diff --git a/client/src/components/imageGen/Flux2InstallModal.test.jsx b/client/src/components/imageGen/Flux2InstallModal.test.jsx
index 75a4cc2951..6e07a36916 100644
--- a/client/src/components/imageGen/Flux2InstallModal.test.jsx
+++ b/client/src/components/imageGen/Flux2InstallModal.test.jsx
@@ -33,6 +33,20 @@ beforeEach(() => {
vi.clearAllMocks();
});
+// The server gates "already installed" on the selected model's pipeline class,
+// so a modal that omits the id gets "nothing to do" for a runtime the banner
+// just called unavailable.
+describe('Flux2InstallModal install target', () => {
+ it('scopes the install stream to the selected model', () => {
+ useInstallStream.mockReturnValue(streamState());
+ render(<Flux2InstallModal open onClose={vi.fn()} onComplete={vi.fn()} modelId="qwen-image-2.1" />);
+ expect(useInstallStream).toHaveBeenCalledWith(
+ '/api/image-gen/setup/flux2-install?modelId=qwen-image-2.1',
+ expect.objectContaining({ method: 'POST' }),
+ );
+ });
+});
+
describe('Flux2InstallModal failure footer', () => {
it('offers the investigation action once the install reports an error', () => {
useInstallStream.mockReturnValue(streamState({
diff --git a/client/src/components/imageGen/LocalRuntimeStatus.jsx b/client/src/components/imageGen/LocalRuntimeStatus.jsx
index ba7412efd6..7703fa599c 100644
--- a/client/src/components/imageGen/LocalRuntimeStatus.jsx
+++ b/client/src/components/imageGen/LocalRuntimeStatus.jsx
@@ -125,7 +125,7 @@ export default function LocalRuntimeStatus({
</span>
)}
</Banner>
- <Flux2InstallModal open={installOpen} onClose={closeInstall} onComplete={handleInstallComplete} />
+ <Flux2InstallModal open={installOpen} onClose={closeInstall} onComplete={handleInstallComplete} modelId={runtime.modelId} />
</>
);
}
diff --git a/client/src/pages/ImageGen.jsx b/client/src/pages/ImageGen.jsx
index a8d32f837b..1e57c3e694 100644
--- a/client/src/pages/ImageGen.jsx
+++ b/client/src/pages/ImageGen.jsx
@@ -1877,6 +1877,7 @@ export default function ImageGen() {
open={flux2InstallOpen}
onClose={handleFlux2ModalClose}
onComplete={handleFlux2InstallComplete}
+ modelId={modelId}
/>
</div>
);
diff --git a/server/lib/pythonSetup.js b/server/lib/pythonSetup.js
index fae0354eda..5e04321ae3 100644
--- a/server/lib/pythonSetup.js
+++ b/server/lib/pythonSetup.js
@@ -393,6 +393,22 @@ 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
+// 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".
+export const FLUX2_VERIFY_PIPELINE_CLASSES = Object.freeze(['Flux2KleinPipeline', 'QwenImage21Pipeline']);
+
+// Whether re-running the installer would be a no-op: every class the verify
+// stage checks imports, plus the one the caller's selected model needs.
+export async function isFlux2InstallSatisfied(pipelineClass = '') {
+ const required = [...new Set([...FLUX2_VERIFY_PIPELINE_CLASSES, pipelineClass].filter(Boolean))];
+ const results = await Promise.all(required.map((cls) => isFlux2VenvHealthy(cls)));
+ return results.every(Boolean);
+}
+
export function invalidateFlux2Health() {
cachedFlux2Python = null;
flux2Health.clear();
@@ -1072,7 +1088,7 @@ export function installFlux2Venv(onLog) {
if (killed) return { ok: false, stage: 'install', cancelled: true };
stage('verify', 'Verifying FLUX.2 and Qwen 2.1 pipeline imports…');
- if (!await runPython([venvPython, '-c', 'from diffusers import Flux2KleinPipeline, QwenImage21Pipeline; print("ok")'])) {
+ if (!await runPython([venvPython, '-c', `from diffusers import ${FLUX2_VERIFY_PIPELINE_CLASSES.join(', ')}; print("ok")`])) {
onLog({ type: 'error', message: 'Verification failed: FLUX.2 or Qwen 2.1 pipeline did not import. Try INSTALL_FLUX2=1 FLUX2_FORCE_REINSTALL=1 bash scripts/setup-image-video.sh' });
return { ok: false, stage: 'verify' };
}
diff --git a/server/lib/pythonSetup.test.js b/server/lib/pythonSetup.test.js
index d209a0a4c2..8043c08e2f 100644
--- a/server/lib/pythonSetup.test.js
+++ b/server/lib/pythonSetup.test.js
@@ -548,6 +548,26 @@ describe('isFlux2VenvHealthy', () => {
await expect(isFlux2VenvHealthy('QwenImage21Pipeline')).resolves.toBe(true);
});
+ it('reports the install as unsatisfied when a verified pipeline class is missing', async () => {
+ // The bug this pins: the installer's readiness GATE probed only the base
+ // FLUX.2 pipeline, so a venv whose diffusers predates QwenImage21Pipeline
+ // answered the Install button with "already installed — nothing to do"
+ // while the per-model banner said the runtime was unavailable.
+ mockState.presentPaths.add('/Users/test/.portos/venv-flux2/bin/python3');
+ mockState.missingPipeline = 'QwenImage21Pipeline';
+ const { isFlux2InstallSatisfied, isFlux2VenvHealthy } = await loadModule();
+ await expect(isFlux2VenvHealthy()).resolves.toBe(true);
+ await expect(isFlux2InstallSatisfied()).resolves.toBe(false);
+ });
+
+ it('also requires the selected model pipeline class the verify stage does not cover', async () => {
+ mockState.presentPaths.add('/Users/test/.portos/venv-flux2/bin/python3');
+ mockState.missingPipeline = 'ErnieImagePipeline';
+ const { isFlux2InstallSatisfied } = await loadModule();
+ await expect(isFlux2InstallSatisfied()).resolves.toBe(true);
+ await expect(isFlux2InstallSatisfied('ErnieImagePipeline')).resolves.toBe(false);
+ });
+
it('caches a healthy result indefinitely', async () => {
mockState.presentPaths.add('/Users/test/.portos/venv-flux2/bin/python3');
vi.useFakeTimers();
diff --git a/server/routes/imageGen.integrity.test.js b/server/routes/imageGen.integrity.test.js
index 732c0faf7f..0b8353d6a1 100644
--- a/server/routes/imageGen.integrity.test.js
+++ b/server/routes/imageGen.integrity.test.js
@@ -57,6 +57,7 @@ vi.mock('../services/mediaJobQueue/index.js', () => ({
vi.mock('../lib/pythonSetup.js', async (importOriginal) => ({
...(await importOriginal()),
isFlux2VenvHealthy: vi.fn(async () => true),
+ isFlux2InstallSatisfied: vi.fn(async () => true),
resolveFlux2Python: vi.fn(() => null),
}));
diff --git a/server/routes/imageGen.test.js b/server/routes/imageGen.test.js
index 1f94be70b7..dbb9ecfdc1 100644
--- a/server/routes/imageGen.test.js
+++ b/server/routes/imageGen.test.js
@@ -187,6 +187,7 @@ vi.mock('../lib/pythonSetup.js', () => ({
FLUX2_VENV_DEFAULT: '/fake/flux2-venv',
installFlux2Venv: vi.fn(),
isFlux2VenvHealthy: vi.fn(async () => true),
+ isFlux2InstallSatisfied: vi.fn(async () => true),
}));
// Stat the python binary to key the cache. Override per-test for mtime
@@ -1306,8 +1307,8 @@ describe('Image Gen Routes', () => {
describe('FLUX.2 installer contract', () => {
it('GET /setup/flux2-install reports status without starting an install', async () => {
- const { installFlux2Venv, isFlux2VenvHealthy } = await import('../lib/pythonSetup.js');
- isFlux2VenvHealthy.mockResolvedValueOnce(false);
+ const { installFlux2Venv, isFlux2InstallSatisfied } = await import('../lib/pythonSetup.js');
+ isFlux2InstallSatisfied.mockResolvedValueOnce(false);
const response = await request(app).get('/api/image-gen/setup/flux2-install');
expect(response.status).toBe(200);
expect(response.body).toMatchObject({
@@ -1324,13 +1325,22 @@ describe('Image Gen Routes', () => {
expect(response.text).toContain('Already installed');
});
+ // The Install button appeared BECAUSE the per-model verdict probed that
+ // model's own pipeline class; the installer's gate has to ask the same
+ // question or it answers a real gap with "nothing to do".
+ it('POST /setup/flux2-install scopes the already-installed gate to the selected model pipeline', async () => {
+ const { isFlux2InstallSatisfied } = await import('../lib/pythonSetup.js');
+ await request(app).post('/api/image-gen/setup/flux2-install?modelId=qwen-image-2.1');
+ expect(isFlux2InstallSatisfied).toHaveBeenCalledWith('QwenImage21Pipeline');
+ });
+
// The client renders a stream that closes with no terminal frame as
// "Connection to installer lost. Restart PortOS or try again." — a phantom
// transport error that hides the real failure. installFlux2Venv emits its
// own error frame; this is the route's backstop for a path that doesn't.
it('POST /setup/flux2-install reports a silent installer failure instead of closing the stream bare', async () => {
- const { installFlux2Venv, isFlux2VenvHealthy } = await import('../lib/pythonSetup.js');
- isFlux2VenvHealthy.mockResolvedValueOnce(false);
+ const { installFlux2Venv, isFlux2InstallSatisfied } = await import('../lib/pythonSetup.js');
+ isFlux2InstallSatisfied.mockResolvedValueOnce(false);
installFlux2Venv.mockReturnValueOnce({
promise: Promise.resolve({ ok: false, stage: 'install' }),
kill: vi.fn(),
@@ -1344,8 +1354,8 @@ describe('Image Gen Routes', () => {
});
it('POST /setup/flux2-install stays silent when the client cancelled the install', async () => {
- const { installFlux2Venv, isFlux2VenvHealthy } = await import('../lib/pythonSetup.js');
- isFlux2VenvHealthy.mockResolvedValueOnce(false);
+ const { installFlux2Venv, isFlux2InstallSatisfied } = await import('../lib/pythonSetup.js');
+ isFlux2InstallSatisfied.mockResolvedValueOnce(false);
installFlux2Venv.mockReturnValueOnce({
promise: Promise.resolve({ ok: false, stage: 'install', cancelled: true }),
kill: vi.fn(),
@@ -1357,9 +1367,9 @@ describe('Image Gen Routes', () => {
});
it('does not start an install after the client disconnects during the health probe', async () => {
- const { installFlux2Venv, isFlux2VenvHealthy } = await import('../lib/pythonSetup.js');
+ const { installFlux2Venv, isFlux2InstallSatisfied } = await import('../lib/pythonSetup.js');
let finishProbe;
- isFlux2VenvHealthy.mockReturnValueOnce(new Promise((resolve) => { finishProbe = resolve; }));
+ isFlux2InstallSatisfied.mockReturnValueOnce(new Promise((resolve) => { finishProbe = resolve; }));
const server = await startLoopbackServer(app);
const { port } = server.address();
const clientRequest = httpRequest({
@@ -1373,7 +1383,7 @@ describe('Image Gen Routes', () => {
let serverClosed = false;
try {
- await vi.waitFor(() => expect(isFlux2VenvHealthy).toHaveBeenCalled());
+ await vi.waitFor(() => expect(isFlux2InstallSatisfied).toHaveBeenCalled());
const closed = new Promise((resolve) => clientRequest.once('close', resolve));
clientRequest.destroy();
await closed;
diff --git a/server/routes/imageGenSetup.js b/server/routes/imageGenSetup.js
index a55a48e485..77f644fe8d 100644
--- a/server/routes/imageGenSetup.js
+++ b/server/routes/imageGenSetup.js
@@ -21,7 +21,7 @@ import { getImageModels, isFlux2 } from '../lib/mediaModels.js';
import { createInstallLogger } from '../lib/installLogger.js';
import {
detectPython, installPackages, createVenv, isAllowedPython,
- resolveFlux2Python, FLUX2_VENV_DEFAULT, installFlux2Venv, isFlux2VenvHealthy,
+ resolveFlux2Python, FLUX2_VENV_DEFAULT, installFlux2Venv, isFlux2InstallSatisfied,
} from '../lib/pythonSetup.js';
import { PATHS } from '../lib/fileUtils.js';
import { onClientDisconnect, openSseStream } from '../lib/sseDownload.js';
@@ -47,8 +47,21 @@ router.get('/python', asyncHandler(async (_req, res) => {
// gate the second click — the first install hasn't created the python yet.
let flux2InstallInFlight = 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 : '';
+}
+
async function flux2Status(req) {
- const [token, healthy] = await Promise.all([getHfToken(), isFlux2VenvHealthy()]);
+ const [token, healthy] = await Promise.all([
+ getHfToken(),
+ isFlux2InstallSatisfied(requestedPipelineClass(req)),
+ ]);
const venvPython = resolveFlux2Python();
// The 9B (bf16) and 4B variants ship as separately-gated repos with
// distinct HF license URLs. Use the active model's `licenseUrl` when the
@@ -92,10 +105,12 @@ router.post('/flux2-install', asyncHandler(async (req, res) => {
safeEnd();
});
- // Skip only when the venv binary AND the import work — a half-broken venv
- // (binary present, packages missing from a killed mid-install) needs to
- // re-run the install, not be reported as ready.
- if (await isFlux2VenvHealthy()) {
+ // Skip only when re-running the install would change nothing — the venv
+ // binary, every pipeline class the verify stage guarantees, and the selected
+ // 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))) {
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 3ae74880f4..12993f4519 100644
--- a/server/services/imageGen/localRuntime.js
+++ b/server/services/imageGen/localRuntime.js
@@ -88,10 +88,23 @@ export async function diagnoseLocalRuntime({ modelId: requestedModelId, settings
const healthy = await isFlux2VenvHealthy(model.pipelineClass).then((value) => value).catch(() => null);
if (healthy === true) return verdict({ readiness: READY });
if (healthy === false) {
+ // Distinguish "no runtime" from "runtime is there but too old for THIS
+ // 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;
return verdict({
readiness: UNAVAILABLE,
- reason: `The shared torch image runtime is not installed or healthy (expected at ${FLUX2_VENV_DEFAULT})`,
- remedy: { kind: IMAGE_RUNTIME_REMEDY.INSTALL_TORCH_VENV, label: 'Install runtime', venvPath: FLUX2_VENV_DEFAULT },
+ reason: baseHealthy
+ ? `The shared torch image runtime is installed but too old for ${model.pipelineClass} — it needs an update (${FLUX2_VENV_DEFAULT})`
+ : `The shared torch image runtime is not installed or healthy (expected at ${FLUX2_VENV_DEFAULT})`,
+ remedy: {
+ kind: IMAGE_RUNTIME_REMEDY.INSTALL_TORCH_VENV,
+ label: baseHealthy ? 'Update runtime' : 'Install runtime',
+ venvPath: FLUX2_VENV_DEFAULT,
+ },
});
}
return verdict({ readiness: UNKNOWN, reason: 'Could not verify the shared torch image runtime' });
diff --git a/server/services/imageGen/localRuntime.test.js b/server/services/imageGen/localRuntime.test.js
index e111ae7929..84dc41022a 100644
--- a/server/services/imageGen/localRuntime.test.js
+++ b/server/services/imageGen/localRuntime.test.js
@@ -41,6 +41,19 @@ describe('diagnoseLocalRuntime remedies', () => {
expect(isFlux2VenvHealthy).toHaveBeenCalledWith('QwenImage21Pipeline');
});
+ it('says the runtime needs an UPDATE when the venv works but predates the model pipeline', async () => {
+ // Otherwise the banner claims nothing is installed while the installer it
+ // launches answers "already installed — nothing to do".
+ models.value = [{ ...mflux, id: 'qwen-image-2.1', runner: 'qwen', pipelineClass: 'QwenImage21Pipeline' }];
+ settings.value = { imageGen: { local: { modelId: 'qwen-image-2.1' } } };
+ isFlux2VenvHealthy.mockImplementation(async (cls) => !cls);
+
+ const verdict = await diagnoseLocalRuntime();
+ expect(verdict.readiness).toBe('unavailable');
+ expect(verdict.reason).toContain('too old for QwenImage21Pipeline');
+ expect(verdict.remedy).toMatchObject({ kind: 'install-torch-venv', label: 'Update runtime' });
+ });
+
it('offers the pip install, with the pip-spec names, for a missing mflux package', async () => {
getSetupCheck.mockResolvedValue({ missing: ['cv2'], missingPip: ['opencv-python'], archMismatch: false });