Fix dev mode sidecar launch and engine reload on mode change
All checks were successful
Tests / Python Backend Tests (push) Successful in 6s
Tests / Frontend Tests (push) Successful in 7s
Tests / Rust Sidecar Tests (push) Successful in 1m57s

1. Dev mode: use `uv run python` instead of bare `python` to ensure
   the project venv is used. Also use CARGO_MANIFEST_DIR to find the
   project root reliably.

2. Engine reload: changing remote.mode (local/managed/byok) now
   triggers a full engine reload. Previously only model and device
   changes triggered reload, so switching to Deepgram had no effect
   until the app was restarted.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Developer
2026-04-07 16:25:07 -07:00
parent 411779f578
commit 8db9b8298b
2 changed files with 27 additions and 12 deletions

View File

@@ -577,12 +577,18 @@ class AppController:
if self.config.get('server_sync.enabled', False): if self.config.get('server_sync.enabled', False):
self._start_server_sync() self._start_server_sync()
# Check if model/device changed # Check if model/device/remote mode changed -- any of these require
# a full engine reload since they change which engine class is used
new_model = self.config.get('transcription.model', 'base.en') new_model = self.config.get('transcription.model', 'base.en')
new_device = self.config.get('transcription.device', 'auto') new_device = self.config.get('transcription.device', 'auto')
new_remote_mode = self.config.get('remote.mode', 'local')
current_remote_mode = 'local'
if self.transcription_engine:
current_remote_mode = getattr(self.transcription_engine, 'mode', 'local')
engine_reload_needed = ( engine_reload_needed = (
self.current_model_size != new_model self.current_model_size != new_model
or self.current_device_config != new_device or self.current_device_config != new_device
or current_remote_mode != new_remote_mode
) )
if engine_reload_needed: if engine_reload_needed:

View File

@@ -554,18 +554,27 @@ impl SidecarManager {
// -- private helpers ------------------------------------------------------- // -- private helpers -------------------------------------------------------
fn build_dev_command(&self) -> Result<std::process::Command, String> { fn build_dev_command(&self) -> Result<std::process::Command, String> {
let mut cmd = std::process::Command::new("python"); // Use `uv run` to ensure we use the project's venv, not system Python
cmd.args(["-u", "-m", "backend.main_headless"]); // -u = unbuffered let mut cmd = std::process::Command::new("uv");
cmd.args(["run", "python", "-u", "-m", "backend.main_headless"]);
// Find the project root: try CARGO_MANIFEST_DIR first (set at compile time),
// then fall back to resource_dir parent chain
let manifest_dir = option_env!("CARGO_MANIFEST_DIR").map(std::path::PathBuf::from);
let project_root = manifest_dir
.as_ref()
.and_then(|d| d.parent()) // src-tauri -> project root
.or_else(|| {
DIRS.get()
.and_then(|d| d.resource_dir.parent())
.and_then(|p| p.parent())
});
// Try to find the project root (parent of src-tauri)
if let Some(dirs) = DIRS.get() {
let project_root = dirs
.resource_dir
.parent() // src-tauri
.and_then(|p| p.parent()); // project root
if let Some(root) = project_root { if let Some(root) = project_root {
eprintln!("[sidecar] Dev mode: working dir = {}", root.display());
cmd.current_dir(root); cmd.current_dir(root);
} } else {
eprintln!("[sidecar] Dev mode: WARNING - could not determine project root");
} }
cmd.env("PYTHONUNBUFFERED", "1"); cmd.env("PYTHONUNBUFFERED", "1");