Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (2)
Walkthrough本次变更为 GraphStore 和 VectorStore 增加未落盘变更跟踪。runtime persistence service 在确认无变更时跳过全量持久化。项目依赖将 ChangesA_Memorix 持久化优化
Dashboard 依赖版本固定
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The change is merge-ready after normal checks; no actionable merge-blocking risk remains. Sequence Diagram(s)sequenceDiagram
participant RuntimeDependencyService
participant GraphStore
participant VectorStore
participant SparseIndex
RuntimeDependencyService->>GraphStore: 检查 has_pending_changes()
GraphStore-->>RuntimeDependencyService: 返回图存储脏状态
RuntimeDependencyService->>VectorStore: 检查 has_pending_changes()
VectorStore-->>RuntimeDependencyService: 返回向量存储脏状态
RuntimeDependencyService->>SparseIndex: 确保启用的稀疏索引已加载
RuntimeDependencyService-->>RuntimeDependencyService: 无变更时跳过全量持久化
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1⚔️ Resolve merge conflicts 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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.
Inline comments:
In `@src/A_memorix/core/storage/graph_store.py`:
- Around line 1581-1582: 仅在加载完整成功且无需修复时建立 clean 基线:在 graph_store.py
的加载流程中,若矩阵或边哈希映射被修复则保持 dirty,或先持久化修复结果后再更新 _last_saved_graph_revision;在
vector_store.py 的完整加载成功路径之后再重置 revision,加载失败时保留旧状态或禁止复用该实例。
- Around line 1659-1662: 扩展图与向量存储的脏状态版本跟踪,避免仅凭现有 revision 相等而跳过未持久化变更:在
src/A_memorix/core/storage/graph_store.py:1659-1662 的 has_pending_changes
及相关路径中,为 _edge_hash_map 的新增、删除和重建更新 revision;在
src/A_memorix/core/storage/vector_store.py:2575-2583
为压缩、清空和失败事务引入独立提交版本,并在保存未完成时保留 dirty 状态。
- Around line 1470-1471: 更新 GraphStore.save() 中围绕 _last_saved_graph_revision
的保存逻辑,避免将传入备用目录 data_dir 的成功保存标记为绑定目录 self.data_dir 已落盘;参照 VectorStore.save()
的绑定目录校验,限制 data_dir 必须等于 self.data_dir,并仅在校验通过且保存成功后更新
_last_saved_graph_revision。
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 52431f11-efc7-4b8e-95d2-ddcdf3c94608
📒 Files selected for processing (4)
changelogs/changelog.mdsrc/A_memorix/core/runtime/services/runtime_dependency_service.pysrc/A_memorix/core/storage/graph_store.pysrc/A_memorix/core/storage/vector_store.py
| # 全部落盘成功后才记录已保存版本,供脏检测使用 | ||
| self._last_saved_graph_revision = self._graph_revision |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
不要把备用目录的保存结果标记为绑定目录已落盘。
GraphStore.save(data_dir=...) 允许传入其他目录,但这里无条件更新全局 _last_saved_graph_revision。如果实例绑定目录 A、却先保存到目录 B,目录 A 仍可能没有这次变更。runtime_dependency_service.py 的后续脏检测会跳过目录 A 的保存。
请限制 data_dir 必须等于 self.data_dir,或按目录分别记录已保存版本。VectorStore.save() 已采用绑定目录校验。
建议修复
+ if self.data_dir is not None and data_dir.resolve() != self.data_dir.resolve():
+ raise ValueError("GraphStore 只能向初始化时绑定的 data_dir 提交")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # 全部落盘成功后才记录已保存版本,供脏检测使用 | |
| self._last_saved_graph_revision = self._graph_revision | |
| if self.data_dir is not None and data_dir.resolve() != self.data_dir.resolve(): | |
| raise ValueError("GraphStore 只能向初始化时绑定的 data_dir 提交") | |
| # 全部落盘成功后才记录已保存版本,供脏检测使用 | |
| self._last_saved_graph_revision = self._graph_revision |
🤖 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/storage/graph_store.py` around lines 1470 - 1471, 更新
GraphStore.save() 中围绕 _last_saved_graph_revision 的保存逻辑,避免将传入备用目录 data_dir
的成功保存标记为绑定目录 self.data_dir 已落盘;参照 VectorStore.save() 的绑定目录校验,限制 data_dir 必须等于
self.data_dir,并仅在校验通过且保存成功后更新 _last_saved_graph_revision。
b68e689 to
9bdf22a
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
问题
主进程主线程长期 CPU 100%(实测主进程 ~110%、主线程 99.9% R 状态),重启后暂时缓解但会复发。
根因
A_Memorix 持久化链路存在「无意义/重复全量保存」:
ingest_service.py:448每次ingest_text末尾无条件_persist(),无脏标记/节流。_episode_materialization_loop默认 1 秒轮询,只要rebuilt_items非空就_persist()(实际不写图/向量,是纯重复保存)。单次
_persist()全量序列化 graph(3493 节点)+ vector(9777 向量)+ SQLite(357MB),且存储位于 juicefs(FUSE)上,实测单次墙钟约 1 秒,并同步阻塞主事件循环。改动
为图/向量存储增加变更脏检测,无未落盘变更时跳过全量保存:
graph_store.py:_last_saved_graph_revision+has_pending_changes();save 成功后记录、load 后同步vector_store.py:_revision/_last_saved_revision+has_pending_changes();add/restore/delete 递增、load 重置runtime_dependency_service.py:_persist()开头脏检测,图/向量均无变更时跳过;force_vectors/向量重建路径不跳过;无法判断的对象保守视为有变更(hasattr防御)_close_runtime仍无条件_persist(),正常退出时强制落盘兜底验证(真实负载:群聊 + 私聊约 2 小时)
pytests/A_memorix_test/:708 passed,0 回归(另有 4 个失败为既有环境问题,已在原始代码上验证同样失败,与本次改动无关)风险与回退
_record_graph_change入口、vector 四个写入入口全覆盖、关闭时强制落盘兜底、保守的hasattr策略(拿不准就保存)后续可优化(不在本 PR 范围)
_persist移出主事件循环(需给 graph 写入路径加线程锁)Summary by CodeRabbit