fix:checkpoint,issue #157#444
Conversation
|
Duplicate cleanup note: #177 is already the canonical PR for #157. #177 covers checkpoint recalibration after cleanup and on scheduler startup, includes focused tests, and has been locally verified and approved. Compared with #177, this PR overlaps on recalibrating Recommendation: close this in favor of #177, or re-scope it only if there is a small follow-up behavior not covered after #177 lands. |
|
Thank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program! |
关联 Issue
Fix #157
背景
当前
recall_checkpoint.json中的total_memories_extracted和l0_conversations_count是增量累加字段。当
memory-cleaner清理历史数据,或者用户手动删除records/*.jsonl/ SQLite 中的记录后,checkpoint 中的计数不会同步下降,导致 checkpoint 计数高于真实数据。这会让后续依赖 checkpoint 的 pipeline / scheduler 使用过期的聚合计数。
本 PR 做了什么
在
CheckpointManager中新增recalibrate()方法:total_memories_extractedl0_conversations_countrunner_states和pipeline_states,避免破坏已有 session 状态恢复。新增安全的 JSONL 统计逻辑:
records/*.jsonl中的非空行数,作为真实 L1 memory 数量。conversations/*.jsonl中的非空行数,作为 L0 fallback 数量。0。L0 计数优先使用 VectorStore:
vectorStore可用,优先调用vectorStore.countL0()。vectorStore不可用、处于 degraded 状态,或countL0()抛错,则 fallback 到conversations/*.jsonl非空行数。在 scheduler 启动恢复 checkpoint 前执行校准:
TdaiCore.ensureSchedulerStarted()中,读取 checkpoint 并恢复 pipeline state 之前,先调用:scheduler.start(...)使用的是校准后的 checkpoint。调整
captureAtomically()的 L0 计数语义:l0_conversations_count += 1。vectorStore.countL0()/conversations/*.jsonl的真实行数语义保持一致。新增单元测试:
50,但records/*.jsonl真实只有42行时,校准后变为42。runner_states/pipeline_states在校准后保持不变。vectorStore.countL0()优先路径。vectorStore.countL0()失败后 fallback 到conversations/*.jsonl。captureAtomically()按消息行数累加 L0 计数。验证
已执行:
验证结果
1 passed (1), 4 tests passedChange Type | 修改类型
Additional Notes | 其他说明
本 PR 没有直接修改
dist/index.mjs,只修改src源码并新增单元测试。