From 818d2acd9471295408198a37b6d40bd63795fe17 Mon Sep 17 00:00:00 2001 From: Siddharth Kumar Sah Date: Sun, 22 Mar 2026 20:41:04 +0800 Subject: [PATCH] fix: Python bridge fallback only on missing venv, not script errors The bridge.ts catch block was catching ALL errors from the venv Python and falling back to system python3. This masked real script errors (like rembg model loading failures) by reporting "rembg not installed" from the system python3 fallback. Now only falls back on ENOENT (venv binary not found). --- packages/ai/src/bridge.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/ai/src/bridge.ts b/packages/ai/src/bridge.ts index 4d1f361f..50a662ac 100644 --- a/packages/ai/src/bridge.ts +++ b/packages/ai/src/bridge.ts @@ -69,8 +69,21 @@ export async function runPythonScript( execOpts, ); return { stdout: stdout.trim(), stderr: stderr.trim() }; - } catch { - // Try system python as fallback + } catch (venvError: unknown) { + // Only fall back to system python if the venv python binary doesn't exist + // (ENOENT). If the script itself failed, re-throw — don't hide the error. + const isNotFound = + venvError && + typeof venvError === "object" && + "code" in venvError && + (venvError as { code?: string }).code === "ENOENT"; + + if (!isNotFound) { + const message = extractPythonError(venvError); + throw new Error(message); + } + + // venv python not found — try system python3 as fallback try { const { stdout, stderr } = await execFileAsync( "python3",