dsh-memu-memory 1.3.4 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # 更新日志 / Changelog
2
2
 
3
+ ## [1.3.5] - 2026-11-14
4
+
5
+ > 修复宿主对同一条用户消息给出两次 `agent/pre-step` 时的重复注入:第二次召回会把已投候选全去重、注入 0 条,还多推一格 memoryClock。现在按真实用户消息 id 幂等,一条消息只注入一次;回合回滚时清标记,真重试仍会重投。
6
+
7
+ ### 注入
8
+
9
+ - **一条用户消息只跑一次注入**:`registerInjection` 记录 `lastInjectedUserMessageId`;同一 session 收到同一条用户消息的第二次 enter 决策时只保留 guide 检查,不再召回。压缩后的 reinject(`reinjectPending`)不参与该幂等。
10
+ - **回滚清标记**:`rollbackInjectionForTurn` 撤回本轮账目时一并删除标记,宿主重试同一条消息仍会正常注入。
11
+
12
+ ### 文档与测试
13
+
14
+ - `docs/troubleshooting.md` 新增 §3.30(症状 / 根因 / 守卫)与症状速查入口。
15
+ - `tests/injection-rollback.test.mjs` 新增两条:两次 enter 决策只注入一次(memoryClock 不前进、去重账目不增加);回合回滚后重试重投。
16
+
3
17
  ## [1.3.4] - 2026-11-14
4
18
 
5
19
  > 整理执行器(实验功能)与增量回合日志:设置页可选 fork / 持久 worker(worker 按 200k 字符 / 16 窗换新,窗内批量写);整理快照增加持久日志交叉核对,修掉外部追加不可见导致的整理冻结;WebUI 空闲合成负载归零。产品文档移除 benchmark 记录与文档(测试资产不进产品文档)。
package/README.md CHANGED
@@ -30,7 +30,7 @@ It is **local-first by default**. The default `agent` backend stores full text i
30
30
  > [!WARNING]
31
31
  > **Early-stage software.** This plugin is still early and may contain unforeseen errors, bugs or breaking changes. Back up your data, and please [report an issue](https://github.com/Tkingxiao/dsh-memu-memory/issues) or send a pull request — feedback helps the project improve.
32
32
 
33
- > **Status:** 1.3.4. The first public release was 1.0.0. The manual now lives in [`docs/`](docs/), with [`AGENTS.md`](AGENTS.md) as a short index. Back up `~/.dsh/dsh-memu-memory` before upgrades, and read [Compatibility & limits](#compatibility--limits) before storing data you cannot re-create.
33
+ > **Status:** 1.3.5. The first public release was 1.0.0. The manual now lives in [`docs/`](docs/), with [`AGENTS.md`](AGENTS.md) as a short index. Back up `~/.dsh/dsh-memu-memory` before upgrades, and read [Compatibility & limits](#compatibility--limits) before storing data you cannot re-create.
34
34
 
35
35
  ## Screenshots
36
36
 
package/README.zh.md CHANGED
@@ -30,7 +30,7 @@
30
30
  > [!WARNING]
31
31
  > **早期版本提示。** 本插件仍处于早期阶段,可能存在无法预见的错误、bug 或不兼容变更。请先备份数据;欢迎[提交 Issue](https://github.com/Tkingxiao/dsh-memu-memory/issues) 或 PR 帮助改进。
32
32
 
33
- > **状态:** 1.3.4。首个公开发布版本为 1.0.0。细节文档已迁到 [`docs/`](docs/),[`AGENTS.md`](AGENTS.md) 只做索引。升级前请备份 `~/.dsh/dsh-memu-memory`;如果要存无法重建的数据,请先读[兼容性与边界](#兼容性与边界)。
33
+ > **状态:** 1.3.5。首个公开发布版本为 1.0.0。细节文档已迁到 [`docs/`](docs/),[`AGENTS.md`](AGENTS.md) 只做索引。升级前请备份 `~/.dsh/dsh-memu-memory`;如果要存无法重建的数据,请先读[兼容性与边界](#兼容性与边界)。
34
34
 
35
35
  ## 界面
36
36
 
@@ -38,6 +38,7 @@
38
38
  图谱改了没生效 / 缩到最小打架 / 导航被掰竖 → §3.27
39
39
  WebUI 开着 GPU 占用高 / 时钟钉高档 → §3.28
40
40
  长链跑批库不增长 / 考试大面积「不知道」→ §3.29
41
+ 同一条用户消息每轮注入两次 / 第二次召回 0 条 → §3.30
41
42
  ```
42
43
 
43
44
  ## 3. 出过的问题:症状 → 落点 → 守卫
@@ -391,6 +392,7 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
391
392
  | §3.26 | 整理超时(fork 预算) | `tests/consolidation-fork.test.mjs`:预算随事件数缩放(0/100/200/935/5000/非法值),显式 `maxWaitMs` 仍生效,超时不推进 `lastSleepSeq`。 |
392
393
  | §3.27 | 图谱改了没生效 / 缩到最小打架 / 导航被掰竖 | `npm run check` 的 `graph bundle`(源码与 bundle 逐字节比对);`tests/graph-view.test.mjs` 的 relayout 收敛、冷启动零帧、最小缩放命中迟滞;`tests/client-render.test.mjs` 的独立外壳归属。 |
393
394
  | §3.28 | WebUI 开着 GPU 占用高 / 时钟钉高档 | `tests/webui.test.mjs` 的 `the shell keeps no always-on compositor drivers`(无限动画只许 boot、ambient 静态、模糊只许小 chrome、缩略图不轮询);`scripts/check-idle-compositing.mjs` 真机数帧(空闲 fps > 2 即 FAIL)。 |
395
+ | §3.30 | 同一条用户消息每轮注入两次 | `tests/injection-rollback.test.mjs` 的 one-pass 幂等与回滚清标记两条(同一消息 id 只注入一次;回滚后重试重投)。 |
394
396
 
395
397
  ## 附录 A · 模块地图(原 §2.1)
396
398
 
@@ -574,3 +576,13 @@ section 的 `text(context)` 能拿到 `context.agent`,所以 system prompt **
574
576
  **根因(2026-11-14 复现实测)**:跑批脚本的 `seed-session.mjs` **直接重写** `session.v4.jsonl.zstd` 追加历史(不走网关 RPC)。宿主的 `observeSession`/`readSession` 都是 live-preferred:会话一旦是活对象,两者都读活视图、不再看持久日志,外部改写完全不可见。把种子会话钉成活对象的是 inherit 模式的 `inheritedAgentOptions` resume 回退;`host`/`custom` 模式本不需要父 route,旧代码却照样探测。于是追加 372 轮后活视图仍冻结在 6 事件 → 每窗恒等 → already-consolidated 洪水 → 游标不推进。**连带**:turn-log 录制器只收 `session/event`,直接改文件同样看不到。跑批侧 `consolidateAll` 又把 already-consolidated 当完成,不校验 `throughSeq`,把可检测故障变成静默腰斩。
575
577
 
576
578
  **守卫**:`captureSessionSnapshot` 在活视图落后于持久日志时,用 `sessionPersistence` + 宿主公开导出的 `readColdSessionLog` 冷读,取更长的一份(source `persisted-ahead`;60 秒 TTL 缓存,正常活会话不受影响)。`consolidationModelMode` 为 `host`/`custom` 时不探测父会话 route,避免无意义 resume。跑批的 `consolidateAll` 对 skipped 结果校验 `through >= targetSeq`,连续 3 次落后判定 `stale` 并终止本轮。
579
+
580
+ ### 3.30 同一条用户消息每轮注入两次(第二次召回 0 条)
581
+
582
+ **症状**:WebUI 时间线里每条用户消息后出现两条「上下文注入 · plugin:dsh-memu-memory」;召回记录成对出现(例如 13:41:41 注入 4 条 / 0 条,13:45:14 / 13:45:15),turn 号成对跳(221→222、223→224)。不报错,第二次只是纯空跑。
583
+
584
+ **根因**:宿主对同一条真实用户消息给出两次 `agent/pre-step` enter 决策;插件把每次 pre-step 都当成新的一轮,重新召回。第一次已把候选记入 `injectedIds`,第二次候选全被去重,注入 0 条,同时把 memoryClock 多推一格。
585
+
586
+ **现在**:`registerInjection` 按真实用户消息 id 幂等(`binding.lastInjectedUserMessageId`)——一条消息只跑一次注入;`turn/end` 失败且注入没进转录时,`rollbackInjectionForTurn` 清掉标记,真重试仍会重投;压缩后的 reinject(`reinjectPending`)不受影响。
587
+
588
+ **守卫**:`tests/injection-rollback.test.mjs` 的 `the same real user message gets one injection pass when the host emits two enter decisions`、`a rolled-back turn clears the one-pass marker so a real retry injects again`。
@@ -56,7 +56,7 @@ export const RUNTIME_STATE = Object.freeze([
56
56
  { layer: 'temporary-map', file: 'lib/media.js:19', name: 'captures', keyedBy: 'sessionId', clearedBy: 'capture settle' },
57
57
  { layer: 'temporary-map', file: 'lib/private.js:982', name: 'inFlight', keyedBy: 'sessionId', clearedBy: 'consolidation settle' },
58
58
  { layer: 'temporary-map', file: 'lib/curator.js:56', name: 'jobs', keyedBy: 'job id', clearedBy: 'curation settle' },
59
- { layer: 'cache', file: 'lib/state.js:1230', name: 'indexCache', keyedBy: 'libraryId', clearedBy: 'next load / external write' },
59
+ { layer: 'cache', file: 'lib/state.js:1233', name: 'indexCache', keyedBy: 'libraryId', clearedBy: 'next load / external write' },
60
60
  { layer: 'cache', file: 'lib/paths.js:52', name: 'readFailures', keyedBy: 'absolute file', clearedBy: 'a later successful read' },
61
61
  ])
62
62
 
package/lib/inject.js CHANGED
@@ -1800,13 +1800,33 @@ export function registerInjection(ctx) {
1800
1800
 
1801
1801
  const offPre = ctx.on('agent/pre-step', async (payload, next) => {
1802
1802
  const decision = await next()
1803
+ // 宿主会在同一轮里对同一条真实用户消息给出两次 enter 决策(0.2.2-rc.1 实测:
1804
+ // turn 号成对跳 221→222、223→224)。第二次会重新走一遍召回,候选又全被去重,
1805
+ // 结果是 0 条注入的纯空跑,还会把 memoryClock 多推一格。按真实用户消息 id 幂等:
1806
+ // 一条消息只投一次;回合回滚时由 state.rollbackInjectionForTurn 清掉标记,真重试仍会重投。
1807
+ const stepSessionId = payload?.agent?.session?.header?.id || null
1808
+ const stepLastUser = decision?.kind === 'enter' && Array.isArray(decision.messages)
1809
+ ? lastRealUser(decision.messages)
1810
+ : null
1811
+ const stepBinding = stepSessionId
1812
+ ? (() => { try { return getSessionBinding(stepSessionId) } catch { return null } })()
1813
+ : null
1814
+ const duplicateStep = Boolean(
1815
+ stepSessionId && stepLastUser?.id && stepBinding?.reinjectPending !== true
1816
+ && stepBinding?.lastInjectedUserMessageId === stepLastUser.id,
1817
+ )
1803
1818
  try {
1804
- const injected = await injectForStep({
1805
- ...payload,
1806
- decision,
1807
- ctx,
1808
- log: (message) => { try { ctx.logger?.warn?.(`dsh-memu-memory: ${message}`) } catch {} },
1809
- })
1819
+ const injected = duplicateStep
1820
+ ? decision
1821
+ : await injectForStep({
1822
+ ...payload,
1823
+ decision,
1824
+ ctx,
1825
+ log: (message) => { try { ctx.logger?.warn?.(`dsh-memu-memory: ${message}`) } catch {} },
1826
+ })
1827
+ if (!duplicateStep && stepSessionId && stepLastUser?.id) {
1828
+ try { setSessionBinding(stepSessionId, { lastInjectedUserMessageId: stepLastUser.id }) } catch {}
1829
+ }
1810
1830
  return ensureUnifiedGuide(ctx, payload, injected)
1811
1831
  } catch (error) {
1812
1832
  try { setRecallError(payload?.agent?.session?.header?.id, `injection failed: ${error?.message || error}`) } catch {}
package/lib/state.js CHANGED
@@ -1177,6 +1177,9 @@ export function rollbackInjectionForTurn(sessionId, hostTurn) {
1177
1177
  }
1178
1178
  // 哨兵已不再进 injectedIds,必须单独撤掉它的"已投"标记,否则回滚后锚点不再重投。
1179
1179
  if (ids.has('__anchor__')) delete binding.anchorPushed
1180
+ // 这一轮注入没进转录,宿主重试时同一条用户消息会再送一次 pre-step:
1181
+ // 清掉「一消息一投」标记,让重试还能正常注入。
1182
+ delete binding.lastInjectedUserMessageId
1180
1183
  if (record.guideKey && binding.guideRulesKey === record.guideKey) {
1181
1184
  delete binding.guideRulesKey
1182
1185
  delete binding.guideMessageAt
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-memu-memory",
3
3
  "icon": "./assets/icon.png",
4
- "version": "1.3.4",
4
+ "version": "1.3.5",
5
5
  "description": "面向长篇 RP 与陪伴对话的 DeepSeek Harness 记忆插件:三层记忆、逐轮召回、来源标注、关系图、图片附件与独立 WebUI。",
6
6
  "keywords": [
7
7
  "deepseek-harness",
@@ -228,3 +228,37 @@ test('rollback also clears the day marks so dated blocks can return', async () =
228
228
  assert.equal(Object.keys(after.anniversariesShown || {}).length, 0, 'the day mark is withdrawn with the turn')
229
229
  assert.equal(Object.keys(after.openLoopRemindedAt || {}).length, 0, 'and so is the re-reminder clock')
230
230
  })
231
+
232
+ test('the same real user message gets one injection pass when the host emits two enter decisions', async () => {
233
+ const session = makeSession('dup-step')
234
+ const first = await step(session, 221, [user(1, '林眠的相机镜头维修到哪一步了?')])
235
+ const afterFirst = state.getSessionBinding(session.id)
236
+ assert.equal(afterFirst.lastInjectedUserMessageId, 'u-1', 'the first pass marks the message it handled')
237
+ const clockAfterFirst = afterFirst.inbound?.clock
238
+ const injectedAfterFirst = facts(session.id).injected
239
+ const pluginBlocks = (messages) => messages.filter((message) => message?.source?.kind === 'plugin:dsh-memu-memory').length
240
+ const blocksAfterFirst = pluginBlocks(first)
241
+ assert.ok(blocksAfterFirst > 0, 'the first pass actually injected something')
242
+
243
+ // 宿主把同一条用户消息又交给了一次 enter 决策(turn 号成对跳),第二次不应再召回。
244
+ const second = await step(session, 222, [...first])
245
+ assert.equal(pluginBlocks(second), blocksAfterFirst, 'the duplicate pass adds no second memory block')
246
+ const afterSecond = state.getSessionBinding(session.id)
247
+ assert.equal(afterSecond.lastInjectedUserMessageId, 'u-1', 'the marker stays on the handled message')
248
+ assert.equal(afterSecond.inbound?.clock, clockAfterFirst, 'the duplicate pass does not advance the memory clock')
249
+ assert.equal(facts(session.id).injected, injectedAfterFirst, 'nor does it write new dedupe accounting')
250
+ })
251
+
252
+ test('a rolled-back turn clears the one-pass marker so a real retry injects again', async () => {
253
+ const session = makeSession('dup-retry')
254
+ const first = await step(session, 1, [user(1, '林眠的相机镜头修好了吗')])
255
+ assert.equal(countWith(first, ANCHOR_RE), 1)
256
+ assert.equal(state.getSessionBinding(session.id).lastInjectedUserMessageId, 'u-1')
257
+
258
+ await failTurn(session, 1)
259
+ assert.equal(state.getSessionBinding(session.id).lastInjectedUserMessageId, undefined,
260
+ 'the rollback forgets the message so a real retry can inject again')
261
+
262
+ const retry = await step(session, 1, [user(1, '林眠的相机镜头修好了吗')])
263
+ assert.equal(countWith(retry, ANCHOR_RE), 1, 'the retry places the anchor again')
264
+ })