From 7e779288339de17b07d966cbc5195ab740dff5ae Mon Sep 17 00:00:00 2001 From: Leonid Gorkin Date: Fri, 25 Sep 2026 12:24:19 -0400 Subject: [PATCH] fix: disable Electron file watchers --- frontend/electron/main.test.ts | 9 +++++++++ frontend/vite.config.ts | 8 +++++++- scripts/electron-dev.sh | 19 +++++++------------ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/frontend/electron/main.test.ts b/frontend/electron/main.test.ts index 189c2d4..ce839d6 100644 --- a/frontend/electron/main.test.ts +++ b/frontend/electron/main.test.ts @@ -26,6 +26,15 @@ describe("Electron launcher detail controls", () => { }); }); +describe("Electron file watching", () => { + it("disables backend reload and Vite watching for Electron development", () => { + expect(devScriptSource).not.toContain("--reload"); + expect(devScriptSource).not.toContain("--reload-dir"); + expect(devScriptSource).toContain('ELECTRON_DEV="1"'); + expect(readFileSync(path.join(__dirname, "../vite.config.ts"), "utf8")).toContain("watch: null"); + }); +}); + describe("Electron launcher paths", () => { it("resolves the repository from the script location when launched elsewhere", () => { const output = execFileSync("bash", [devScriptPath], { diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index dd8b36f..9f2840f 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -5,9 +5,15 @@ import tailwindcss from "@tailwindcss/vite"; // Which backend the dev proxy forwards /api to: `make dev`'s backend on 8000 by default, or // whatever port electron-dev.sh's dedicated Electron backend is actually listening on. const backendPort = process.env.VITE_BACKEND_PORT || "8000"; +const isElectronDev = process.env.ELECTRON_DEV === "1"; export default defineConfig({ plugins: [react(), tailwindcss()], - server: { proxy: { "/api": { target: `http://127.0.0.1:${backendPort}`, changeOrigin: true } } }, + server: { + // Electron development is intentionally restart-to-update: Vite's watcher can consume + // enough resources during repository changes to freeze the UI while sending messages. + ...(isElectronDev ? { watch: null } : {}), + proxy: { "/api": { target: `http://127.0.0.1:${backendPort}`, changeOrigin: true } }, + }, test: { environment: "node" }, } as any); diff --git a/scripts/electron-dev.sh b/scripts/electron-dev.sh index 9bfd200..ac45b9f 100755 --- a/scripts/electron-dev.sh +++ b/scripts/electron-dev.sh @@ -30,8 +30,8 @@ kill_process_group() { local pid="$1" [[ -z "$pid" ]] && return 0 - # uvicorn --reload and Vite each create children. Kill the process group so - # those children do not outlive the launcher, then escalate if necessary. + # Backend and Vite each create children. Kill the process group so those children do not + # outlive the launcher, then escalate if necessary. kill -TERM -- "-${pid}" 2>/dev/null || true for _ in {1..20}; do kill -0 "$pid" 2>/dev/null || return 0 @@ -74,20 +74,15 @@ os.execvp(sys.argv[1], sys.argv[1:]) PY } -# Use the same root-relative commands as the Makefile targets. OPENBOT_API_URL is passed to -# Electron/preload so packaged-style absolute API requests use this dedicated backend, and -# VITE_BACKEND_PORT points Vite's own dev proxy (relative /api/* fetches from the loaded page) -# at the same port, so both request paths reach the one backend actually running here. +# Use the same root-relative commands as the Makefile targets. Electron intentionally runs +# without backend reload or Vite file watching: changes take effect after an app restart, +# avoiding watcher activity that can freeze the UI while messages are being sent. echo "Starting Electron backend on ${BACKEND_URL}" -# --reload-dir scopes the file watcher to actual source: without it, uvicorn watches this whole -# repo root recursively -- .venv, node_modules, and every git worktree checked out under it -- which -# can exceed 100k files and has wedged the reload watcher outright during unrelated git activity -# elsewhere in the tree. -run_in_process_group uv run --project backend python -m openbot.cli "$DETAILS_FLAG" --reload --reload-dir backend/openbot --reload-dir tools --port "$ELECTRON_BACKEND_PORT" & +run_in_process_group uv run --project backend python -m openbot.cli "$DETAILS_FLAG" --port "$ELECTRON_BACKEND_PORT" & backend_pid=$! echo "Starting Vite frontend on ${FRONTEND_URL}" -run_in_process_group env FRONTEND_PORT="$FRONTEND_PORT" VITE_BACKEND_PORT="$ELECTRON_BACKEND_PORT" bash -c ' +run_in_process_group env FRONTEND_PORT="$FRONTEND_PORT" VITE_BACKEND_PORT="$ELECTRON_BACKEND_PORT" ELECTRON_DEV="1" bash -c ' cd frontend pnpm dev --host localhost --port "$FRONTEND_PORT" ' &