Skip to content

[PR] fix: client mid-history system messages ride verbatim on every wire (carrier re-voice narrowed to bili's own) (#4166, fixes #4159) - #4171

Merged
ranxianglei merged 11 commits into
masterfrom
2026-10-21_4166-midsystem-impl
Oct 21, 2026
Merged

ranxianglei merged 11 commits into
masterfrom
2026-10-21_4166-midsystem-impl

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

(ai: zhipuai-lb/glm-5.3)

kernel-change: mid-history system/developer verbatim sidecars on the openai + responses wires (the #4166 plan filed in #3939's sibling issue; stacked on the pins PR #4167 — merge that first, the diff here collapses to the real change after).

Part of #4165 (总账). Fixes #4159.

What

Two wires still treated client mid-history system messages as bili artifacts to rewrite (the anthropic wire fixed it yesterday in #3992):

Visible behavior

  • openai/responses clients: mid-history system/developer messages keep role + position + bytes across every request (previously: re-voiced to user on openai / hoisted into instructions on responses).
  • Kernel summary carriers: unchanged — still user-voiced mid-history for strict backends.
  • A strict single-system backend now 400s a client's own mid system honestly (escape hatch: compat.roles) instead of bili silently rewriting it.

Tests

  • kernel pins re-flipped to the new contract (openai 6, responses 5, incl. unfoldable-protection + verbatim round-trips); kernel suite 1419 green.
  • New e2e tests/issue4159-client-mid-system-verbatim.test.ts: DSH-shaped tool_addition mid system rides verbatim, byte-stable across 3 requests.
  • tests/responses-mode-switch-fingerprint.test.ts: degrade-to-proxy no longer re-projects — resent prefix byte-identical, no projection-switch event.
  • tests/e2e-mid-system.test.ts (carrier re-voice [Bug] ACP: ≥2 compressed blocks render as multiple system messages → SGLang (vLLM-compatible) upstreams return 400 #377) unchanged and green — the narrowing does not touch carriers.
  • 287 responses/codex/cache-proof/wire-contract/loop tests green; basic/plugin/cache-friendly 312 green; tsc clean.

Rollback

Each commit is isolated (kernel openai / kernel responses / host narrowing); revert any single one and its pins go red, nothing else.

Stacked on #4167 — merge order: #4167 → this PR.

ework-agent added 4 commits October 21, 2026 21:06
)

openaiToCore keeps the raw wire message on mid-history system/developer
cores (rawOpenaiMessage); coreToOpenai re-emits it byte-exact, re-laying
plain text when kernel ops rewrote it. hasUnrecoverableMediaPayload:
structured (non-plain-text) mid system never folds — DSH tool_addition
style declarations survive instead of being stringContent-flattened.
…car cores (#4166)

responsesToCore hoists only the LEADING system/developer prefix into
systemParts (strict single-system upstreams keep their merged head,
#377); mid-history items become positioned cores carrying the raw item
(rawResponsesItem) — replacing the host #1638 re-typing trick for
plugin/codex clients with codec-native position preservation for every
mode. coreToResponses re-emits sidecar items byte-exact (kernel text
rewrites re-lay plain content). hasUnrecoverableMediaPayload: structured
(role-guarded) mid system items never fold.
…only bili's carriers re-voice (#4166, #4159, #4165)

kernel (mirrors #3992 on the remaining two wires):
- openai: mid-history system parses with a rawOpenaiMessage verbatim
  sidecar; coreToOpenai re-emits it byte-exact (re-blocked only when the
  kernel itself edited the text); non-plain-text system is unfoldable
- responses: mid-history system/developer become positioned sidecar
  cores (refs + fold coverage + layout slots); head prefix still hoists
  (#377); coreToResponses re-emits raw verbatim; kernel 0.0.149

host:
- systemToUser/revoiceMidSystemDevelopers take a predicate; both codecs
  re-voice ONLY isRenderedSummaryMessage carriers — client-origin mid
  system/developer is data, never re-voiced (#4159)
- prepare-responses: #1638 re-typing hack retired (codec-native now,
  mode-invariant projection — the plugin->proxy degrade no longer
  re-projects or re-bills, #2867); #3713 masking retired (real cores)
- compress-loop-responses: visibility markers + retrieval injections are
  born user; no blanket re-voice on the re-request
- loop/adapter-openai: same carrier-only narrowing (loop/prepare parity)
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-21_4166-midsystem-impl (a363d5f)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4984-pr.4171.5115dbd

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: client mid-history system messages ride verbatim on every wire (carrier re-voice narrowed to bili's own) (#4166, fixes #4159) [PR] fix: client mid-history system messages ride verbatim on every wire (carrier re-voice narrowed to bili's own) (#4166, fixes #4159) Oct 21, 2026
@ranxianglei
ranxianglei force-pushed the 2026-10-21_4166-midsystem-impl branch from 1895de8 to 8b2da08 Compare October 21, 2026 13:43
@ranxianglei
ranxianglei force-pushed the 2026-10-21_4166-midsystem-impl branch from 8b2da08 to 0ce4a1c Compare October 21, 2026 14:07
ework-agent and others added 3 commits October 21, 2026 22:39
The non-stream JSON loop no longer re-voices mid-history sys/dev items (#4166: client-origin items ride verbatim; bili's own visibility/retrieval injections are born user), so the function's last production caller is gone. Remove it plus its dedicated pin; the surviving systemToUser predicate tests are untouched.
…m since #4166) (#4171 review)

The openai wire-drop detector counted every non-user role's non-text parts as dropped. #4166 makes mid-conversation system/developer messages ride the codec verbatim (rawOpenaiMessage sidecar), so the exact #4159 tool_addition shape would now trigger a false 'will drop' warn on every healed session. Narrow the scan to the surviving drop class — assistant/tool roles plus the leading system/developer run (still stringContent-flattened into systemText) — and pin both directions.
@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: vllm-qwen/qwen3.8-27b)

独立深审(重读 diff + 本地跑码验证)

另一个 agent 会话对同一区域做了独立并行分析(#4166 的平行实现),设计收敛到与本 PR 相同的选择(sidecar 逐字往返 + 载体用形状谓词判别而非新增字段)。以下结论由我独立重读 diff、本地运行代码后产出,未照抄 issue / PR 正文。

① 方向判定:正确

根因(摘要载体伪装成普通 system 消息上 wire、无一等信息身份 → 每条线 × 每种后端按角色形状一刀切补丁)与家族谱一致;把 #3992 的 anthropic 先例推广到另两条线是正确的收口点。responses 线只把开头连续 prefix 提升进 instructions、中途项保位置,修掉了未报告的附带伤害。

② 回归审查(既有行为清单逐项)

③ 测试有效性

新 e2e(tests/issue4159-client-mid-system-verbatim.test.ts)断言有牙:tool_addition exactly-once + role 保持 system + 位置在中间 + 跨 full-resend 轮次字节稳定。pin 文件双向(锚 + 绿契约 + fold-gate 行)。rebaseline 测试断言的是新契约本身,不是恒真改写。

④ 行为变更清单(PR body 均已披露;补一条)

  • mode switch 不再是 projection 事件([Bug] Responses self-heal 切换投影规则后,提示词指纹变化被误归因为宿主改写 #2867 fingerprint rebaseline)——已披露。
  • 严格后端对客户端真实 mid system 诚实 400;compat.roles 仍是显式改写逃生门——已披露。
  • responses mid sys/dev 不再提升进 instructions——已披露。
  • 补充:全折叠 openai 出站形状相对 PR 前不变([system, user×N],每载体一条消息)——3f48e277a 的 kernel 修复避免了升级时的一次性前缀缓存失效。

⑤ 状态

本地定向验证(final head):D-trio 11/11、rebaselines 7/7、verif+pins+byte-stability 44/44、golden pair 17/17、host suites 26/26、drop-warn 20/20、typecheck 干净。远程 CI:2745e8739(死代码清理提交)的完整 CI + 全部 12 条 E2E 车道已全绿;最终 head ae93600(drop-warn 修复)的 push 事件未被送达(PR head 未推进、无自动 run),已按 ci.yml 注释里记载的补偿路径对该分支触发 workflow_dispatch(run 39624996201,排队中)——check-runs 落在同一 head sha(#772/#1744 模式),绿了即补齐。

判定:方向正确、实现收敛、全部确定性红已在分支内解决;最终 head CI 全绿后可合(前提仍是 #4167 打桩 PR 先合,stacking 顺序按 owner 指令)。

@ranxianglei
ranxianglei merged commit fe5ba59 into master Oct 21, 2026
25 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.730-master.fe5ba59 (rolling master tag).

npm install -g billion-context@0.0.730-master.fe5ba59  # 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.

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] DeepSeek/OpenAI wire: compression re-serializes mid-conversation system messages, tool_addition blocks rejected (INVALID_REQUEST)

1 participant