fix: 优先使用 topic_id 更新 todo 列表,确保与工具内存状态一致

This commit is contained in:
oudecheng 2026-06-12 17:25:50 +08:00
parent 4866ea9538
commit ec5ddf644a
2 changed files with 24 additions and 7 deletions

View File

@ -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<crate::storage::TodoRecord> = 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");
}
}

View File

@ -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<string>('')
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()