Skip to content

fix(dsh): replace instead of append compaction-capsule sources - #91

Open
evilh2019 wants to merge 2 commits into
adoresever:mainfrom
evilh2019:fix/replace-compaction-capsule-sources
Open

fix(dsh): replace instead of append compaction-capsule sources#91
evilh2019 wants to merge 2 commits into
adoresever:mainfrom
evilh2019:fix/replace-compaction-capsule-sources

Conversation

@evilh2019

@evilh2019 evilh2019 commented Aug 29, 2026

Copy link
Copy Markdown

问题

recordCompactionCapsule(dsh.ts)每次 DSH 会话滚动压缩产生 compaction/summary 事件时,把被压缩掉的 shadowedSeqs 追加为稳定名节点 session-memory-<sha1(sid)[0:16]> 的 source。由于:

  1. 节点名由 session id 派生 → 同一会话永远 upsert 到同一个节点
  2. saveNodeSourcesINSERT OR IGNORE无任何删除/上限/TTL
  3. 长会话反复压缩 → source 线性膨胀

实测:单一会话节点积累 10559 条 source,占全表 gm_node_sources(34392 行)的 30.7%;节点 content 只有最新一份摘要(12KB),却声称代表 1 万条消息。DB 体积膨胀至 123MB,且每次压缩都重新 embedding 摘要。

修复

  • 新增 replaceNodeSources(db, nodeId, sessionId, sources):DELETE 该节点全部旧 source 后 INSERT 本次,替换而非追加
  • recordCompactionCapsule 改为调用 replaceNodeSources:新摘要取代旧 span,节点永远只引用最近一份压缩。
  • 提取器路径(真实知识节点)语义不变——它们的 source 累积是合理证据。

验证

  • 新增 2 个针对性单测:替换语义(旧 span 消失、新 span 保留)+ 空 sources 清空溯源。
  • 全量测试:132/132 通过(17 files),tsc 构建 exit 0。
  • 行为验证(真实 DB 副本):第 1 次压缩 20 条 source → 第 2 次 10 条(替换非追加)、旧 span 零残留、content 正常更新。

影响面

  • 召回语义不变:gm_node_sources 唯一消费方是 assembleContext 的 episodic 溯源(getNodeSourceMessages),替换后溯源指向最近一份压缩的证据,更准确。
  • 数据膨胀停止:长会话不再无限累积 source。

penggaolai and others added 2 commits August 29, 2026 16:33
recordCompactionCapsule appended every shadowed span to the stable
session-memory-<hash> node forever, so long sessions grew gm_node_sources
without bound (observed: one node with 10559 rows, 30% of the table).

Add replaceNodeSources() and use it for capsule nodes so a fresh summary
supersedes the previously shadowed span instead of accumulating every
old span. Extraction-path nodes keep their append semantics unchanged.

Co-authored-by: xiaod1 <xiaod1@localhost>
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.

2 participants