[P1/高] MemoryManager store INSERT OR REPLACE 永远不 REPLACE,更新语义丢失 #32

Open
opened 2026-07-21 21:55:58 +08:00 by thzxx · 0 comments
Owner

问题类型

缺陷 / 高 / Agent 引擎

文件位置

electron/harness/memory/manager.ts

问题描述

MemoryManager.store 使用:

INSERT OR REPLACE INTO memories (id, content, type, ...) VALUES (?, ?, ?, ...);

但 store 方法每次调用都生成新的 id(nanoid()),所以 INSERT OR REPLACE 永远是 INSERT,REPLACE 子句永不触发。

语义上:

  • store 应该是创建新记忆
  • update 应该是更新已有记忆
  • 当前代码混淆了两者

影响

  • 重复 store 同一内容会创建多条记忆
  • 记忆库膨胀
  • 检索时重复结果

建议修复

方案 A:明确语义,移除 OR REPLACE

INSERT INTO memories (id, ...) VALUES (?, ...);

方案 B:基于 content hash 去重

-- 添加 content_hash 列
ALTER TABLE memories ADD COLUMN content_hash TEXT;
CREATE UNIQUE INDEX idx_content_hash ON memories(content_hash);

-- store 时计算 hash,INSERT OR REPLACE 自动去重

方案 B 更完整,能避免重复存储相同内容。

## 问题类型 缺陷 / 高 / Agent 引擎 ## 文件位置 `electron/harness/memory/manager.ts` ## 问题描述 MemoryManager.store 使用: ```sql INSERT OR REPLACE INTO memories (id, content, type, ...) VALUES (?, ?, ?, ...); ``` 但 store 方法每次调用都生成新的 id(`nanoid()`),所以 `INSERT OR REPLACE` 永远是 INSERT,REPLACE 子句永不触发。 语义上: - store 应该是创建新记忆 - update 应该是更新已有记忆 - 当前代码混淆了两者 ## 影响 - 重复 store 同一内容会创建多条记忆 - 记忆库膨胀 - 检索时重复结果 ## 建议修复 方案 A:明确语义,移除 OR REPLACE ```sql INSERT INTO memories (id, ...) VALUES (?, ...); ``` 方案 B:基于 content hash 去重 ```sql -- 添加 content_hash 列 ALTER TABLE memories ADD COLUMN content_hash TEXT; CREATE UNIQUE INDEX idx_content_hash ON memories(content_hash); -- store 时计算 hash,INSERT OR REPLACE 自动去重 ``` 方案 B 更完整,能避免重复存储相同内容。
thzxx added the ??Agent??? labels 2026-07-21 21:55:58 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MetonaTeam/metona-ai-desktop#32