Skip to content

fix(issue#162): 恢复注入边界花括号转义(v0.7.4 修复在 v0.7.11 误删)+ hot memory 跳过 reasoning - #165

Merged
modusensus merged 2 commits into
mainfrom
fix/issue-162-brace-escaping
Sep 13, 2026
Merged

modusensus merged 2 commits into
mainfrom
fix/issue-162-brace-escaping

Conversation

@modusensus

Copy link
Copy Markdown
Member

背景(issue #162)

DSH 核心的 interpolate() 会扫描注入文本里所有 {{...}},变量名不匹配 /^[a-z][a-z0-9_]*$/ 即 throw。v0.7.4(#40)曾修复过:在注入边界转义花括号,但该修复在 v0.7.11 的重构中被整块误删(escapePromptVars 函数 + config schema + 三处调用全部消失,v0.7.10 有 6 处、v0.7.11 起 0 处)。本次完整找回。

触发面扩大(#162 新增)

hot memory 的 textOf 会把 assistant 的 reasoning part({type:"reasoning", text})也拼进注入文本——模型思考里写 docker --format "{{.Server.Version}}"(或 Go template / Vue / Handlebars / 正则 / 日志原文)就进 prompt → interpolate() 抛错 → 整轮失败,且因 hot memory 每轮从会话日志重建,该消息一直留在窗口内,会话永久卡死。

修复(三层)

改动 内容
src/inject.js 恢复 escapePromptVars(v0.7.4 原文):连续 2+ 个花括号中间插 \,{{a}}→{\{a\}\},奇数连括号 {{{a}}} 也不残留字面 {{;三处注入出口(memory 块 / 短期上下文 / 用户设置)全部包裹转义
src/inject.js textOf 跳过 reasoning part(只取 type==="text" 或字符串)——直接掐断触发源,比 v0.7.4 只做转义更彻底
src/config.js 恢复 escapePromptVariables(默认 true,关闭时原样透传)
test/inject.test.js 5 个 v0.7.4 转义测试找回 + 新增 reasoning 路径回归(docker --format "{{.Server.Version}}" 场景)

测试

  • inject: 17/17 全过
  • 全量:978 全绿(v0.8.0 批次 A 基线之上)
  • lib/ 已 npm run sync 同步,lib-smoke 通过

🆕 fix: 恢复注入边界花括号转义 + hot memory 跳过 reasoning

🆕 test: 6 个回归测试(5 找回 + 1 reasoning 路径)

🐛 issue #162: 会话被 {{.Server.Version}} 卡死的根因(v0.7.11 回归 + reasoning 触发源)

…reasoning in hot memory

- escapePromptVars restored at all three injection exits (memory block /
  hot context / user settings) with config escapePromptVariables (default on),
  resurrected from the v0.7.4 #40 fix that v0.7.11's refactor deleted wholesale
- textOf now skips reasoning parts (type !== 'text'): assistant reasoning
  carrying Go-template/Vue/Handlebars fragments like docker --format
  "{{.Server.Version}}" was being injected into hot memory and crashing the
  turn via DSH interpolate()'s illegal-variable throw (sticky, unrecoverable)
- 6 regression tests (5 restored from #40 + 1 new reasoning-path for #162)
- lib/ synced; 978 tests green on the v0.8.0 batch-A baseline

Co-authored-by: Anans-Ivresse <[email protected]>
Co-authored-by: Claude <[email protected]>
Copilot AI lite review requested due to automatic review settings September 13, 2026 08:56
@coderabbitai

coderabbitai Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: dc2fd643-a12b-4d86-b839-1cf03481dda4

📥 Commits

Reviewing files that changed from the base of the PR and between 3680120 and 16d07d7.

📒 Files selected for processing (5)
  • dsh-mneme/lib/config.js
  • dsh-mneme/lib/inject.js
  • dsh-mneme/src/config.js
  • dsh-mneme/src/inject.js
  • dsh-mneme/test/inject.test.js

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

新增 escapePromptVariables 配置。注入边界默认转义连续花括号,并过滤 assistant 的 reasoning part。memory、短期上下文和用户设置均应用该处理,测试覆盖启用、关闭及多种输入形状。

Changes

提示词注入保护

Layer / File(s) Summary
转义配置契约
dsh-mneme/lib/config.js, dsh-mneme/src/config.js
新增 escapePromptVariables 布尔配置,默认值为 true。
注入文本处理
dsh-mneme/lib/inject.js, dsh-mneme/src/inject.js
textOf 保留字符串和正文 part,并跳过 reasoning part。新增连续花括号转义函数;配置关闭时保留原文。
渲染出口与回归验证
dsh-mneme/lib/inject.js, dsh-mneme/src/inject.js, dsh-mneme/test/inject.test.js
memory、短期上下文和用户设置的输出应用花括号转义。测试覆盖普通、奇数长度花括号、reasoning 内容及关闭配置。

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: anans-ivresse

Merge Risk: ⚪ Minimal · up to ee7cf

The prompt escaping, reasoning filtering, and opt-out behavior are implemented across the intended injection paths and covered by regression tests. No current merge-blocking risk is identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了主要变更:恢复注入边界的花括号转义,并让 hot memory 跳过 reasoning。内容具体,且与变更范围一致。
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-162-brace-escaping

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

Comment @coderabbitai help to get the list of available commands.

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 reached their quota limit.

@codecov

codecov Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI review requested due to automatic review settings September 13, 2026 09:09
@modusensus
modusensus merged commit 14cad35 into main Sep 13, 2026
6 checks passed
@modusensus
modusensus deleted the fix/issue-162-brace-escaping branch September 13, 2026 14:36
pull Bot pushed a commit to 483218131/dsh-mneme that referenced this pull request Sep 29, 2026
issue slow-stack#334:注入路径 4 处截断点(热上下文查询/回复 500/800、
lastUserQuery 500、记忆条目 injectContentMaxChars)UTF-16 slice
切在代理对中间留下孤立高位代理项,序列化成非法 UTF-8 后 DeepSeek
API 每轮 400,且畸形文本永久写入会话历史。新增 safeSlice(尾字符
为高位代理即丢弃),4 处截断点全部换用;测试以「孤立代理项不存在」
锁语义,附变异阴性对照。

issue slow-stack#333(issue #34 恢复):injectTimePrefix 于 v0.7.11 面板
大改版时随一次批量删除静默消失(CHANGELOG 无登记,同刀的
escapePromptVars 已随 slow-stack#162/slow-stack#165 恢复、本函数漏了)。按 v0.7.2
语义原样恢复:键名/默认值/格式不变,per-session 闩锁每会话一次,
时间前缀排记忆块最前(时间 → 热上下文 → 长期记忆)。settings
白名单、面板双语、FEATURE_GROUPS、配置计数锁同步。

全量 1429/1428/0。
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