agent: code-atomiser-fix — test_llm_model respects caller GPU preference (Race-8)

Add an Option<bool> use_gpu parameter to test_llm_model with the same
default-true semantics as load_llm_model. Hard-coding true triggered an
engine tear-down/rebuild when a parallel load_llm_model(use_gpu=false)
was in flight (LlmEngine::load_model triples on id+path+use_gpu) and
silently flipped the user's GPU mode underneath the test.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-13 15:12:24 +01:00
parent 5ba761a4b8
commit afbd33d33e
6 changed files with 253 additions and 19 deletions

View File

@@ -188,6 +188,7 @@ pub async fn test_llm_model(
window: tauri::WebviewWindow,
state: State<'_, AppState>,
model_id: String,
use_gpu: Option<bool>,
) -> Result<LlmTestResult, String> {
ensure_main_window(&window)?;
let id = parse_model_id(model_id)?;
@@ -238,12 +239,19 @@ pub async fn test_llm_model(
});
}
// Not currently loaded. Attempt a real load (with GPU by default
// matches load_llm_model's default) and classify any failure.
// Not currently loaded. Attempt a real load with the caller's
// GPU preference (matching load_llm_model's default of `true` when
// unspecified). Hard-coding `true` here used to race with a parallel
// load_llm_model(use_gpu=false) — LlmEngine::load_model decides
// "same model?" via (id, path, use_gpu) triple-equality and tears
// the engine down on mismatch, silently flipping the user's GPU
// mode underneath the in-flight test.
let resolved_use_gpu = use_gpu.unwrap_or(true);
let engine = state.llm_engine.clone();
let load_result = tokio::task::spawn_blocking(move || engine.load_model(id, &path, true))
.await
.map_err(|e| e.to_string())?;
let load_result =
tokio::task::spawn_blocking(move || engine.load_model(id, &path, resolved_use_gpu))
.await
.map_err(|e| e.to_string())?;
match load_result {
Ok(()) => Ok(LlmTestResult {