Skip to content

[PR] fix: count real prose around a pure refs-only echo as the answer (#6034) - #7632

Merged
ranxianglei merged 2 commits into
masterfrom
2026-11-24_pure-echo-answer-latch
Nov 24, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-11-24_pure-echo-answer-latch

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

TL;DR (human language)

bili 会把「模型这一轮唯一可见输出被剥掉」记成一个内部标记,然后把这个标记里的下一段文字也当成标记——哪怕那段是模型真实答案。触发形状:模型完整复述了一个 refs-only 标签(它自己的账本 tag,open + 编号 + close,没有正文),真实答案紧跟在同一帧或下一帧。标记置位后答案被计入 markup,answerChars = 0 → 判「退化回合」→ 整轮回读重试(全价重读一次)→ 重试再中 → #870 带内错误、会话死。issue #6034 的样本 2(0.1.215 真实事故)即此形状。

修法:标签剥除过滤器在每次剥除时上报一个判决——「这次剥除有没有留下尚未释放的内部」。只有可能还会放出真正文的剥除(帧首开标签、截断开标签 body、包裹正文的闭合、以及单 ref body 撞上写错名字的 close——unclosed-echo 形状)置位;整单元原子丢弃、什么都没留的剥除(refs-only 干净 echo、paired/self/lone 单元、mangled attrs、裸开 split、超额丢弃)不置位。gate 的标志改为 last-write-wins,在文本被释放时读最终值。旧的 one-shot(每流只报一次、且 pending 置位能活过它的内部)的时序缺陷一并消除。

What changed

  • src/loop/tag-echo-filter.ts: createTagEchoFilter 新增第 5 参 onDropVerdict?: (leavesInterior: boolean) => void;recordDrop/drop/dropSwallowSpan 每次剥除都投递判决(默认 false)。置 true 的站点:session-start open、TRUNC_OPEN body、正文包裹闭合,以及 degenCloseAfterRef 终结处按 close 名字判别(</acp> 干净 echo = false,写错名字 = true,【bug】最终版issue: 模型生成的 <acp …> 标签会漏到用户可见输出(附根因、量化与修法建议) #2190 允许任意短 close 所以两形状同路)。
  • src/plugin.ts: onTagDrop 不再无条件置 droppedTagInFrame;新增 per-drop verdict 回调 last-write-wins 置位。sawStrippedEcho / warn 行为不变。
  • tests/issue6034-pure-echo-latch.test.ts(新,10 测试):过滤器级 verdict 序列(干净 echo / 包裹正文 / 单帧完整单元 / mangled close)+ 插件级双向门(2 个修复复现 + 2 个恒绿控制)。

Tests (pre-flight, local targeted)

  • 新文件 10/10 绿;master 上 2 个插件级复现 + 3 个新 API 测试红(已留记录)。
  • 24 个 tag-echo / degenerate-turn 套件(含 plugin-empty-turn-retry)367/367 绿(ubuntu 本地 node 22,tsx)。
  • npm run typecheck 干净;npm run build 干净(dist-import-annotations / dist-external OK)。
  • 完整套件裁决以本 PR head 的 CI test 车道为准。

Non-goals(留 owner 决定,#6034 选项 A–D)

Refs #6034

@ranxianglei ranxianglei changed the title fix: count real prose around a pure refs-only echo as the answer (#6034) [PR] fix: count real prose around a pure refs-only echo as the answer (#6034) Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-24_pure-echo-answer-latch (b7e7755)

Latest build — install this exact version

npm install -g billion-context@0.0.11773-pr.7632.7b703aa

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
b7e7755 billion-context@0.0.11773-pr.7632.7b703aa build
ed367d4 billion-context@0.0.11729-pr.7632.2791e2c build
8b8f7a2 billion-context@0.0.11713-pr.7632.c77be79 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr7632.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

[bot] 🏷

查重:不重复。 本 PR(#6034 选项 E:锁存器误计修复)与在途的 #6993(#4913:degenerate-retry 终局可达性 + compat.degenerateTurn 逃生开关)和 #5897(选项 A:空回合重试默认关闭)机制不同——本 PR 修的是「有真实正文却被记成 markup」的账本误计,另两个修的是「重试机制本身要不要开/能不能关」。三者互补,不重复。

八问

  1. 是什么问题:模型把 bili 自己的渲染标签 <acp ...>mNNNNN</acp> 原样复述回回答里时,一个真正送出了真实正文的回合被误判成退化回合——重试一次再撞上同样的 echo,回合以带内 Plugin passthrough leaves the client an empty turn when the model echoes a render tag #870 错误收尾,健康回合被杀了两次。
  2. 什么原因导致的:pipePluginChatWithStrip 的 droppedTagInFrame 锁存器由 one-shot 的 onTagDrop 置位——流里第一个 drop 无论什么性质都会 arm 这个标志。一个完整的 refs-only echo 单元是「整段死亡」的(剥掉标签后什么都不留下),却照样 arm 了标志;于是帧里真实的答案正文被记成 markup,答案门读到 0 字符 → 退化 → 重试。
  3. 影响范围与严重程度:特定条件触发(模型在带真实正文的回合里复述 refs-only 标签,[Bug] transport connect-timeout misclassified as a degenerate turn → fatal "turn degenerated again after the continuation nudge" | 传输失败被误判为退化回合并经续写重试升级为致命错误 #6034 sample 2 即此类);触发时健康回合被杀两次(一次全价重取 + Plugin passthrough leaves the client an empty turn when the model echoes a render tag #870 带内错误),用户在 300K+ token 的重取后拿到错误而非答案。p2(能用,特定条件下明显问题,需绕行)。
  4. 怎么修复的:把答案账本的 markup 标志从「任意 drop 都 arm」改成「判决驱动」——filter 新增 onDropVerdict(leavesInterior) 回调,在每个 drop 时投递判决(one-shot 的 onTagDrop 保留,只做首次日志)。只有三种 drop 报 true:session-start open(判决悬置到 span 解析完,保住 【bug】空轮重试门闸把 reasoning 记成可见正文 —— Responses 协议下 item.content[] 带 reasoning 的退化轮永不重试(客户端拿到空轮) #2756/plugin pipe: degenerate-turn one-shot retry is dead on the Gemini wire — gate eligibility + per-lane answer-accounting asymmetries (checklist) #2769 in-frame 行为)、TRUNC_OPEN body 释放、释放 prose body 的 close;整段死亡单元、死孤儿、嵌套拆分、[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 内容溢出释放都报 false。plugin 侧 droppedTagInFrame = leavesInterior(last-write-wins),安全性前提:filter 帧内按释放顺序投递判决,且帧的释放文本只在 push() 返回后才计数。
  5. 是否有回归问题:逐项审过既有行为——[BUG] In some cases, with Codex's auto model + DeepSeek, it will suddenly terminate automatically. #732 纯 echo 重试(控制测试 T3 保留)、【bug】空轮重试门闸把 reasoning 记成可见正文 —— Responses 协议下 item.content[] 带 reasoning 的退化轮永不重试(客户端拿到空轮) #2756 wrapped-span 记 markup(控制测试 T4 保留)、plugin pipe: degenerate-turn one-shot retry is dead on the Gemini wire — gate eligibility + per-lane answer-accounting asymmetries (checklist) #2769 in-frame、[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 内容溢出(显式解除悬置判决)、[bug] ACP 标签泄漏:<acp tokens=...> 标签被模型原样复述到回复正文,仅靠系统提示劝阻不足 #1881 bare-open prose(drain 路径判决 false)、tag-echo filter occasionally lets m01233</acp> remnant through to the client reasoning stream (model echoes refs from compress confirmation markers) #2023 refs-only——全部保持,无阈值/时序/输出格式漂移。发现一处罕见边缘回归(Case C,已本地复现):同一帧里既有 wrapped span(prose body)又有 refs-only echo 时,echo 的 false 判决(last-write-wins)覆盖了 body-releasing close 的 true 判决,markup body 被记成答案、不再重试——重新引入 【bug】空轮重试门闸把 reasoning 记成可见正文 —— Responses 协议下 item.content[] 带 reasoning 的退化轮永不重试(客户端拿到空轮) #2756 失败模式(host 拿到 markup 当答案而卡住)。触发条件罕见(需模型同帧既 wrap span 又复述 refs-only 标签),影响等同既有 【bug】空轮重试门闸把 reasoning 记成可见正文 —— Responses 协议下 item.content[] 带 reasoning 的退化轮永不重试(客户端拿到空轮) #2756 限制(非新失败模式,只是更稀有的触发)。无简单修法(any-true-wins 会破坏跨 chunk 的 T2 场景),根治需按释放块逐块判决(更大的改动)。不阻塞合并,建议 PR 作者在描述里把它登记为已知限制;若后续实测出现再单开跟踪。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。wire 字节不变,只有账本与回调接线移动;无架构/边界/数据流转向。
  8. 是否引入了新的配置:不涉及。

代码与测试审核

  • 代码(③):干净、结构清晰。onDropVerdict 独立于 one-shot onTagDrop(后者只到第一个 drop,而第一个 drop 恰恰是需要被推翻的情形——设计正确)。注释准确说明了 last-write-wins 的安全性前提。无 wire 变更、无 model-facing 文本变更、无 golden/wire-contract 影响、不碰 kernel/ 与 update.ts。
  • 测试有效性(④):新文件 tests/issue6034-pure-echo-latch.test.ts 7 个测试,双向(Test Blind Spot Retrospective: Reinforcing Negative Assertion Discipline, Tightening Fake Upstream Strictness, Thin Inst | 测试盲区复盘:补反向断言纪律、假上游严格化、薄安装冒烟、形态矩阵与生命周期覆盖 #3617)。已本地验证 red-on-master / green-on-PR:两个源文件回退到 base(a59a638)后 5/7 失败(bug 方向 T1/T2 + 3 个 filter 判决序列测试),2/7 通过(控制方向 T3/T4);恢复 PR 版本后 7/7 通过。相关 20 个 tag-echo/degenerate 测试文件 313/313 通过。测试有牙(真能抓住 master 上的 bug),不是假测试。
  • diff 整洁度(⑤⑤b):3 文件、+247/-13,无无关改动、无空行/重排噪音,每行都与 PR 目的相关;命名达意(onDropVerdict/leavesInterior),无死代码,风格与仓库一致。
  • typecheck/build:本地 npm run typecheck 干净、build 干净。

流程事项

  • 标签:本 PR 开出来时没打标签(开 PR 的 agent 漏了),我已按 PR 自身 diff 补上 bug · p2 · pi · dsh · scope/wiring。
  • owner 授权:选项 E 在 11-20 的线程分析中被明确标记为「§7.4 人工评审档 + owner 拍板范围」(wire 账本语义变更)。线程里未见对 E 的显式拍板记录——本 PR 虽挂在 owner 账号下,合并前请 owner 在线程里补一句确认(或确认已线下拍板)。
  • CI:head(8b8f7a2)仍在跑——已完成部分无 failure(10 success + 20 skipped,42 个 cancelled 是被取代的旧 run),7 in_progress + 22 queued。全量回归以 CI 为准。

合并判定:可合,两个前置——① owner 确认对选项 E 的授权;② CI 转绿。Case C 不阻塞(罕见 + 等同既有 #2756 限制),建议登记为已知限制。另注:PR 正文用 Related: #6034 而非 Fixes #6034 是正确的——本 PR 只修选项 E,A–D 仍开放,合并不应关单。

The plugin-mode degenerate-turn latch armed on ANY stripped render tag
(one-shot per stream) and never checked what the drop LEFT BEHIND. The
latch design premise — "a stripped tag leaves its interior pending" —
only holds for the prose-wrapping close, which releases its body into
the SAME call. A pure refs-only echo (the kernel emit shape: open + ref
+ close, no prose body) is dropped as a whole unit and leaves nothing
behind, yet the latch armed anyway: the model real answer arriving in
the same or a later delta then counted as markup, answerChars went to
zero, the turn regenerated once (paid full re-read), the retry
re-matched, and the session died with the #870 in-band error.

The tag-echo filter gains a per-drop verdict callback
(onDropVerdict: (leavesInterior: boolean) => void) — delivered on
EVERY drop, unlike the one-shot onDrop log:
- TRUE (pending interior, frame suspect) only when the dropped unit can
  still release real prose: the session-start open, the truncated
  open-body span, the prose-wrapping close — and a single-ref body
  terminated by a MANGLED close name (degenCloseAfterRef matches ANY
  short close, #2190, so that path carries both the clean echo and the
  unclosed-echo shape; verdict by close name: </acp> = clean echo =
  false, anything else = the model opened a render tag and botched the
  close = true, the shape plugin-empty-turn-retry pins).
- FALSE for whole-unit atomic drops that release nothing: paired /
  self-close / lone-close units, the mangled attrs unit, the bare-open
  split, the refs-only close (#6034 shape), the oversized pending-ref
  span and the attested-content overflow drops.

The degenerate gate droppedTagInFrame becomes last-write-wins over the
verdicts delivered as the frame is RELEASED (push() returns, then the
accounting loop reads the flag), which fixes the old one-shot ordering
(a pending arm that outlived its interior, and multi-artifact frames
where only the FIRST drop had a voice) while keeping every shape the
retry tests pin.

Model-visible text changes: none. No wire-byte change (internal
accounting only). No config surface.

Tests (tests/issue6034-pure-echo-latch.test.ts, both directions per
#3617):
- repro, red on master: single-frame real prose + complete refs-only
  echo in one delta → no retry, prose delivered (was: retry + #870).
- repro, red on master: refs-only echo split across frames, answer in
  the close frame → no retry, prose delivered (was: retry + #870).
- filter-level verdict sequences: clean refs-only echo [true, false] vs
  prose-wrapping echo [true, true] vs single-frame complete unit [false]
  vs mangled-close unit [true, true].
- controls, green on both sides: pure-echo turn still retries once +
  recovers; prose-wrapped echo still retries (#2756); the three
  unclosed-echo tests in plugin-empty-turn-retry stay green.
- all 24 tag-echo / degenerate-turn suites (367 tests) green.
@ranxianglei
ranxianglei force-pushed the 2026-11-24_pure-echo-answer-latch branch from 8b8f7a2 to ed367d4 Compare November 24, 2026 03:32
@ranxianglei
ranxianglei merged commit 9114fb1 into master Nov 24, 2026
54 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1317-master.9114fb1 (rolling master tag).

npm install -g billion-context@0.0.1317-master.9114fb1  # 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.

@ranxianglei

Copy link
Copy Markdown
Owner Author

本地 7 天实测数据 + 空停根因研究(qwen3.8-27b @ 本地 sglang,v0.1.216)

先说结论:这个空停家族在本地可复现、根因已定位。模型不是「无缘无故」停的——请求上下文里模型自己的每一条历史回复都带着 <acp tokens="…" type="text" time="…">mNNNN</acp> 头行(kernel render-refs 渲染进 wire 的),模型学会了「我的回复以这个头行开头」。采样尾巴事件里,它只把这个头行吐出来(还会捏造下一个 m 编号和当前时间戳)就 EOS 收尾——代理剥掉头行 → 该回合零可见输出 → 触发重试。

1. 本地 7 天数据(bili.log.archive,11-19 → 11-24)

2. 根因证据(RAW dump 重放实验)

从空停回合的 RAW dump 里取出原始请求体,对本地 sglang 重放(base 12 次 / 去标记 12 次 / 截断历史 8 次 / 6 个不同上下文各 5 次,共 62 次):

  • Tag echo 是纯上下文模仿,因果证明:带标记 10/12 的回复以标记开头;剥掉全部标记后 0/12。模型连 m 编号都是接着上下文捏的(上下文最后 m00943 → 它写 m00946/47/48),时间戳填「当前时刻」。
  • 空停本身抓到 3/30(10%)。三次尸检形状完全一致:thinking 停在一个未完成的意图上("let me trace through…" / "let me start it in the background…"),可见输出只有那个标记头行(还预声明了一个合理的 tokens= 值),然后 EOS。finish=stop 干净收尾、远未触顶——不是截断,是生成在样板开头后提前收掉了。
  • 重试就是同一请求重新采样(refetch,无 nudge 追加),同一上下文在 sweep 里 4/5 成功 → 空停是采样尾巴,不是上下文里某条固定「毒消息」。

3. 对本 PR(E 修复)的含义

  • 本地 84 个 echo 回合绝大多数是纯 echo(标记就是全部回复)→ 那些重试是正确行为;E 误计(echo+真正文被当成 markup)在本地是稀有形状。[PR] fix: count real prose around a pure refs-only echo as the answer (#6034) #7632 的修法方向不受此数据影响,照旧成立。
  • 建议另开一个 issue/PR 跟进(本 PR 不掺和):wire 上不装饰模型自己的 assistant 消息。kernel/src/render-refs.ts 的 renderMessage 给所有带 ref 的消息(含模型自己的历史回复)打标记,这是模仿样本的主要来源;模型引用历史靠的是工具输出里的 ref,不需要自己消息文本里带。去掉它应能大幅压低 ~10% 的空停尾巴和 2700 次/7天 的 tag-echo drop。需评估:ref 系统对「模型自引用」的依赖、前缀缓存影响(wire 字节变化 = 一次重播种)。

复现脚本、62 次重放产物在 owner 本机目录(私有,不入库)。

ranxianglei pushed a commit to mariopasquali/billion-context that referenced this pull request Nov 25, 2026
…ranxianglei#7678 wal-reclaim-passive (walJournalSizeLimitBytes default 0, ranxianglei#7674) + ranxianglei#7617 identity-tables-consolidate + ranxianglei#7581 egress block-flow checkpoint retire + ranxianglei#7659 eg-GA docs wrapup + ranxianglei#7671 degenerate-retry + ranxianglei#7676 megaturn-bridge + ranxianglei#7677 doom-prompt-mass + ranxianglei#7632 pure-echo latch + dsh batch (ranxianglei#7161/ranxianglei#7159/ranxianglei#7158/ranxianglei#7129/ranxianglei#7127)

Only manual conflict: docs/configuration{,.zh-CN}.md env table — union of intent,
original line order: master's walJournalSizeLimitBytes row (default 0, ranxianglei#7674)
+ PR's archiveAfterDays row (with the bili storage migrate ranxianglei#5599 clause).
All code (src/persist.ts, src/storage/shadow.ts, src/storage/store.ts,
tests/storage-unified.test.ts) auto-merged; local typecheck clean and the
targeted storage suites (storage-unified/-ccr/-state-fields/
-batched-verification) pass 38/38 on the merged tree.

(ranxianglei#6773)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant