Repository navigation
[PR] fix: streaming orphan-ref drop no longer depends on SSE chunk boundary (#4179) - #4181
ranxianglei wants to merge 1 commit into
Conversation
#4179) The streaming tag-echo filter voided the leftmost ORPHAN_REF_CLOSE match when its run head was word/tag-adjacent across a chunk boundary (#644), then abandoned the run entirely. Because REFS_RUN may begin at any ref (joiners are not word chars), a valid mid-run start (a ref preceded by a joiner) could sit inside the voided span and was lost — so whether the unit was dropped depended on where the SSE chunk boundary fell: under-deletion vs whole-text, breaking the chunk-split determinism contract (#3198). Re-scan from just past the voided head so that mid-run start is found instead of abandoned; any match at index > 0 already passes the lookbehind gate by construction, so one re-scan suffices. Streaming now matches stripAcpTags for this shape at every split position. Behavior change (intended): for prose word-glued to a multi-ref run + orphan close, streaming previously kept the tail ref on some chunkings; it now drops the joiner+tail-ref+close as one unit, matching whole-text in all chunkings. Regression pins: dedicated every-split test + fuzz corpus entry.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4977-pr.4181.28e33adThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr4181.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复。 本 PR 是 #4179 的修复(方向 a)。与同族 #4162(PARTIAL_TAIL 缺跨块 lookbehind → 过删除)机制不同:本条是 ORPHAN_REF_CLOSE 头部 match 被词相邻判定 void 后未从 match.index+1 重扫、中 run 起点丢失 → 欠删除。两者互不覆盖(#4162 修了 PARTIAL_TAIL 本条仍在),各自独立成立。 标签: bug / p1 / scope/wiring / pr(与源 issue #4179、同族 #4162 已打的标签对齐;p1 按 owner 2026-10-19 修订——chunk 边界决定字节 = 前缀缓存接缝类)。 八问
测试有效性(真测试核验)
CI 状态(关键判定)head ce324a6:除 处置建议与判定代码层面审核通过:机制正确、一次重扫论证成立、测试有牙(红绿双向实测)、无回归、diff 干净。本次未 rebase:三个触碰文件自基点以来零漂移(已核实 diff 为空),现在 rebase 只会对着一套红的管道烧一轮矩阵。最终 green 待:① #4378(或 #4350)合入、master 转绿;② rebase 到 master 重跑 CI。两步完成后请 owner 合并。 判定:代码可合(mergeable,behind);等红风暴清理后 rebase + rerun 拿最终 green 再合。 |
What / why (one line)
The streaming tag-echo filter sometimes failed to strip an echoed render-tag unit because where the SSE stream was split decided whether the drop happened — the same logical model output persisted differently across retries, opening a prefix-cache seam (#3198 contract). This makes that drop independent of the chunk boundary.
Symptom
Input like
textm1111–m2222</acp>(prose glued to a multi-ref run + orphan close):textm1111–(dropsm2222</acp>)text|m1111–m2222</acp>) →textm1111–m2222(m2222survives)Same text, different chunking → different bytes. Whole-text
stripAcpTagsalways droppedm2222; streaming under-deleted on certain boundaries.Root cause
src/loop/tag-echo-filter.ts,ORPHAN_REF_CLOSEhandling (~line 1139). When the leftmost match sits at the buffer head and its run-head is word/tag-adjacent across the chunk boundary (lastEmitted ∈ [\w>], the #644 cross-chunk lookbehind extension), the code voided the whole match and stopped. ButREFS_RUNmay begin at any ref (joiners aren't\w), so a legitimate mid-run start (m2222, preceded by–) sat inside the voided span and was never retried — the deletion got diluted by the chunk boundary. Whole-text has the full string, so its regex engine naturally skips the word-adjacent head and finds the mid-run start; streaming lost it.Fix
After voiding the head match, re-scan from just past it (
lastIndex = match.index + 1) so the valid mid-run start is found instead of abandoned. Any match at index > 0 already passes the lookbehind gate by construction, so one re-scan suffices. ~8 lines inside the matcher; no other code path touched.Behavior change (intended)
For prose word-glued to a multi-ref run + orphan close:
m2222) on some chunkings (chunk-boundary-dependent)joiner + tail-ref + closeas one unit, matching whole-textstripAcpTagsat every split positionBoth compression modes
The filter runs on model prose (content/reasoning/text fields) in both plugin mode and proxy mode; the change is internal to the shared
createTagEchoFilter.process()matcher and is mode-agnostic. It does not touch tool-call arguments (#1039 byte-exact), signed thinking/reasoning channels (KDD #10), config, persistence format, or any wire shape beyond the existing prose-strip contract.Duplicate screening
Not a duplicate. Same family as #4162 (chunk-split determinism, #3198) but opposite direction and different mechanism: #4162 = over-deletion via
PARTIAL_TAIL's missing cross-chunk lookbehind (awaiting owner A/B decision, no PR yet); #4179 = under-deletion viaORPHAN_REF_CLOSEnot re-scanning after a voided head. Different lines, orthogonal fixes; shipped independently because #4179's target is pinned by whole-text parity and needs no decision. Together they fully close the family.Tests
streaming filter matches stripAcpTags for a word-glued multi-ref orphan run at every split position (#4179)— enumerates every single-point split for en-dash/comma/hyphen joiners, a 3-ref deep case, a space-prefixed control, and a single-ref negative control; plus explicit semantic pins. Verified it fails on the unfixed source and passes with the fix.tests/tag-echo-chunking-determinism.test.ts.Fixes #4179
Related: #4162 (opposite direction, same family) · #2023 (orphan unit) · #644 (cross-chunk lookbehind) · #3198 (chunk-split determinism contract)