Skip to content

Commit 1931508

Browse files
authored
Merge pull request #535 from slow-stack/fix/534-dream-decision-evidence
fix(dream): 失败轮不再什么都不留下:原文进 raw_output、skipped 补三布尔、校验判决补回审计行(#534)
2 parents 2139237 + 2ab0b7e commit 1931508

13 files changed

Lines changed: 672 additions & 31 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-3E63DD?style=flat-square" alt="license"></a>
1111
<a href="https://github.com/slow-stack/mneme/actions"><img src="https://img.shields.io/github/actions/workflow/status/slow-stack/mneme/ci.yml?style=flat-square&label=CI" alt="CI"></a>
1212
<a href="https://nodejs.org"><img src="https://img.shields.io/badge/node-22%2B-3E63DD?style=flat-square&logo=nodedotjs&logoColor=white" alt="node"></a>
13-
<a href="https://github.com/slow-stack/mneme"><img src="https://img.shields.io/badge/tests-2547%20passed-3E63DD?style=flat-square" alt="tests"></a>
13+
<a href="https://github.com/slow-stack/mneme"><img src="https://img.shields.io/badge/tests-2558%20passed-3E63DD?style=flat-square" alt="tests"></a>
1414
<a href="https://codecov.io/gh/slow-stack/mneme"><img src="https://img.shields.io/codecov/c/github/slow-stack/mneme/main?style=flat-square" alt="coverage"></a>
1515
<a href="https://github.com/awesome-dsh-plugin/awesome-dsh-plugin"><img src="https://awesome-dsh-plugin.com/badge.svg" alt="Awesome"></a>
1616
</p>
@@ -270,7 +270,7 @@ dsh-mneme-serve # 默认 ~/.dsh/memory + 127.0.0.1:8790
270270

271271
```bash
272272
cd dsh-mneme && npm install
273-
npm test # 2547 个测试
273+
npm test # 2558 个测试
274274
npm run stress # 三轴线压测
275275
npm run sync # src → lib 同步
276276
```
@@ -550,7 +550,7 @@ Community projects that wire mneme into more platforms — not part of this repo
550550

551551
```bash
552552
cd dsh-mneme && npm install
553-
npm test # 2547 tests
553+
npm test # 2558 tests
554554
npm run stress # three-axis stress test
555555
npm run sync # src → lib sync
556556
```

‎dsh-mneme/CHANGELOG.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
- **宿主「极简模式」为什么不生效,现在写在用户点开关的那一页(#514)**:现象是用户在「设置 → 个性化 → 人格定义」开了人格却发现没生效,而解释一直只长在状态页那张告示卡上——他开关了归开关,原因在另一个 tab。定位结论是**宿主侧压制、不是插件缺陷**:极简预设(minimal)把整条 system prompt 接管,`runtime context` 整个不进,记忆 / 画像 / 人格一律到不了模型;插件的轻量档刻意不关人格。这一版把告示搬到人格卡与运行模式卡各渲染一次,两处共用同一份取数(`useInjectStatus`),并把「轻量 / 标准」与「极简模式(minimal 预设)」这两个会同屏出现的词在文案里明确分开——不先分开说,用户永远会把宿主的 minimal 记成插件的 light。告示只在 `suppressed`(autoInject 开着**且**宿主确实报了 minimal)时为真:主动关掉注入的用户、preset 未知的宿主一个字的打扰都收不到。
2323
## 🐛 修复
2424

25+
- **dream 的失败轮不再什么都不留下:模型原文进 `dream_runs.raw_output`、每条被跳过的决策带三个「模型到底给没给」的布尔、校验判决补回审计行(#534,报告与实测由 @strange2000 提供)**:报告者的现场是一台跑了 13 小时的库——19 轮巩固里 **17 轮整轮无效**(16 轮 `invalid decisions: 1 errors`、1 轮 `no json array`),只有 2 轮 ok 而其中 applied 也是 0,941,476 输入 / 339,079 输出 token 花出去,**一条记忆都没落**。真正要命的不是失败,是**失败没有留下任何东西**:整轮被拒时行上的 `decisions` 只有一个 `{ _validationFailed: true, errors, skipped }` 哨兵,`skipped` 每条只有 `{ index, action, ids, error }` 四键,而「压根没解析出 JSON 数组」那条分支连这个哨兵都没有(`decisions` 落 NULL)——模型到底吐了什么形状,事后一个字都查不到,只能靠猜。三处一起补,**都是只加观测、不动任何判定**:① `skipped` 每条补 `has_keepSource` / `has_title` / `has_content` 三个布尔(原四键一字不动)。它们把 `skipped` 从「一句错误串」变成可计数的形状:读到「merge 缺 title」时,`has_title: false` 说明模型根本没给这个字段(该改提示词),`has_title: true` 说明给了但值不合规(该改校验或提示词里的样例)——两种病因的修法完全不同,而此前只能读到同一句错误。**只加布尔不加原文**:原文在下面两处,而 `skipped` 会按轮累积进一行 JSON,逐条抄正文会让这一列随失败轮数线性膨胀。② 新增列 `dream_runs.raw_output`(幂等 `addColumn`,存量行 NULL),内容是模型原文的**头 300 字 + 仅当超过 500 字时补末 200 字**,口径逐字沿用 #502/#504 的 `summarizeParseFailureAudit`。只留头尾是刻意的:模型跑飞时中段是重复噪声,头尾才分别在「它怎么起手」和「它怎么收尾」上给线索,而整段原文一轮可有数十 KB。**只在「拿到文本但解析或校验没过」时写**:流以错误结束(`result === undefined`,一次限流或超时)根本没有文本可留,落 NULL 而不是落一个空壳对象——把「没有」写成「有但为空」正是这一版要消灭的那种误导。③ 两套账分账。审计行在 LLM 返回的那一刻就写死了 `status`,而决策校验发生在调用**之后**,于是一轮「调用成功、输出被整单拒绝」在 `llm_audit_logs` 里永远是 `success`——聚合出来的成功率 95%、`dream_runs` 的真实整轮成功率 10.5%,同一件事两个数。做法是 `runAuditedLlm` 把刚落库那一行的 id 交回调用方(`spec.auditRef`),校验判决出来时用新增的 `store.annotateLlmAudit(id, patch)` 把 `metadata.decision_validation = { verdict, error_count, skipped_count, survivor_count, invalid_actions }` **浅合并**进那一行。`verdict` 四档:`unparsed`(没解析出数组)/ `rejected`(整单拒绝)/ `degraded`(应用了合法子集)/ `ok`。**绝不改 `status` / token / 时间戳**——那些是调用层的事实,改写它们等于伪造账本;`metadata` 在表里本来就写明是 free-form extras,把校验判决放进去既补上了分账,又不制造第二张表。分账**刻意不进 `GET /dream-status` 的 `lastRun`**:那九个字段有测试整组 `deepEqual` 锁着,而这次要的是「能对上账」,不是「面板多一个数」。**三处刻意的取舍**:(a) 原文**不做进 `decisions` 列**——那一列的语义是「可重放的决策数组」(`applyDecisions` 直接吃它),塞非决策对象会污染重放者与所有按决策数组消费的下游,而失败轮哨兵 `_validationFailed` 也只表达「整单拒绝」这一件事;(b) **不新开 `operation_type`**(如 `dream_validate`)——`dream.test.js` 把 `dream_consolidate` / `dream_summarize` 两个值锁死了,而校验不是一次 LLM 调用,给它单独记一行反而让「调用成功率」这个分母失真;(c) 报告者建议里那条「最小字段的 merge 降级成 keep」**不做**:它确实能把轮次从 failed 救回 ok,代价是把模型的格式错误静默吞掉——那正是这一版要修的病,救回来的是一轮看起来成功了的空转。**另外**:报告者建议的「全 keep 空转标 noop」在现有代码里**已经实现**(`noChange` 判据 + `status = summaryStored ? "ok" : "noop"`),作者看到的 ok 是因为总览那一步成功存了一版新的——那是仓库里写明的口径(「all-keep + summary 是一次实质的总览刷新」),要改得先改这条定性,不在本批。回归测试 +11(`test/dream-decision-evidence.test.js`):截断口径与空文本整键不写、拒收轮与合法子集的载荷形状一致、`skipped` 三布尔的真假三格(含「字段齐但值不合规」与「空白字符串」)、解析失败轮原文落库而 `decisions` 仍为 NULL、整单拒绝轮同样落原文、流错误落 NULL、校验判决补回后 `status` 不变、调用成功但整单拒绝时同一行读出两层结论、degraded 的 `survivor_count` 对得上、全部合法的轮次 metadata 不长多余键,外加一条静态锁禁止往 `decisions` 列塞非决策对象。
26+
2527
- **dream 的 merge 被 `dreamMergeGuard` 永久拦死:提示词还在催合并,46 轮零合并、每轮照付满载 token(#521)**:两个护栏从来没对齐过——`archive` 早就有逃生门(`reason` 命中 `ARCHIVE_RATIONALE_RE` 的「重复/过时」词表就放行长保留类型),`merge` 没有;而 `src/lang.js` 的巩固提示词【任务】第 1 条明确要求「识别主题相近的条目 → merge」,【硬性规则】里的长保留类型禁区**只对 archive 说过**。报告者的实测:46 轮巩固、`skipped` 决定 299 条里 280 条(93.6%)被这条护栏拦下且 `action` 全是 merge,整轮 `applied` 合计 375 条、**merge 恒为 0**;模型提的永远是同一簇 preference,全被拦 → 什么也没变 → `updated_at` 不动 → 下一轮同样条目还在 200 条窗口里 → 再提一次。单轮 `input_count` 46 轮全部 200(窗口饱和),同一条记忆 46 轮里被提出去合并 40 次。**模型没错,护栏也没错,两者从未对上。** 两条一起改:① 提示词(zh/en × consolidation + conflictFull 四处)补上 merge 的类型禁区,与 archive 那句同形——「长保留类型仅当确属重复或过时才可 merge,且 reason 必须写明;只是主题相近请输出 keep」;② `src/dream/decisions.js` 的 merge 护栏加逃生门,条件与 archive 护栏同一条词表且**要求所有 id 同类型**(跨类型合并本就另受 `allowCrossTypeMerge` 约束,逃生门不跟着放宽)。reason 只写「主题相近」不会命中词表——这是故意的:相近不等于重复,只有确属重复/过时才值得牺牲两条独立表述。**默认值不变**(`dreamMergeGuard` 仍默认 `true`),报告者也明确不请求关掉它——它默认开有理由(E8 实测 10/26 条被丢约束已归位 guarded 类型仍被 merge 吃掉)。两条链路共用同一 `validateDecisions`(`src/dream.js:1244` 主链路 + `src/dream/sleep.js:393` sleep 链路),改一处两处都受益。回归测试 +3:真重复放行、只有理由不同类不放行、同类型但只写「主题相近」仍拦。
2628
- **面板看不出「一整类动作 100% 失败」:`status: degraded` + `applied: 3` 从外面看完全是健康轮(#521 附带)**:`skipped` 明细此前只落库,`GET /dream-status` 的响应里没有聚合,不自己写 SQL 展开 `dream_runs.skipped` 根本看不出问题——报告者那个 bug 跑了一整天才发现。`skipped[].error` 还带 `decision[N]:` 序号前缀,朴素 `GROUP BY` 会把同一原因拆成 20 组。新增 `normalizeSkipReason` / `summarizeSkipped`(住在 `src/dream/decisions.js`,与产生这些 error 的校验器同一文件,措辞不会漂移),只剥序号前缀与具体 id/类型集合,其余措辞原样保留;按 `(action, reason)` 二元组计数——同一句原因在 merge 和 archive 上是两回事,混在一起会误导。响应新增 `skippedCount`(原始条数)与 `skippedReasons`(聚合桶,按条数降序),面板状态页在最近巩固卡下方多一张告警色卡,最多列 4 类、其余折叠成「另有 N 类」。
2729
- **上一版那三条(#521)在评审里被挑出五处,逐条修完**:① **跳过明细原先藏在默认折叠区里**——`StatusPanel` 的「后台运转」区默认收起且收起时不挂载子卡,而跳过卡就挂在那儿,于是「一整类动作 100% 被拦」在首屏照样看不见,等于把 #521 的病换个地方犯。现在明细提到 `TokenFlowSection` 的 KPI 带下方(首屏,复用同一次 `/dream-status` 请求,不新增请求),渲染体抽成 `SkippedReasonsNotice` 供两处共用,折叠区不再重复一份——同一个数字在首屏与展开区各出现一次,读者会以为有两批跳过。② **`normalizeSkipReason` 只剥得掉第一个序号前缀**:一条决策可能攒下多条错误,`skipped[].error` 用 `"; "` 拼接,而原正则 `^` 锚定、只换一次,`decision[1]:` 留在字符串中间,聚合时同类原因又被拆成多组——正是 #521 抱怨的那个病。改成先按 `; decision[N]:` 切段再逐段归一化。③ **审计文本随开放路由出网关**:校验器回给模型的自由文本尾巴(`got: "<reason 截 60 字>"`)可能夹带记忆正文、也可能被截断成没有右引号(那样按引号配对的替换根本剥不掉),而 `/dream-status` 的 policy 是 `open`。现在整段丢掉,明细仍原样留在 `dream_runs.skipped` 供排查;`action` 也一并走 `ACTIONS` 白名单,不在枚举里的归成空串——面板少一个动作标签,比让上游脏数据决定响应形状安全。④ **否定理由能穿过 merge 逃生门**:「并不重复,只是主题相近」与 `"not a duplicate"` 都含「重复」/`duplicate` 子串,放它们过闸等于让模型用一句否认换来合并许可——恰好把 #339 要防的失真放回来。新增 `NEGATED_DUPLICATE_RE` 一票否决(archive 护栏从 #104 起带着同一个洞,属既有行为,本批不动,已记在代码注释里)。⑤ **提示词示例与新规则自相矛盾**:`conflictFull` 的 merge 示例没有 `reason` 字段,模型照搬就会输出无理由的 merge 而被校验器拒掉;`consolidation` 的示例理由写的是「主题相近」,恰是新禁区明说不要 merge 的那种。四处示例(zh/en × consolidation + conflictFull)一并改成「重复」/`duplicate`。回归测试 +3(否定理由中英各一例、多段前缀 + `got:` 尾巴剥离、跳过明细首屏可见且只有一份实现)。
@@ -35,7 +37,7 @@
3537
### 贡献者 / Thanks
3638

3739
- **@z2Ace0107** — 本轮四条 PR:`/context` 的 `tier` 档位信号(#508,#383)、记忆溯源读出口 `GET /memory/provenance`(#509,#421,含「409 表示用户关了、503 表示装配坏了」这套状态码口径)、M.O. 违规去重键的两步修复(#507 与 #513,#461)。
38-
- **@strange2000** — #493 的现场报告与对照数据:蒸馏把转录当成「该我回话了」导致同一窗口确定性失败、重试越试越贵。#501(五处 prompt 未围栏)与 #502(`type` 枚举不对称)这两半都是从这份报告展开的。
40+
- **@strange2000** — 两轮现场报告。① #493:蒸馏把转录当成「该我回话了」导致同一窗口确定性失败、重试越试越贵——#501(五处 prompt 未围栏)与 #502(`type` 枚举不对称)这两半都是从这份报告展开的。② #534:19 轮巩固 17 轮整轮无效、两轮 ok 也 applied=0,而失败轮不落原始决策——「两套账对不上」(审计算 95%、真实整轮 10.5%)与「事后查不到模型吐了什么」两条都是从这份数据定位的。
3941
- **@SternChiri** — #505 的报告与复现条件:`saveWithDedupe` 的去重候选是「该类型最重要的 100 行」,库一大就静默不再合并同标题记忆。
4042
- **@zingreqe** — #514 的现象与定位线索:在 DSH 极简模式下开启人格定义却不生效。结论是宿主侧 minimal 预设压制(非插件缺陷),而「解释只长在状态页」是这一版面板改动的原因。
4143
- **@youli42** — #518 的功能请求:设置页攒到要滚半屏才找得着一个开关,希望有分类索引能直接跳。

‎dsh-mneme/README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![npm version](https://img.shields.io/npm/v/@modusensus/dsh-mneme?color=blue&label=npm)](https://www.npmjs.com/package/@modusensus/dsh-mneme)
66
[![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
77
[![Awesome](https://awesome-dsh-plugin.com/badge.svg)](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)
8-
[![tests](https://img.shields.io/badge/tests-2547%20passed-success)](https://github.com/slow-stack/mneme)
8+
[![tests](https://img.shields.io/badge/tests-2558%20passed-success)](https://github.com/slow-stack/mneme)
99
[![CI](https://img.shields.io/github/actions/workflow/status/slow-stack/mneme/ci.yml)](https://github.com/slow-stack/mneme/actions)
1010
[![node](https://img.shields.io/badge/node-22%2B-blue)](https://nodejs.org)
1111
[![npm downloads](https://img.shields.io/npm/d18m/@modusensus/dsh-mneme.svg?color=blue&label=downloads)](https://www.npmjs.com/package/@modusensus/dsh-mneme)
@@ -214,6 +214,8 @@ v0.3.0 起新增**记忆基因**层:从记忆里抽取**命名实体**、**带
214214

215215
每次**后台 LLM 调用**都会写入 `llm_audit_logs` 表:`tokens` / `duration` / `status` / `source`(由哪个触发产生)。失败调用记为 `status=error`,绝不阻塞功能本体;`retentionDays`(默认 90)在启动时清理超期行。
216216

217+
巩固那一轮还有一层**事后判决**:调用成功不等于决策可用,而校验发生在调用之后。判决以 `metadata.decision_validation`(`verdict` / `error_count` / `skipped_count` / `survivor_count` / `invalid_actions`)浅合并回同一行——`status`、tokens、时间戳一律不改,它们是调用层的事实。`verdict` 四档:`unparsed`(没解析出 JSON 数组)/ `rejected`(整单拒绝)/ `degraded`(只应用了合法子集)/ `ok`。有了这一层,「调用成功率」与「整轮有效率」才对得上账。
218+
217219
覆盖的后台调用(`source` 即触发源,`operation_type` 区分同一源下的不同调用):
218220

219221
| `source` | `operation_type` | 说明 |
@@ -717,7 +719,7 @@ src/
717719
├── api.js # HTTP 路由(Web 面板数据通道,含 /conflicts 冲突队列)
718720
└── index.js # 插件接线
719721
lib/ # src 的同步分发产物(npm run sync,prepack 钩子在发布时自动跑;一致性由 scripts/check-sync.js 在 CI 与 release.yml 校验——它只查不同步;唯一手写例外 lib/client.js——Web 面板 bundle,sync 不覆盖)
720-
test/ # 2547 个 node:test 测试(审计与三轴线压测不变量;src↔lib 一致性由 scripts/check-sync.js 发布闸门校验)
722+
test/ # 2558 个 node:test 测试(审计与三轴线压测不变量;src↔lib 一致性由 scripts/check-sync.js 发布闸门校验)
721723
scripts/ # e2e-dsh.js 端到端演示 · stress-dsh.js 三轴线压测 · sync-lib.js 同步 · check-sync.js 发布闸门 · benchmark-recall.js / benchmark-embed.js / benchmark-rerank.js 基准 · sync-test-badge.mjs 测试徽章 · build-runtime-manifest.mjs 运行时清单
722724
```
723725
@@ -726,7 +728,7 @@ scripts/ # e2e-dsh.js 端到端演示 · stress-dsh.js 三轴线压
726728
```bash
727729
cd dsh-mneme
728730
npm install # 安装 peer 依赖(以 devDependencies 形式,用于本地测试)
729-
npm test # 运行 2547 个测试
731+
npm test # 运行 2558 个测试
730732
npm run stress # 三轴线压测:长会话检索 / 冲突仲裁 / 多 Agent 并发(离线 mock LLM)
731733
npm run sync # 把 src/ 同步到 lib/(发布时由 prepack 钩子自动执行)
732734
```

‎dsh-mneme/docs/STORAGE.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dsh-mneme reclaim --json # 原始 JSON,给脚本用
3131
|---|---|---|
3232
| `dream_runs.input`(窗口外) | 置空 | 它是当时的记忆库快照,可由记忆库重建 |
3333
| `dream_runs` 的骨架 / `decisions` / `outcome` / `receipt` | 不动 | 不可重建:拆了就回放不了那次裁决 |
34+
| `dream_runs.raw_output` | 不动 | 失败轮的诊断摘要(#534):收到文本但解析或校验失败时留下的原文头尾,只在那一次调用里存在过,日志滚掉就再也拿不回来。**它不参与回放**——删了不会让保留的决策放不出来,只是丢掉「模型当时到底吐了什么」这条证据;无正文的流错误本来就是 `NULL` |
3435
| `memories.embedding`(`archived = 1`) | 置空 | 检索恒带 `archived = 0`,按定义不可达 |
3536
| `memories` 的行 | 一条不删 | 本入口止体积不止条数;条数与重复归 #254 与整理动作面 |
3637
| 活跃行的向量 | 不动 | 检索正在用 |

0 commit comments

Comments
 (0)