fix(recall): 固定场景导航顺序以稳定提示前缀#469
Conversation
YOMXXX
left a comment
There was a problem hiding this comment.
Approved.
I verified the PR locally on the branch with Node 24.15.0:
COREPACK_ENABLE_AUTO_PIN=0 pnpm vitest run src/core/scene/scene-order.test.ts— 1 file / 2 tests passedCOREPACK_ENABLE_AUTO_PIN=0 pnpm test— 5 files / 69 tests passedCOREPACK_ENABLE_AUTO_PIN=0 pnpm build— passedgit diff --check HEAD~1..HEAD— passed
The change is focused and deterministic: scene entries are canonicalized by heat descending and filename ascending across read/write/sync plus final Scene Navigation rendering. The regression test covers the important cache-stability case where equal-heat scenes arrive in different input orders without mutating the caller's array.
|
Thank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program! |
关联 Issue
Related to #120
问题说明
scene-navigation属于每轮召回时生成的稳定系统上下文,其内容会参与后续提示构建和前缀缓存。当前实现只按场景
heat降序排列。同热度场景的相对顺序取决于scene_index.json的原始顺序,而该索引重建自文件系统目录枚举,目录枚举顺序并不构成稳定契约。因此,即使场景内容、热度和用户配置完全没有变化,索引重建后同热度场景仍可能换序,使生成的系统上下文字节发生变化,降低 prefix-matching cache 的可复用性。
修复方案
引入统一的确定性场景排序规则:
heat降序排列;heat相同时按filename升序排列。该规则同时应用于:
这样,相同场景集合无论来自何种目录枚举顺序,都会产生完全相同的索引和导航文本。
测试覆盖
新增回归测试验证:
范围说明
本 PR 是独立的确定性修复,不修改:
recall.injectionMode;recall.showInjected;本 PR 不声称修复 #120 后续澄清的 OpenClaw webchat 主因,只修复 TencentDB 稳定系统上下文中一个可复现的非确定性排序问题。
验证方法
针对性回归测试
验证不同输入顺序的同一组场景会生成完全相同的 Scene Navigation,同时验证索引读写顺序稳定:
npm test -- src/core/scene/scene-order.test.ts完整测试
npm test预期结果:
-Test Files 5 passed (5)
-Tests 69 passed (69)
完整构建
预期结果:
Build complete
Diff whitespace 检查
预期结果:无输出,退出码为 0。
##本地验证环境
其中针对性测试就是最小复现:测试会把相同场景按两种不同顺序传入,旧实现会让同热度场景的导航顺序随输入变化;修复后两次生成结果严格相同。这样维护者既能复现问题,也能验证修复。
验证结果
验证截图