Skip to content

fix: serve strict-JSON compress serialization guidance on all host surfaces (#2579) - #2588

Closed
ranxianglei wants to merge 2 commits into
masterfrom
2026-10-10_compress-json-surface
Closed

ranxianglei wants to merge 2 commits into
masterfrom
2026-10-10_compress-json-surface

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2579

背景

DSH 侧偶发「tool input is invalid JSON」整轮失败(~4% 的 compress 调用,issue 内 30 会话统计)。issue 证据确凿:坏 JSON 是模型流式输出本身(10/10 chunk 逐字节一致),诱因在提示/示例层——下发给模型的 compress 工具描述与 nudge 文本用不带引号的 ref header 举例('m00150–m00220 optional topic' header line),并把字符串形式描述成 no JSON escaping / no JSON structure。模型照抄 ⇒ A 类(content 写成裸 token);引用代码时转义不一致 ⇒ B 类(字符串内未转义引号提前闭合)。

修法(宿主层,不动 kernel/)

规范文案住在 kernel/**(owner-gated,Kernel Boundary),本 PR 在宿主下发面做临时 override:

  1. src/compress-tool.ts:重写四种 wire shape(anthropic/openai/responses/google)的 compress 工具描述、content 参数、line-form item、google 参数——严格 JSON 契约前置(未加引号的值 / 字符串内未转义的 \"、换行会使整个调用失败),PREFERRED 改为对象数组并给可粘贴骨架 {"content":[{"startId":"m00122","endId":"m00127","summary":"...","topic":"..."}]},字符串形式保留但写明仍是带引号的 JSON 字符串;删除全部 no JSON escaping / no JSON structure / lossy gateways 措辞。
  2. 每条渲染出的 nudge(4 wire × fallback+legacy 共 8 处)与 post-compress 剩余区间尾巴追加静态 [JSON validity] 注记(withCompressJsonNote / COMPRESS_JSON_NOTE)。
  3. opencode native(V1 zod 注册)与 opencode V2 的进程内注册同步改用 override 后的 compress 条目——此前它们直接用 kernel 常量数组,会绕过本修复(decompress/search_context 注册不动)。

覆盖:proxy wire 注入、plugin manifest(dsh/pi/omp/opencode/kimi/hermes/zcode native plugins)、MCP tools/list。

行为变更披露(旧 → 新)

  • 下发的 compress 工具/参数描述文案:旧版以「ONE plain string … no JSON structure, no escaping」为 PREFERRED;新版以对象数组为 PREFERRED,且所有形式均声明严格 JSON 转义规则。schema 结构未变(content 仍为 anyOf:[array,string],字段未增删改名,解析路径不变)。
  • 每条 nudge / post-compress 尾注新增固定 [JSON validity] 后缀(纯提示词增量,不改指令语义)。
  • opencode native/V2 注册的 compress 描述同上(仅 compress 条目)。
  • 无新配置项、无 env、无持久化格式变化、无缓存/重试策略变化、无时序变化。

Golden 再生成(#1304)

tests/golden/wire-contract/{bili,manifest-default,manifest-optin}.json 经 scripts/update-wire-contract-goldens.ts 再生成:仅上述描述文本变化(合计 29+/29-),kernel.json 字节级未变(kernel 未动)。理由即本 PR 目的:#2579。

测试

新增 tests/compress-json-surface.test.ts(4 用例:全部 8 个下发面声明严格 JSON 契约且旧措辞清零、line-form item 携带带引号值规则、广告示例自身可被严格 JSON.parse、注记字节稳定)。定向套件全绿:wire-contract* + dsh-native/dsh-acp + absorb/ccr-plugin + basic + acp-status + one-call-payload + opencode-native/v2 + compress-* 等 ~250 用例;typecheck / build / check:unused-exports 干净。全量回归交给 CI。

边界与后续

自动合并门禁:涉及 wire-visible 表面 ⇒ 人工审核。

…rfaces (#2579)

Models intermittently emit invalid JSON for compress content (bare unquoted values; unescaped quotes/newlines inside strings) because the served tool descriptions and nudge text exemplify unquoted ref headers and frame the line form as 'no JSON escaping'. Rewrite every host-served copy of that guidance - tool descriptions for all four wire shapes (proxy injection + plugin manifest + MCP), the content param, the line-form item, the google param - to state the strict-JSON contract with a paste-ready object-array skeleton, keep the string form legal but explicit that it is still a quoted JSON string, and append a short [JSON validity] note to every rendered nudge and the post-compress remaining-ranges tail. The opencode native/V2 in-process registrations now use the overridden compress entry too.

The canonical text lives in kernel/** (owner-gated); this is a temporary host-side override until the kernel default is updated via the follow-up issue.

Goldens tests/golden/wire-contract/{bili,manifest-default,manifest-optin}.json regenerated via scripts/update-wire-contract-goldens.ts: description text only, no schema structure change; kernel.json untouched.
@ranxianglei
ranxianglei force-pushed the 2026-10-10_compress-json-surface branch from a67901d to 3f351c7 Compare October 10, 2026 03:36
@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-10_compress-json-surface (0e43068)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2793-pr.2588.4214ec2

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-pr2588.tgz
npm install -g package

Install instructions are refreshed on each push.

…ess override

The 'no other tool may change' guard compared every BILI array entry
against the kernel default; the #2579 fix intentionally rewrites the
compress description/params host-side, so compress is now excluded from
the rest-comparison and positively asserted to carry the strict-JSON
contract (exact text pinned in tests/compress-json-surface.test.ts).
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

PR #2588 review — serve strict-JSON compress guidance on all host surfaces (#2579)

结论先行:代码正确、边界干净、新测试有牙。CI 的唯一红灯是一个测试期望回归,已在分支上被 commit 0e43068 修好——我独立复现并定位到同一根因,核对该修复正确且比我的草拟更强,因此丢弃了本地改动、不重复提交。当前 CI:两个 ubuntu 全量分片(含原失败分片 ubuntu-24)已绿,24/26 检查全绿、零失败,仅剩 2 个 windows 分片在跑(同代码同套件,预计同样转绿)。wire-visible 表面 ⇒ 需人工合并,不自动合并。

按八问:

  1. 是什么问题:DSH 侧偶发「tool input is invalid JSON」整轮失败(约 4% 的 compress 调用);坏 JSON 是模型流式输出本身(10/10 chunk 逐字节一致)。
  2. 什么原因导致的:下发给模型的 compress 工具描述与 nudge 文案沿用 kernel 默认措辞——以「ONE plain string … no JSON structure / no escaping」为 PREFERRED、并用不带引号的 ref header 举例('m00150–m00220 optional topic')。DeepSeek 类模型照抄 ⇒ A 类(content 写成裸 token)/ B 类(字符串内未转义引号提前闭合)。根因在提示/示例层,不在 wire 或解析器。
  3. 影响范围与严重程度:影响所有发往严格 JSON 客户端(DSH/DeepSeek 类)的 compress 调用;约 4% 命中时因 DSH fail-fast 且不纳入重试 ⇒ 表现为整轮硬失败。属「特定条件下有问题」(严格 JSON 客户端 + 模型照抄示例),非全面不可用,其它工具/轮次不受影响。
  4. 怎么修复的:宿主下发面做临时 override(不动 kernel):重写四种 wire shape 的 compress 工具描述 / content 参数 / line-form item / google 参数,把严格 JSON 契约前置、PREFERRED 改为对象数组并给可粘贴骨架 {"content":[{"startId":"m00122","endId":"m00127","summary":"...","topic":"..."}]};8 处 nudge(fallback+legacy × 4 wire)+ post-compress 尾注追加静态 [JSON validity];opencode native(V1 zod)与 V2 进程内注册改走同一 override。kernel 默认文案后续经 kernel 默认 compress 文案仍引导非法 JSON(#2579 的内核侧后续) #2587 走 Kernel Boundary 统一改,届时移除宿主 override。schema 结构未变(content 仍 anyOf:[array,string],字段未增删改名,解析路径不变)。
  5. 是否有回归问题:审过既有行为——唯一风险已发现并处理:#841 schema-drift guard(「no other tool may change」)因 BILI 数组现在也 override compress 而被触发,这是测试期望而非产品行为,已由分支上的 0e43068 修复(compress 从 rest 比较中排除,与 decompress 同理,并正向断言 bili compress 带 STRICT JSON、kernel 默认未被 mutate)。acp_status/acp_cache 确认字节级一致(无漂移);patch 逻辑与每种真实 kernel shape 精确匹配(anthropic/openai/responses 共享 COMPRESS_PARAMETERS 且 anyOf 内含 line-form;google 为独立 flat shape 无 anyOf),deep-clone 保证 kernel 常量不被改动。产品行为无回归,唯一有意的行为变更即下发的描述文案(见第 8 问后披露)。
  6. 是否破坏缓存:cache 策略 / 去重键 / 重试 / 增量游标均不受影响。诚实披露一点:工具与 nudge 文案变化会改变升级后首个请求体字节 ⇒ 升级当次一次性的 prefix-cache miss(任何 prompt 措辞变化的固有代价),下一轮即收敛为新稳定前缀;nudge 与 post-compress 尾注是静态 append(byte-stable,见新测试用例 4),会话内不会反复失效缓存。
  7. 是否改了设计方向:无架构转向。刻意做成宿主侧临时 override,kernel 归属的正解路由到 kernel 默认 compress 文案仍引导非法 JSON(#2579 的内核侧后续) #2587(Kernel Boundary,owner-gated),kernel/host 边界保持不变。
  8. 是否引入新配置:无。无新 env/config/默认值;COMPRESS_JSON_NOTE / withCompressJsonNote 为内部导出而非配置项;无持久化格式变化。

行为变更披露(旧→新):① 下发的 compress 工具/参数描述:旧 PREFERRED =「plain string,no JSON structure/escaping」,新 PREFERRED = 对象数组且所有形式声明严格 JSON 转义规则(schema 结构不变)。② 每条 nudge / post-compress 尾注新增固定 [JSON validity] 后缀(纯提示词增量,不改指令语义)。③ opencode native/V2 注册的 compress 描述同上(仅 compress 条目)。

判定:代码与边界 OK;CI 红灯已修复并验证(原失败分片 ubuntu-24 已绿、零失败);无版本 bump(正确,非 release 分支)。待剩余 2 个 windows 分片确认后即可人工合并。

PR: #2588

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

CI 已全绿:commit 0e43068 上 26/26 检查全部 success、零失败(含全部 4 个 OS×Node 全量分片、kernel/lane/pi-subagents guard、registry e2e、各真实客户端 lane)。原红灯分片 test (ubuntu-latest, 24) 已转绿。

结论不变且现在有了完整证据:可人工合并。wire-visible 表面按规则不自动合并,请 owner 手动 merge: #2588

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

收到「上游 PR 冲突」唤醒。先查证再动手 —— 结论:当前无真实冲突,我未做任何 rebase / push。

按八问:

  1. 是什么问题:系统转发「PR fix: serve strict-JSON compress serialization guidance on all host surfaces (#2579) #2588 与其基线分支冲突(merge state: dirty)」的唤醒通知。
  2. 什么原因导致的:通知基于过期快照。核查事实:master 仍停在 8e7bb1294(即 PR 创建时的原始 base,未前进);PR head 0e43068 是 master 的干净 fast-forward 后代(merge-base == master,祖先校验通过);GitHub 实时 API 报告 mergeable: true / mergeable_state: clean。因此「冲突」是瞬时/陈旧状态,不是真实文本冲突。
  3. 影响范围与严重程度:无实际影响——PR 尚未合并、无代码落地,当前状态可正常合并。属误报/状态层面,无功能或数据影响。
  4. 怎么处理:核实后不修复(无需修复)。依据冲突唤醒规则「冲突解完状态会自动转干净,不要重复 rebase」「若 PR 已无需合并,回复说明即可,不要硬救」:对一个已是干净后代的分支做 no-op rebase + force-push 只会无谓改写历史,且会惊扰该分支上的并发会话(此前另一 agent 刚在此推过 0e43068)。补充:git merge origin/master 在此场景下也是字面 no-op(master 已是后代,不会产生任何提交),所以根本不存在「安全地 bump head」的路径,任何 head 变更都只能靠有风险的 force-push 改写历史。故选核实并报告。
  5. 是否有回归问题:不涉及(未改任何代码或历史)。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入新配置:不涉及。

判定:master 未动、head 为干净后代、GitHub 判 clean ⇒ 无冲突需要解决;平台的 dirty 标记应随下次同步自动转干净。本次未 push 任何内容(工作树干净)。PR 保持 open、CI 26/26 全绿,待人工合并: #2588

@ranxianglei

Copy link
Copy Markdown
Owner Author

Closing per owner decision: the host-side override layer is an interim band-aid (double maintenance across ~10 serving surfaces). The fix moves to the canonical kernel text (#2587 scope) — same strict-JSON contract wording, PREFERRED object-array form, explicit escaping rules — so every consumer (host wire/manifest/MCP/opencode + independent acp-kernel consumers) gets it from the source. Salvage PR #2591 is orthogonal and stays.

ranxianglei pushed a commit that referenced this pull request Oct 10, 2026
The kernel defaults still carried the pre-#2579 framing — "no JSON
escaping", unquoted 'm00150–m00220 topic' header exemplars, ONE plain
string PREFERRED, "lossy gateways" — the prompt-layer inducement behind
the malformed compress calls measured in #2579 (~4% of calls: bare
unquoted values / unescaped quotes). Rewrite all default surfaces to the
strict-JSON contract already shipped host-side in #2588:

- COMPRESS_PARAMETERS.content.description: strict JSON up front; PREFERRED
  = object array; string form kept legal but quoted-JSON-explicit
- line-form item description: entry is still a quoted JSON string value
- COMPRESS_TOOL.description: STRICT JSON clause + paste-ready skeleton,
  byte-identical to #2588's COMPRESS_TOOL_DESCRIPTION_FIXED
- system-prompt tools section: same direction (no #2588 counterpart)
- COMPRESS_TOOL_GOOGLE content.description: same contract, anyOf-free form
- ONE_CALL_HINT + gentle nudge line: object-array-first, quoted-string
  alternative, no lossy-gateway framing
- lean-pack paramDescriptions.content: same contract
- kernel version 0.0.111 -> 0.0.112 (CI-enforced)
- tests pinning the old wording updated (one-call-payload,
  compress-schema-contract, nudge-text, first-sight-drain-wire marker)
- goldens regenerated via scripts/update-wire-contract-goldens.ts
  (description text only — no schema structure change)

Schema and parser semantics unchanged: all three content forms
(array / one string / flat) parse exactly as before.
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.

compress 的 content 偶发非法 JSON,导致 DSH 整轮失败(实测 0.1.189)

1 participant