Skip to content

[PR] fix(loop): re-adjudicate nested openings arriving across a chunk boundary in the tag-echo bare-open swallow - #4170

Closed
ranxianglei wants to merge 2 commits into
masterfrom
2026-10-21_tag-echo-bare-open-boundary
Closed

ranxianglei wants to merge 2 commits into
masterfrom
2026-10-21_tag-echo-bare-open-boundary

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #4163

Root cause

The #1720 nesting evidence for a lone open render tag ("more tag structure follows in this same chunk -> drop alone, let the inner markup decide") was judged on the CURRENT buffer only. When an SSE boundary fell after the first bare open, the later opening accumulated into the live swallow span and the #1881 EOF bare-release / close-resolution release branch handed it to the client verbatim: whole-buffer push stripped both opens, the split push leaked the second one — same logical output, different persisted bytes per chunking (#3198 determinism contract violated).

Fix

While a bare-open RELEASE session is live, a new LONE_OPEN inside the accumulated span is exactly that nesting evidence arriving late: release the prefix as prose, count the outer opening as dropped alone, and re-adjudicate from the inner opening through the normal loop — the code path the whole-buffer run takes. Gated to bare-open release sessions (attrs-bearing tails are tag content end-to-end per the #644 EOF rule; wrapped turns discard their payload wholesale) and to openings that precede any close terminator (close-first still resolves on the existing path). Establishes the invariant that swallowed never holds a LONE_OPEN, so no flush-side change is needed.

Behavior change (old -> new)

Only the reported shape changes: with two or more bare opens, a chunk boundary falling after one of them previously leaked the later open(s) into body text; every chunking now produces exactly the whole-buffer bytes (e.g. <acp><acp>text -> text for all splits; was <acp>text for between-tags splits). No other input class is touched — single bare opens keep the #1881 prose-wearing semantics, attrs/wrapped sessions are gated out (asserted by negative-control tests).

Residual corner (documented, not fixed)

A pending ref run longer than IMITATION_SWALLOW_CAP (4096 chars) flips the session to non-releasing BEFORE a later-arriving opening can trigger the split, so a >4KB pure-ref run followed by markup can still diverge whole-push vs boundary-push. Flipping releases back on arrival would resurrect discarded payloads; left as-is (bounded extreme).

Adjacent finding

Verified while working this: an attrs-bearing payload with a nested bare open (<acp tokens="1">junk<acp>text</acp>) streams to junk<acp>text while whole-text stripAcpTags yields junktext — a deterministic streaming-vs-whole-text parity gap (whole-buffer push already diverges; unrelated to chunking, distinct mechanism: release branches hand back interior without re-stripping). Out of scope here (semantic decision on re-adjudicating attrs-payload interiors); tracked in #4169.

Tests

  • New tests/issue4163-bare-open-boundary.test.ts: pinned bytes for 10 shapes x every single-cut split x 20 seeded random splittings x dropCount (#2405c) chunk-invariance, plus negative controls (single bare open [bug] ACP 标签泄漏:<acp tokens=...> 标签被模型原样复述到回复正文,仅靠系统提示劝阻不足 #1881 semantics; attrs/wrapped sessions untouched by the gate).
  • tests/tag-echo-chunking-determinism.test.ts: 4 permanent corpus entries for the family.
  • Local targeted runs green: issue4163-bare-open-boundary, tag-echo-chunking-determinism, tag-echo, tag-echo-absorb-emission, marker-echo, issue1881-reasoning-tag-leak, issue2190-degen-close, issue2023-refs-residue; typecheck clean. Full suite: CI.

@ranxianglei ranxianglei changed the title fix(loop): re-adjudicate nested openings arriving across a chunk boundary in the tag-echo bare-open swallow [PR] fix(loop): re-adjudicate nested openings arriving across a chunk boundary in the tag-echo bare-open swallow Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-21_tag-echo-bare-open-boundary (8b6c098)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4973-pr.4170.c9abc0a

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-pr4170.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)

查重: 不重复。 检索 open+closed issue/PR(按失败签名:tag-echo 裸开标签 × chunk 边界 × LONE_OPEN swallow 释放路径):本 PR 是该失败域的唯在途修复。相关但不同:#4163 = 本 PR 修的 bug 本体(#Closes);#4169 = PR 正文自述的另一个机制(整段推入时 release 分支不重剥的内部 parity gap,与分块无关),已单独跟踪,不属本 PR 范围;#4162 = 同文件另一边界族(PARTIAL_TAIL 头部后行断言盲区),不同机制。无并列重复 PR。

标签: bug scope/wiring p2(缺陷类;请求管道 wire 改写层 src/loop/tag-echo-filter.ts;能用但有明显问题——特定分块下输出随机多一个裸开标签 + 持久化字节随分块漂移,非不可用、非失控增长,故 p2 非 p1)。宿主车道标签不打:tag-echo 过滤器是车道中立的流式 wire 处理,报告未指向具体客户端。

正在做完整 PR 审核(读 diff/既有行为回归清点/测试有效性/CI),结论按结构化八问随后给出。

@ranxianglei ranxianglei added bug Something isn't working p2 scope/wiring labels Oct 21, 2026
…ing arriving across a chunk boundary — #4163

The #1720 nesting evidence for a lone open render tag ('more tag structure
follows in this same chunk -> drop alone, let the inner markup decide')
was judged on the CURRENT buffer only. When an SSE boundary fell after the
first bare open, the later opening accumulated into the live swallow span
and the #1881 EOF bare-release / close-resolution release branch handed it
to the client verbatim: whole-buffer push stripped both opens, the split
push leaked the second one — same logical output, different persisted
bytes per chunking (#3198 determinism contract violated).

While a bare-open RELEASE session is live, a new LONE_OPEN inside the
accumulated span is exactly that nesting evidence arriving late: release
the prefix as prose, count the outer opening as dropped alone, and
re-adjudicate from the inner opening through the normal loop — the code
path the whole-buffer run takes. Gated to bare-open release sessions
(attrs-bearing tails are tag content end-to-end per the #644 EOF rule,
wrapped turns discard their payload wholesale) and to openings that
precede any close terminator (close-first still resolves on the existing
path). Establishes the invariant that swallowed never holds a LONE_OPEN,
so no flush-side change is needed.
@ranxianglei
ranxianglei force-pushed the 2026-10-21_tag-echo-bare-open-boundary branch from bf1513d to 3454d84 Compare October 21, 2026 13:47
…nt leak (#4107 shape 2)

The bare-open re-adjudication changes the streaming output for the
pinned C#4107-2 shape (close fragment at chunk boundary + nested bare
open behind it): the split path now matches whole-text byte-for-byte
instead of releasing the nested open verbatim. The pin asserted the
bug was still present and instructed itself to be flipped when fixed —
done. It becomes a permanent parity pin (streaming === whole-text,
no leaked nested open).

Shape 1 (C#4107 dead-ref residue) is still broken and stays pinned;
the P1 domain exclusion stays in place for it. verif/README.md ledger
updated accordingly.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Review 完成(独立审过代码、测试与 CI,不只是读描述)。先说我在 review 过程中做的两件事,再按八问给结论。

Review 中执行的动作(均已落到 PR 分支)

  1. Rebase:PR 基于 56a0f5a,落后 master 72 个提交。逐提交核对:72 个提交均未触碰本 PR 的 3 个文件(kernel/ 在窗口内有变更,已重建后验证)。干净 rebase:bf1513ddb → 3454d84dc(force-with-lease,diff 不变:3 文件 +190/-0)。
  2. CI 红排查 + 顺手修:rebase 后 CI 三个测试分片红(ubuntu-22-2、windows-22-2、ubuntu-24-1),零 annotation、日志端点 401,无法从 API 定位。本地用同一分片脚本(CI_TEST_SHARD=2/3)定向复现:唯一失败是 tests/verif-tag-echo-filter.test.ts 的 C#4107-2 钉——这是一个「bug 仍然存在」型断言(assert.notEqual(whole, split)),而本 PR 的修复恰好把该形状(Streaming tag filter output depends on chunk position: when the same text arrives in two chunks, internal residual m1255 | 流式标签过滤器输出依赖分块位置:同一文本分两块到达时内部残留 m1255</acPA 泄漏给客户端 #4107 形状 2:close 碎片在块边界 + 其后嵌套裸开)的流式输出修成了与整段文本逐字节一致,钉因此变红。钉自身的注释就写着「fix 后翻转」,我按模块协议翻转了它(独立 commit 8b6c09858:改为恒等断言 + 无泄漏嵌套开的负断言,更新 P1 域排除注释与 verif/README.md 台账)。Streaming tag filter output depends on chunk position: when the same text arrives in two chunks, internal residual m1255 | 流式标签过滤器输出依赖分块位置:同一文本分两块到达时内部残留 m1255</acPA 泄漏给客户端 #4107 形状 1(dead-ref residue)仍坏,保持原钉不动。翻转后该文件 17/17 绿、typecheck 干净。
    • shard 1/3 本地全绿,且 CI 里同文件集的 ubuntu-22-1 也是绿的 → ubuntu-24-1 那个红疑似瞬态/runner 或 node-24 特有问题,等新 head 的 CI 结果确认(若复现需单独隔离)。

结构化八问

  1. 是什么问题:响应文本里出现两个及以上裸开标签时,SSE 分块边界若落在它们之间,后到的开标签会漏进正文;同一段逻辑输出因分块不同产生不同的持久化字节。
  2. 什么原因导致的:「孤立裸开后面还有嵌套结构 → 外层单独丢弃」这条判定(缺陷:PAIRED 正则吞掉最多 64 个字符的助手正文 #1720)只在 push 当时对当前缓冲做判断;流式状态下 swallow span 是跨 push 累积的,flush 时的 release 分支不重新裁决 span 内累积物,迟到的嵌套开就被原样放行。修的是判定层(让流式路径复用整段路径的同一条裁决代码),不是出口过滤——疏不是堵。
  3. 影响范围与严重程度:触发条件较窄(≥2 个裸开 + 边界恰好落在其间);后果是客户端持久化历史随机多出裸开字节,进而漂移上游前缀缓存接缝。p2:可用、有确定性噪声,非不可用、非失控增长。
  4. 怎么修复的:bare-open release 会话存活期间,累积 span 里出现新的孤立开 = 「嵌套证据迟到」→ 前缀按 prose 释放、外层开计为 dropped-alone、剩余从内层开起走正常循环(即整段缓冲跑的那条路径)。门控到 bare-open release 会话(attrs 尾按 [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 整体是标签内容、wrapped 轮次整体丢弃,均不进入)且只处理出现在任何 close 终结符之前的开;确立 swallowed 永不持有 LONE_OPEN 的不变量,flush 侧无需改动。
  5. 是否有回归问题:逐项审过既有行为——单裸开 [bug] ACP 标签泄漏:<acp tokens=...> 标签被模型原样复述到回复正文,仅靠系统提示劝阻不足 #1881 语义(负控制 + issue1881 套件)、attrs-bearing 尾 [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、wrapped 奇引号轮次、degen-close(issue2190)、refs-residue(issue2023)、dropCount #2405c 跨块不变性,全部保持。一处有意的行为变化必须披露(正向):Streaming tag filter output depends on chunk position: when the same text arrives in two chunks, internal residual m1255 | 流式标签过滤器输出依赖分块位置:同一文本分两块到达时内部残留 m1255</acPA 泄漏给客户端 #4107 形状 2 被顺带修复——旧行为:split 输出 ...日本</apc <apc>quotes...(嵌套开泄漏);新行为:与整段文本逐字节一致 ...日本</apc quotes...。这就是上面翻钉的原因;该形状此前由 verif 钉明确记录为已知 bug,修复方向与 A/B experiment: ACP_RENDER_NONE=1 (renderTags=none) eliminates dsh render seams — hit rate 85.6% -> 91.2% #3198 契约一致。tag-echo filter: a nested bare open inside an attrs-tag payload survives in streaming mode but is removed by whole-text stripAcpTags #4169(整段 push 与 stripAcpTags 全文本之间的另一处确定性差异,机制不同)作者已正确划出 scope,同意。
  6. 是否破坏缓存:没有。本修复消除的是一个缓存接缝漂移源(分块导致的字节漂移);未触碰任何缓存键、重试策略或增量游标。
  7. 是否改了设计方向:没有。仍是「流式必须等于整段」(A/B experiment: ACP_RENDER_NONE=1 (renderTags=none) eliminates dsh render seams — hit rate 85.6% -> 91.2% #3198),修法是把流式判定对齐到整段的既有代码路径,未引入新机制。
  8. 是否引入了新的配置:没有。

测试有效性:新测试是真测试——10 个固定形状 × 每个单切点 × 20 组种子随机拆分,全部钉住期望字节;另有 dropCount 跨块不变性与两组负控制(单开 #1881 语义不被新门控波及、attrs/wrapped 会话不受影响)。我把新测试文件拷到未打补丁的 master 上跑过,确认它会失败(回归钉属性成立)。8 个定向套件本地绿;全量以 CI 为准。

判定:根因修复、回归面已清点、diff 干净(现共 2 个 commit:原修复 + 翻钉)。按 §7.4,本 PR 触碰响应流字节(wire/message shape)→ 人审合并档,不走 auto-merge。新 head 8b6c09858 的 CI 跑完后我跟进一条确认(重点看 shard 2 转绿与 ubuntu-24-1 是否复现);CI 干净即可合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI 确认(新 head 8b6c09858):全部绿。过程如下——

  1. shard 2(ubuntu + windows)首跑红:即上一条回复说的 verif C#4107-2 钉。翻钉后 ubuntu-22-2 转绿(确定性失败已消除)。
  2. ubuntu-24-1:上一轮红、这一轮同文件集直接绿 → 证实为瞬态,与本 PR 无关。
  3. windows-22-2:翻钉后仍红一次(零 annotation、日志端点对该 token 返回 401 拿不到)。排查:该分片文件集在 ubuntu-22 与本地 node-22 上全绿(本地复跑 shard 2/3 通过),且分片内含 16 个进程级(LIVE_FILES)套件——正是 Windows 侧已知的端口/进程类 flake 家族(fix: emit /acp panel as persistent custom message and strip it from the proxy model context (#359) #360/无单实例守卫:多个 bili 代理进程并存共写 sessions 目录,伴随孤儿 ref、有注册表无 transcript、计数自相矛盾的污染簇 #394)。我触发了 rerun-failed-jobs 只重跑该失败 job:绿。整个 run 39619198502 现为 completed/success。

结论不变且现在证据齐了:本 PR 无确定性失败残留,windows 那次红是环境性 flake(如需留痕可自行决定是否单独记一笔,我没有为此开 issue——它不构成本 PR 的合并阻塞,也查不到具体挂在哪条测试)。

收工判定:代码与回归面审毕、行为变化已披露(#4107 形状 2 顺带修复 + 翻钉)、CI 干净。按 §7.4 属人审合并档(触碰响应流字节),可以合并:#4170

@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
…lose-fragment leak (ranxianglei#4107 shape 2)

The bare-open re-adjudication changes the streaming output for the
pinned C#4107-2 shape (close fragment at chunk boundary + nested bare
open behind it): the split path now matches whole-text byte-for-byte
instead of releasing the nested open verbatim. The pin asserted the
bug was still present and instructed itself to be flipped when fixed —
done. It becomes a permanent parity pin (streaming === whole-text,
no leaked nested open).

Shape 1 (C#4107 dead-ref residue) is still broken and stays pinned;
the P1 domain exclusion stays in place for it. verif/README.md ledger
updated accordingly.

(cherry picked from commit 8b6c098)
@github-actions github-actions Bot mentioned this pull request Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working p2 scope/wiring

Projects

None yet

1 participant