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)
This commit is contained in:
ZhenYi 2026-04-27 13:57:47 +08:00
parent 09645d8641
commit 0a272ed63a
2 changed files with 13 additions and 12 deletions

View File

@ -419,8 +419,7 @@ impl ChatService {
.collect();
let mut tool_messages = Vec::new();
for call in &calls {
let ctx = &mut crate::tool::ToolContext::new(
let mut ctx = crate::tool::ToolContext::new(
request.db.clone(),
request.cache.clone(),
request.config.clone(),
@ -430,9 +429,9 @@ impl ChatService {
if let Some(ref registry) = self.tool_registry {
ctx.registry_mut().merge(registry.clone());
}
for call in &calls {
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);

View File

@ -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()?;