Skip to content

fix(checkpoint): 保留 Persona 生成期间的并发更新#474

Open
Qiyuanqiii wants to merge 1 commit into
TencentCloud:mainfrom
Qiyuanqiii:fix/issue-157-persona-counter-race
Open

fix(checkpoint): 保留 Persona 生成期间的并发更新#474
Qiyuanqiii wants to merge 1 commit into
TencentCloud:mainfrom
Qiyuanqiii:fix/issue-157-persona-counter-race

Conversation

@Qiyuanqiii

Copy link
Copy Markdown

Description | 描述

本 PR 修复 Persona 生成完成时覆盖并发 checkpoint 更新的问题。

维护者已将 #177 确定为 #157 的标准计数重校准方案。本 PR 不实现 recalibrate(),也不替代 #177,而是解决其未覆盖的运行时并发问题。

问题根因

L1、L2、L3 使用三条相互独立的队列。Persona 模型生成最长可运行 180 秒,在此期间其他会话仍可继续完成 L1/L2 处理。

当前 Persona 完成后会:

  • 使用完成时的 total_processed 更新 last_persona_at
  • last_persona_time 设置为完成时间
  • 无条件把 memories_since_last_persona 清零

因此,生成期间新增的 L1 记忆会被错误视为已经包含在当前 Persona 中;同时,生成期间更新的场景也可能落在新的时间水位之前,导致下一轮无法识别这些变化。

修复方案

  • 在 Persona 生成开始前保存 checkpoint 覆盖快照。
  • 使用同一份快照构造 Persona 提示并完成 checkpoint 回写。
  • 完成时只扣除生成开始前已有的记忆数量。
  • 保留生成期间新增的记忆,供下一轮 Persona 触发使用。
  • last_persona_at 写为生成开始时的消息水位。
  • last_persona_time 写为读取场景前的时间水位,确保并发场景更新仍可在下一轮被识别。
  • 保留 markPersonaGenerated(totalProcessed) 单参数调用的原有清零行为,避免破坏外部兼容性。

行为示例

生成开始时:

  • memories_since_last_persona = 3

生成期间另一条 L1 队列新增:

  • +2 条记忆

旧行为:

  • 完成后直接清零为 0

修复后:

  • 只消费当前 Persona 覆盖的 3
  • 新增的 2 条继续保留

Related Issue | 关联 Issue

Related to #157

#177 仍是清理后计数重校准的标准修复;本 PR 仅处理 Persona 生成期间的并发覆盖竞态,因此不使用 Fixes #157

Change Type | 修改类型

  • Bug fix | Bug 修复
  • Concurrency safety | 并发安全

Verification | 验证

  • 定向测试:4/4 通过
  • 完整测试:71/71 通过
  • 插件及三个脚本构建:通过
  • git diff --check:通过

自测覆盖:

  • Persona 生成期间新增记忆不会被清零
  • 无并发更新时仍正常消费全部基线
  • 旧单参数 API 保持兼容
  • 清理导致计数低于基线时不会出现负数
  • 场景更新时间使用生成开始水位

验证截图

image

@YOMXXX YOMXXX left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved.

I verified the PR locally on the branch with Node 24.15.0:

  • COREPACK_ENABLE_AUTO_PIN=0 pnpm vitest run src/utils/checkpoint.test.ts — 1 file / 4 tests passed
  • COREPACK_ENABLE_AUTO_PIN=0 pnpm test — 5 files / 71 tests passed
  • COREPACK_ENABLE_AUTO_PIN=0 pnpm build — passed
  • git diff --check HEAD~1..HEAD — passed

This is complementary to #177 rather than a duplicate of the recalibration lane. #177 handles post-cleanup counter reconciliation; this PR fixes the runtime race where persona generation clears work that arrived while the persona model was running. The baseline/coverage approach preserves concurrent L1 memory increments, keeps the legacy single-argument API behavior, and uses the scene time watermark captured before reading scene data.

@Maxwell-Code07

Copy link
Copy Markdown
Collaborator

Thank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program!
We have successfully received your submission. The program is currently in full swing, and we will complete the Code Review for you as soon as possible. Please keep an eye on the status notifications for this PR so you can follow up promptly once the review feedback is provided.
Thanks again for your contribution and open-source spirit! 🚀

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.

3 participants