Skip to content

[PR] fix: drop a tool-typed tag-echo span whole instead of keeping its fabricated body (#6557) - #6633

Merged
ranxianglei merged 2 commits into
ranxianglei:masterfrom
gongfpp:fix/tool-typed-echo-drop
Nov 15, 2026
Merged

ranxianglei merged 2 commits into
ranxianglei:masterfrom
gongfpp:fix/tool-typed-echo-drop

Conversation

@gongfpp

@gongfpp gongfpp commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

What

A model-emitted render tag whose type names a tool lane (type="tool:acp_cache") frames a fabricated tool result. The tag-echo filter treated it like type="text": it stripped the markup and kept the body, so the invented result became ordinary assistant text — and from then on the model opened nearly every reply by copying "tag + that body" (production session in #6557: the same JSON block 25 times in 23 minutes, until the range was folded).

A tool-typed span now dies whole, in both paths:

path before after
whole-text (stripAcpTags → stripPass) markup stripped, body kept as prose TOOL_TYPED_PAIR drops the span from the opening through its close; an opening with no close in the field owns the rest of it (the wrapped-turn EOF rule, reused)
streaming (createTagEchoFilter) the swallow released the body as prose at the #644 budget the swallow takes the attested-imitation setting (swallowReleases = false + IMITATION_SWALLOW_CAP), so the body is discarded — closed and never-closed (EOF) shape alike

The distinction is the one the #1720/#2023 rule already makes, extended to a third case: a render tag wraps only kernel refs, so a body that is not refs-only is prose wearing tags when the type is text — there the body IS the model's own words and keeping it is correct. Under type="tool:…" the body can only be an invented tool result; the #1720 rule applied verbatim is what turns one echo into a self-reinforcing loop.

type is matched through casing drift (#1731 joins here: an echoed type drifts like an echoed name), and the quote after type= is part of the match so a type= inside another attribute's value cannot be mistaken for the attribute.

Accepted trade

A model that legitimately quotes a tool-typed render tag (e.g. "the kernel emits <acp tokens="1" type="tool:acp_cache">…</acp>") loses that span — the same bounded trade the filter already makes for an echoed type="text" pair, and the reason the #1039 invariant (tool-call arguments byte-exact) is untouched: nothing here routes through the argument channel.

Not in scope, deliberately

  • Suggestion 3 (repeat guard on near-identical consecutive bodies) — a similarity heuristic layered over the mechanism. With the carrier gone there is nothing left to repeat, and a "near-identical" threshold is an owner-set number.
  • Suggestion 4 (a text echo whose remainder is only <br>/whitespace should emit empty text) — that changes type="text" body semantics (缺陷:PAIRED 正则吞掉最多 64 个字符的助手正文 #1720), which is an owner call, not a side effect of this fix.

Testing

Fixes #6557

…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.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复 — searched open + closed issues/PRs for a tool-typed tag-echo span fix; no other thread targets the #6557 mechanism, and the only open [PR] row on this thread is this one.

Review

① Issue direction: correct. The producer of the fabricated tool result is the filter's own verdict: the #1720/#2023 rule ("body not refs-only = prose wearing tags: tags go, content stays") was written for type="text", where the body IS the model's words. Under type="tool:…" the body can only be an invented tool result, and applying the rule verbatim commits the invention into the assistant turn — which the model then imitates at the head of every later reply (the #6557 session: the same JSON block 25× in 23 min). Fixing the verdict at the decision point (the filter) is the right layer; a downstream mask would have been a latent bug. The accepted trade (a model legitimately quoting a tool-typed tag loses that span) is documented in the PR body and is the same bounded trade the filter already makes for an echoed type="text" pair.

③ Code: the fix is at the right layer, one defect found and fixed directly on the branch.

  • Callers verified: stripAcpTags/createTagEchoFilter run only on model-output paths; user content is safe (the marker engine deliberately does not touch render-tag spans); tool-call arguments never route through this channel ([bug] 插件透传会剥掉工具调用参数里的 render tag(arguments 流挂了 tag-echo 过滤器) #1039 intact).

  • Whole-text: the new drop pass runs before the paired/lone passes — that ordering is load-bearing (either of those would strip the markup alone and keep the fabricated body).

  • Streaming: the tool-typed opening reuses the attested-imitation swallow setting (swallowReleases = false + IMITATION_SWALLOW_CAP), so the body is discarded whether the span closes or hits EOF.

  • Defect found (fixed as commit 32aa9d7 on the PR branch): TOOL_TYPED_OPEN's tail [^<>]*> read a self-closing imitation (<acp type="tool:…"/>) as an opening. Differential repro on the original head:

    input whole-text streaming master
    x <acp type="tool:acp_cache"/> rest of prose x — rest of field lost x rest of prose both x rest of prose
    x <acp …/> body </acp> tail x tail — body lost (paired with the orphan close) x body tail both x body tail

    That is a whole-text/streaming divergence on the same input — the tag-echo filter: space-separated long reference strings trigger catastrophic regex backtracking; 30 references block the | tag-echo 过滤器:空格分隔的长引用串触发正则灾难性回溯,30 个引用阻塞流式管线约分钟级(DoS) #4178/[PR] fix: make streaming tag-echo verdicts chunk-split independent (#4169/#4107) #4210 split-invariance class this channel exists to prevent (and the discipline the PR itself cites) — plus a loss of the model's real prose after the imitation. Fix: the character before the final > must not be /, so the self-closing form falls through to the existing SELF_CLOSE pass (killed in place) — the same verdict streaming already reaches via candidate order. One-line regex change, no state-machine change; all four repro corners now agree across paths, and the fix case (closed span) still dies whole in both.

  • Adjacent corner judged acceptable, not a bug: a refs-only body with a non-acplike degenerate close (<acp type="tool:x">m01234</p> rest) 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; rarer triple-corner, no cross-path divergence.

④ Tests: real teeth. 11 original cases (split-invariance via every 2-way split + byte-at-a-time, drop-callback fires once, guards for the rules that must not move). I verified the negative direction: filter reverted to master → 7 of 11 fail; restored → 11/11. My fix-up adds 4 more (self-close dies in place with following prose surviving, both whole-text shapes; streaming split-invariance for the self-close shape; a guard that a type="text" self-close keeps its following prose).

⑤/⑤b Diff & cleanliness: clean. Two files, every line on-purpose; naming, dense cross-referenced comments, and hex-escaped angle brackets match the file's existing style; no dead code, no new dependencies.

Verification (targeted, per §7.2):

  • New test file: 15/15 pass on the new head.
  • All 18 suites importing the module: 297/297 pass.
  • tsc --noEmit: clean.
  • CI on head 32aa9d7 (verified live just now): 0 failed so far — 12 success, 13 skipped, 5 checks still queued (test lanes running).

八问

  1. 是什么问题: 模型在输出里模仿 type="tool:…" 的 render tag 并编造工具结果时, tag-echo 过滤器按 type="text" 的规则只剥标记、保留正文, 编造的工具结果变成 assistant 普通文本, 模型随后在几乎每条回复开头复读"tag+正文"([DSH plugin mode] Echoed render tag with type="tool:…" leaves a fabricated tool result in assistant text and starts a self-copying loop (0.1.213, kimi-k3.1-pro) #6557 生产会话: 同一 JSON 块 23 分钟 25 次, 直到整段被压缩)。
  2. 什么原因导致的: 缺陷:PAIRED 正则吞掉最多 64 个字符的助手正文 #1720/tag-echo filter occasionally lets m01233</acp> remnant through to the client reasoning stream (model echoes refs from compress confirmation markers) #2023 规则"正文非纯 refs = 穿 tag 的散文——tag 去、内容留"是为 type="text" 设计的(那里正文就是模型自己的话); type="tool:…" 下正文只可能是编造的工具结果, 规则照搬就把编造结果提交进会话, 模型再模仿它形成自我强化循环。缺陷在过滤器判决层: tool 型 span 与 text 型 span 共用同一判决。
  3. 影响范围与严重程度: 影响所有客户端的模型输出路径(whole-text 与 streaming 双路径); 触发条件是模型模仿 tool 型 render tag 并编造正文([DSH plugin mode] Echoed render tag with type="tool:…" leaves a fabricated tool result in assistant text and starts a self-copying loop (0.1.213, kimi-k3.1-pro) #6557 观测于 DSH 插件模式 + kimi-k3.1-pro)。严重度: 能用但有明显问题——会话被编造工具结果污染、模型陷入复读循环、上下文膨胀直到压缩机制兜底; 不造成数据丢失或会话不可用。
  4. 怎么修复的: 把 缺陷:PAIRED 正则吞掉最多 64 个字符的助手正文 #1720 规则扩到第三种情况——tool 型 span 整体死亡(开 tag 到闭 tag; 无闭 tag 则拥有字段剩余, 复用 wrapped-turn EOF 规则)。whole-text 路径新增 TOOL_TYPED_PAIR 丢弃 pass(必须先于 paired/lone pass, 否则编造正文会留下); streaming 路径复用模仿吞并配置(swallowReleases=false + IMITATION_SWALLOW_CAP), 正文丢弃。type 匹配容忍大小写漂移(tag-echo 过滤器漏掉大写 <ACP …> 与超长属性形态——渲染标签原样到达客户端 #1731)。审核另发现并已在分支上修复自关闭角: <acp …/> 是完整单元不是开 tag, 原正则误读后 whole-text 吞掉字段剩余/与孤儿闭 tag 配对, 与 streaming 分叉(违反 tag-echo filter: space-separated long reference strings trigger catastrophic regex backtracking; 30 references block the | tag-echo 过滤器:空格分隔的长引用串触发正则灾难性回溯,30 个引用阻塞流式管线约分钟级(DoS) #4178/[PR] fix: make streaming tag-echo verdicts chunk-split independent (#4169/#4107) #4210 分裂不变性); 现自关闭形式从开 tag 匹配中排除, 落入既有 SELF_CLOSE pass 原地死亡, 双路径重新一致。
  5. 是否有回归问题: 逐项审过 diff 触碰路径的既有行为——(a) 非 tool 型输入: 新代码在两条路径均为 no-op, 既有行为保持(18 个导入该模块的套件 297/297); (b) type="text" 回显: 正文仍保留(guard 测试钉住); (c) refs-only 正文: 仍整体死亡(guard 测试); (d) tool-call 参数: 字节精确, 不经过本通道([bug] 插件透传会剥掉工具调用参数里的 render tag(arguments 流挂了 tag-echo 过滤器) #1039, guard 测试); (e) 用户内容: marker 引擎刻意不碰 render-tag span, 不受影响。一处有意行为变更(PR 正文已披露): tool 型 span 正文从"保留为散文"变为"整体丢弃"——即本修复本身。原 PR 引入的自关闭角回归(whole-text 吞字段剩余)已在审核中修复(commit 32aa9d7)。
  6. 是否破坏缓存: 不涉及——过滤器只作用于模型输出文本, 不触碰前缀缓存键、会话身份或增量游标。
  7. 是否改了设计方向: 不涉及——无架构/边界/数据流转向; 单模块判决扩展(src/loop/tag-echo-filter.ts)。
  8. 是否引入了新的配置: 不涉及。

判定: 修复方向正确、机制成立, 审核发现的自关闭缺陷已直接在 PR 分支修掉(commit 32aa9d7, +4 回归测试, 双路径复现全部一致)。本 PR 是 wire/message-shape 变更(模型输出路径, 双压缩模式均受影响)→ 按 §7.4 auto-merge 门禁需人工合并。CI 在新 head 上运行中(0 failed, 5 项 queued)。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Status after the daemon restart (the session went idle after posting the full review above — no work was lost, nothing pending on my side):

  • Review complete. The self-close defect found during review is fixed on the PR branch (commit 32aa9d7, +4 regression tests, both paths verified to agree on all repro corners).
  • PR state (verified live): head 32aa9d7, 2 commits, open, not merged — unchanged.
  • CI (verified live just now): a fresh run is queued on head 32aa9d7 — 24 checks, 0 failed so far; the earlier partial run on the same head also had 0 failures.
  • Verdict stands: fix is sound; human merge required per §7.4 (wire/message-shape change, both compression modes affected).

@ranxianglei
ranxianglei merged commit 9f1c291 into ranxianglei:master Nov 15, 2026
38 of 52 checks passed
@ranxianglei

Copy link
Copy Markdown
Owner

Closes pair #6557 was auto-closed by the batch merge.

Superseded by #6765 (merged to master as 9f1c291).

Your commit 32aa9d7 is in master verbatim — same content, same authorship, only the object ID changed (the batch used a real git merge, no rebase or cherry-pick rewrite). Merged under a different branch name, so GitHub does not flip this PR by itself.

Thanks for the fix — it is live in master from 9f1c291 onward.

(Your source branch was deleted after the merge, which is why GitHub could not detect the ancestor relationship either — tip 32aa9d7 is an ancestor of master.)

@ranxianglei

Copy link
Copy Markdown
Owner

Superseded by #6765 (merged to master as 9f1c291). Your commit 32aa9d7 is in master verbatim — same content, same authorship, only the object ID changed (real git merge, no rebase/cherry-pick rewrite). Your source branch was deleted after the merge, which is why GitHub could not detect the ancestor relationship — tip 32aa9d7 is an ancestor of master. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants