From 0a272ed63a9ec352137b5b85a380760b7f8bd695 Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Mon, 27 Apr 2026 13:57:47 +0800 Subject: [PATCH] fix: start SSH rate limiter cleanup and fix ToolContext reset per tool call - Start SSH rate limiter cleanup task that was missing (prevent memory leak) - Create single ToolContext outside tool execution loop so max_tool_calls and max_depth guards actually fire across batch tool calls (was creating fresh context per call, bypassing all limits) --- libs/agent/chat/service.rs | 23 +++++++++++------------ libs/git/ssh/mod.rs | 2 ++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/libs/agent/chat/service.rs b/libs/agent/chat/service.rs index 7eb7f8d..16eb352 100644 --- a/libs/agent/chat/service.rs +++ b/libs/agent/chat/service.rs @@ -419,20 +419,19 @@ impl ChatService { .collect(); let mut tool_messages = Vec::new(); + let mut ctx = crate::tool::ToolContext::new( + request.db.clone(), + request.cache.clone(), + request.config.clone(), + request.room.id, + Some(request.sender.uid), + ); + if let Some(ref registry) = self.tool_registry { + ctx.registry_mut().merge(registry.clone()); + } for call in &calls { - let ctx = &mut crate::tool::ToolContext::new( - request.db.clone(), - request.cache.clone(), - request.config.clone(), - request.room.id, - Some(request.sender.uid), - ); - if let Some(ref registry) = self.tool_registry { - ctx.registry_mut().merge(registry.clone()); - } - let executor = crate::tool::ToolExecutor::new(); - let results = match executor.execute_batch(vec![call.clone()], ctx).await { + let results = match executor.execute_batch(vec![call.clone()], &mut ctx).await { Ok(r) => r, Err(e) => { let err_text = format!("[Tool call failed: {}]", e); diff --git a/libs/git/ssh/mod.rs b/libs/git/ssh/mod.rs index 13c8514..0f2ad72 100644 --- a/libs/git/ssh/mod.rs +++ b/libs/git/ssh/mod.rs @@ -138,6 +138,8 @@ impl SSHHandle { // Start the rate limiter cleanup background task so the HashMap // doesn't grow unbounded over time. + let _cleanup = server.rate_limiter.clone().start_cleanup(); + let ssh_port = self.app.ssh_port()?; let bind_addr = format!("0.0.0.0:{}", ssh_port); let public_host = self.app.ssh_domain()?;