Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/cortex-app-server/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ pub struct StoredToolCall {

/// Session storage manager.
pub struct SessionStorage {
#[allow(dead_code)]
base_dir: PathBuf,
sessions_dir: PathBuf,
history_dir: PathBuf,
}
Expand All @@ -66,7 +64,6 @@ impl SessionStorage {
info!("Session storage initialized at {:?}", base_dir);

Ok(Self {
base_dir,
sessions_dir,
history_dir,
})
Expand Down
11 changes: 0 additions & 11 deletions src/cortex-apply-patch/src/hunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@ pub struct SearchReplace {
pub search: String,
/// The text to replace with.
pub replace: String,
/// Replace all occurrences (true) or just the first (false).
#[allow(dead_code)]
pub replace_all: bool,
}

impl SearchReplace {
Expand All @@ -266,16 +263,8 @@ impl SearchReplace {
path: path.into(),
search: search.into(),
replace: replace.into(),
replace_all: false,
}
}

/// Set whether to replace all occurrences.
#[allow(dead_code)]
pub fn with_replace_all(mut self, replace_all: bool) -> Self {
self.replace_all = replace_all;
self
}
}

#[cfg(test)]
Expand Down
103 changes: 1 addition & 102 deletions src/cortex-mcp-client/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ use cortex_mcp_types::{
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
use tokio::process::{Child, Command};
use tokio::sync::{Mutex, RwLock};
use tokio::time::sleep;
use tracing::{debug, error, info, warn};
use tracing::{debug, info, warn};

// ============================================================================
// Transport Trait
Expand Down Expand Up @@ -199,61 +198,6 @@ impl StdioTransport {
Ok(())
}

/// Reconnect with exponential backoff.
///
/// Properly cleans up existing connections before each attempt to prevent
/// file descriptor leaks (#2198).
#[allow(dead_code)]
async fn reconnect(&self) -> Result<()> {
if !self.reconnect_config.enabled {
return Err(anyhow!("Reconnection disabled"));
}

let mut attempt = 0;
let mut delay = self.reconnect_config.initial_delay;

while attempt < self.reconnect_config.max_attempts {
attempt += 1;
info!(
attempt,
max = self.reconnect_config.max_attempts,
"Attempting reconnection"
);

// Clean up any existing connection before attempting reconnect
// This prevents file descriptor leaks on repeated failures (#2198)
{
let mut process_guard = self.process.lock().await;
if let Some(mut child) = process_guard.take() {
// Kill the process and wait for it to clean up
let _ = child.kill().await;
// Wait a short time for resources to be released
drop(child);
}
self.connected.store(false, Ordering::SeqCst);
}

// Clear any stale pending responses
self.pending_responses.write().await.clear();

match self.connect().await {
Ok(()) => {
info!("Reconnection successful");
return Ok(());
}
Err(e) => {
error!(error = %e, attempt, "Reconnection failed");
if attempt < self.reconnect_config.max_attempts {
sleep(delay).await;
delay = (delay * 2).min(self.reconnect_config.max_delay);
}
}
}
}

Err(anyhow!("Failed to reconnect after {} attempts", attempt))
}

/// Send a request and wait for response.
async fn send_request(&self, request: JsonRpcRequest) -> Result<JsonRpcResponse> {
// Ensure connected
Expand Down Expand Up @@ -516,51 +460,6 @@ impl HttpTransport {
fn next_request_id(&self) -> RequestId {
RequestId::Number(self.request_id.fetch_add(1, Ordering::SeqCst) as i64)
}

/// Test connection.
#[allow(dead_code)]
async fn test_connection(&self) -> Result<()> {
let request = JsonRpcRequest::new(self.next_request_id(), methods::PING);
self.send_request(request).await?;
Ok(())
}

/// Reconnect with exponential backoff.
#[allow(dead_code)]
async fn reconnect(&self) -> Result<()> {
if !self.reconnect_config.enabled {
return Err(anyhow!("Reconnection disabled"));
}

let mut attempt = 0;
let mut delay = self.reconnect_config.initial_delay;

while attempt < self.reconnect_config.max_attempts {
attempt += 1;
info!(
attempt,
max = self.reconnect_config.max_attempts,
"Attempting HTTP reconnection"
);

match self.test_connection().await {
Ok(()) => {
info!("HTTP reconnection successful");
self.connected.store(true, Ordering::SeqCst);
return Ok(());
}
Err(e) => {
error!(error = %e, attempt, "HTTP reconnection failed");
if attempt < self.reconnect_config.max_attempts {
sleep(delay).await;
delay = (delay * 2).min(self.reconnect_config.max_delay);
}
}
}
}

Err(anyhow!("Failed to reconnect after {} attempts", attempt))
}
}

#[async_trait]
Expand Down
Loading