Skip to content

Commit 272e9cd

Browse files
authored
Merge pull request #347 from slow-stack/feat/graph-passive-confirm
feat(graph): 被动确认 Passive Confirmation(issue #24 块4)
2 parents df0dabe + a798f17 commit 272e9cd

11 files changed

Lines changed: 187 additions & 10 deletions

File tree

‎dsh-mneme/CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
- **边权重演化 Weight Evolution(issue #24 块2)**:`entity_relations` 加 `weight`/`source` 两列(幂等迁移,存量行按 manual 1.0 认账)——建边来源决定初值(manual/confirmed 1.0、llm 0.4、tag 0.3),LLM 抽取自动建的边标 `source='llm'`;演化走 `bumpRelationWeight`(只加不减、封顶 1.0,单条 `UPDATE ... MIN(1.0, weight + ?)` 原子抬升,负/非有限增量在存储边界拒绝)。新增两键 `graphWeightEnabled`/`graphWeightDelta` 注册进 feature_flags 白名单,面板可启停;lightMode 强制关。触达侧接线见块4(被动确认)。
1313
- **关联提示防幻觉 Injection Budget(issue #24 块3)**:图召回候选进注入时默认只参与排序、不改变注入块构成(`graphInjectHint` 关,保守档);开启后以固定句式「[检索线索]」标注、并在首个线索行前加引导语(链路信息非事实断言),条数由独立预算 `graphInjectBudget` 约束——既不受 document 预算约束、也不挤占 `maxItems` 槽位。线索行不进 pin 池(pin 会在保守档下把它放回块内,绕过开关)。新增两键注册进 feature_flags 白名单;lightMode 强制关。
1414

15+
- **被动确认 Passive Confirmation(issue #24 块4)**:把「人工认可/删除/忽略」的确认门槛收敛成例外管理——正常触达(记忆被召回/注入)即视为对挂联关系边的被动确认,`store.getRelationsByMemory` 反查关联边后 `bumpRelationWeight` 抬一格(只加不减、封顶 1.0,自激回路由封顶遏制)。`graphPassiveConfirm` 与 heat 是独立闸门(`heatEnabled=false` 时仍可演化边权),且受块2 总闸 `graphWeightEnabled` 约束——两键同开才生效,单开通道键绕不过「演化默认关」。仅异常路径暴露给用户复核的复核 UI 留后续块。新增键注册进 feature_flags 白名单;lightMode 强制关。
16+
1517
## 🧹 工程
1618

1719
- **基线持久化回归集 9 条,全量测试 1441 → 1450**:无种子对照组与播种组同库同写入(一个仍触发、一个被拦下——锁的正是这个差异,否则播种被忽略时两条断言同真同假)、阈值照常累积(+10 条仍触发)、run 自报基线优先于现场计算(运行后再长 15 条仍不触发)、成功轮落库 / 失败轮不落、sleep 行不进 auto 基线、半个基线被拒、老库补列幂等、非法种子(半个 / 负数 / 非整数 / 非对象)一律按「没有基线」处理、收尾取证失败既不反噬审计行也不写假基线、`index.js` 接线源码锁。**变异检验**:把播种改成忽略种子(`toBaseline(baselineSeed)` 恒为空)→ 2 条变红;把「成功轮落基线」分支短路 → 1 条变红。

‎dsh-mneme/lib/config.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@ export const Config = z.object({
469469
graphWeightEnabled: z.boolean().default(false),
470470
// 单次有效触达的抬升幅度。
471471
graphWeightDelta: z.number().min(0).max(1).default(0.1),
472+
// 被动确认(issue #24 块4):heat 触达(记忆被召回/注入=被用)即对该记忆
473+
// 挂联的关系边做被动确认——bumpRelationWeight 抬一格。默认关=零行为变化;
474+
// 开=正常触达演化边权,「关系是用出来的」闭环落地(异常路径复核留后续块)。
475+
graphPassiveConfirm: z.boolean().default(false),
472476

473477
// --- 图谱锚定层(issue #24 · 块1 Activation Anchoring)-------------------
474478
// entityRecallEnabled 之上再开一层:以查询命中的实体为种子,沿实体关系表
@@ -743,6 +747,8 @@ const LIGHT_MODE_OFF = [
743747
"graphWeightEnabled",
744748
// 轻量模式不开关联提示标注(#24 块3,常驻注入文本多一段提示成本)。
745749
"graphInjectHint",
750+
// 轻量模式不开被动确认(#24 块4,依赖实体抽取产出;抽取关则无 v08 边可抬升)。
751+
"graphPassiveConfirm",
746752
// 轻量模式不开叙述条(额外 LLM 调用;#164 对齐,opt-in)。
747753
"dreamNarrativeEnabled",
748754
// 轻量模式不开 document 指针行(#230,opt-in:注册/注入/检索增强全随闸)。

‎dsh-mneme/lib/service.js‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,28 @@ export function createService({ store, mirror, config, onWrite, logger, document
593593
* on the hot recall path). A touch failure must never break search/inject.
594594
*/
595595
function touchRecalled(memories) {
596-
if (config?.heatEnabled === false || !Array.isArray(memories) || memories.length === 0) return;
596+
if (!Array.isArray(memories) || memories.length === 0) return;
597+
// heatEnabled=false 只关 touchLastAccess 的热度消费(既有语义),但 #24
598+
// 块4 被动确认独立于 heat——graphPassiveConfirm 开时照常 bump 关联边。
599+
// graphWeightEnabled 是块2 立的演化总闸:它关着时任何触达都不该改边权,被动
600+
// 确认只是它底下的一个通道(后续块还会接别的确认通道),两键同开才 bump,
601+
// 否则单开通道键就等于绕过「演化默认关」的承诺。
602+
// 两条路径都 best-effort,失败绝不阻断检索/注入。
603+
const heatOn = config?.heatEnabled !== false;
604+
const passive = config?.graphPassiveConfirm === true && config?.graphWeightEnabled === true;
605+
const delta = config?.graphWeightDelta ?? 0.1;
597606
for (const m of memories) {
598607
if (!m?.id) continue;
599608
try {
600-
store.touchLastAccess(m.id);
609+
if (heatOn) store.touchLastAccess(m.id);
610+
if (passive) {
611+
// 正常触达=对该记忆挂联关系边的被动确认;bump 只加不减封顶 1.0,
612+
// 自激回路由封顶天然遏制。「仅异常路径暴露给用户复核」的确认记录
613+
// 侧在此落地,复核 UI 留后续块。
614+
for (const rel of store.getRelationsByMemory(m.id)) {
615+
store.bumpRelationWeight(rel.id, delta);
616+
}
617+
}
601618
} catch { /* touch is best effort */ }
602619
}
603620
}

‎dsh-mneme/lib/settings.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ const FEATURE_FLAG_BOOLEANS = [
6161
// Issue #24 块1:图谱锚定层级联——命中实体作种子、沿关系表向邻居扩散
6262
// (默认关;依赖实体抽取产出,lightMode 强制关闭)。
6363
"graphAnchoringEnabled",
64-
// Issue #24 块2:边权重演化——touch 门控把被寻回路径的边权重抬升
65-
// (默认关;依赖实体抽取产出,lightMode 强制关闭)。
64+
// Issue #24 块2:边权重演化总闸——关着时任何触达都不改边权(默认关;
65+
// 依赖实体抽取产出,lightMode 强制关闭)。块4 的被动确认是它底下的一个通道。
6666
"graphWeightEnabled",
6767
// Issue #24 块3:关联提示防幻觉——图召回线索行以「[检索线索]」标注进注入
6868
// (默认关=线索只参与排序不进块;依赖实体抽取产出,lightMode 强制关闭)。
6969
"graphInjectHint",
70+
// Issue #24 块4:被动确认通道——正常触达即对该记忆挂联的边 bump 一格
71+
// (默认关;需总闸 graphWeightEnabled 同开)。
72+
"graphPassiveConfirm",
7073
// Issue #164:叙述条——dream 期间按 tag 主题簇合成叙述落库(source=
7174
// narrative,evidence 回链簇内记忆;按需检索不常驻注入;默认关)。
7275
"dreamNarrativeEnabled",

‎dsh-mneme/lib/store.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,6 +2553,7 @@ export function createStore(path) {
25532553
).all(entityId, entityId).map(toRelation);
25542554
}
25552555

2556+
/**
25562557
/**
25572558
* 批量邻接(issue #24 · 块1 锚定层级联):给定多条实体 id,一并取全部关系行
25582559
* 并归并成「每个实体 → 相邻实体 id 去重列表」的邻接表。供 anchoring.js 的
@@ -2585,6 +2586,19 @@ export function createStore(path) {
25852586
if (!list.includes(neighbor)) list.push(neighbor);
25862587
}
25872588

2589+
/**
2590+
* 按记忆反查关联边(issue #24 块4 被动确认):一条记忆被召回/注入(触达)
2591+
* 时,挂在同一记忆上的关系行即「这条关系被用过了」的证据——正常触达视为
2592+
* 被动确认,调用方据此 bumpRelationWeight。返回 toRelation 行(含 weight/
2593+
* source)。索引 idx_relations_memory 已建(#219)。
2594+
*/
2595+
function getRelationsByMemory(memoryId) {
2596+
if (!memoryId) return [];
2597+
return db.prepare(
2598+
"SELECT * FROM entity_relations WHERE memory_id = ?"
2599+
).all(memoryId).map(toRelation);
2600+
}
2601+
25882602
/** All entities (optionally name-filtered, newest first). Used by sleep phase 4
25892603
* orphan detection: an entity with zero relations is a candidate for relation
25902604
* completion. */
@@ -2971,6 +2985,7 @@ export function createStore(path) {
29712985
migrateAttrsToMemory,
29722986
getRelations,
29732987
getEntityNeighbors,
2988+
getRelationsByMemory,
29742989
setMirrorState,
29752990
getMirrorState,
29762991
markMirrorDirty,

‎dsh-mneme/src/config.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@ export const Config = z.object({
469469
graphWeightEnabled: z.boolean().default(false),
470470
// 单次有效触达的抬升幅度。
471471
graphWeightDelta: z.number().min(0).max(1).default(0.1),
472+
// 被动确认(issue #24 块4):heat 触达(记忆被召回/注入=被用)即对该记忆
473+
// 挂联的关系边做被动确认——bumpRelationWeight 抬一格。默认关=零行为变化;
474+
// 开=正常触达演化边权,「关系是用出来的」闭环落地(异常路径复核留后续块)。
475+
graphPassiveConfirm: z.boolean().default(false),
472476

473477
// --- 图谱锚定层(issue #24 · 块1 Activation Anchoring)-------------------
474478
// entityRecallEnabled 之上再开一层:以查询命中的实体为种子,沿实体关系表
@@ -743,6 +747,8 @@ const LIGHT_MODE_OFF = [
743747
"graphWeightEnabled",
744748
// 轻量模式不开关联提示标注(#24 块3,常驻注入文本多一段提示成本)。
745749
"graphInjectHint",
750+
// 轻量模式不开被动确认(#24 块4,依赖实体抽取产出;抽取关则无 v08 边可抬升)。
751+
"graphPassiveConfirm",
746752
// 轻量模式不开叙述条(额外 LLM 调用;#164 对齐,opt-in)。
747753
"dreamNarrativeEnabled",
748754
// 轻量模式不开 document 指针行(#230,opt-in:注册/注入/检索增强全随闸)。

‎dsh-mneme/src/service.js‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,28 @@ export function createService({ store, mirror, config, onWrite, logger, document
593593
* on the hot recall path). A touch failure must never break search/inject.
594594
*/
595595
function touchRecalled(memories) {
596-
if (config?.heatEnabled === false || !Array.isArray(memories) || memories.length === 0) return;
596+
if (!Array.isArray(memories) || memories.length === 0) return;
597+
// heatEnabled=false 只关 touchLastAccess 的热度消费(既有语义),但 #24
598+
// 块4 被动确认独立于 heat——graphPassiveConfirm 开时照常 bump 关联边。
599+
// graphWeightEnabled 是块2 立的演化总闸:它关着时任何触达都不该改边权,被动
600+
// 确认只是它底下的一个通道(后续块还会接别的确认通道),两键同开才 bump,
601+
// 否则单开通道键就等于绕过「演化默认关」的承诺。
602+
// 两条路径都 best-effort,失败绝不阻断检索/注入。
603+
const heatOn = config?.heatEnabled !== false;
604+
const passive = config?.graphPassiveConfirm === true && config?.graphWeightEnabled === true;
605+
const delta = config?.graphWeightDelta ?? 0.1;
597606
for (const m of memories) {
598607
if (!m?.id) continue;
599608
try {
600-
store.touchLastAccess(m.id);
609+
if (heatOn) store.touchLastAccess(m.id);
610+
if (passive) {
611+
// 正常触达=对该记忆挂联关系边的被动确认;bump 只加不减封顶 1.0,
612+
// 自激回路由封顶天然遏制。「仅异常路径暴露给用户复核」的确认记录
613+
// 侧在此落地,复核 UI 留后续块。
614+
for (const rel of store.getRelationsByMemory(m.id)) {
615+
store.bumpRelationWeight(rel.id, delta);
616+
}
617+
}
601618
} catch { /* touch is best effort */ }
602619
}
603620
}

‎dsh-mneme/src/settings.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ const FEATURE_FLAG_BOOLEANS = [
6161
// Issue #24 块1:图谱锚定层级联——命中实体作种子、沿关系表向邻居扩散
6262
// (默认关;依赖实体抽取产出,lightMode 强制关闭)。
6363
"graphAnchoringEnabled",
64-
// Issue #24 块2:边权重演化——touch 门控把被寻回路径的边权重抬升
65-
// (默认关;依赖实体抽取产出,lightMode 强制关闭)。
64+
// Issue #24 块2:边权重演化总闸——关着时任何触达都不改边权(默认关;
65+
// 依赖实体抽取产出,lightMode 强制关闭)。块4 的被动确认是它底下的一个通道。
6666
"graphWeightEnabled",
6767
// Issue #24 块3:关联提示防幻觉——图召回线索行以「[检索线索]」标注进注入
6868
// (默认关=线索只参与排序不进块;依赖实体抽取产出,lightMode 强制关闭)。
6969
"graphInjectHint",
70+
// Issue #24 块4:被动确认通道——正常触达即对该记忆挂联的边 bump 一格
71+
// (默认关;需总闸 graphWeightEnabled 同开)。
72+
"graphPassiveConfirm",
7073
// Issue #164:叙述条——dream 期间按 tag 主题簇合成叙述落库(source=
7174
// narrative,evidence 回链簇内记忆;按需检索不常驻注入;默认关)。
7275
"dreamNarrativeEnabled",

‎dsh-mneme/src/store.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,6 +2553,7 @@ export function createStore(path) {
25532553
).all(entityId, entityId).map(toRelation);
25542554
}
25552555

2556+
/**
25562557
/**
25572558
* 批量邻接(issue #24 · 块1 锚定层级联):给定多条实体 id,一并取全部关系行
25582559
* 并归并成「每个实体 → 相邻实体 id 去重列表」的邻接表。供 anchoring.js 的
@@ -2585,6 +2586,19 @@ export function createStore(path) {
25852586
if (!list.includes(neighbor)) list.push(neighbor);
25862587
}
25872588

2589+
/**
2590+
* 按记忆反查关联边(issue #24 块4 被动确认):一条记忆被召回/注入(触达)
2591+
* 时,挂在同一记忆上的关系行即「这条关系被用过了」的证据——正常触达视为
2592+
* 被动确认,调用方据此 bumpRelationWeight。返回 toRelation 行(含 weight/
2593+
* source)。索引 idx_relations_memory 已建(#219)。
2594+
*/
2595+
function getRelationsByMemory(memoryId) {
2596+
if (!memoryId) return [];
2597+
return db.prepare(
2598+
"SELECT * FROM entity_relations WHERE memory_id = ?"
2599+
).all(memoryId).map(toRelation);
2600+
}
2601+
25882602
/** All entities (optionally name-filtered, newest first). Used by sleep phase 4
25892603
* orphan detection: an entity with zero relations is a candidate for relation
25902604
* completion. */
@@ -2971,6 +2985,7 @@ export function createStore(path) {
29712985
migrateAttrsToMemory,
29722986
getRelations,
29732987
getEntityNeighbors,
2988+
getRelationsByMemory,
29742989
setMirrorState,
29752990
getMirrorState,
29762991
markMirrorDirty,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,9 @@ test("GET /api/dsh-mneme/features returns empty overrides and effective config d
671671
// issue #254 新增 writeAdmission.enabled/writeAdmission.enforce,
672672
// issue #34 恢复(#333)新增 injectTimePrefix、
673673
// issue #24 块1 新增 graphAnchoringEnabled/graphSeedCap/graphCascadeDepth、
674-
// 块2 新增 graphWeightEnabled/graphWeightDelta、块3 新增 graphInjectHint/graphInjectBudget)
675-
assert.equal(Object.keys(data.effective).length, 59 + 3 + 2 + 1 + 2 + 2 + 2 + 1 + 1 + 1 + 2 + 1 + 2 + 1 + 3 + 2 + 2);
674+
// 块2 新增 graphWeightEnabled/graphWeightDelta、块3 新增 graphInjectHint/graphInjectBudget、
675+
// 块4 新增 graphPassiveConfirm)
676+
assert.equal(Object.keys(data.effective).length, 59 + 3 + 2 + 1 + 2 + 2 + 2 + 1 + 1 + 1 + 2 + 1 + 2 + 1 + 3 + 2 + 2 + 1);
676677
assert.equal(data.effective.dreamSkipInvalid, true);
677678
assert.equal(data.effective.allowCrossTypeMerge, false);
678679
assert.equal(data.effective.dreamMinIntervalMinutes, 0);

0 commit comments

Comments
 (0)