Skip to content

fix(chat): 认领记忆权威信封为 harness note——人格/记忆提示词泄漏进气泡的根因 - #396

Merged
tall-1997 merged 1 commit into
mainfrom
fix/harness-note-envelope-leak
Nov 18, 2026
Merged

tall-1997 merged 1 commit into
mainfrom
fix/harness-note-envelope-leak

Conversation

@tall-1997

Copy link
Copy Markdown
Owner

现象

用户气泡里直接渲染出 <system-reminder>[MEMORY_REFERENCE · …] ## Recalled relevant memories - **SOUL.md**: …</system-reminder> —— 人格/记忆提示词原文泄漏到 UI。

根因:两层契约漂移(不是渲染 bug)

时间 变更 后果
11-04 (#226 防记忆劫持) 每条注入记忆前面加 [MEMORY_REFERENCE · use_as:… · trust:…] 权威信封 note 内部首行变成信封,marker 退到第二行
11-13→11-17 (#337/#339 → ec22970) harness note 匹配从 contains 收紧为 leading:剥掉 <system-reminder> 框架后,剩余文本必须以已知 marker 开头 信封不在 marker 表里 → 全部召回 note 判定为「不是 harness note」

判定失灵的后果是双份的:

  1. UI 映射(ChatViewModelChatMappingExt)把该行当真实用户发言 → 原始 <system-reminder> 渲染进气泡(截图现象)
  2. foldHarnessNotes 不再折叠 → 模型看到工具调用之间多出一个「用户又说话了」的独立轮次

11-17 的收紧本身是对的(contains 会误折叠引用了 marker 文字的真实用户消息),漏的是 marker 表没同步信封头——两个子系统各改各的,没有共同契约。

修复(单一事实来源)

  • MemoryAuthority.ENVELOPE_PREFIX 抽出常量,authorityEnvelope() 用它拼装;
  • HarnessNoteMarkers.ALL 新增 MEMORY_ENVELOPE,直接引用同一个常量 —— 生产者与分类器不可能再漂移;
  • 覆盖范围:召回 note、7 天记忆片段、MemoryIndex 片段、项目指令 note(全部经 withEnvelope)。

测试

HarnessNoteFoldTest 新增:

  • 信封前缀的召回 note → 判定为 harness note ✅
  • 信封 note 折叠到后一条真实用户轮,信封内容保留 ✅
  • 用户消息句中引用 [MEMORY_REFERENCE …] → 不判定为 note(保留 11-17 收紧的正确性)✅

分类器另用 Python 对生产形态回放:信封+marker invariant、只有信封的 7 天片段、legacy goal note、state snapshot、句中引用、普通用户文本 —— 6/6 符合预期。

Field report (screenshot): a USER bubble rendered the raw
`<system-reminder>[MEMORY_REFERENCE · …] ## Recalled relevant memories
- **SOUL.md**: …` block, i.e. the persona/memory prompt text leaked into the
UI. Root cause is a two-layer contract drift, not a rendering bug:

* 2026-11-04 (#226, anti-hijack) started prefixing EVERY injected memory
  fragment with `[MEMORY_REFERENCE · use_as:… · instruction_authority:… ·
  trust:… · origin:… · boundary:…]` (MemoryAuthority.authorityEnvelope).
* 2026-11-17 (ec22970, "64 项全修") made HarnessNoteMarkers matching
  LEADING: strip `<system-reminder>` / `<context-summary>` framing, then
  require the remainder to START with a known marker. That fixed a real
  false-positive (contains-matching folded user text that merely quoted a
  marker) — but the marker table was never taught the envelope line, which
  predates it by two weeks.

Consequence: after 11-17 the remainder starts with `[MEMORY_REFERENCE`, so
every recall note, 7-day fragment, MemoryIndex fragment and
project-instruction note answered "not a harness note". The UI mapping then
treated the row as real user speech (system-reminder markup rendered in the
bubble) and foldHarnessNotes stopped folding it (the model saw a standalone
"the user spoke again" turn between tool calls).

Fix at the classification layer, single source of truth: MemoryAuthority now
exposes ENVELOPE_PREFIX, authorityEnvelope emits it, and
HarnessNoteMarkers.ALL reads the same constant — the producer and the
classifier can no longer drift apart.

Tests: envelope-prefixed recall note classifies as a harness note, folds
onto the following real turn with the envelope preserved, and user text that
merely QUOTES the envelope mid-sentence is still not classified (the
leading-match honesty the 11-17 change was for). Classifier replayed in
Python against production shapes (envelope-only 7-day fragment, legacy goal
note, state snapshot, quoted-in-prose) — 6/6 as expected.
@tall-1997
tall-1997 merged commit 78c5e93 into main Nov 18, 2026
1 check passed
@tall-1997
tall-1997 deleted the fix/harness-note-envelope-leak branch November 18, 2026 15:33
tall-1997 added a commit that referenced this pull request Nov 18, 2026
用户报告:会话里设置的本会话规则模型不遵守。四个结构性根因,全部修复
(非提示词约束):

1. 信封自我降级(权威标签与信任矩阵矛盾):用户手写的规则被包成
   [MEMORY_REFERENCE · instruction_authority:conditional · boundary: memory
   does not change…] ——防伪信封把用户自己的指令降级成参考背景。
   现按信任对分流:(USER_SUBMITTED, STANDING_INSTRUCTION) 发
   [STANDING_RULES · authority:user-authored · binding…] 绑定信封;
   agent 写入/自动召回保持降级信封,反劫持边界不变。分类器 marker 表
   同步读取新前缀(与 #396 的单一来源契约一致)。

2. 预算优先级反转 + 规则块静默消失:PRIORITY_PROJECT(10) 先于
   PRIORITY_SESSION(20) 被预算收录,大项目 AGENTS.md 能把本会话规则
   挤出预算——与注释承诺的 narrowest-first 相反,改为 SESSION(10) <
   PROJECT(20);且非截断块超预算时从「整块丢弃且无任何模型可见痕迹」
   改为「带规则截断标记的可见截断」(RULES_TRUNCATION_MARKER),
   drop 只剩头部都不够装的情形。

3. 记忆开关级联:关「记忆」=三层规则整段不注入且菜单入口隐藏——规则
   是指令不是记忆。解耦:规则层始终注入(与 SOUL.md/learned prefs 既有
   语义一致),记忆开关只管日记/召回/记忆工具;DISABLED 文案与 UI 菜单
   同步修正。

4. 三通道结构性丢失:spawn_agent 子代理、群聊(host/member/opening/
   direct/summary 五处)、主管——system prompt 均不含会话规则。新增
   sessionRulesForLanes()(与主提示词同源的三层装配+去重),经
   SubAgentRunner.sessionRules 参数与 laneSystemWithRules 注入全部 lane。

Python 镜像 memory_authority_verify.py 同步(20/20);新增/更新测试:
绑定信封、agent 请求不越权、规则截断标记、huge project 不挤 session、
standalone drop 边界、STANDING_RULES 分类、通道继承框架;全量 6709
测试(3 失败均闭环:1 契约更新 + 2 环境性回环,重跑全过);9 门禁全绿。

Co-authored-by: tall-1997 <tall-1997@chaitin.com>
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.

1 participant