dsh-memu-memory 1.3.9 → 1.3.10

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,13 @@
1
1
  # 更新日志 / Changelog
2
2
 
3
+ ## [1.3.10] - 2026-11-19
4
+
5
+ > 冻结退避优化(1.3.9 复审建议级项落地):snapshot-failed 熔断期不再每 5 分钟重读快照/种子、不占整理 budget,且冻结后到来的新真人回合立即让路。
6
+
7
+ - **冻结会话退避**:熔断回执补 `frozenAt`(连同已有 `cooldownUntil`),`cycle.js` 据此写独立持久字段 `sleepFrozenUntil`/`sleepFrozenAt`,候选阶段守卫跳过「仍在冻结期且无新活动」的重复扫入——省去冻结期每扫的快照捕获 + 种子召回与 budget 名额占用。刻意不复用 `sleepRetryAt`:它不因新消息清零,复用会挡死冻结期到来的新活动。
8
+ - **新活动让路**:守卫在 `lastTurnAt` 越过 `frozenAt` 时立即放行——新事件改快照哈希、闸门本就放行,退避只挡无新活动的重复扫入,不惩罚新活动。成功结算与 sessionGone 路径清零冻结字段;非冻结 deferral 顺手清残留。
9
+ - 用例:`tests/regression-sweep.test.mjs` 新增「冻结期退避 + 新真人回合立即让路」(以探针时间戳判定是否重入,对守卫缺失敏感);冷却到期用例同步拨动绑定侧 `sleepFrozenUntil`,与账本冷却同时到期。
10
+
3
11
  ## [1.3.9] - 2026-11-19
4
12
 
5
13
  > 联合扫雷 #3 / #4 / #5:全局提炼兼容两代宿主激活契约、空闲整理不再被熔断/多窗尾段/归档会话/冷 inbound 残骸永久卡死。附带复审修正与保守死代码清理。
