agent: switch from tokio::sync::Mutex to std::sync::Mutex

The agent lock is never held across await points — turns lock briefly,
do work, drop, then do async API calls. std::sync::Mutex works and
can be locked from sync contexts (screen tick inside terminal.draw).

Fixes: blocking_lock() panic when called inside tokio runtime.

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2026-04-05 19:56:56 -04:00
parent f29b4be09c
commit 3e1be4d353
8 changed files with 41 additions and 39 deletions

View file

@ -14,7 +14,7 @@ pub(super) fn tools() -> [super::Tool; 3] {
.ok_or_else(|| anyhow::anyhow!("'model' parameter is required"))?;
if model.is_empty() { anyhow::bail!("'model' parameter cannot be empty"); }
if let Some(agent) = agent {
let mut a = agent.lock().await;
let mut a = agent.lock().unwrap();
a.pending_model_switch = Some(model.to_string());
}
Ok(format!("Switching to model '{}' after this turn.", model))
@ -24,7 +24,7 @@ pub(super) fn tools() -> [super::Tool; 3] {
parameters_json: r#"{"type":"object","properties":{}}"#,
handler: |agent, _v| Box::pin(async move {
if let Some(agent) = agent {
let mut a = agent.lock().await;
let mut a = agent.lock().unwrap();
a.pending_yield = true;
a.pending_dmn_pause = true;
}
@ -36,7 +36,7 @@ pub(super) fn tools() -> [super::Tool; 3] {
handler: |agent, v| Box::pin(async move {
let msg = v.get("message").and_then(|v| v.as_str()).unwrap_or("Waiting for input.");
if let Some(agent) = agent {
let mut a = agent.lock().await;
let mut a = agent.lock().unwrap();
a.pending_yield = true;
}
Ok(format!("Yielding. {}", msg))