Skip to content

fix: 修复工作记忆来源显示未知的问题(Bug644) - #762

Open
jia030928 wants to merge 2 commits into
MemTensor:v1.2.7from
jia030928:fix-work-memory-source
Open

jia030928 wants to merge 2 commits into
MemTensor:v1.2.7from
jia030928:fix-work-memory-source

Conversation

@jia030928

@jia030928 jia030928 commented Oct 27, 2026 •

Copy link
Copy Markdown

工作记忆创建时遗漏了所属会话的来源,导致记忆管理页显示“未知”,按 Agent 筛选也无法找到对应记录。本次将 Session 传入工作记忆持久化流程,新建时保存 agentId、info.source 和工作区 appId,使列表、详情及 Agent 筛选能够识别来源。

跨 Agent 合并已有工作记忆时,保留原记录的来源和会话信息,避免被最后更新它的 Agent 覆盖。本次仅修复新记录写入,不批量回填历史无来源记录,不新增数据库字段或修改公开接口。

关联问题:Bug644。

验证:

  • 修复前,Codex 和 Claude Code 的新增来源断言失败;修复后工作记忆与管理页读模型相关测试 46 项通过。
  • 创建来源测试扩展为 15 组:11 个标准来源,以及 claude-code、claude、open-code、deepseek-harness 别名。检查来源字段、管理页来源、详情和对应 Agent 筛选,并确认其他 Agent 筛选不误收录。
  • Memory 全量测试:1453 项通过、1 项跳过;各 Agent Hook/插件接入层测试:101 项通过;Memmy 自身 Memory Hook:31 项通过。
  • npm run lint、npm run typecheck 和交付差异检查通过;打包检查:127 项通过、1 项跳过。
  • 重新构建 macOS arm64 CN unsigned DMG,并从镜像复制应用,在隔离资料中用包内实际工作记忆流程分别生成 11 个来源的工作记忆。验证 SQLite 字段、HTTP 对应来源筛选和其他 10 个来源的排除。
  • 真实桌面页面逐一检查下列 11 个来源的标签、筛选与详情,完全退出并重启后再逐一复查,均通过:
Agent 新包公共流程与 HTTP 首次启动及重启后的标签、筛选、详情
Memmy 通过 通过
Cursor 通过 通过
Claude Code 通过 通过
Codex 通过 通过
OpenCode 通过 通过
OpenClaw 通过 通过
Hermes 通过 通过
DeepSeek Harness 通过 通过
WorkBuddy 通过(来源兼容性) 通过
Pi 通过(来源兼容性) 通过
QwenWork 通过(来源兼容性) 通过

验证边界:

  • 工作记忆提取和合并决策使用固定模型返回值;未逐个启动第三方 Agent 客户端进行真实模型对话,在线模型推理及版本升级场景未验证。
  • WorkBuddy、Pi、QwenWork 当前只有 Skill 接入;本轮通过构造 v2 会话验证公共流程的来源兼容性,不代表已支持自动触发工作记忆生成。
  • 当前 PR 目标分支为 v1.2.7,其基线提交与此前的 1.2.7 相同;测试包沿用该分支源码声明的桌面版本 1.2.4。

包内 Memory buildId 已与源码核对一致,DMG 完整性校验为 VALID。测试包 SHA256:981b62df476b47aa0ff64de81b5a637ed51d59d4b5bc363346eb232b503fdd82。

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #762
Task: 256e238333551f69
Base: v1.2.7
Head: fix-work-memory-source

🔍 OpenCodeReview found 2 issue(s) in this PR.

⚠️ 3 warning(s) occurred during review.


1. Memory/src/service/work-memory/work-memory-pipeline.ts (L556-L557)

Distinct from the empty-source normalization issue: the merge branch takes existing.agentId / existing.appId verbatim, but work memories written before this change never had agent_id / app_id set, so existing.agentId is undefined for exactly the rows that most need provenance backfilled. Writing agentId: undefined also relies on the repository's memory.agentId ?? previous.agentId (repositories.ts:658) to preserve the old null, i.e. the merged row still ends up with no Agent/workspace at all. Net effect: the provenance this PR adds is applied to create only, while merges into legacy rows stay unpinned even though the merge may cross Agents. Consider falling back to the current session when the existing row has no Agent (and keep the guarded-spread style used for conversationId / memoryKey a few lines below so an absent value is omitted rather than assigned as undefined).

💡 Suggested Change

Before:

      agentId: existing ? existing.agentId : sourceSession.source,
      appId: existing ? existing.appId : sourceSession.workspaceId,

After:

      ...(existing?.agentId !== undefined || sourceSession.source ? { agentId: existing?.agentId ?? sourceSession.source } : {}),
      ...(existing?.appId !== undefined || sourceSession.workspaceId ? { appId: existing?.appId ?? sourceSession.workspaceId } : {}),

2. Memory/src/service/work-memory/work-memory-pipeline.ts (L545)

The comment states the intent is to retain original provenance on merges, but for rows persisted before this change existing.info.source is often absent, so the new provenance is dropped entirely for the merge branch (while create gets source). Consider falling back to the current session's source when the existing row has none, otherwise these older work memories stay permanently unattributed.

💡 Suggested Change

Before:

    const info: Record<string, unknown> = { ...(existing ? existing.info : { source: sourceSession.source }) };

After:

    const info: Record<string, unknown> = { ...(existing ? { source: sourceSession.source.trim() || "unknown", ...existing.info } : { source: sourceSession.source }) };

🧹 Filtered 1 low-confidence OCR finding(s) before posting/fix-loop (duplicate: 1).

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

✅ Automated Test Results: PASSED

All tests passed (6/6 executed). common/smoke: 6/6. Duration: 2s

Branch: fix-work-memory-source

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants