fix(memory): 场景键两路合并去重(现网日志实测 scenes=[chan:qq chan:qq])

现网 21:49 的 QQ 轮次日志打出 `scenes=[chan:qq chan:qq]` —— 同一键
出现两次。查因:tooldefs.go:63 与 task.go:793 是同一段拼接写法,

    scenes := a.sceneKeysFor(...)      // 内部有 seen 去重
    turn := a.resolveTurnScenes(...)
    for _, k := range turn.Keys {
        scenes = append(scenes, k)     // ← 两路之间没有共同的 seen
    }

而声明路与通道派生路都会产出 chan:qq(既是插件声明的、也是从
evt.Source 派生的),于是重复。

功能上无害(RecallByScene 内部会再去重),但有两个实际代价:日志里
的 scenes=[...] 误导排查——会让人以为场景集合本身有问题;以及每次
白走一遍前缀匹配。

修法:抽 mergeSceneKeys 共用函数(顺带消掉两处重复代码),两处调用点
都走它。判据 scenemerge_test.go 5 例:3 个合并场景(同名 / 归一化后
同名 / 多路重复)+ scene_policy=none 时两路皆空(防「声明路关了但
涌现路还开着」的半开状态)。

记忆 8 包 + agent/core 全绿,8 包齐全、无 FAIL/panic/race。
This commit is contained in:
JianFeeeee
2026-09-26 21:55:12 +08:00
parent 9f85e58c64
commit 80cbda1059
4 changed files with 105 additions and 7 deletions

View File

@ -790,9 +790,7 @@ func (a *Agent) stepToolAfter(f *TaskFrame) stepOutcome {
// 召回用两条路的并集:声明场景(注入点/通道/工具)+ 涌现场景
scenes := a.sceneKeysFor(f.Evt, tc.Name)
turn := a.resolveTurnScenes(f, tc.Name)
for _, k := range turn.Keys {
scenes = append(scenes, k)
}
scenes = mergeSceneKeys(scenes, turn.Keys)
recallText = a.memoryPass(query, "tool:"+tc.Name, needPrune, needRecall, scenes).RecallText
}
}