Skip to content

fix(summarize): 持久化增量蒸馏游标(#229) - #274

Merged
modusensus merged 1 commit into
slow-stack:mainfrom
z2Ace0107:codex/issue-229-distill-cursor
Sep 21, 2026
Merged

modusensus merged 1 commit into
slow-stack:mainfrom
z2Ace0107:codex/issue-229-distill-cursor

Conversation

@z2Ace0107

@z2Ace0107 z2Ace0107 commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

变更

  • 新增 distill_cursors SQLite 表,按 session.id 持久化最近成功消费的事件序。
  • 宿主重启后恢复游标,避免历史窗口重复蒸馏。
  • 记忆写入与游标推进在同一 SQLite 事务中完成。
  • LLM、解析、中止、记忆写入或游标写入失败时保留窗口,并正确记录失败审计。
  • 补充旧库迁移、重启恢复、失败重试、事务回滚、空数组和混合数组测试。
  • 同步 src/lib/

验证

  • npm test:1247 passed
  • node scripts/check-sync.js
  • node --check
  • git diff --check

Fixes #229

Summary by CodeRabbit

  • 新功能
    • 新增蒸馏进度游标的持久化能力,支持按会话保存和恢复最近处理位置。
    • 服务重启后可继续增量蒸馏,减少重复处理。
    • 游标仅向前推进,避免较小序号覆盖已保存进度。
  • 错误修复
    • 摘要处理失败或游标写入失败时,相关状态会回滚并记录错误审计信息。
  • 测试
    • 补充游标持久化、数据库迁移、回滚及异常场景的测试覆盖。

@coderabbitai

coderabbitai Bot commented Sep 20, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: slow-stack/dsh-mneme/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 815d2c8c-b4bc-4429-ada2-89357286f411

📥 Commits

Reviewing files that changed from the base of the PR and between 9089a71 and c08ab76.

📒 Files selected for processing (8)
  • dsh-mneme/lib/service.js
  • dsh-mneme/lib/store.js
  • dsh-mneme/lib/summarize.js
  • dsh-mneme/src/service.js
  • dsh-mneme/src/store.js
  • dsh-mneme/src/summarize.js
  • dsh-mneme/test/store.test.js
  • dsh-mneme/test/summarize.test.js

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

本次变更为蒸馏流程新增按会话持久化的游标。存储层提供游标读写和单调更新。服务层透传 API。摘要流程恢复并提交游标,同时补充失败审计和回滚测试。

Changes

蒸馏游标持久化

Layer / File(s) Summary
游标存储与迁移
dsh-mneme/lib/store.js, dsh-mneme/src/store.js, dsh-mneme/test/store.test.js
新增 distill_cursors 表、getDistillCursorsetDistillCursor。写入时保留较大的 last_seq。测试覆盖初始化、旧库迁移和游标不回退。
服务层游标 API
dsh-mneme/lib/service.js, dsh-mneme/src/service.js
服务对象新增 getDistillCursorsetDistillCursor,并委托给存储层。
摘要流程与回滚验证
dsh-mneme/lib/summarize.js, dsh-mneme/src/summarize.js, dsh-mneme/test/summarize.test.js
摘要流程优先读取持久游标,并在成功消费、空摘要和窗口过小时提交游标。异常时记录 error 审计状态并重新抛出。测试覆盖重启恢复、混合条目、写入失败和游标提交失败。

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~30 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: modusensus

Sequence Diagram(s)

sequenceDiagram
  participant 摘要流程
  participant 服务层
  participant 存储层
  摘要流程->>服务层: 读取会话持久游标
  服务层->>存储层: getDistillCursor(sessionId)
  存储层-->>服务层: 返回 last_seq
  服务层-->>摘要流程: 返回 previousSeq
  摘要流程->>服务层: 提交窗口末尾 nextSeq
  服务层->>存储层: setDistillCursor(sessionId, nextSeq)
  存储层-->>服务层: 返回更新后的游标
Loading

Merge Risk: ⚪ Minimal · up to c08ab

No actionable merge-blocking risk remains. The cursor persistence change can proceed with normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.17% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了 PR 的主要变更:为 summarize 持久化增量蒸馏游标,并包含关联 Issue 编号 #229
Linked Issues check ✅ Passed PR 实现了 Issue #229 的编码要求。distill_cursorssession_id 持久化 last_seq,并在服务重启后读取游标。初始化和旧库测试覆盖表创建,支持幂等结构迁移。游标写入使用单调不回退的 UPSERT。摘要流程在成功写入、空摘要和窗口过小路径推进游标;混合数组推进到窗口末尾,全无效数组不推进。记忆写入或游标写入失败时执行回滚并记录 error
Out of Scope Changes check ✅ Passed 变更集中在 Issue #229 所需的存储层、服务透传、摘要流程和对应测试。src/lib/ 同步属于该功能的构建产物一致性要求。未发现与持久化游标、事务语义、迁移或测试无关的变更。
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

@Anans-Ivresse Anans-Ivresse left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

审阅通过,实现很稳 👍 游标与记忆写入同事务原子提交(恰一次语义)、旧库迁移幂等、与 summarizeMinWindowChars / summarizePeakHours 的游标消费语义完全兼容、并发下单调不倒退,lib 同步 ✓,全量 1251 测试通过。

非阻塞小建议(可后续优化):

  • src/summarize.js:410 persistCursorsetDistillCursor 缺失时硬抛错,建议降级为 warn + 内存态回退(理论场景:第三方宿主用旧版 service 构造时)
  • 每轮 turn/end 都先读库取游标,绕过了内存 map 缓存,可改内存优先(每事件少一次 PK 查询)
  • 可补「峰值时段 / 最小窗口」与持久化游标的交叉用例

@codecov

codecov Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.27778% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
dsh-mneme/src/store.js 90.24% 4 Missing ⚠️
dsh-mneme/src/summarize.js 89.65% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@modusensus
modusensus merged commit 360f7c8 into slow-stack:main Sep 21, 2026
10 checks passed
modusensus added a commit to heptaspirit/dsh-mneme that referenced this pull request Sep 21, 2026
Anans 复审留下的非阻塞建议第 1 条:第三方宿主用旧版 service 构造时,
persistCursor 在方法缺失分支硬抛错,会把 slow-stack#274 之前能正常工作的宿主
变成每轮蒸馏即崩。降级为 warn + 内存游标(slow-stack#274 前语义,本进程不重蒸,
跨重启重放由 saveWithDedupe 三元组兜底);方法存在但抛错仍向上传播,
恰一次回滚语义不动(对应回滚测试用例保持原样)。

补回归测试:缺方法时蒸馏照跑、记忆落库、不持久化、进程内不重蒸。
Anans 建议第 2 条(内存优先读)经评估不改:memoryDir 允许双宿主共用,
DB 优先是跨进程游标一致的依据,内存优先会复活跨进程重复蒸馏。
modusensus added a commit that referenced this pull request Sep 21, 2026
CHANGELOG 的 [Unreleased] 转为 v0.8.6 小节,并补上三份未登账的改动:
工具暴露开关与描述纪律(#276)、蒸馏游标持久化(#229/#274)与旧宿主降级路径
(#279)、能力说明第 5 条文案精确性(#277)、CI 与徽章口径收敛(#281/#273/#272)。
两个 README 的 v0.8.6 占位行补描述(版本历史 + 路线图),测试徽章与注释数按
badge:sync 对齐到 1275。
modusensus added a commit that referenced this pull request Sep 21, 2026
* chore: v0.8.6 发布准备(版本号 + 测试徽章 + CHANGELOG/路线图占位行)

请在 CHANGELOG 与两个 README 的占位行补描述后再合并。

* chore(release): v0.8.6 发布说明与路线图补齐

CHANGELOG 的 [Unreleased] 转为 v0.8.6 小节,并补上三份未登账的改动:
工具暴露开关与描述纪律(#276)、蒸馏游标持久化(#229/#274)与旧宿主降级路径
(#279)、能力说明第 5 条文案精确性(#277)、CI 与徽章口径收敛(#281/#273/#272)。
两个 README 的 v0.8.6 占位行补描述(版本历史 + 路线图),测试徽章与注释数按
badge:sync 对齐到 1275。

---------

Co-authored-by: modusensus <modusensus@users.noreply.github.com>
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.

[Bug] lastDistilledSeq 为进程内存态:宿主重启后蒸馏窗口从头重放,已蒸馏历史被重复处理

3 participants