package/lib/cycle.js CHANGED
@@ -134,6 +134,12 @@ export async function runSleepPass(ctx, { now = Date.now(), log = () => {}, limi
134
134
  const inboundFreshAt = Math.max(Date.parse(binding.lastInboundAt) || 0, Date.parse(binding.lastInboundOutcome?.at) || 0)
135
135
  if (binding.inbound?.pending?.length && now - inboundFreshAt < INBOUND_PENDING_HOT_MS) continue
136
136
  if ((Date.parse(binding.sleepRetryAt || '') || 0) > now) continue
137
+ // 冻结退避(1.3.10):snapshot-failed 熔断期不再每扫重读快照/种子、不占 budget 名额。
138
+ // 但冻结后来了新真人回合(lastTurnAt 越过 frozenAt)立刻让路——新事件改快照哈希、
139
+ // 闸门本就会放行;退避只挡「无新活动的重复扫入」,不惩罚新活动。独立字段,不碰
140
+ // sleepRetryAt(后者不因新消息清零,复用它会挡死冻结期新活动)。
141
+ const frozenUntil = Date.parse(binding.sleepFrozenUntil || '') || 0
142
+ if (frozenUntil > now && (Date.parse(binding.lastTurnAt) || 0) <= (Date.parse(binding.sleepFrozenAt) || 0)) continue
137
143
  // Backlog first, then real idle, then cheap probes: a sweep with a limited
138
144
  // budget must not let probe-only sessions crowd out work that is actually due.
139
145
  candidates.push({ binding, activeAt, trigger: idle ? 'idle' : 'backlog', priority: backlog ? 3 : idle ? 2 : 1 })
@@ -181,10 +187,14 @@ export async function runSleepPass(ctx, { now = Date.now(), log = () => {}, limi
181
187
  if (result.settled === false) {
182
188
  // 任何没结算的结果都要记探针时间,不只是「水位不足」那两种:low-score 也
183
189
  // 会读一遍转录并打分,不记就会在每次 5 分钟扫描里把同一段重读一遍。
184
- // 后续:snapshot-failed 冻结回执带 cooldownUntil,可据此退避省去冻结期每扫
185
- // 重读快照/种子;但不能直接写 sleepRetryAt——它不因新消息清零,会把冻结期
186
- // 到来的新活动一并挡死,需「冻结感知且不惩罚新活动」的独立字段再做。
187
- setSessionBinding(binding.sessionId, { lastConsolidationProbeAt: new Date(now).toISOString() })
190
+ const patch = { lastConsolidationProbeAt: new Date(now).toISOString(), sleepFrozenUntil: null, sleepFrozenAt: null }
191
+ // snapshot-failed 冻结:写独立退避字段,候选阶段守卫据此跳过无新活动的重复
192
+ // 扫入;新真人回合到来即让路。非冻结的 deferral 顺手清掉可能残留的冻结字段。
193
+ if (result.reasonCode === 'snapshot-failed-too-many' && result.cooldownUntil) {
194
+ patch.sleepFrozenUntil = result.cooldownUntil
195
+ patch.sleepFrozenAt = result.frozenAt || null
196
+ }
197
+ setSessionBinding(binding.sessionId, patch)
188
198
  log(`sleep consolidation deferred for ${binding.sessionId}: ${result.skipped || 'not settled'}`)
189
199
  continue
190
200
  }
@@ -198,13 +208,14 @@ export async function runSleepPass(ctx, { now = Date.now(), log = () => {}, limi
198
208
  }
199
209
  setSessionBinding(binding.sessionId, {
200
210
  sleepRetryAt: null, sleepAttempts: 0, lastSleepError: null,
211
+ sleepFrozenUntil: null, sleepFrozenAt: null,
201
212
  lastConsolidationProbeAt: new Date(now).toISOString(),
202
213
  })
203
214
  // A terminal policy skip (greetings, no new events) advances the sleep stamp
204
215
  // but is not a verified worker run; `ran` must keep that distinction.
205
216
  if (!result.skipped) ran += 1
206
217
  } else if (isGoneSessionError(result?.error)) {
207
- setSessionBinding(binding.sessionId, { sessionGone: true, sessionGoneAt: new Date(now).toISOString(), sleepRetryAt: null, sleepAttempts: 0, lastSleepError: String(result.error) })
218
+ setSessionBinding(binding.sessionId, { sessionGone: true, sessionGoneAt: new Date(now).toISOString(), sleepRetryAt: null, sleepAttempts: 0, sleepFrozenUntil: null, sleepFrozenAt: null, lastSleepError: String(result.error) })
208
219
  try { clearSessionState(binding.sessionId) } catch {}
209
220
  log(`sleep consolidation dropped ${binding.sessionId}: the conversation no longer exists`)
210
221
  } else {
@@ -214,7 +225,7 @@ export async function runSleepPass(ctx, { now = Date.now(), log = () => {}, limi
214
225
  }
215
226
  } catch (error) {
216
227
  if (isGoneSessionError(error?.message)) {
217
- setSessionBinding(binding.sessionId, { sessionGone: true, sessionGoneAt: new Date(now).toISOString(), sleepRetryAt: null, sleepAttempts: 0, lastSleepError: String(error.message) })
228
+ setSessionBinding(binding.sessionId, { sessionGone: true, sessionGoneAt: new Date(now).toISOString(), sleepRetryAt: null, sleepAttempts: 0, sleepFrozenUntil: null, sleepFrozenAt: null, lastSleepError: String(error.message) })
218
229
  try { clearSessionState(binding.sessionId) } catch {}
219
230
  continue
220
231
  }
package/lib/private.js CHANGED
@@ -1524,11 +1524,11 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
1524
1524
  const result = {
1525
1525
  ok: true, sessionId, skipped: 'snapshot-failed', settled: false, deferred: true,
1526
1526
  reasonCode: 'snapshot-failed-too-many', cooldownUntil: new Date(frozenAt + CONSOLIDATION_SNAPSHOT_FAILURE_COOLDOWN_MS).toISOString(),
1527
- snapshot: snapshotMeta, failures: Number(previous.failures) || 0, lastError,
1527
+ frozenAt: previous.at || null, snapshot: snapshotMeta, failures: Number(previous.failures) || 0, lastError,
1528
1528
  }
1529
- // 冻结期内的重复扫入不重复写活动日志:同一份冻结记录(按 previous.at 判同)
1530
- // 只在第一次返回时走 finish() 落一条,之后 sweep 每 5 分钟扫进来一次,
1531
- // 静默返回结果(cycle.js 只记 probe 时间),避免日志刷屏。
1529
+ // 冻结期活动日志去重:同一份冻结记录(按 previous.at 判同)只落一条。
1530
+ // cycle.js 现已用 sleepFrozenUntil 在候选阶段退避,正常不再每扫扫入;这里的
1531
+ // 去重兜住「冻结期新活动让路后、同哈希再次冻结」的重复返回,避免刷屏。
1532
1532
  const freezeStamp = String(previous.at || '')
1533
1533
  if (frozenLogStamps.get(opKey) !== freezeStamp) {
1534
1534
  frozenLogStamps.set(opKey, freezeStamp)
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.9",
4
+ "version": "1.3.10",
5
5
  "description": "面向长篇 RP 与陪伴对话的 DeepSeek Harness 记忆插件:三层记忆、逐轮召回、来源标注、关系图、图片附件与独立 WebUI。",
6
6
  "keywords": [
7
7
  "deepseek-harness",
@@ -223,7 +223,8 @@ test('issue #4/defect 1: a frozen snapshot is not settled, keeps the error visib
223
223
 
224
224
  test('issue #4/defect 1: the freeze expires after its cooldown and a real retry is allowed', async () => {
225
225
  // 沿用上一条冻结的 issue4-freeze:把冻结记录的 at 改到冷却期之外
226
- //(failures 保持 2),下一扫应当清零连击并真的 fork 一次。
226
+ //(failures 保持 2),下一扫应当清零连击并真的 fork 一次。绑定侧的
227
+ // sleepFrozenUntil 也要同步拨到过去——候选守卫读它,与账本冷却同时到期。
227
228
  const frozen = ledger.loadLedger().sessions['issue4-freeze']
228
229
  assert.ok(frozen, 'the ledger entry exists')
229
230
  const failedKeys = Object.entries(frozen.operations || {})
@@ -235,13 +236,42 @@ test('issue #4/defect 1: the freeze expires after its cooldown and a real retry
235
236
  }
236
237
  entry.retryAt = null
237
238
  })
238
- state.setSessionBinding('issue4-freeze', { sleepRetryAt: null, sleepAttempts: 0 })
239
+ state.setSessionBinding('issue4-freeze', { sleepRetryAt: null, sleepAttempts: 0, sleepFrozenUntil: new Date(Date.now() - 60_000).toISOString() })
239
240
 
240
241
  const ctx = fakeCtx({ live: ['issue4-freeze'], receipts: 'error' })
241
242
  await cycle.runSleepPass(ctx, { limit: 10 })
242
243
  assert.equal(ctx.created.length, 1, 'the cooldown expiry lets one real fork through (was frozen forever before the fix)')
243
244
  })
244
245
 
246
+ test('issue #4/defect 1 (1.3.10): the freeze backoff skips idle re-sweeps but yields to a new human turn', async () => {
247
+ state.updateSettings({ sleepConsolidation: true, sleepAfterIdleMinutes: 5 })
248
+ ensureIdle('issue4-freeze-yield', { minutesAgo: 60 })
249
+ const errorCtx = () => fakeCtx({ live: ['issue4-freeze-yield'], receipts: 'error' })
250
+ // 两次真实失败 + 一次闸门扫入 → 冻结并写下 sleepFrozenUntil/At。
251
+ await cycle.runSleepPass(errorCtx(), { limit: 10 })
252
+ clearBackoffs('issue4-freeze-yield')
253
+ await cycle.runSleepPass(errorCtx(), { limit: 10 })
254
+ clearBackoffs('issue4-freeze-yield')
255
+ await cycle.runSleepPass(errorCtx(), { limit: 10 })
256
+ const frozenBinding = state.getSessionBinding('issue4-freeze-yield')
257
+ const frozenAt = Date.parse(frozenBinding.sleepFrozenAt)
258
+ assert.ok(Date.parse(frozenBinding.sleepFrozenUntil) > frozenAt, 'the freeze backoff fields are written')
259
+ const probeAtFrozen = frozenBinding.lastConsolidationProbeAt
260
+
261
+ // 冻结期内、无新活动:候选守卫直接跳过——不重读快照、不更新探针时间。
262
+ clearBackoffs('issue4-freeze-yield')
263
+ await cycle.runSleepPass(errorCtx(), { limit: 10, now: frozenAt + 60_000 })
264
+ assert.equal(state.getSessionBinding('issue4-freeze-yield').lastConsolidationProbeAt, probeAtFrozen,
265
+ 'a guarded sweep does not re-enter consolidation (probe stamp untouched)')
266
+
267
+ // 冻结后来了新真人回合(lastTurnAt 越过 frozenAt):守卫立刻让路,重新扫入。
268
+ state.setSessionBinding('issue4-freeze-yield', { lastTurnAt: new Date(frozenAt + 120_000).toISOString() })
269
+ clearBackoffs('issue4-freeze-yield')
270
+ await cycle.runSleepPass(errorCtx(), { limit: 10, now: frozenAt + 120_000 })
271
+ assert.equal(state.getSessionBinding('issue4-freeze-yield').lastConsolidationProbeAt, new Date(frozenAt + 120_000).toISOString(),
272
+ 'a new human turn after the freeze yields immediately — the backoff never penalizes new activity')
273
+ })
274
+
245
275
  // —— Issue #4 缺陷 2:多窗尾段 ——
246
276
 
247
277
  test('issue #4/defect 2: a mid-window completion leaves the cursor behind and the tail is picked up by the next sweep', async () => {