Skip to content

fix(A_memorix):调整episode重建逻辑#1709

Merged
A-Dawn merged 2 commits into
Mai-with-u:devfrom
A-Dawn:dev
May 16, 2026
Merged

fix(A_memorix):调整episode重建逻辑#1709
A-Dawn merged 2 commits into
Mai-with-u:devfrom
A-Dawn:dev

Conversation

@A-Dawn
Copy link
Copy Markdown
Collaborator

@A-Dawn A-Dawn commented May 16, 2026

  • ✅ 接受:与main直接相关的Bug修复:提交到dev分支
  • 新增功能类pr需要经过issue提前讨论,否则不会被合并
  • 🌐 i18n 提醒:除 bootstrap 或紧急修复外,请不要把非 zh-CN 目标翻译作为常规 GitHub 编辑面;常规翻译以 Crowdin -> l10n_* PR 回流为准,详见 docs/i18n.md

请填写以下内容

(删除掉中括号内的空格,并替换为小写的x

    • main 分支 禁止修改,请确认本次提交的分支 不是 main 分支
    • 我确认我阅读了贡献指南
    • 本次更新类型为:BUG修复
    • 本次更新类型为:功能新增
    • 本次更新是否经过测试
    • 如果本次修改涉及 src/A_memorix,我确认已阅读 src/A_memorix/MODIFICATION_POLICY.md,不涉及则无需勾选
  1. 请填写破坏性更新的具体内容(如有):
  2. 请简要说明本次更新的内容和目的:调整episode重建逻辑,减少不必要的token消耗

其他信息

  • 关联 Issue:Close #
  • 截图/GIF
  • 附加信息:

Summary by CodeRabbit

发布说明

  • 重构
    • 优化了摘要导入的结果数据结构和处理流程,增强系统内部的结果追踪能力。
    • 调整了内部工作流程,改进了错误处理和事件队列管理的效率。

Review Change Stack

Copilot AI review requested due to automatic review settings May 16, 2026 18:01
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

Walkthrough

此 PR 重构了摘要导入的返回值结构和 episode 增量处理流程:新增 SummaryImportResult 数据类(包含段落 hash 和源信息),将 import_from_stream 的所有失败/成功分支统一返回该结构体,并在 summarize_chat_stream 中用段落 hash 驱动增量 episode 入队,替代原先的全量重建。

Changes

摘要导入结果重构与 Episode 增量处理

Layer / File(s) Summary
SummaryImportResult 数据结构定义
src/A_memorix/core/utils/summary_importer.py
补充 dataclassesIterator 导入,新增 SummaryImportResult 不可变数据类,包含 successdetailparagraph_hashsource 字段,并通过 __iter__ 产出 successdetail 以维持二元组解包兼容性。
_execute_import 显式返回段落 hash
src/A_memorix/core/utils/summary_importer.py
_execute_import 方法返回类型改为 str,在导入完成后显式 return hash_value,为上层获取段落 hash 提供数据源。
import_from_stream 返回类型与全流程适配
src/A_memorix/core/utils/summary_importer.py
import_from_stream 返回类型改为 SummaryImportResult;自检失败、无有效聊天记录、无可用模型、LLM 异常、内容为空等场景均返回 SummaryImportResult(False, ...);成功路径从 _execute_import 获取 paragraph_hash 并返回 SummaryImportResult(True, ..., paragraph_hash=..., source=...)
summarize_chat_stream 增量 episode 入队
src/A_memorix/core/runtime/sdk_memory_kernel.py
summarize_chat_stream 改为从 import_result 提取 paragraph_hashsource,通过 metadata_store.enqueue_episode_pending 进行增量入队并立即持久化,替代原先的 rebuild_episodes_for_sources 全量重建;返回值新增 stored_idsepisode_pending_ids 字段。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR标题清晰指向主要变更,准确反映了调整episode重建逻辑的核心目的。
Description check ✅ Passed PR描述包含了必要的核心信息,但缺少详细的技术背景说明,仅简要描述了变更目的。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 调整了 A_memorix 的聊天摘要导入返回结构,并在运行时侧将 episode 重建从“按 source 全量重建”改为“按新段落 hash 增量入队”,以减少不必要的 token 消耗并为后续增量处理提供更精确的输入。

Changes:

  • SummaryImporter.import_from_stream() 返回值从 (success, detail) 二元组升级为 SummaryImportResult,并在成功时返回新增摘要段落的 paragraph_hashsource
  • _execute_import() 改为返回段落 hash,供上层做 episode 增量入队。
  • sdk_memory_kernel.summarize_chat_stream() 改为将 paragraph_hash 入队到 episode pending 队列,并在返回 payload 中附带相关 id 列表。

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/A_memorix/core/utils/summary_importer.py 引入 SummaryImportResult,并让导入流程返回新增段落 hash 以支撑增量 episode 处理。
src/A_memorix/core/runtime/sdk_memory_kernel.py 使用新的导入结果结构,将摘要段落增量入队 episode pending,并扩展返回 payload。

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

def __iter__(self) -> Iterator[bool | str]:
yield self.success
yield self.detail

Comment on lines +1192 to +1196
success = bool(getattr(import_result, "success", False))
detail = str(getattr(import_result, "detail", "") or "")
paragraph_hash = str(getattr(import_result, "paragraph_hash", "") or "").strip()
source = (
str(getattr(import_result, "source", "") or "").strip()
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/A_memorix/core/runtime/sdk_memory_kernel.py (1)

1192-1198: ⚡ Quick win

直接访问已确认存在的 dataclass 属性,避免不必要的 getattr()

SummaryImportResult 是一个 frozen dataclass,其字段 successdetailparagraph_hashsource 都已显式声明。在确认属性存在的情况下使用 getattr() 违反了代码规范(应最小化 getattr/setattr 的使用)。改用直接属性访问:

♻️ 建议修改
-        success = bool(getattr(import_result, "success", False))
-        detail = str(getattr(import_result, "detail", "") or "")
-        paragraph_hash = str(getattr(import_result, "paragraph_hash", "") or "").strip()
-        source = (
-            str(getattr(import_result, "source", "") or "").strip()
-            or self._build_source("chat_summary", chat_id, [])
-        )
+        success = bool(import_result.success)
+        detail = str(import_result.detail or "")
+        paragraph_hash = str(import_result.paragraph_hash or "").strip()
+        source = str(import_result.source or "").strip() or self._build_source("chat_summary", chat_id, [])
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/A_memorix/core/runtime/sdk_memory_kernel.py` around lines 1192 - 1198,
The code uses getattr() to read fields from the frozen dataclass
SummaryImportResult (via import_result) even though its attributes success,
detail, paragraph_hash and source are defined; replace the getattr calls with
direct attribute access (e.g., import_result.success, import_result.detail,
import_result.paragraph_hash, import_result.source) and preserve the existing
fallback/normalization logic (bool(...) for success, str(...).strip() for
paragraph_hash and source, and fallback to self._build_source("chat_summary",
chat_id, []) when import_result.source is empty).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/A_memorix/core/runtime/sdk_memory_kernel.py`:
- Around line 1192-1198: The code uses getattr() to read fields from the frozen
dataclass SummaryImportResult (via import_result) even though its attributes
success, detail, paragraph_hash and source are defined; replace the getattr
calls with direct attribute access (e.g., import_result.success,
import_result.detail, import_result.paragraph_hash, import_result.source) and
preserve the existing fallback/normalization logic (bool(...) for success,
str(...).strip() for paragraph_hash and source, and fallback to
self._build_source("chat_summary", chat_id, []) when import_result.source is
empty).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d9a84c41-5af1-4a2c-ab4e-4532887d14de

📥 Commits

Reviewing files that changed from the base of the PR and between 5fc0f3c and 91520a7.

📒 Files selected for processing (2)
  • src/A_memorix/core/runtime/sdk_memory_kernel.py
  • src/A_memorix/core/utils/summary_importer.py

@A-Dawn A-Dawn merged commit 73562bb into Mai-with-u:dev May 16, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants