Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Use non-blocking mutex (#7467)

Ahmed Ibrahim21ad1c1c9054
diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs
index 8ae83d0034..ef0a237f75 100644
--- a/codex-rs/core/src/codex.rs
+++ b/codex-rs/core/src/codex.rs
@@ -976,6 +976,7 @@ impl Session {
.read()
.await
.resolve_elicitation(server_name, id, response)
+ .await
}
/// Records input items: always append to conversation history and
diff --git a/codex-rs/core/src/mcp_connection_manager.rs b/codex-rs/core/src/mcp_connection_manager.rs
index 22cb84e2c9..e8c289b573 100644
--- a/codex-rs/core/src/mcp_connection_manager.rs
+++ b/codex-rs/core/src/mcp_connection_manager.rs
@@ -12,7 +12,6 @@ use std::env;
use std::ffi::OsString;
use std::path::PathBuf;
use std::sync::Arc;
-use std::sync::Mutex;
use std::time::Duration;
use crate::mcp::auth::McpAuthStatusEntry;
@@ -55,6 +54,7 @@ use serde::Serialize;
use serde_json::json;
use sha1::Digest;
use sha1::Sha1;
+use tokio::sync::Mutex;
use tokio::sync::oneshot;
use tokio::task::JoinSet;
use tokio_util::sync::CancellationToken;
@@ -128,7 +128,7 @@ struct ElicitationRequestManager {
}
impl ElicitationRequestManager {
- fn resolve(
+ async fn resolve(
&self,
server_name: String,
id: RequestId,
@@ -136,7 +136,7 @@ impl ElicitationRequestManager {
) -> Result<()> {
self.requests
.lock()
- .map_err(|e| anyhow!("failed to lock elicitation requests: {e:?}"))?
+ .await
.remove(&(server_name, id))
.ok_or_else(|| anyhow!("elicitation request not found"))?
.send(response)
@@ -151,9 +151,8 @@ impl ElicitationRequestManager {
let server_name = server_name.clone();
async move {
let (tx, rx) = oneshot::channel();
- if let Ok(mut lock) = elicitation_requests.lock() {
- lock.insert((server_name.clone(), id.clone()), tx);
- }
+ let mut lock = elicitation_requests.lock().await;
+ lock.insert((server_name.clone(), id.clone()), tx);
let _ = tx_event
.send(Event {
id: "mcp_elicitation_request".to_string(),
@@ -365,13 +364,15 @@ impl McpConnectionManager {
.context("failed to get client")
}
- pub fn resolve_elicitation(
+ pub async fn resolve_elicitation(
&self,
server_name: String,
id: RequestId,
response: ElicitationResponse,
) -> Result<()> {
- self.elicitation_requests.resolve(server_name, id, response)
+ self.elicitation_requests
+ .resolve(server_name, id, response)
+ .await
}
/// Returns a single map that contains all tools. Each key is the