Skip to content

[PR] fix(plugin): don't drain held tags on inert mid-stream frames (#5848) - #5849

Merged
ranxianglei merged 2 commits into
ranxianglei:masterfrom
tax-mux:2026-11-07_progress-frame-held-tag-flush
Nov 9, 2026
Merged

ranxianglei merged 2 commits into
ranxianglei:masterfrom
tax-mux:2026-11-07_progress-frame-held-tag-flush

Conversation

@tax-mux

@tax-mux tax-mux commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #5848. Refs #5192.

Problem

processOpenai drained the tag-echo filter on every text-less frame while a tail was held. MTPLX (and any OpenAI-compatible server that interleaves non-terminal delta:{} frames) sends such a frame every ~15 tokens, so a render tag split across one lost its held head (<acp tokens="3) and the rest (1" type="text" …>m00039) reached the host as prose — the opener-less residue of #5192. Full mechanism and log evidence in #5848.

Change

src/plugin.ts — the no-text drain now requires the frame to carry something a held tail must precede (hadTextOtherThanTextFields: a non-empty finish_reason, tool_calls, or any other delta key). An empty-delta frame passes through untouched and the held tail joins the next text delta, where the tag is recognized whole.

Unchanged: the terminal drain (isTerminal, #1546), the [DONE] drain, the no-choices path, and the Anthropic / Google lanes (no mid-stream text-less frames observed there).

Behavior change: on an empty-delta, non-terminal frame a held tail is no longer flushed early — it is released by the next text delta or the terminal drain, i.e. the same bytes the client would have seen without the frame.

Tests

New tests/plugin-passthrough-progress-frame.test.ts (3 cases, all fail on master, pass here):

  • a progress frame inside a paired tag does not leak the tag's tail (前の文章。後の文章);
  • a progress frame inside an unclosed tag yields the same text as the stream without it;
  • a progress frame after every chunk leaves the visible text identical to the stream without frames (on master the whole tag leaks).

Locally on this head (rebased on master c45ac21): all tests that touch pipePluginChatWithStrip / the tag-echo filter / stripAcpTags — 574/574 pass, including plugin-passthrough-finish-tail.test.ts (#1546); npm run typecheck clean. Full regression is left to CI per §7.2.

…nglei#5848)

MTPLX interleaves a text-less progress frame
({"choices":[{"delta":{},"finish_reason":null}],"mtplx_progress":{...}})
roughly every ~15 decoded tokens. processOpenai's no-text path drained the
tag-echo filter on it, so a render tag split across the frame lost its held
head (`<acp tokens="3`) and the rest (`1" type="text" ...>m00039`) reached
the host as prose -- the opener-less residue reported in ranxianglei#5192.

Only drain on a text-less frame when it carries something a held tail must
precede (finish_reason, tool_calls or another delta key); terminal and
[DONE] drains (ranxianglei#1546) are unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ranxianglei ranxianglei changed the title fix(plugin): don't drain held tags on inert mid-stream frames (#5848) [PR] fix(plugin): don't drain held tags on inert mid-stream frames (#5848) Nov 7, 2026
@tax-mux

tax-mux commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

CI note: the 3 red test shards (ubuntu 22/2, ubuntu 24/2, windows 22/4) all fail on the same two cases in tests/issue5719-msgid-lane-identity.test.ts (#5719 T1 and T8). They fail identically on plain master c45ac21 when the file is run standalone, so they are pre-existing and unrelated to this change; every other shard and e2e lane is green.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。 open+closed 全检索(含 PR):没有其他条目修同一机制(mid-stream 空 delta 帧 drain tag-echo filter);GitHub 按 5848/5192/MTPLX 搜 open PR 只命中本 PR。相关历史:#5192(现象总账)、#1546(terminal drain,本 PR 不动)、#2405(空 finish_reason 先例,代码注释已引)。

标签:bug / scope/wiring / p2 —— 特定上游帧形状(MTPLX 系 progress frame)下渲染标签残片漏进宿主可见文本;可用、无数据丢失、无缓存影响。注:本沙箱的镜像 label API 未实现(endpoint not implemented),意图标签在此报备。

审核结论:APPROVE(代码可合;CI 三红为继承性 master 红,待其修复落地后重跑)

① 原 issue 方向

#5848 给了日志证据:MTPLX 每 ~15 token 发一个 {"choices":[{"index":0,"delta":{},"finish_reason":null}],"mtplx_progress":{...}};master 上 processOpenai 的 no-text 出口对这种帧 drain 掉 tag-echo filter 里 held 的渲染标签,把开标签撕成无 opener 残片送到客户端(前的文章。1" type="text" time="…">m00039后的文章)。修法打在决策点(drain 门)而不是在出口改写字节——不是 mask;复用的是 master 已有的 hadTextOtherThanTextFields(src/plugin.ts:3752,#2405 语义),没有新造轮子。方向正确。

② 回归审查(触碰路径上的既有行为逐项清点)

pipePluginChatWithStrip 内全部 drain 点逐一核对:

唯一行为变化:非终态、无文本、且每个 choice 的 delta 为空或仅 reasoning 系键、finish_reason 为 null/空/缺省的帧,不再提前 flush;held tail 由下一个文本 delta 或 terminal/[DONE] drain 释放——客户端净可见字节与「没有该帧」的流一致。带 role/tool_calls/其他 delta 键或非空 finish_reason 的帧照旧 drain(helper 返回 true)。无 fail-fast 变吞错、无阈值/时序/输出格式漂移;PR 正文已正确披露旧→新。

③ 代码

一行门 + 四行 why 注释(引案号)。helper 复用非复制;无死代码、无魔法值、风格与文件一致。干净。

④ 测试有效性

3 个新用例全部是客户端可见文本的字节级断言(不是 mock 套 mock)。牙口独立验证:把那一行 revert 回 master 行为 → 3/3 全挂;合上修复 → 3/3 全过(本地实测)。同 head 相邻 12 个套件(tag-echo 核心/chunking-determinism/verif-guard/finish-tail(#1546)/两个 tag-strip passthrough/passthrough-visibility/strip-idempotency/proxy-noinject/bili-artifact/e2e-tag hermetic)193/193 绿。负向方向由未改动的 finish-tail 套件兜住(terminal drain 仍触发),符合 §3617 正反双向门禁纪律。

⑤ diff 整洁度

2 文件 +112/−1,每一行都在主题上。一处纯外观小疵(不阻塞、不值得改写外部贡献者历史):commit message 里嵌了 agent 会话引用字面量 (m00039)。

⑤b 代码整洁(外部提交从严)

命名达意;注释讲为什么(引案号)不复述代码;测试文件沿用仓库既有惯例(tests 里裸写标签字面量与 tests/tag-echo.test.ts 等存量文件一致,无 CI lint 反对);零新增依赖。过。

本地证据(仅定向,§7.2)

新文件 3/3(revert 后 0/3);相邻套件 193/193;npm run typecheck clean;全量留给 CI。

CI 状态(镜像缓存,run @48076d28b)

三个红分片(win22-s4 / ubu24-s2 / ubu22-s2)= 继承性 master 红,非本 PR:与 #4599 最新一轮刚登记的继承签名同分片同机制——#5734 E5 self-checkpoint reanchor(30a8bc2d0e,经 1f2efba00 入 master)在 src/session-resolve.ts 的 tagChanged 分支新增的 selfCheckpointDeclares() 优先档打穿了 tests/issue5719-msgid-lane-identity.test.ts 的 T1(:115)+T8(:280)两枚旧钉,确定性挂(毫秒级时长)。本 PR head 本地复现:6/8 绿、恰 T1/T8 红;PR diff(src/plugin.ts + 新测试文件)与该路径零交集。ci-fixes 相对 master 零增量(git 实测无可 merge),故分支不动;master 侧修复落地后重跑即绿。已按协调政策在 #4599 留了一行记录。

八问

  1. 是什么问题:会发 text-less progress 帧的 OpenAI-wire 上游(MTPLX 家族)让 bili 提前 flush 了 tag-echo filter 里 held 的渲染标签,无 opener 的标签残片漏进宿主可见文本。
  2. 什么原因导致的:processOpenai 的 no-text 出口把「这帧没内容」当成「可以安全 drain」;但真正惰性的帧(空 delta、无 finish_reason)前面没有任何东西需要它先行,drain 就把下一个真实文本 delta 本该补完整的标签撕开了。
  3. 影响范围与严重程度:插件模式 + OpenAI 兼容上游且该上游发 delta:{} progress 帧(MTPLX 约每 15 token 一帧);严重度=可见文本被标签残片污染,无数据丢失、不可用或缓存影响 → p2。
  4. 怎么修复的:把 drain 门做精确——只有当帧携带 held tail 必须先行之物(非空 finish_reason / tool_calls / 任一非文本 delta 键)才 drain,复用既有 【bug】bili 0.1.188 · ACP 标签形态异常 + 摘要泄漏 + 剥离日志可观测性 #2405 helper;惰性帧原样透传,tail 并入下一个文本 delta 或由 terminal/[DONE] drain 释放。
  5. 是否有回归问题:未发现——terminal drain、[DONE] drain、流尾 flush、Anthropic/Responses/Google 车道逐项核验未变;唯一变化的惰性帧行为已在 PR 正文披露(旧→新+原因)。
  6. 是否破坏缓存:不涉及——未触任何缓存/ref/游标/去重逻辑;非惰性流的出站字节不变,惰性帧流的净可见字节等于无帧流。
  7. 是否改了设计方向:不涉及——现有 tag-echo 状态机内的决策点修正,无架构/边界转向。
  8. 是否引入新配置:不涉及。

判定:可合——代码审核通过(外部提交从严清单全过);CI 三红为 #4599 在档的继承性 issue5719 master 红,与 PR diff 零交集,master 侧修复落地重跑后转绿即可合并。合并动作归 owner。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

结论先行:三个红 shard 是继承性 master-level born-red,对本 PR diff 归因为零;修复已收敛为独立小 PR #5857(对 master,test-only),合入后本 PR 下次 CI 触发即转绿。本 PR 代码本身无需任何改动。

验证过程(不信转述,全部本地复现)

  1. 拉 CI 日志确认失败签名:三个红 shard 均只挂 tests/issue5719-msgid-lane-identity.test.ts 的 T1/T8 两个 case(亚毫秒级断言失败,确定性,非负载 flake),T2–T7 全过。
  2. 在 plain master c45ac21 上单文件独立运行:同样恰好 T1/T8 红——与作者描述一致,且证明与本 PR 无关(本 PR diff 仅 src/plugin.ts + 一个新测试文件,与该测试文件零交集)。
  3. 根因定位:[PR] fix: keep the live conversation on its raw lane when a full compaction lands with a persona-text drift (#5719) #5734(fix: re-anchor on the authored checkpoint's conv declaration,已并入 master)在 resolveSessionOrder tagChanged 分支置顶了新的 E5 self-checkpoint rung(src/session-resolve.ts:338,reason 字符串 self-authored checkpoint declares this raw id — …),并自带 pin 文件 tests/issue5719-self-checkpoint-reanchor.test.ts,但漏更新了旧的 [resolveSessionOrder] Full compaction and persona tag drift occurring in the same turn → inevitably forks to |sub: side | [resolveSessionOrder] Full compaction and persona tag drift occurring in the same turn → inevitably forks to |sub: side | [resolve… #5719 pin 文件:该文件共享 fixture incidentHistory() 的第一个 user cell 内嵌了 bili 自己的 checkpoint 身份头(conv="<raw id>"),于是 E5 抢先命中——
    • T1:reanchor 的 reason 从 msgid-rung 文案变成 E5 文案,正则 pin 失配;
    • T8:store=null 场景被 marker 直接 reanchor,不再走 byte-only 降级 → fork;
    • T5/T6 更隐蔽地静默失效:它们靠 E5 通过、从未真正查询 store,「stored rows outlive the wire」「restart 后 STORE 存活」两个性质不再被实际验证。

为什么不在本 PR 分支内修

PR head 位于作者的外部 fork(tax-mux/billion-context),且该 head 分支已在远端删除(GitHub 仅冻结 refs/pull/5849/head)——CI 工程师无 fork 写权限,分支内追加 commit 物理不可行。master-level 缺陷按惯例收敛为独立小 PR(先查 #4599:ci-fixes 已全量并入 master,合并无意义;查重:open issues/PRs 无同签名条目,#5851 只动 src/session-resolve.ts 不冲突)。

修复(#5857,已开)

fixture 的 conv 声明改为 FOREIGN(conv="${tag}-other",一行):E5 gate 像对待任何外部引用一样 miss(其边界由 E5 自己的 suite acceptance 2 钉住),本文件的每个 rung 恢复原设计触发路径,全部原始断言逐字保留(T1 的 reason 正则、T8 的 fork 期望),未削弱任何 pin。本地实测:两个 issue5719 文件 14/14 绿(修复前 12/14,恰为 T1/T8)。已在 #4599 登记该继承家族,请其他车道遇到同签名引用 #5857 而非重复修。

八问

  1. 是什么问题:三个红 test shard 挂在 tests/issue5719-msgid-lane-identity.test.ts T1/T8——与本 PR 改动无关的存量测试漂移。
  2. 什么原因导致的:[PR] fix: keep the live conversation on its raw lane when a full compaction lands with a persona-text drift (#5719) #5734 上线 E5 checkpoint re-anchor rung(有意行为变更,commit message 明示)时未同步更新旧 [resolveSessionOrder] Full compaction and persona tag drift occurring in the same turn → inevitably forks to |sub: side | [resolveSessionOrder] Full compaction and persona tag drift occurring in the same turn → inevitably forks to |sub: side | [resolve… #5719 pin 文件;其 fixture 自带的自有 checkpoint 头让新 rung 抢走了旧 pin 要钉的场景。
  3. 影响范围与严重程度:凡包含 c45ac21 的树(master 及 rebase 到它的 PR),只要 shard 分到该测试文件就红——舰队级阻塞(每个在途 PR 都受影响);运行时行为零影响(纯测试漂移,E5 行为本身是已上线的设计意图)。
  4. 怎么修复的:fixture 改 foreign conv 一行,让被测 rung(msgid 重叠 / store 救援 / store-null 降级)重新成为实际触发路径,原断言逐字保留;E5 自身覆盖由其专属 suite 继续承担。test-only 提交,无 src 改动。
  5. 是否有回归问题:无运行时行为变更;既有的 E5 pin(acceptance 1/2/2b/3 + 四 wire shape)全数保持绿;T5/T6 覆盖率反而从「空转」恢复为真实验证。
  6. 是否破坏缓存:不涉及(测试文件改动)。
  7. 是否改了设计方向:不涉及。
  8. 是否引入新配置:无。

收工判定:本 run 三个红项全部为继承性 born-red,归因零残留;修复闭环在 #5857(单一小 PR,非拆片)。#5857 合入 master 后,本 PR 的下一次 CI 触发(author re-push 或手动重跑)这三个 shard 即转绿——在此之前本 PR 无需再动。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

总结(完整审核已在上方本线程发出,此处为收工摘要):

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

收工确认(完整八问结论已在本线程上方发出,此处只报新进展): 修复 PR #5857 CI 已全绿(30/30 checks,0 失败),当前 open、behind(master 又前移,一行 test-fixture 改动无冲突风险,BEHIND 不构成阻塞)。等 owner 合并 #5857 后,本 PR 的下一次 CI 触发(作者 re-push 或手动重跑)三个红 shard 即转绿——届时即可按上方审核意见合并本 PR。本 run 无其他动作。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] auto-fix stalled: test (windows-latest, 22, 4), test (ubuntu-latest, 24, 2), test (ubuntu-latest, 22, 2) — stopping for human review

1 similar comment
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] auto-fix stalled: test (windows-latest, 22, 4), test (ubuntu-latest, 24, 2), test (ubuntu-latest, 22, 2) — stopping for human review

@ranxianglei
ranxianglei merged commit e7b3d28 into ranxianglei:master Nov 9, 2026
50 checks passed
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1106-master.e7b3d28 (rolling master tag).

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

Louie0806 added a commit to Louie0806/billion-context that referenced this pull request Nov 9, 2026
…itespace gate, ranxianglei#5849 held-tag flush on inert frames

Advances the base from 7d18b7a to 1f311dd (8 files). Two files overlap with
this lane: src/plugin.ts and src/loop/core.ts. Upstream added a whitespace-only
degenerate-retry gate (ranxianglei#732 follow-up) around the request-scoped budget warn in
runChatLoop, and stopped draining held tags on inert mid-stream frames (ranxianglei#5848).
Both hunks sit clear of the lane's strip gates, so the auto-merge needed no
manual resolution.

Notable upstream commits adopted:
 - c5fed0e loop: retry degenerate turns that end with whitespace-only text (ranxianglei#732 follow-up)
 - 65dd4b3 refactor(loop): drop redundant forwardedVisibleText from the degenerate-retry gate
 - 5182559 fix(loop): correct double-degenerate warn attribution to the request-scoped budget
 - 7a51346 test(loop): pin the double-degenerate warn both directions
 - 4c15903 fix(stream): extend the return-to-task instruction to all parse-failure receipts
 - 48076d2 fix(plugin): don't drain held tags on inert mid-stream frames (ranxianglei#5848)
 - 8c3a3f1 test(ci): align issue411 waitFor with the ranxianglei#4161 timing-window idiom
 - 016d933 test(launcher): cover the ranxianglei#5955 wedged same-lane takeover ladder
ranxianglei pushed a commit to NewbieXvwu/billion-context that referenced this pull request Nov 15, 2026
ranxianglei#5849 added hadTextOtherThanTextFields to the chat lane after a text-less
frame drained a held render-tag head, letting the rest of the tag reach the
host as prose. The google lane kept the unconditional drain, on the
assumption that it never sees such frames -- an absence of observation, not
a property of the lane.

A Gemini progress frame whose only part is {text:""} reproduces the same
split here, so gate that exit on googleFrameHasNonText, the predicate the
rebuilt branch three lines above already uses.
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.

[pi/OpenAI] text-less mid-stream frames (delta:{}) drain the tag-echo filter → opener-less render-tag residue (one mechanism of #5192)

2 participants