Skip to content

fix(MEMMY-647): make episode evolution updates idempotent and keep contributions distinct - #740

Open
yxyi123 wants to merge 2 commits into
MemTensor:v1.2.8from
yxyi123:test/memmy-647-reproduction-v126
Open

yxyi123 wants to merge 2 commits into
MemTensor:v1.2.8from
yxyi123:test/memmy-647-reproduction-v126

Conversation

@yxyi123

@yxyi123 yxyi123 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

什么问题

Episode 演进用同一个标识同时承担了三件事:来源身份、输入修订、内容生成顺序。三者混在一起,导致重试、修订和重建时会重复计数,或者用旧的 trial 结果去验证后来才生成的内容。

具体表现:

  • Episode 再次关闭后重复计入同一份证据;重判旧的 trial 时会回滚整份统计快照,连带抹掉中间的 Policy 更新和人工检查点。
  • 自动退役的 Span 恢复原边界时,固定 id 与自己的墓碑冲突(UNIQUE constraint failed: memories.id),整批事务回滚且重试无法消除。
  • 已经通过晶化计入的来源,修订时又追加一次可信度漂移,同一来源两次影响 eta。
  • 正文真正变化后重建,旧的成功 trial 被重放,新候选直接变成 active。
  • 旧格式 A+B 共享的负经验与新来源 C 合并后,原保护被绕过,A 被计入两次。
  • 开启 cooldown 时,版本冲突要求的重试被冷却分支吞掉,worker 记为 succeeded 但 Skill 没有生成。

怎么改的

不改变统计公式,不做表结构迁移,只补身份与时序边界。

幂等

  • Episode 再次关闭不再重复计入。
  • 多 trial 重判按历史事件顺序替换原贡献,保留其间的 Policy 更新与人工检查点。
  • 隐式反馈仍可触发重判;显式反馈按记录身份保护,归属变化不再重复增加贡献。
  • 旧 trial 恢复只接受可验证的历史快照;只改了反馈归属或结算时间、其余字段不变的日志会被跳过,继续寻找真正的原始结算。

贡献身份

  • Span:同来源、同工具范围允许恢复被自动退役的 Span。只接受明确的自动退役标记(或版本匹配的退役日志),用户主动删除仍受保护。
  • Skill eta:修订时识别已经由晶化计入的 Policy 来源,只更正原贡献;新独立来源仍正常计入。
  • 内容重建:真正的正文变化放在既有 trial 历史之后,保持 candidate,使之前成功的 trial 无法验证后来生成的内容。同正文刷新只重算数值;A → B → A 也算新的重建。
  • legacy 负经验:继续保护不可拆分的旧聚合,同时让已独立记账的来源可以修订和撤回;单来源 legacy + C 可精确转换归属。
  • Skill 生成:版本冲突丢弃草稿时,撤销本次占用的冷却记录,使 worker 重试真正执行。

目标分支与基线

本 PR 目标分支为 1.2.7,基线 0ad11348。647 的全部改动以单个提交 cherry-pick 到该基线,未带入同一分支上其他工单的修改。

验证

项 结果
根级全量 npm test 7079 通过,134 跳过,0 失败
Memory 全量 1562 通过,1 跳过
Memory / Viewer TypeScript 均通过
git diff --check 通过
新增回归用例 647 复现、晶化、Span/负经验边界、冲突重试、聚类证据身份、Policy 桶新鲜度

安装包验证(macOS 26.4 / Apple Silicon / arm64 / cn / unsigned,1.2.3):

项 结果
正式打包脚本 + hdiutil verify 成功,VALID
包内 memory-runtime 与源码编译产物 5 个改动文件逐字节一致
包内运行时跑测试 135/135 定向、202/202 演进套件
同一套测试跑在上一版安装包 25 项失败
真实模型链路(包内 CLI) 正常回复

说明

  • 安装包验证在 v1.2.6 基线上完成;本轮迁移到 1.2.7 后重新执行了完整自动化测试,未重新打包 DMG。
  • 验证平台仅 macOS 26.4 / Apple Silicon / 未签名 / 国内版;Windows、Intel Mac、签名公证、Gatekeeper 放行未覆盖。
  • 安装后的覆盖升级路径未验证。
  • GUI 内的交互操作未覆盖(需要屏幕录制与辅助功能权限),底层逻辑已通过包内运行时验证。

