From ec5ddf644a7b2ff70c3f633441cfb384cc417616 Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Fri, 12 Jun 2026 17:25:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=85=88=E4=BD=BF=E7=94=A8=20t?= =?UTF-8?q?opic=5Fid=20=E6=9B=B4=E6=96=B0=20todo=20=E5=88=97=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E7=A1=AE=E4=BF=9D=E4=B8=8E=E5=B7=A5=E5=85=B7=E5=86=85?= =?UTF-8?q?=E5=AD=98=E7=8A=B6=E6=80=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gateway/session.rs | 14 +++++++++++--- web/src/App.tsx | 17 +++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/gateway/session.rs b/src/gateway/session.rs index 8da0ed1..c2bc751 100644 --- a/src/gateway/session.rs +++ b/src/gateway/session.rs @@ -131,7 +131,15 @@ impl BusToolCallEmitter { }; let session_id = crate::storage::persistent_session_id(&self.channel_name, &self.chat_id); - let scope_key = &session_id; + // 优先用 topic_id(与 list_todos handler 和 tool 内存状态保持一致) + let scope_key = self + .metadata + .get("topic_id") + .filter(|t| !t.is_empty()) + .cloned() + .unwrap_or_else(|| session_id.clone()); + + let topic_id = self.metadata.get("topic_id").filter(|t| !t.is_empty()).cloned(); let records: Vec = todos_array .iter() @@ -140,7 +148,7 @@ impl BusToolCallEmitter { id: item.get("id")?.as_str()?.to_string(), scope_key: scope_key.clone(), session_id: session_id.clone(), - topic_id: None, + topic_id: topic_id.clone(), content: item.get("content")?.as_str()?.to_string(), status: item.get("status")?.as_str()?.to_string(), priority: item.get("priority")?.as_str()?.to_string(), @@ -156,7 +164,7 @@ impl BusToolCallEmitter { "BusToolCallEmitter: persisting todo_write result" ); - if let Err(e) = self.store.replace_todos(scope_key, &records) { + if let Err(e) = self.store.replace_todos(&scope_key, &records) { tracing::warn!(error = %e, %scope_key, "Failed to persist todo list from BusToolCallEmitter"); } } diff --git a/web/src/App.tsx b/web/src/App.tsx index 2536bb1..23ce1d0 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -332,11 +332,20 @@ function App() { const skillCmd = requestSkillList() handleCommand(skillCmd) sendMessage({ type: 'command', payload: JSON.stringify(skillCmd) }) - const todoCmd = requestTodoList() - handleCommand(todoCmd) - sendMessage({ type: 'command', payload: JSON.stringify(todoCmd) }) } - }, [status, handleCommand, sendMessage, requestMemoryList, requestSkillList, requestTodoList]) + }, [status, handleCommand, sendMessage, requestMemoryList, requestSkillList]) + + // 连接就绪、切换 topic、或进出子代理视图时刷新 todo 列表 + const prevTodoTriggerRef = useRef('') + useEffect(() => { + if (status !== 'connected') return + const key = `${selectedTopic ?? ''}|${subAgentView?.taskId ?? ''}` + if (key === prevTodoTriggerRef.current) return + prevTodoTriggerRef.current = key + const todoCmd = requestTodoList() + handleCommand(todoCmd) + sendMessage({ type: 'command', payload: JSON.stringify(todoCmd) }) + }, [status, selectedTopic, subAgentView, handleCommand, sendMessage, requestTodoList]) const handleRefreshMemories = useCallback(() => { const cmd = requestMemoryList()