Skip to content

Commit c114c56

Browse files
committed
fix(graph): #24 块3 复审修正——线索行不进 pin 池(保守档泄漏)、拆掉死变量、白名单接线(+2 键)
1 parent c44833e commit c114c56

9 files changed

Lines changed: 54 additions & 14 deletions

File tree

‎dsh-mneme/CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
## 🆕 新增
6+
7+
- **关联提示防幻觉 Injection Budget(issue #24 块3)**:图召回候选进注入时默认只参与排序、不改变注入块构成(`graphInjectHint` 关,保守档);开启后以固定句式「[检索线索]」标注、并在首个线索行前加引导语(链路信息非事实断言),条数由独立预算 `graphInjectBudget` 约束——既不受 document 预算约束、也不挤占 `maxItems` 槽位。线索行不进 pin 池(pin 会在保守档下把它放回块内,绕过开关)。新增两键注册进 feature_flags 白名单;lightMode 强制关。
8+
39
## [0.8.11] - 2026-09-30
410

511
## 🐛 修复

‎dsh-mneme/lib/inject.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,9 @@ export function createInjector(ctx, service, settings, config) {
274274
// 日志抢同一份预算后被降级」正是本议题要修的结构缺陷。单条仍有硬顶
275275
// (PINNED_CONTENT_MAX),超出照旧带截断提示,不静默。
276276
const pinnedCount = Math.max(0, Math.min(candidates.length, pinnedStats?.shown ?? 0));
277-
// #24 块3:图召回线索行(graphHint)——渲染前数出数量,若 >0 在块头插入
278-
// 一段固定引导语(链路信息非事实断言,防幻觉扩散)。线索行自身按
279-
// graphHintLine 渲染(线索/ 前缀区别于普通记忆行)。
280-
const graphCount = candidates.filter((m) => m.graphHint === true).length;
277+
// #24 块3:图召回线索行(graphHint)——引导语插在第一个线索行之前(保持块头
278+
// 语义:先声明「这些不是事实」)。线索行自身按 graphHintLine 渲染(线索/ 前缀
279+
// 区别于普通记忆行)。
281280
let graphSeen = 0;
282281
for (let i = 0; i < candidates.length; i++) {
283282
const m = candidates[i];

‎dsh-mneme/lib/service.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,10 @@ export function createService({ store, mirror, config, onWrite, logger, document
15591559
// 超预算的条数回报给调用方,在块内如实标注(绝不静默省略)。
15601560
const pinnedBudget = Math.max(0, Math.min(5, Math.floor(config?.pinnedInjectBudget ?? 0)));
15611561
// eligible 留到块外:未展示条数要等 general 槽选完才算得准(见 selected 之后)。
1562-
const eligible = pinnedBudget > 0 ? candidates.filter((m) => PINNED_MEMORY_TYPES.has(m.type)) : [];
1562+
// graphHint 行不进 pin 池:pin 是「每轮必进的约束/偏好」,而线索行按定义是
1563+
// 「链路信息、非事实断言」,且 pin 长在候选池遍历之前——不排除的话,保守档
1564+
// (graphInjectHint 关)也能从 pin 侧把它放回注入块,线索开关就被绕过去了。
1565+
const eligible = pinnedBudget > 0 ? candidates.filter((m) => PINNED_MEMORY_TYPES.has(m.type) && m.graphHint !== true) : [];
15631566
let pinned = [];
15641567
if (pinnedBudget > 0 && eligible.length > 0) {
15651568
pinned = eligible.slice(0, pinnedBudget);

‎dsh-mneme/lib/settings.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ const FEATURE_FLAG_BOOLEANS = [
5858
// Issue #219:图召回轴——查询命中实体名时把挂联记忆并入检索融合池
5959
// (默认关;依赖实体抽取产出,lightMode 强制关闭)。
6060
"entityRecallEnabled",
61+
// Issue #24 块3:关联提示防幻觉——图召回线索行以「[检索线索]」标注进注入
62+
// (默认关=线索只参与排序不进块;依赖实体抽取产出,lightMode 强制关闭)。
63+
"graphInjectHint",
6164
// Issue #164:叙述条——dream 期间按 tag 主题簇合成叙述落库(source=
6265
// narrative,evidence 回链簇内记忆;按需检索不常驻注入;默认关)。
6366
"dreamNarrativeEnabled",
@@ -143,7 +146,9 @@ const FEATURE_FLAG_INT_RANGES = {
143146
// Issue #257:sleep 冲突/模式阶段的 LLM 输出预算(原硬编码 2048,实测不足)。
144147
sleepMaxTokens: [256, 131072],
145148
// Issue #258:总览(dream_summarize)输入条数硬上限(0 = 不设上限)。
146-
dreamSummaryMaxInputs: [0, 100000]
149+
dreamSummaryMaxInputs: [0, 100000],
150+
// Issue #24 块3:图线索行的独立注入预算(0 = 线索不进块)。
151+
graphInjectBudget: [0, 5]
147152
};
148153
// 浮点开关的闭区间(与 config.js 的 z.number().min().max() 对齐)。与整数开关
149154
// 分开:面板的整数控件要求 Number.isInteger,而余弦相似度阈值必须允许小数。

‎dsh-mneme/src/inject.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,9 @@ export function createInjector(ctx, service, settings, config) {
274274
// 日志抢同一份预算后被降级」正是本议题要修的结构缺陷。单条仍有硬顶
275275
// (PINNED_CONTENT_MAX),超出照旧带截断提示,不静默。
276276
const pinnedCount = Math.max(0, Math.min(candidates.length, pinnedStats?.shown ?? 0));
277-
// #24 块3:图召回线索行(graphHint)——渲染前数出数量,若 >0 在块头插入
278-
// 一段固定引导语(链路信息非事实断言,防幻觉扩散)。线索行自身按
279-
// graphHintLine 渲染(线索/ 前缀区别于普通记忆行)。
280-
const graphCount = candidates.filter((m) => m.graphHint === true).length;
277+
// #24 块3:图召回线索行(graphHint)——引导语插在第一个线索行之前(保持块头
278+
// 语义:先声明「这些不是事实」)。线索行自身按 graphHintLine 渲染(线索/ 前缀
279+
// 区别于普通记忆行)。
281280
let graphSeen = 0;
282281
for (let i = 0; i < candidates.length; i++) {
283282
const m = candidates[i];

‎dsh-mneme/src/service.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,10 @@ export function createService({ store, mirror, config, onWrite, logger, document
15591559
// 超预算的条数回报给调用方,在块内如实标注(绝不静默省略)。
15601560
const pinnedBudget = Math.max(0, Math.min(5, Math.floor(config?.pinnedInjectBudget ?? 0)));
15611561
// eligible 留到块外:未展示条数要等 general 槽选完才算得准(见 selected 之后)。
1562-
const eligible = pinnedBudget > 0 ? candidates.filter((m) => PINNED_MEMORY_TYPES.has(m.type)) : [];
1562+
// graphHint 行不进 pin 池:pin 是「每轮必进的约束/偏好」,而线索行按定义是
1563+
// 「链路信息、非事实断言」,且 pin 长在候选池遍历之前——不排除的话,保守档
1564+
// (graphInjectHint 关)也能从 pin 侧把它放回注入块,线索开关就被绕过去了。
1565+
const eligible = pinnedBudget > 0 ? candidates.filter((m) => PINNED_MEMORY_TYPES.has(m.type) && m.graphHint !== true) : [];
15631566
let pinned = [];
15641567
if (pinnedBudget > 0 && eligible.length > 0) {
15651568
pinned = eligible.slice(0, pinnedBudget);

‎dsh-mneme/src/settings.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ const FEATURE_FLAG_BOOLEANS = [
5858
// Issue #219:图召回轴——查询命中实体名时把挂联记忆并入检索融合池
5959
// (默认关;依赖实体抽取产出,lightMode 强制关闭)。
6060
"entityRecallEnabled",
61+
// Issue #24 块3:关联提示防幻觉——图召回线索行以「[检索线索]」标注进注入
62+
// (默认关=线索只参与排序不进块;依赖实体抽取产出,lightMode 强制关闭)。
63+
"graphInjectHint",
6164
// Issue #164:叙述条——dream 期间按 tag 主题簇合成叙述落库(source=
6265
// narrative,evidence 回链簇内记忆;按需检索不常驻注入;默认关)。
6366
"dreamNarrativeEnabled",
@@ -143,7 +146,9 @@ const FEATURE_FLAG_INT_RANGES = {
143146
// Issue #257:sleep 冲突/模式阶段的 LLM 输出预算(原硬编码 2048,实测不足)。
144147
sleepMaxTokens: [256, 131072],
145148
// Issue #258:总览(dream_summarize)输入条数硬上限(0 = 不设上限)。
146-
dreamSummaryMaxInputs: [0, 100000]
149+
dreamSummaryMaxInputs: [0, 100000],
150+
// Issue #24 块3:图线索行的独立注入预算(0 = 线索不进块)。
151+
graphInjectBudget: [0, 5]
147152
};
148153
// 浮点开关的闭区间(与 config.js 的 z.number().min().max() 对齐)。与整数开关
149154
// 分开:面板的整数控件要求 Number.isInteger,而余弦相似度阈值必须允许小数。

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,9 @@ test("GET /api/dsh-mneme/features returns empty overrides and effective config d
669669
// issue #239 第 4 项镜像到巩固新增 dreamPeakHours/dreamPeakMaxDeferMinutes,
670670
// issue #292 新增 autoDreamFailureBackoff、
671671
// issue #254 新增 writeAdmission.enabled/writeAdmission.enforce,
672-
// issue #34 恢复(#333)新增 injectTimePrefix)
673-
assert.equal(Object.keys(data.effective).length, 59 + 3 + 2 + 1 + 2 + 2 + 2 + 1 + 1 + 1 + 2 + 1 + 2 + 1);
672+
// issue #34 恢复(#333)新增 injectTimePrefix、
673+
// issue #24 块3 新增 graphInjectHint/graphInjectBudget)
674+
assert.equal(Object.keys(data.effective).length, 59 + 3 + 2 + 1 + 2 + 2 + 2 + 1 + 1 + 1 + 2 + 1 + 2 + 1 + 2);
674675
assert.equal(data.effective.dreamSkipInvalid, true);
675676
assert.equal(data.effective.allowCrossTypeMerge, false);
676677
assert.equal(data.effective.dreamMinIntervalMinutes, 0);

‎dsh-mneme/test/graph-inject-budget.test.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,23 @@ test("[检索线索] 引导语与线索行文本渲染正确(zh/en 双语)",
8282
assert.ok(lineZh.startsWith("- [线索/entity]"));
8383
const lineEn = STR.graphHintLine.en("technology", "Foo", "bar");
8484
assert.ok(lineEn.startsWith("- [hint/technology]"));
85+
});
86+
87+
// ---- 复审回归 ---------------------------------------------------------------
88+
89+
// 保守档(graphInjectHint 关)下线索行不许从 pin 池侧漏进注入块:pin 池取自打标
90+
// 之后、又不占 maxItems 名额,pin 若不排除 graphHint 行,「图召回 + 约束型记忆」
91+
// 就会在默认关档下照常进常驻注入文本,把线索开关整个绕过去。
92+
test("conservative mode: a graph hint row cannot leak in via the pin pool", () => {
93+
const { store, service } = setup({ entityRecallEnabled: true, maxInjectedItems: 5, pinnedInjectBudget: 1 });
94+
// 约束型记忆 + 命中查询实体:同时是 pin 候选与图线索候选(最坏交叉)。
95+
const mem = service.saveWithDedupe({
96+
type: "constraint", title: "部署约束", content: "生产环境不许直接改库", importance: 4
97+
}).memory;
98+
const ent = store.createEntity({ name: "PostgreSQL", type: "technology" });
99+
store.saveAttr({ entity_id: ent.id, attr_key: "k", attr_value: "v", memory_id: mem.id });
100+
101+
const selected = service.injectCandidates({ maxItems: 5, query: "PostgreSQL" });
102+
assert.equal(selected.filter((m) => m.graphHint === true).length, 0, "hint rows stay out while graphInjectHint is off");
103+
store.close();
85104
});

0 commit comments

Comments
 (0)