…ntributions distinct

Episode evolution treated one identifier as source identity, input revision
and content generation order at the same time, so retries, revisions and
rebuilds could double-count contributions or validate new content with old
trial results. Separate the three concerns without changing the statistics
formulas or the table schema.

Idempotency
- Re-running an episode after it closes again no longer counts the same
  evidence twice. Multi-trial rejudgement replaces the original contribution
  in event order, preserving Policy updates and manual checkpoints that sit
  between them instead of rolling back the whole statistics snapshot.
- Implicit feedback can still trigger rejudgement; explicit feedback is
  protected by record identity, so an ownership change does not add a second
  contribution.
- Restoring an old trial only accepts a verifiable historical snapshot. A log
  that changed nothing but feedback ownership or settlement time is skipped
  while the search continues for the real original settlement.

Contribution identity
- Span: allow a retired Span to be restored at the same source and tool
  range, so a fixed id no longer collides with its own tombstone. Only an
  explicit automatic-retirement marker (or a version-matched retirement log)
  permits restoration; user deletions stay deleted.
- Skill eta: recognise Policy sources already counted through
  crystallization and revise the existing contribution instead of adding a
  second reward drift for the same source. New independent sources still
  contribute on their own.
- Content rebuild: place a genuine text change after the existing trial
  history and keep the Skill as candidate, so an earlier successful trial
  cannot validate content generated later. Same-text refreshes only
  recompute numbers; A -> B -> A is a new rebuild.
- Legacy negative experience: keep protecting unsplittable legacy aggregates
  while allowing an already tracked source to be revised and withdrawn. A
  single-source legacy row plus C can be attributed exactly.
- Skill generation: when a version conflict discards the draft, release the
  cooldown recorded by that attempt so the worker retry actually runs.

Verification
- Memory suite: 1454 passed, 1 skipped.
- Memory and viewer TypeScript checks pass.
- Installed package rebuilt from this tree (1.2.3, arm64, cn, unsigned):
  135/135 targeted tests and 202/202 evolution tests pass against the
  runtime inside the DMG, versus 25 failures on the previous package.
- Real-model smoke test through the packaged CLI replies normally.
Follow-up to the contribution-identity work, covering two places where the
separation was still incomplete.

Cluster processing identity
- processedFingerprint now hashes the evidence actually packed for the model
  instead of the Episode input revision. The input revision also moves on
  scoring timestamps and lifecycle metadata, which re-opened unchanged
  evidence; and it excludes alpha, so a genuine step change could stay
  invisible. Hashing the packed turns covers both directions. A changed
  reward still re-opens the member.

Policy induction bucket freshness
- Re-read the candidate pool for each signature with the current clock. The
  previous code reloaded candidates but filtered them by a timestamp captured
  once per job, so a candidate whose TTL expired mid-loop stayed readable, and
  the evidence revision guard compared two equally stale readings. Expired
  buckets now stay pending instead of being promoted behind a Policy that
  never legitimately saw them.

Span retirement semantics
- Align span-big-turn with the replacement rule MEMMY-647 introduced: a second
  split retires the previous span set, so only the latest split stays
  searchable. The test asserted the older accumulate-everything behaviour and
  now checks that the retired spans are marked deleted as well.

Verification (upstream/1.2.7 base):
- Root npm test passes end to end: 7079 passed, 134 skipped, 0 failed.
- Memory suite 1562 passed, 1 skipped.
- Memory and viewer TypeScript checks pass.
- Each new expectation was confirmed to fail with its fix reverted.
@yxyi123
yxyi123 changed the base branch from v1.2.6 to 1.2.7 October 26, 2026 12:29
@yxyi123
yxyi123 requested a review from Wang-Daoji as a code owner October 26, 2026 12:29
@yxyi123
yxyi123 force-pushed the test/memmy-647-reproduction-v126 branch from c25e35e to 660b3b9 Compare October 26, 2026 12:32

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants