From 57e8442c9e61a6530c19205bdda2ea1ebd10a6bb Mon Sep 17 00:00:00 2001 From: hbruceweaver Date: Tue, 20 Jan 2026 17:12:42 -0700 Subject: [PATCH] fix: prefer source backend over stale settings path in dev mode When running `npm run dev` after having previously used the packaged DMG app, settings.json may contain an `autoBuildPath` pointing to the packaged app's backend instead of the source code backend. This causes confusing errors like "require is not defined" in the Graphiti setup wizard because the wrong Python venv is used. This fix detects dev mode (`!app.isPackaged`) and automatically prefers the source backend when it exists, overriding stale settings paths. Packaged app behavior is unchanged. Co-Authored-By: Claude Opus 4.5 --- apps/frontend/src/main/index.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/apps/frontend/src/main/index.ts b/apps/frontend/src/main/index.ts index eebbcc7c7d..df3fb4c270 100644 --- a/apps/frontend/src/main/index.ts +++ b/apps/frontend/src/main/index.ts @@ -304,6 +304,28 @@ app.whenReady().then(() => { // Validate and migrate autoBuildPath - must contain runners/spec_runner.py // Uses EAFP pattern (try/catch with accessSync) instead of existsSync to avoid TOCTOU race conditions let validAutoBuildPath = settings.autoBuildPath; + + // DEV MODE FIX: When running in development (not packaged), prefer the source backend + // over any stale path saved in settings (e.g., from a previously installed packaged app). + // This prevents confusing errors when `npm run dev` uses a venv without required dependencies. + if (!app.isPackaged) { + const sourceBackendPath = resolve(__dirname, '..', '..', '..', 'backend'); + const sourceSpecRunnerPath = join(sourceBackendPath, 'runners', 'spec_runner.py'); + let sourceBackendExists = false; + try { + accessSync(sourceSpecRunnerPath); + sourceBackendExists = true; + } catch { + // Source backend doesn't exist + } + + if (sourceBackendExists && validAutoBuildPath !== sourceBackendPath) { + console.log('[main] Dev mode detected - preferring source backend over settings'); + console.log('[main] Settings path:', validAutoBuildPath); + console.log('[main] Source path:', sourceBackendPath); + validAutoBuildPath = sourceBackendPath; + } + } if (validAutoBuildPath) { const specRunnerPath = join(validAutoBuildPath, 'runners', 'spec_runner.py'); let specRunnerExists = false;