Skip to content

kernel: swap the JSON-poisoning phrases in the compress copy for escape hints (#2587) - #2647

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-10_kernel-json-escape-hint
Oct 10, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-10_kernel-json-escape-hint

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

kernel-change: kernel/src copy edits + kernel/package.json 0.0.112 → 0.0.113; wire-contract goldens regenerated; golden/fixture updates are mechanical.

Fixes #2580 (the tool-description root cause; original report #2579) — minimal-diff redo of #2622 (closed): keep the ONE-string line-form as the PREFERRED compress shape everywhere, and swap only the phrases that taught models to emit invalid tool-call JSON, each delta under ten words.

The failure being fixed (#2587 cluster)

Models wrote compress tool arguments with bare unquoted ranges ({"content": m00099–… + real newlines) or unescaped quotes inside strings. Anthropic-lane arguments are the only transport and are parsed as strict JSON, so one bad call fails the whole turn (DSH: MALFORMED_RESPONSE, unretried). The kernel copy was actively teaching this: "ONE plain string", "no JSON escaping", "no JSON structure, no escaping", "plain text survives lossy gateways best", "most robust through lossy gateways".

Changes (7 spots, ≤10 words each)

Surface Before After
content param description (plain text survives lossy gateways best; …) (a valid JSON string: internal quotes \" and newlines \n; …)
line-form array entry verbatim (no JSON escaping) verbatim (a JSON string: quotes \", newlines \n)
COMPRESS_TOOL description (no JSON structure, no escaping; …) (a valid JSON string — internal quotes \", newlines \n; …)
TOOLS system-prompt example (plain text survives lossy gateways best) (a valid JSON string: \" and \n)
ONE_CALL_HINT (nudge) one plain string one JSON-escaped string
gentle nudge 💡 line (most robust through lossy gateways) (a valid JSON string: \" and \n)
lean pack content param ONE plain string ONE JSON-escaped string

The preferred wire format is unchanged: content = "m00110–m00115 topic\nsummary…" — one string, header line, newline, summary — with the newline written \n and internal quotes \" inside the quoted value. Array entries stay accepted as before.

Verification

  • kernel suite 1284/1284; root one-call-payload + wire-contract + first-sight-drain-wire + search-context-cross-session 31/31 (the pinned "ONE call, ONE string" signature is untouched — zero test repins needed beyond the regenerated fixture/goldens); tsc --noEmit clean.
  • 4 wire-contract golden files + kernel/tests/fixtures/prompt-function-default.txt regenerated (mechanical).

#2591 (host-side salvage of malformed compress args) remains the backstop for residual B-class failures.

…pe hints (#2587)

Minimal-diff redo of #2622 per review: the ONE-string line-form stays the
PREFERRED shape everywhere; only the phrases that taught models to write
invalid tool-call JSON are replaced, each delta under ten words:

- compress-tools.ts content param: '(plain text survives lossy gateways
  best; …)' -> '(a valid JSON string: internal quotes \" and newlines \n; …)'
- compress-tools.ts line-form entry: 'verbatim (no JSON escaping)' ->
  'verbatim (a JSON string: quotes \", newlines \n)'
- COMPRESS_TOOL description: '(no JSON structure, no escaping; …)' ->
  '(a valid JSON string — internal quotes \", newlines \n; …)'
- TOOLS system-prompt example: '(plain text survives lossy gateways best)'
  -> '(a valid JSON string: \" and \n)'
- nudge ONE_CALL_HINT / gentle 💡 line / lean pack: 'plain string' ->
  'JSON-escaped string'; '(most robust through lossy gateways)' ->
  '(a valid JSON string: \" and \n)'

Wire-contract goldens + prompt-function-default fixture regenerated.
kernel 0.0.112 -> 0.0.113.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-10_kernel-json-escape-hint (540f440)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2862-pr.2647.a7678bc

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr2647.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,开始 review PR #2647(head 540f44028,branch 2026-10-10_kernel-json-escape-hint)。背景已对齐:#2587 内核侧文案修复的最小 diff 重做——保留 ONE-string line-form 为 PREFERRED,只替换教坏 JSON 的措辞。已核实 #2622(整段重写方案)已被你关闭、方向转为最小 diff,本 PR 与该指令一致。正在逐行读 diff、核对版本纪律/golden 再生成/pinned 测试面,随后按八问体例给结论。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 结论:可合并——CI 26/26 独立核实全绿、分支干净落在当前 master、diff 收敛、Kernel Boundary 逐项合规。合并动作按规矩留给你(human-only)。

结构化八问

  1. 是什么问题:kernel 规范 compress 文案里 4 个措辞("no JSON escaping"、"no JSON structure, no escaping"、"plain text survives lossy gateways best"、"most robust through lossy gateways")主动教模型流出不合法 JSON(裸 token A 类 / 未转义引号 B 类),严格 JSON 宿主(Anthropic lane)上坏调用在 message_stop 被拒、整轮失败(compress 的 content 偶发非法 JSON,导致 DSH 整轮失败(实测 0.1.189) #2579 实测 ~4%)。本 PR 按你的最小 diff 指令重做 kernel 默认 compress 文案仍引导非法 JSON(#2579 的内核侧后续) #2587:保留 ONE-string line-form 为 PREFERRED,只把这 4 个毒化短语换成短 escape hint。
  2. 什么原因导致:根因是措辞而非解析器——文案把 string 形态描述成「纯文本、无需转义」,模型照做。修法在提示层教「这是带引号的 JSON 字符串,内部 " 写 \"、换行写 \n」,不放宽校验、不改 schema。
  3. 影响范围与严重程度:所有下发 kernel compress 文案的宿主(wire 注入 / plugin manifest→MCP / opencode native)一次吃到;修复前在严格 JSON 宿主持续整轮失败级,合后消除。fix(#2580): salvage invalid compress tool-call args on the plugin verbatim lane (#1518 stage 2) #2591 salvage 仍是 B 类残余的 backstop(正交)。
  4. 怎么修复的:7 处各 ≤10 词替换(正文表格已逐项列旧→新),escape hint 统一为 (a valid JSON string: \" and \n) 变体;ONE_CALL_HINT/gentle 💡 行只换尾缀短语,前缀不动。schema 结构(anyOf array|string)、宽容解析器、工具名、flat 单 range 形态、数组形态接受度全部不动——三种形态照旧同解析。
  5. 是否回归问题:无。逐项审过既有行为:① schema/解析器/工具名/cadence(flat 50K)/id-never-reused 保证零触碰(diff 仅 description 串);② pinned-wording 面全部保活——"ONE call, ONE string" 前缀(one-call-payload:37/47/50、nudge-text:410/430/443、first-sight NUDGE_HINT 探针)、m00150–m00220 header 示例(compress-schema-contract)均未改,零 repin;③ golden 台账只增不减:4 个文件 56 行变更逐行核实全部是 "description" 行,结构键零变化;④ 渲染实测(tsx 直接 import kernel src):7 处输出均为字面 \"/\n 转义序列而非真实引号/换行,fixture 与 goldens 一致;⑤ 两种压缩模式同向:proxy wire 注入与 plugin manifest/native 注册吃同一份文本,无模式特定语义;⑥ 高危模式逐项过:无 fail-fast 变吞错、无阈值/时序漂移、wire 形状零变化。本地定向电池(head 540f44028):root one-call-payload+wire-contract(+golden)+first-sight-drain-wire+search-context-cross-session 36/36;kernel compress-schema-contract+nudge-text+surface-config(fixture 消费方)55/55。CI 26/26 我走 API 实查全绿(含 kernel-guard/version-guard/pi-subagents-guard/docs-sync/lane-guard/build-artifact/全部 e2e lanes)。
  6. 是否破坏缓存:机制不变(缓存/重试/游标/去重键零触碰)。措辞切换对长会话是一次性 system/tool 文本块改写 → 前缀缓存一次性失效,任何文案修复固有,fix: serve strict-JSON compress serialization guidance on all host surfaces (#2579) #2588/[PR] kernel: strict-JSON contract on default compress tool wording (#2587) #2595/kernel: teach the strict-JSON serialization contract in the canonical compress copy (#2587) #2622 谁先合谁触发这一次,字节相同后合者不再二次触发。
  7. 是否改设计方向:无转向。PREFERRED 保持 ONE-string line-form(与 [PR] kernel: strict-JSON contract on default compress tool wording (#2587) #2595/kernel: teach the strict-JSON serialization contract in the canonical compress copy (#2587) #2622 的数组翻转方案相反,正是你关 kernel: teach the strict-JSON serialization contract in the canonical compress copy (#2587) #2622 时定的方向),仅提示层语义收紧。
  8. 是否引入新配置:无。无新 env/config/默认值。

Kernel Boundary 逐项核对

kernel-change: 声明 ✓ · commit 前缀 kernel: ✓ · kernel/package.json 0.0.112→0.0.113(master 现值 0.0.112,merge-base == 当前 master 7c993f9ed,非陈旧基线)✓ · goldens 经脚本再生成且理由已述(机械继承新措辞)✓ · 两层测试绿 ✓ · human-only tier:本条即 review,合并等你。

两个收尾项(均不阻塞本 PR)

@ranxianglei
ranxianglei merged commit cd35263 into master Oct 10, 2026
26 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.228-master.cd35263 (rolling master tag).

npm install -g billion-context@0.0.228-master.cd35263  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

ranxianglei added a commit that referenced this pull request Oct 10, 2026
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
@ranxianglei
ranxianglei deleted the 2026-10-10_kernel-json-escape-hint branch October 15, 2026 05:33
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.

[Bug] compress 工具描述推荐「ONE plain string … no JSON escaping」,模型照做即写出非法 JSON,宿主整轮 MALFORMED_RESPONSE 中止

1 participant