Repository navigation
fix(memory): align extraction, tool outcomes and bounded recall - #751
openjiuwen-sync-bot[bot] wants to merge 1 commit into
Conversation
|
zhengpeng seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
1 similar comment
|
zhengpeng seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
head_sha: 变更摘要本 PR 围绕记忆能力的“抽取—工具结果—召回”三条链路做对齐:统一显式记忆工具的返回契约为 主要改动
|
|
head_sha: 代码审查审查结论
💬 仅评论 |
| async def recall(): | ||
| return await asyncio.wait_for(provider.prefetch("question", project="proj-x"), 0.4) | ||
|
|
||
| out_with_proj = asyncio.run(recall()) |
There was a problem hiding this comment.
head_sha: 552ce84d8323025a5c64064fe4189d5b27417675
🟡 Medium Priority
建议:去掉 0.4s/0.5s 的时间竞赛:让 _FallbackClient.search 不再等待事件(或在需要"搜索挂起"语义时直接 raise TimeoutError),并把外层 asyncio.wait_for(..., 0.4) 换成直接的 await provider.prefetch(...);同时在用例内(asyncio.run 内部)创建 asyncio.Event,避免跨 loop 复用。
| if not isinstance(items, list) or any( | ||
| not isinstance(item, dict) or not isinstance(item.get("content"), str) for item in items | ||
| ): | ||
| raise AgentMemoryClientError("Memory search returned an invalid response.") |
There was a problem hiding this comment.
head_sha: 552ce84d8323025a5c64064fe4189d5b27417675
🟡 Medium Priority
变更点:_HttpClient.search 新增整响应强校验(2844-2847 行)——只要 items 中任意一条不是 dict 或 item.get("content") 不是 str,就抛出 AgentMemoryClientError("Memory search returned an invalid response.");而下方的映射(2848-2856 行)仍用 it.get("content", "") 兜底,说明代码本身就容忍 content 缺失。
受影响契约:HTTP 检索原先只跳过非 dict 项、缺失 content 时回落空串,允许部分命中可用;变更后单条异常字段即可让整批结果作废。
失败模式:当服务端版本返回的命中项不带顶层 content(本模块 docstring 明确说明序列化 MemoryUnit 不含 content 属性、需从 segments 重建,add/read_md_file/edit_md_file 均如此)、或个别命中项字段为 null 时,本次检索整体抛错:显式工具(agent_memory_search / team_memory_search / coding 检索)由“返回其余命中”退化为返回 {"success": false, ...};自动预取(经 _bounded)退化为 0 命中,coding_memory._prefetch 会因此落到 MEMORY.md 文档兜底,整轮语义召回失效。
建议:结构级校验(data 为 dict、items 为 list)保留抛错;条目级校验改为过滤/兜底:跳过非 dict 项,content 缺失时用 self._content_view(it) 从 segments 重建,避免单条异常字段作废整批检索结果。
| return json.dumps({ | ||
| "success": False, | ||
| "error": "Memory write failed; check the service logs for details.", | ||
| }) |
There was a problem hiding this comment.
head_sha: 552ce84d8323025a5c64064fe4189d5b27417675
🟡 Medium Priority
变更:本 diff 把 work 场景的 _search(296-297)、_conclude(304-306、326-330、338)、_video_submit/_video_status、未知工具与新禁用分支(212、215、223、233)统一改成 {"success": bool, ...} 信封,失败时显式带 success: False。
影响面:WorkMemoryScene.handle_tool_call(199-205)仍同时分发 agent_memory_procedural 与 agent_memory_profile 两个未改动的处理器,它们保持旧结构:_procedural 在参数缺失、写入失败(data is None)、以及 not data.item_id(第 370-376 行注释明确“不可报成功(false success)”)三种失败路径下只返回 {"error": ...};_profile 返回 {"result": ...}。
失败模式:同一场景、同一 dispatch 表内的工具输出契约出现分叉——调用方/模型按新约定读取 result["success"] 时会 KeyError(工作场景写入类工具中只有 procedural 缺该字段),而按旧约定 result 读取 conclude/search 会拿不到值。本 PR 的目标(issue #367:记忆工具调用失败必须可被感知)对 agent_memory_procedural 的失败路径没有生效,仍与 provider 层 _tool_error_json 的 {"success": False, "error": ...} 约定不一致(agent_memory_provider.py:832-833)。触发条件:显式直调 agent_memory_procedural(未注册进 schema,但 handle_tool_call 仍可达)且写入失败或抽取为空。
建议:将 _procedural(346、361、371-376、377 行)与 _profile(244、255 行)的返回统一改为 {"success": ...} 信封,与本次修改的 _search/_conclude 保持一致;这类失败分支应返回 {"success": False, "error": ...}。
| hits = await context.client.search(query, context.scope, top_k=top_k, filters=filters) | ||
| if exclude_credentials: | ||
| return [hit for hit in hits if not is_credential_item(hit)] | ||
| return hits |
There was a problem hiding this comment.
head_sha: 552ce84d8323025a5c64064fe4189d5b27417675
🟡 Medium Priority
变更点:base_document_scene.py:202 删除了 _search_collective_project 内的 cls._bounded(...) 包裹,改为直接 hits = await context.client.search(...);同时 search_project_memory(同文件 141-152 行)改为 asyncio.gather(ordinary, supplement) 且未对 supplement 加 _bounded。
受影响契约:BaseDocumentScene.project_recall() 的调用方依赖“补充召回是可选增强、失败即降级为空列表”。本次同一 PR 又把 _HttpClient.search(raise_on_error=True)与 _InProcessClient.search 改成失败时抛 AgentMemoryClientError(原先返回 []),两条改动叠加后,补充召回从“静默降级”变成“必然抛出”。
失败模式:work_memory.py:273 的 agent_memory_search 工具与 coding_memory.py:157 的显式 search(supplement=True) 都直接走 search_project_memory,其中 supplement(带 collective 坐标的项目召回)没有被 _bounded 保护。当服务端熔断开启、连接失败、超时或返回非法响应时,即使主检索 ordinary 已成功,整个 asyncio.gather 也会抛出异常,导致显式检索工具整体返回失败,而不仅是丢掉补充条目;此前该路径会返回主检索结果。agent_memory_provider.prefetch(1619-1630 行)已在外层补了 _bounded,说明本意是让补充召回可降级,但 search_project_memory 这个共用入口没有同步。
建议:在 _search_collective_project 内把 await context.client.search(...) 重新包回 cls._bounded(..., operation="project search"),或在 search_project_memory 中对 supplement 使用 cls._bounded,保证补充召回失败时降级为空列表而不是让整次检索失败。
Paired: GitHub #751 ↔ GitCode !533
What type of PR is this?
/kind
Self-checklist:(请自检,在[ ]内打上x,我们将检视你的完成情况,否则会导致pr无法合入)
Linked Closing Issues: