Skip to content

[PR] fix: make streaming tag-echo verdicts chunk-split independent (#4169/#4107) - #4210

Closed
ranxianglei wants to merge 2 commits into
masterfrom
2026-10-22_tag-echo-nested-bare-open-parity
Closed

ranxianglei wants to merge 2 commits into
masterfrom
2026-10-22_tag-echo-nested-bare-open-parity

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Closes #4169
Fixes #4107

修什么

#4169:streaming 过滤器(createTagEchoFilter)与整段参考实现(stripAcpTags)对同一字节给出不同结果——attrs payload 里嵌套的裸开标签在 streaming 存活、整段剥掉。按 #4107 pin 的指示重开完整 verif 种子域后,同机制家族(流式判决依赖分块位置 / 哪个闭合赢得解析竞争)又暴露出更多形状。本 PR 在各自的判决点关闭全部形状,让 streaming 对同一字节取整段判决。

行为变更(旧→新,全部 = streaming 对齐整段)

  1. attrs payload 内嵌裸开标签(tag-echo filter: a nested bare open inside an attrs-tag payload survives in streaming mode but is removed by whole-text stripAcpTags #4169 原形):A <acp tokens="1">junk<acp>text</acp>B. 旧流式保留内层裸开 → 新 A junktextB.(= 整段)
  2. 确定尾(definite tail)之前的死引用单元:尾必解析为已记录的 drop(完整标签 / 断属性 / EOF TRUNC_OPEN/TRUNC_CLOSE),其前已结算单元现在强制过门 —— 旧行为:闭合 > 落在后续 chunk 时单元漏出
  3. 同一缓冲内 open 之后完整的退化对(acplike open + 单 ref body + 任意短 close):整体 drop —— 旧行为:判决随「同缓冲是否还有别的 open」漂移(缺陷:PAIRED 正则吞掉最多 64 个字符的助手正文 #1720 early-drop 依赖缓冲内容)
  4. 非确定尾前的死引用单元:preHeld 递延到尾解析 —— prose 尾保持门关([bug] 单行中文答案被误判为退化轮:marker 行首前缀按设计被扣住,终点释放却被计成 markup(chat-completions 线整轮报错) #1760 内容保全)、tag 尾开门 —— 旧行为:单元在 attestation 落定前被放出
  5. bare 会话 EOF payload 内的完整结构:回灌主循环重审 —— 旧行为:verbatim 放行,会话持有期间到达的内层完整开标签原始泄漏
  6. 退化单元位于更晚 acplike close 之前:loose-close 解析竞争前先消费 —— 旧行为:竞争败北,单元随 prose 释放漏出

不变项(既有钉逐字节验证):refs-only body 整体 drop、attested imitation 丢弃、prose body 内引用的 ref 存活(#1720)、EOF 未闭合 attrs 尾 = tag 内容(#644)、word-glued token 保全(#1760/#2862)、marker 行 column-0 锚定语义、artifact 计数(#2405c)。

测试

与其他在途 PR 的关系

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-22_tag-echo-nested-bare-open-parity (57dd887)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.5014-pr.4210.d1fa4e1

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: nested bare open inside attrs payload now stripped in streaming mode (#4169) [PR] fix: nested bare open inside attrs payload now stripped in streaming mode (#4169) Oct 21, 2026
…ag echoes take main-loop verdicts (#4169)

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

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。 检索 open+closed issue/PR(tag-echo / nested bare open / streaming parity / stripAcpTags / #4107 / #4079),无同机制在途条目;本 PR 与 #4163(分块漂移)机制不同,#4169 正文已写明区分。

开始审核 PR #4210。初步状态:代码 diff 已拉取(单 commit,3 文件,+57/-3);CI 有 3 个 test 分片红——test (ubuntu-latest, 22, 2) 失败的是 C#4107 pinned: chunk split leaks dead-ref residue today 与 C#4107-2 pinned: close fragment at chunk boundary leaks today(tag-echo 相关,疑似与本 PR 行为变更交互),test (windows-latest, 22, 1) 失败的是 e2e #4079 两条(egress fuse,待确认是否本分支基线问题)。正在本地定向复现并核对 master 基线,结论按八问体例随后给出。

…4169)

The #4169 close-resolution re-adjudication left four more split-dependent
shapes in the seeded verif domain; each is closed at its own decision
point so streaming takes whole-text verdicts on the same bytes:

- definite-tail prefix: force the dead-unit gate when a held tail is
  guaranteed to resolve into a recorded drop (third shape);
- degenerate pair complete in the same buffer after an open: drop the
  unit whole instead of letting #1720 early-drop's buffer content decide
  it (fourth shape);
- non-definite tail prefix: defer settled prose containing a dead unit
  (preHeld) until the tail resolves — prose tails keep the gate closed
  (#1760), tag tails open it (fifth shape);
- bare-session EOF payload: re-run the main loop over it so complete
  structures that arrived while the session held take their normal
  verdicts (sixth shape);
- degenerate unit ahead of a later acplike close: consume it before the
  loose-close resolution race (seventh shape).

tests/verif-tag-echo-filter.test.ts: re-enable the full P1 domain and
flip C#4107/C#4107-2 from pinned-divergence to assert-equal per the pin
instruction. P5's duality detectors are aligned to removal semantics
(column-0 marker anchor; word-glued residue preserved by design) and a
documented exclusion covers the known-open #4106 gated-pass-ordering
facet.

(ai: vllm-qwen/qwen3.8-27b)
@ranxianglei
ranxianglei force-pushed the 2026-10-22_tag-echo-nested-bare-open-parity branch from 3f90a2a to 57dd887 Compare October 21, 2026 19:18
@ranxianglei ranxianglei changed the title [PR] fix: nested bare open inside attrs payload now stripped in streaming mode (#4169) fix: make streaming tag-echo verdicts chunk-split independent (#4169/#4107) Oct 21, 2026
@ranxianglei ranxianglei changed the title fix: make streaming tag-echo verdicts chunk-split independent (#4169/#4107) [PR] fix: make streaming tag-echo verdicts chunk-split independent (#4169/#4107) Oct 21, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复(首条回复已述,维持)。

审核完成。审核期间作者把分支 rebase 到 master 并追加了第二个 commit(57dd887c4:补上 #4107 的其余分块形状、翻转 C#4107/C#4107-2 pin、P1 全量域重启用)——本结论针对该最终 head。CI 全绿:46/46 check-runs success/skipped,含此前在 master 上红过的 windows shards(本次全部通过,证实 e2e #4079 失败是 runner 状态 flake,非本 PR 引入)。

结构化八问:

  1. 是什么问题:同一字节流,streaming 过滤器与 whole-text 参考实现输出不一致——attrs payload 里嵌套裸开标签时 streaming 泄漏 markup;更广泛地,多个形状的输出取决于分块边界落在哪(Streaming tag filter output depends on chunk position: when the same text arrives in two chunks, internal residual m1255 | 流式标签过滤器输出依赖分块位置:同一文本分两块到达时内部残留 m1255</acPA 泄漏给客户端 #4107 家族)。客户端可见字节成了「传输运气」。
  2. 什么原因导致的:判决做在了错误的时机——close-resolution 的 release 分支把 body 原样交回,其内部的 tag-shaped echo 没走主循环判决;同族根因是 dead-ref 单位的判决发生在标签解析「之前」(预算边界、EOF、或碰巧哪个 open 共享了缓冲区),而 whole-text 本质是「先解析完再判」。streaming 必须把判决推迟到解析点。
  3. 影响范围与严重程度:p3 echo-noise 家族——无数据丢失,方向是向 whole-text 一致性收敛(少剥或一致剥)。受影响面:proxy 与 plugin 两种模式下响应流中模型回声的 ACP 标记泄漏进客户端可见 prose;分块依赖变体意味着同一响应的持久化历史字节随传输不同而不同(同时也是前缀缓存接缝的风险源)。
  4. 怎么修复的:根治机制=「推迟到解析」:release 分支只消费 close、把 body 拼回 buf 头部交主循环重审(截断 attrs 尾巴与该 close 构成一个 broken-attrs span 整体丢弃);preHeld 把已结算 prose 与未决 tail 一起推迟到解析时(tag→gate 开→死单位死,prose tail→[bug] 单行中文答案被误判为退化轮:marker 行首前缀按设计被扣住,终点释放却被计成 markup(chat-completions 线整轮报错) #1760 gate 保持关);definite tail 释放前缀时强制 gate(其解析结果必为 drop,与 whole-text out !== text gate 条件等价);degenerate pair 在 loose-close 之前原子消费(对齐 whole-text DEGEN_PAIR pass 顺序);EOF flush 不再原样交回,改为主循环重跑至多 64 次排空 deferred 状态——复用与 whole-text 相同的 TRUNC_*/REFS_ONLY 语义,故任何 no-progress 兜底释放恰好等于 whole-text 会保留的字节。测试侧:两个 pin 从「leaks today」翻转为逐 split 点稳定断言;P1 属性测试去掉 tag 文本排除、全量域重启用;P5 两条断言改为与真实语义一致(marker 必须列首、residue 仅 unglued——我逐项对照 MARKER_LINE/DEAD_REF_CLOSE 正则验证过,这是规格对齐,不是放宽凑绿)。
  5. 是否有回归问题:审过的既有行为清单——缺陷:PAIRED 正则吞掉最多 64 个字符的助手正文 #1720 refs-only body 整体丢/prose body 内引用保留(REFS_ONLY 分支未动;重跑循环里 REFS_ONLY 只对整段 payload 生效且 r==="" 时才丢,保住 [bug] 单行中文答案被误判为退化轮:marker 行首前缀按设计被扣住,终点释放却被计成 markup(chat-completions 线整轮报错) #1760 引用存活)✓;tag-echo filter occasionally lets m01233</acp> remnant through to the client reasoning stream (model echoes refs from compress confirmation markers) #2023/【bug】最终版issue: 模型生成的 <acp …> 标签会漏到用户可见输出(附根因、量化与修法建议) #2190 degenerate close(守卫条件不变,wrapped 模式永远到不了新 degen 检查)✓;[bug] #361 residual, form 3: turn whose entire text is a render-tag echo strips to an EMPTY message — agent records a marker-only turn, stalls until manual nudge (v0.1.92, post-#365) #644 EOF 未闭合 attrs span 整体丢(分支未动)✓;[bug] tag-echo 在 0.1.194 仍放行一条 #2190 形态残渣(mNNNNN</acp 内联在正文行首,#2229 治理后复现) #2862 死单位优先于 truncate(未动)✓;tcHold tool-call emission 路径(未动)✓;thinking 通道与工具参数(KDD release v0.1.3 #10/[bug] 插件透传会剥掉工具调用参数里的 render tag(arguments 流挂了 tag-echo 过滤器) #1039:过滤器仍只作用于 text/reasoning 通道)✓。无有意语义漂移;行为变更见下方披露。
  6. 是否破坏缓存:不破坏任何缓存格式/增量游标;反而消除了分块边界依赖的输出字节——同一响应的客户端可见字节现在与切法无关,前缀缓存接缝更稳。
  7. 是否改了设计方向:没有。过滤器仍是 text-channel prose 过滤器,无新模块、无新依赖、无新状态外溢。
  8. 是否引入了新的配置:没有。

行为变更披露(旧 → 新):除 PR 正文表格列出的 #4169 形状外,第二个 commit 把更多输入类从「分块相关的任意输出」变为「whole-text 一致的确定输出」(dead 单位在各剩余形状下一致地死、prose 内引用的 ref 一致地活)。旧值 = 同一输入在不同切法下输出不同;新值 = 唯一输出且与 stripAcpTags 语义一致。这正是修复目的所在。

验证证据:本地在最终 head 跑全部 12 个 tag-echo-filter 相关测试文件(253/253 绿,node 22)+ typecheck 干净 + process()/flush() 全文精读(每个机制对照 whole-text pass 顺序逐一核对)。一个对后续有用的发现:C#4107 形状一的泄漏只在 Node 24 上表现(node 22 上 dead-ref attestation 根本不触发)——旧 pin 在 master 上是依赖 shard 分配的潜在 flake,已写进 pin 注释供后续参考。

协调说明:作者的第二个 commit 顺带关闭了 #4107 的已知形状(P1 全量域绿)——若日后还有未发现形状,#4107 可留观察,无需另立;#4220(#4164)与本 PR 无关、互不阻塞。审核期间我独立复现了同样的 pin 翻转(本地 WIP,与作者最终实现方向一致),未推送任何东西。

判定:CI 全绿、修的是根因(判决时机)、测试有牙(P1 全量域 + 逐 split 点硬断言 + pin 翻转 + 双方向门控)、diff 收敛在本目的相关的 4 个文件——可以人工合并:#4210

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

已并入合并列车 #4525(master 6d7c587,合并方式 merge commit,提交保留原作者署名)。本 PR 关单收尾;若列车中对应提交出问题,回滚点为 #4525 单提交 revert。

z0d0dOr pushed a commit to z0d0dOr/billion-context that referenced this pull request Oct 24, 2026
@github-actions github-actions Bot mentioned this pull request Oct 27, 2026
ranxianglei pushed a commit to gongfpp/billion-context that referenced this pull request Nov 14, 2026
…anxianglei#6557)

TOOL_TYPED_OPEN's tail [^<>]*> read a self-closing imitation
(<acp type="tool:…"/>) as an OPENING, so the whole-text path made it own
the rest of the field (or pair it with a later orphan close) while the
streaming path killed it in place via SELF_CLOSE — a whole-text/streaming
divergence on the same input, the ranxianglei#4178/ranxianglei#4210 split-invariance class this
channel exists to prevent, and a loss of the prose that follows the
imitation.

Exclude the self-closing form from the opening match (the character before
the final > must not be /); it then falls through to the SELF_CLOSE pass,
killed in place — the same verdict streaming already reaches, so both paths
agree again. A refs-only body with a non-acplike degenerate close still
owns the rest of the field in both paths: the corrupted close is not the
span's terminator, consistent with the wrapped-turn EOF rule.

+4 regression tests: self-close dies in place with following prose
surviving (whole-text, both shapes), streaming split-invariance for the
self-close shape, and a guard that a type="text" self-close keeps its
following prose (SELF_CLOSE semantics unchanged).

Reviewer fix-up on the PR branch: found by whole-text vs streaming
differential repro during review; one-line regex change, no state-machine
change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment