Skip to content

[PR] verif: adapter buildRequest link stability judge (three vendors + cacheMarks variants) | verif: adapter buildRequest 线稳定判官(三家 + cacheMarks 变体) - #4112

Merged
ranxianglei merged 2 commits into
masterfrom
verif/adapter-wire-judge
Oct 21, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
verif/adapter-wire-judge

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

这是什么

方向 3(脆弱面调查的第 2 项):给三个 provider adapter 的 buildRequest 出站重建层加回归判官 tests/verif-adapter-wire-stability.test.ts(纯回放,不需要求解器,CI 可跑)。

为什么

#3837 家族的核心主张是"入站纯追加,出站也必须纯追加"。adapter-anthropic.ts 的注释(#1637 累计 cache_control 前缀稳定、#1876 system 追加不合并、#2499 客户端 marks 回退)只护住了 anthropic 一家;openai / google 的同一层没有任何判官。这条性质推广到三家并钉死。

判官内容(17 项,全绿)

  • P1 追加稳定(轮合并感知):历史加一条消息,已完成轮次的 wire 字节必须逐字节不变。轮合并是真实语义(assistant reasoning+text 合并成一条、anthropic 把 tool-result 并进 user 轮、notes 并进开轮),所以性质按"完成轮不可动、开轮可生长"表述;在轮完整边界(k=1/5/8)上取严格形式(全元素逐项相等)。
  • P2 幂等 + 输入不可变:两次重建 deep-equal;core 数组本身不被就地修改。
  • P3 相邻增长对稳定性 + P3b notes 只动尾部(anthropic/google 并进开轮、openai 独立成条,两种都允许,完成字节不许动)。
  • P4 非空性:工具轮的 toolCallId/args/result 逐字保全(防未来"智能合并"回归)。

覆盖 createOpenaiAdapter / createAnthropicAdapter(含 cacheMarks 变体)/ createGoogleAdapter,消息形状含 user 文本、tool-call+result 双轮、reasoning(thinkingTokens)、连续 assistant。

结果

全部通过——buildRequest 层当前是稳的(#1637/#1876 的工作生效)。这条判官的作用是把该性质变成常驻回归:任何未来的出站重建改动若动了已完成轮次的字节,CI 直接红。

已知缺口(不在本 PR)

parseStream 的 SSE 分块重切稳定性(#4107 家族真正的所在)需要按 provider 造 SSE 夹具,留作下一步。

测试

  • node --import tsx --test tests/verif-adapter-wire-stability.test.ts → 17/17
  • 全套 tests/verif-*.test.ts → 64/64
  • npx tsc --noEmit 干净(仅既有 pi-subagents/mysql 例外)

人工合并(AGENTS.md 规矩)。

ework-agent added 2 commits October 21, 2026 13:31
tests/verif-tag-echo-filter.test.ts: property judge over the REAL filter
family (src/loop/tag-echo-filter.ts). No solver — the interesting entry
points are outside the symbolic sublanguage today (lookaround +
\\p{So} regexes in stripAcpTags' family, stateful re.exec loops in the
stream filters), so this judge runs real code over adversarial
grammar-generated shapes (deterministic seed 0x7ea4c0de):

- P1 chunk-split equivalence (streaming ≡ whole-text) across 5 filter
  factories, all split points for short texts + sampled + 3-way
- P1b absorb-instructed emission hold split-stability
- P2 stripAcpTags/normalizeEchoArtifacts idempotence
- P3 monotone length, P4 clean-prose passthrough, P5 residue duality
  (strip-acted ⇒ strict detectors silent), P6 stats accounting,
  P7 identity/compose sanity
- per-issue controls pinning the file's own history: #644 #1720 #1760
  #1881 #2023 #2862 #717 #2405

TWO real bugs found immediately by the properties:

- #4106 stripAcpTags is NOT idempotent: the gated DEAD_REF_CLOSE pass
  evaluates `out !== text` BEFORE the marker-line pass (which runs
  LAST), so a marker line + trailing dead-ref-close text strips once
  (keeps the dead ref) then strips MORE on the second call (marker
  removal enabled an end-anchored TRUNC_REF_CLOSE match). Re-normalized
  messages shrink per pass = unstable sent bytes. Pinned C#4106;
  P2 domain excludes the shape until fixed.
- #4107 stream output depends on chunk boundaries (two shapes): (a)
  dead-ref residue `m1255</acPA` is cleaned on whole-text push but
  RELEASED to the client when the transport splits at the payload/close
  boundary; (b) a bare close fragment `</apc ` at the chunk boundary
  leaks in the split path. Both pinned (C#4107/C#4107-2); P1 domain
  excludes tag-bearing texts until fixed.

Property overreach fixed during calibration (documented in-test):
containsMarkerLineText is the raw includes() pre-check (#717) while
removal is line-anchored (detect-but-keep for mid-line markers);
containsEchoResidue is an audit signal, not a strip guarantee
(#1760 close-only preservation); dropped vs dropCount are different
documented concepts.

README: judge table rows for the conflict-watch/snapshot/wire quartet,
responses-ingress, tag-echo-filter; found-bugs list += #4052 #4106
#4107.

Suite: 47/47 green (17/17 here). tsc clean.
…ogle)

Turn-merging-aware append stability: completed turns' wire bytes must
never change when history grows (P1 strict at turn boundaries, drop-last
open-turn carve-out); idempotence + input non-mutation; notes tail-only;
tool rounds verbatim. Generalizes the #1637/#1876/#2499 byte-prefix
property across all three adapters. No solver needed (pure replay).
@ranxianglei ranxianglei changed the title verif: adapter buildRequest 线稳定判官(三家 + cacheMarks 变体) [PR] verif: adapter buildRequest link stability judge (three vendors + cacheMarks variants) | verif: adapter buildRequest 线稳定判官(三家 + cacheMarks 变体) Oct 21, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

注:本 PR 基于未合并的 #4108(tag-echo 判官)之上——#4108 先合并后这里只剩 adapter 判官一个提交,可直接合并。

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: verif/adapter-wire-judge (48f7d11)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4901-pr.4112.626258d

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-pr4112.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

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

查重: 不重复。 本 PR 的实质内容(tests/verif-adapter-wire-stability.test.ts +216、verif/README.md +1 行表格)与任何既有 issue/PR 不重叠;唯一关联是基座——本分支叠在 #4108 的提交 9f85c2a31 之上(已核对该 sha 与 #4108 当前 head 完全一致),#4108 合并后本 PR 只剩 adapter 判官一个干净提交。PR 正文自述的已知缺口(parseStream SSE 分块重切稳定性)已在 #4107 家族立项跟踪,无需另开。

标签: pr + scope/ci + p3(测试基建新增,非缺陷;跨三家 vendor 无特定客户端车道,不打客户端标)

审核结论(独立审,不复读 issue 描述)

八问:

  1. 是什么问题: 给三个 provider adapter(openai/anthropic/google)的出站重建层 buildRequest 加一个常驻回归判官——历史每多一条消息,已完成轮次的 wire 字节必须逐字节不变(开轮可生长),外加幂等、输入不可变、notes 只动尾部、工具轮逐字保全,共 17 项断言。
  2. 什么原因驱动: 不是修 bug,是把不变量钉死。OpenAI/Codex channel: Per-request body rewriting causes the prefix cache to periodically reset to zero (degenerate foldi | OpenAI/Codex 通道:每请求改写请求体导致前缀缓存周期性归零(退化折叠 foldPoint=m00001 + abort 后 stamped 漂移),单会话 66.7% 计费为全价输入 #3837 家族「入站纯追加 ⇒ 出站也必须纯追加」的性质此前只有 anthropic 一家的注释在护([Bug] Anthropic lane never emits cache_control breakpoints — prompt cache can only ever cover the system head (~11K), the whole history re-bills at full price every request #1637 累计 cache_control 前缀稳定 / anthropic lane: buildSystem 将客户端多块 system 合并为单块,破坏下游按块形状的 CC 识别(如 sub2api billing-block 前缀检查) #1876 system 追加不合并 / [bug] anthropic 线 proxy 模式:压缩回合的 round-2 重建丢失客户端 cache_control,折叠后下一条请求只能命中 system 前缀 #2499 客户端 marks 回退),openai/google 同一层零判官。此 PR 把该性质推广到三家并变成 CI 强制。
  3. 影响范围与严重程度: 运行时零影响(纯测试 + README 一行,未碰任何 src)。不加它的风险面是:未来任何出站重建改动若动了已完成轮次字节 → 前缀缓存失效,属 p1 级缓存泄露形态;判官把这从「静默发生」变成「CI 当场红」。
  4. 怎么修的(钉法): 回放判官(无求解器、CI 直跑)——驱动真实 adapter 的 buildRequest 端到端,按 9 个前缀长度 + 全部相邻增长对做元素级 deepEqual,并在轮完整边界(k=1/5/8)取严格全等形式;「豁免最后一元素」的 carve-out 对应真实的轮合并语义(reasoning+text 合并、tool-result 并进 user 轮、notes 并进开轮),不是放水。
  5. 是否有回归问题: 无。生产代码零变更,plugin/proxy 两模式的推理被空满足(两模式共用同一 buildRequest,行为未动只被钉住)。高危模式逐项过:语义漂移/fail-fast 变吞错/阈值时序漂移/输出格式变化——均不涉及。
  6. 是否破坏缓存: 不涉及(未触碰缓存/重试/游标逻辑)。
  7. 是否改了设计方向: 无转向;按 verif 模块教义(真入口/通用不变量/回放)接入,与既有回放判官(view-latch 等)同族同风格。
  8. 是否引入新配置: 无。

独立验证(不止读 diff):

小瑕疵(不拦):P4 非空性检查与 P3b 末轮检查用子串 contains 而非元素级断言——作为非空性守卫可接受,承重断言(P1/P3 的 deepEqual)是严格的,不值得为此返工。

判定: 可合。 顺序按你的注来——先合 #4108,本 PR 即剩单提交直接合。合并由人执行(AGENTS.md 规矩)。

@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.720-master.7790bea (rolling master tag).

npm install -g billion-context@0.0.720-master.7790bea  # 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant