Skip to content

Commit 95cd15c

Browse files
committed
fix: saveWithDedupe 透传显式 epistemic_status——trustEpistemicWeighting 的写入通路缺口
- 此前创建路径丢弃显式字段,store 回退内容标记推断(中文正则);英文/无标记内容一律 落 subjective,EPISTEMIC_WEIGHTS 对整池均匀 ×0.7,重排整体空转 - E2 四臂实验(Kaggle v11)当场抓到:R+ 臂与 A 臂注入序逐条相同,2×2 的重排维失效 - undefined 保持推断行为(现有中文推断测试不受影响);显式值优先,契约同 resolveEpistemicStatus - 回归测试锁加权前后分数关系(observation 权重 1.0 不变;字段丢失则全体缩放当场红) - 测试 1204 → 1205,全量绿;src 变更已 sync
1 parent b64e924 commit 95cd15c

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎dsh-mneme/CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
## 🐛 修复
1818

19+
- **saveWithDedupe 透传显式 epistemic_status(trustEpistemicWeighting 写入通路缺口)**:创建路径此前丢弃显式字段,store 回退内容标记推断(中文正则)——英文/无标记内容一律落 subjective,EPISTEMIC_WEIGHTS 对整池均匀 ×0.7,`trustEpistemicWeighting` 的重排对工具主路径写入的记忆**整体空转**(v0.4.5 起消费者在、写入通路断;patch 路径 store.update 本来就通)。E 系列四臂实验现场抓到(重排臂与对照臂注入序逐条相同)。修复后 undefined 保持推断行为(存量零变化),显式值优先(契约同 resolveEpistemicStatus);回归测试锁「observation 加权前后分数不变——字段丢失则全体缩放当场红」。测试 1204 → **1205**。
20+
1921
- **睡眠冲突/模式阶段的输出预算可配(issue #257)**:`src/dream/sleep.js` 冲突消解与模式发现两处 `maxTokens: 2048` 硬编码提为 `sleepMaxTokens`(默认 8192,schema + 整数白名单成对落位,面板可调)。实测依据(报告者 llama.cpp 环境):默认档 24 对裁决需 2097 token,恰好压在 2048 边界(53 次运行 48 败 5 胜的「间歇性失败」指纹);`sleepActionSet: full` 六分支实测需 6967(3.4 倍越界)——该档位自 #126 引入起从未跑通过。流式计费按实际用量,调大不增加成本。
2022

2123
- **审计记账改读 `chunk.usage`,token 不再恒为 0(issue #242)**:dsh-llm 的 StreamChunk 契约把用量嵌在 `{type:"usage", usage:TokenUsage}`(TokenUsage = inputTokens / outputTokens / …),chunk 顶层没有 token 字段——dream / summarize 的审计读取把整个 chunk 当用量对象,input/output 恒为 undefined,审计行落 0(实测 7 天 49 次 success 调用 token 全 0,面板「LLM 消耗」长期显示 0)。改读 `chunk.usage ?? chunk`,`?? chunk` 兜底兼容用量平铺在顶层的替身(嵌套 + 平铺双形状回归测试)。

‎dsh-mneme/lib/service.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,11 @@ export function createService({ store, mirror, config, onWrite, logger }) {
12271227
tags: memory.tags ?? [],
12281228
importance: memory.importance ?? 3,
12291229
source: memory.source ?? "manual",
1230+
// epistemic_status 必须显式透传:省略时 store 会回退到内容标记推断
1231+
// (中文正则),英文/无标记内容一律落 subjective——E2 四臂实验当场抓到
1232+
// (trustEpistemicWeighting 的重排对 saveWithDedupe 写入的记忆整体空转,
1233+
// R+ 臂与 A 臂注入序逐条相同)。undefined 保持推断行为,显式值优先。
1234+
epistemic_status: memory.epistemic_status,
12301235
...(memory.evidence !== undefined ? { evidence: memory.evidence } : {}),
12311236
// v0.8.0 A1:scope 标注透传(store 端归一化,未标注落 NULL)。
12321237
// v0.8.1 底座:来源(auto/explicit)与决策时间随行透传。

‎dsh-mneme/src/service.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,11 @@ export function createService({ store, mirror, config, onWrite, logger }) {
12271227
tags: memory.tags ?? [],
12281228
importance: memory.importance ?? 3,
12291229
source: memory.source ?? "manual",
1230+
// epistemic_status 必须显式透传:省略时 store 会回退到内容标记推断
1231+
// (中文正则),英文/无标记内容一律落 subjective——E2 四臂实验当场抓到
1232+
// (trustEpistemicWeighting 的重排对 saveWithDedupe 写入的记忆整体空转,
1233+
// R+ 臂与 A 臂注入序逐条相同)。undefined 保持推断行为,显式值优先。
1234+
epistemic_status: memory.epistemic_status,
12301235
...(memory.evidence !== undefined ? { evidence: memory.evidence } : {}),
12311236
// v0.8.0 A1:scope 标注透传(store 端归一化,未标注落 NULL)。
12321237
// v0.8.1 底座:来源(auto/explicit)与决策时间随行透传。

‎dsh-mneme/test/epistemic.test.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,30 @@ test("conflict resolution keeps the LLM winner when disabled", () => {
296296
assert.equal(store.getById(w.memory.id).archived, false);
297297
assert.equal(store.getById(l.memory.id).archived, true);
298298
});
299+
300+
// E2 四臂实验(Kaggle v11)当场抓到的回归:saveWithDedupe 此前丢弃显式
301+
// epistemic_status,store 回退内容推断,英文/无标记内容一律 subjective——
302+
// EPISTEMIC_WEIGHTS 对整池均匀 ×0.7,trustEpistemicWeighting 的重排整体空转
303+
// (R+ 臂与 A 臂注入序逐条相同)。显式值必须穿透创建路径;undefined 保持推断。
304+
test("saveWithDedupe forwards explicit epistemic_status (rerank needs non-uniform weights)", async () => {
305+
const store = createStore(":memory:");
306+
const builder = createService({ store, mirror: null, config: {} });
307+
const bait = builder.saveWithDedupe({ type: "preference", title: "m#0", content: "User feels that daily stand-up meetings are micromanagement theater", importance: 3, epistemic_status: "subjective" });
308+
const fact = builder.saveWithDedupe({ type: "preference", title: "m#1", content: "User is a Lead Software Engineer with 15 years of experience", importance: 3, epistemic_status: "observation" });
309+
assert.equal(store.getById(bait.memory.id).epistemic_status, "subjective", "explicit subjective stored");
310+
assert.equal(store.getById(fact.memory.id).epistemic_status, "observation", "explicit field must survive saveWithDedupe (English content, inference cannot classify)");
311+
312+
const plain = createService({ store, mirror: null, config: { signalTransparency: true } });
313+
const weighted = createService({ store, mirror: null, config: { signalTransparency: true, trustEpistemicWeighting: true } });
314+
for (const s of [plain, weighted]) s.setVectorIndex(createVectorIndex({ store }));
315+
const opts = { mode: "auto", topK: 5, useRerank: false };
316+
const pRows = await plain.searchMemories("software engineer", opts);
317+
const wRows = await weighted.searchMemories("software engineer", opts);
318+
const pScore = Object.fromEntries(pRows.map((r) => [r.id, r.signals?.final]));
319+
const wScore = Object.fromEntries(wRows.map((r) => [r.id, r.signals?.final]));
320+
assert.ok(pScore[fact.memory.id] > 0, "observation entry is a candidate");
321+
assert.ok(
322+
Math.abs(wScore[fact.memory.id] - pScore[fact.memory.id]) < 1e-9,
323+
"observation keeps weight 1.0 — if scaled, the explicit field was dropped (all rows uniform subjective)"
324+
);
325+
});

0 commit comments

Comments
 (0)