fix(memory): 跨会话记忆断裂修复 — profile_store连接+双数据库统一+诊断日志
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

根因: 3个断裂点
1. profile_store未连接: create_middleware_chain()中GrowthIntegration未设置
   UserProfileStore, 导致extract_combined()的profile_signals被静默丢弃
2. 双数据库不一致: UserProfileStore写入data.db, agent_get读取memories.db,
   两库隔离导致UserProfile永远读不到
3. 缺少关键日志: 提取/存储/检索链路无info级别日志, 问题难以诊断

修复:
- create_middleware_chain()中添加 with_profile_store(memory.pool())
- agent_get改为使用kernel.memory()而非viking_commands::get_storage()
- Kernel暴露memory()方法返回Arc<MemoryStore>
- growth.rs增强日志: 存储成功/失败/提取详情/profile更新数

验证: Tauri端E2E测试通过
- 会话A发送消息 → 提取6记忆+4 profile signals → 存储成功
- 新会话B发送消息 → Injected memories → LLM回复提及之前话题
- 管家Tab显示: 用户画像(医疗/健康)+近期话题+53条记忆分组
This commit is contained in:
iven
2026-04-22 19:07:14 +08:00
parent 52078512a2
commit adf0251cb1
3 changed files with 57 additions and 17 deletions

View File

@@ -185,16 +185,23 @@ pub async fn agent_get(
let mut info = kernel.get_agent(&id);
// Extend with UserProfile if available
// Extend with UserProfile if available (reads from same MemoryStore pool as middleware writes to)
if let Some(ref mut agent_info) = info {
if let Ok(storage) = crate::viking_commands::get_storage().await {
let profile_store = zclaw_memory::UserProfileStore::new(storage.pool().clone());
if let Ok(Some(profile)) = profile_store.get(&agent_id).await {
let memory_store = kernel.memory();
let profile_store = zclaw_memory::UserProfileStore::new(memory_store.pool());
match profile_store.get(&agent_id).await {
Ok(Some(profile)) => {
match serde_json::to_value(&profile) {
Ok(val) => agent_info.user_profile = Some(val),
Err(e) => tracing::warn!("[agent_get] Failed to serialize UserProfile: {}", e),
}
}
Ok(None) => {
tracing::debug!("[agent_get] No UserProfile found for agent {}", agent_id);
}
Err(e) => {
tracing::warn!("[agent_get] Failed to read UserProfile: {}", e);
}
}
}