From 5273a7b335105ce58e9905cc0589a8d17ebb259f Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Tue, 2 Jun 2026 16:18:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=AE=B0=E5=BF=86?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E6=A3=80=E6=9F=A5=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E5=9C=A8=E4=BF=9D=E7=95=99=E6=95=B0=E4=B8=8D=E8=B6=B3=E6=97=B6?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gateway/memory_maintenance.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/gateway/memory_maintenance.rs b/src/gateway/memory_maintenance.rs index e516d2c..4eaa223 100644 --- a/src/gateway/memory_maintenance.rs +++ b/src/gateway/memory_maintenance.rs @@ -132,6 +132,18 @@ impl MemoryMaintenanceService { return Ok(None); } + // 记忆数量不足最小保留数时,无需整理,直接跳过 + // 避免浪费 LLM token 并触发无意义的 "保留数不足" 错误 + if memories.len() < self.maintenance_config.min_memories_to_keep { + tracing::info!( + scope_key = %scope_key, + count = memories.len(), + min_required = self.maintenance_config.min_memories_to_keep, + "Skipping scope: not enough memories to organize" + ); + return Ok(None); + } + Ok(Some(build_memory_maintenance_plan(&memories))) } @@ -619,6 +631,9 @@ pub(crate) fn is_recoverable_maintenance_llm_error(error: &str) -> bool { || normalized.contains("stream timeout") || normalized.contains("timed out") || normalized.contains("timeout") + // 验证拒绝 — 记忆太少,跳过本次 scope 即可,不应视为作业失败 + || error.contains("保留数不足") + || error.contains("合并比例超限") } fn is_recoverable_maintenance_scope_error(error: &AgentError) -> bool {