Skip to content

fix(#692): 两个默认开的开关改按 !== false 读(记忆护栏 / 模型下载韧性) - #695

Merged
modusensus merged 2 commits into
mainfrom
fix/692-default-true-read
Nov 13, 2026
Merged

modusensus merged 2 commits into
mainfrom
fix/692-default-true-read

Conversation

@modusensus

@modusensus modusensus commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

问题

「默认开」的开关,默认值只写在 zod schema(src/config.js)里。经 Config(config) 的调用方(宿主 src/index.js)拿得到默认值;绕过 Config 的调用方——测试、第三方程序化 createService、直接 import 单元的装配——拿到的是 undefined。而这些开关的读法是 === true,undefined === true 为 false,于是「默认开」实际上等于默认关。

这类不一致很隐蔽:宿主里一切正常,只有程序化接入的人踩,而且现象是「开关好像没生效」,不会报错。

改了哪两处

位置 原来 现在
src/dream.js mergeGuard config?.dreamMergeGuard === true config?.dreamMergeGuard !== false
src/dream/sleep.js mergeGuard 同上 同上
src/semantic.js(装配层) cfg.resilientModelDownload(裸传,构造里 === true) resilientDownloadEnabled(cfg) → cfg?.resilientModelDownload !== false

resilientModelDownload 的判据不进构造函数:LocalEmbedder / Reranker 刻意保持「只有显式 true 才启用」,这是 issue #194 定下的直连构造契约(test/local-embedder.test.js:79 锁着「直连构造不显式给 true = 保持现状」)。默认值在装配层落定,两条装配路径共用同一个 helper。

第三处为什么不在这个 PR 里

memoryQualityFilter.enabled 也是 === true,但它挂在一个自身带 .default({}) 的对象里:只要经过 Config,对象一定存在,过滤器一直是开的。=== true 与 !== false 的差别只出现在整个对象都不传的裸配置调用方身上。

把那半边也翻过来,等于重定义「程序化 createService 的默认契约」。实测代价:全量 421 条断言变红——大量 fixture 用两三字短正文("入门"、"喜欢猫"),靠过滤器默认关才能留在库里被检索到,一旦默认开就被质量分档归档。这是接口决定,不该混在两处读法修正里悄悄发生,留在 #692 里单独拍板。

测试

  • 新增 test/issue-692-default-on-reads.test.js 3 条:裸配置下 guarded 类型(constraint,在 ARCHIVE_GUARDED_TYPES 里)的 merge 被 skip 且理由点名 dreamMergeGuard;显式 dreamMergeGuard: false 时同一条 merge 落库;resilientDownloadEnabled 三态。
  • 变异自证:两处各自改回 === true → 2 红(默认开那两条),还原 → 3/3 绿;「改成恒真」会被两条反向对照分别抓住。
  • 全量:3,499 tests / 3,498 pass / 0 fail / 1 skip(基线 3,496 / +3)。

文档

dsh-mneme/CHANGELOG.md 的 [Unreleased] 记录了这两处、落点选择,以及第三处为什么单独处理(含 421 条的数字)。

Ref #692

Summary by CodeRabbit

  • 功能更新
    • 合并保护和模型下载韧性现在默认开启;将对应配置明确设为 false 可关闭。
  • 测试
    • 增加测试,验证配置缺失和显式关闭时的行为。

dreamMergeGuard(dream 主链路与 sleep 链路各一处)与 resilientModelDownload
的默认值只写在 zod schema 里:经 Config 的调用方拿得到,绕过 Config 的调用方
(测试、第三方程序化 createService)拿到 undefined,被 `=== true` 当 false,
于是「默认开」等于默认关。两处统一改成 `!== false`。

resilientModelDownload 的判据收成 `resilientDownloadEnabled(cfg)` 放在装配层
(src/semantic.js):LocalEmbedder / Reranker 的构造函数刻意保持「只在显式
true 时启用」(issue #194 的直连构造契约,test/local-embedder.test.js 锁着),
默认值只在装配层落定。

第三处 memoryQualityFilter.enabled 本批不动——它挂在自身带 .default({}) 的
对象里,经 Config 的调用方一直是开的;翻裸配置等于重定义程序化契约,实测牵动
421 条既有断言,留在 issue 里单独拍板。

测试 3,496 → 3,499;变异自证:两处各自改回 `=== true` → 2 红。

用户 2026-11-13 反馈
Copilot AI lite review requested due to automatic review settings November 13, 2026 08:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

本次变更将 dream 合并护栏和 resilient model download 的读取逻辑改为默认启用,只有配置显式为 false 时才关闭。新增测试覆盖裸配置和显式关闭情况。

Changes: 默认开启配置读取

Layer / File(s) Summary
Dream 合并护栏
dsh-mneme/src/dream.js, dsh-mneme/src/dream/sleep.js, dsh-mneme/lib/dream.js, dsh-mneme/lib/dream/sleep.js, dsh-mneme/test/issue-692-default-on-reads.test.js
dream 合并护栏在配置不是 false 时启用。测试验证裸配置下护栏生效,显式设为 false 时护栏关闭。
Resilient model download 判定与装配
dsh-mneme/src/semantic.js, dsh-mneme/lib/semantic.js, dsh-mneme/test/issue-692-default-on-reads.test.js, dsh-mneme/CHANGELOG.md
新增并导出 resilientDownloadEnabled(cfg),并将其用于本地 embedder 和 reranker 的装配。测试覆盖空配置、undefined、true 和 false。变更记录说明 memoryQualityFilter.enabled 本批未调整。

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Possibly related issues

  • slow-stack/mneme issue 692:本次变更覆盖 dreamMergeGuard 和 resilientModelDownload 的默认开启目标;该 issue 提及的 memoryQualityFilter.enabled 未在本次调整。

Suggested reviewers: anans-amarre, heptaspirit

Merge Risk: Minimal · up to eb208

The change makes two default-on settings stay on when callers bypass Config, while an explicit false still turns them off. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题描述了本 PR 的主要改动:两个默认开启的开关(记忆护栏 dreamMergeGuard 与模型下载韧性 resilientModelDownload)改为按 !== false 读取。raw_summary 与 pr_objectives 均确认 dream.js、sleep.js 与 semantic.js 中的对应改动,标题与改动一致。标题未涵盖 CHANGELOG 与测试等细节,但…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

标题描述了本 PR 的主要改动:两个默认开启的开关(记忆护栏 dreamMergeGuard 与模型下载韧性 resilientModelDownload)改为按 !== false 读取。raw_summary 与 pr_objectives 均确认 dream.js、sleep.js 与 semantic.js 中的对应改动,标题与改动一致。标题未涵盖 CHANGELOG 与测试等细节,但这属于可接受范围。标题为 48 个字符、7 个词,格式清晰。

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1f3613c and eb2082f.

Files selected for processing: 8

  • dsh-mneme/CHANGELOG.md
  • dsh-mneme/lib/dream.js
  • dsh-mneme/lib/dream/sleep.js
  • dsh-mneme/lib/semantic.js
  • dsh-mneme/src/dream.js
  • dsh-mneme/src/dream/sleep.js
  • dsh-mneme/src/semantic.js
  • dsh-mneme/test/issue-692-default-on-reads.test.js

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Copilot AI lite review requested due to automatic review settings November 13, 2026 08:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
dsh-mneme/src/semantic.js 71.42% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@modusensus
modusensus merged commit a1d99c5 into main Nov 13, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants