Skip to content

fix: strip model-degraded render-tag closes (#2176) - #2183

Closed
ranxianglei wants to merge 1 commit into
masterfrom
wt-2176-ework-daemon
Closed

ranxianglei wants to merge 1 commit into
masterfrom
wt-2176-ework-daemon

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Part of #2176 — fixes the tag-leakage mechanism (report categories A/B). Category C (reasoning-as-answer + premature stop) is a separate mechanism, documented below, not bundled here.

Root cause

The render-tag close-name matcher was a closed set (NAME = acplike 3–4-letter case-folded alternation), but models degrade the close into an open set we cannot enumerate — in non-reasoning mode the observed degraded closes were /ap, /a, /p, /aph, /ck. The open side stays strict (it anchors legitimacy); only the close slips. Because every close recognizer demanded a close-name in NAME:

  • stripAcpTags's PAIRED replace left the ref-plus-degraded-close residue behind the stripped open;
  • the streaming createTagEchoFilter swallow path could not terminate at a degraded close, over-ran its cap, and released the whole span as prose.

Both let the tags reach the visible answer, where they then re-echo and amplify across turns (the "5-in-a-row" bursts).

Fix (all in src/loop/tag-echo-filter.ts)

Relax only the close side; keep the open side and standalone closes strict so user prose markup is untouched (#1039):

  1. PAIRED close relaxed from NAME to any bounded letter-name {1,16} → a bare-ref span now terminates on a garbled close in both the whole-text and streaming paths.
  2. New CLOSE_ANY_ANCHORED (bounded letter-name) used only as a fallback.
  3. looseCloseSpan(s, lenient) gains a gated lenient mode; the streaming swallow branch invokes it only when the swallowed body is a bare ref (the echo shape). Wrapped-turn/prose bodies keep the strict path, so their inner tool-call wrapper closes are never cut early.

Regression audited

Behavior change (old → new)

Downlink client-visible text: model-degraded render-tag closes that previously leaked verbatim (a leaked ref-plus-degraded-close plus surrounding tag bursts) are now stripped, with the real answer preserved. This is intended — it removes the source of the self-reinforcing echo amplification. No change to well-formed handling; tool-call argument bytes remain byte-exact (#1039).

Modes

Fix lives in the shared downlink text stripper used by BOTH proxy mode and pluginMode, so both are covered.

Config surface

None added. No new env var, config key, CLI flag, or default changed.

Tests

New tests/issue2176-degraded-close.test.ts (7 cases): well-formed regression, degraded pairs whole-text + streaming, multi-tag burst incl. degraded closes (answer preserved, no tags/refs leak), whitespace-padded ref, and the #1039 prose guard. Targeted run: 64/64 pass (57 existing + 7 new). Typecheck clean; build succeeds. Full suite left to CI.

Category C (not fixed here)

"Reasoning emitted as the answer in analysis/summary form, then the turn stops" is a distinct mechanism (reasoning-channel/format leak + premature termination), not the close-set defect. It needs a wire trace (raw SSE of one C-type turn without the plugin) to isolate model-side vs proxy-side before a fix. Kept as a separate facet of #2176.

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: wt-2176-ework-daemon (d0b1915)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2256-pr.2183.6293268

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-pr2183.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 Review 规范审查本 PR(源 issue #2176 的 A/B 类机制修复)。流程:拉取分支 → 审原 issue 方向 → 回归审查(既有行为清单)→ 代码审查 → 测试有效性 → diff 整洁度 → CI 状态。结论将按结构化七问给出。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Independent second-pass review (code + tests + CI). Verdict up front: fix is correct, scope is right, mergeable — the only red CI lane is a pre-existing master breakage unrelated to this diff.

What I verified

Regression audit (existing behaviors carried by the touched paths)

  1. Well-formed pair stripping (whole-text + streaming) — preserved, pinned by the new regression case + existing suite.
  2. Wrapped-turn swallowing (inner tool-call wrapper closes) — preserved: strict terminator unchanged; lenient mode gated out for non-bare-ref bodies.
  3. Ordinary-prose short closes — preserved: LONE_CLOSE strict and untouched; new [bug] 插件透传会剥掉工具调用参数里的 render tag(arguments 流挂了 tag-echo 过滤器) #1039 guard pins it.
  4. Tool-call argument bytes — untouched: filters apply to prose channels only; the [bug] 插件透传会剥掉工具调用参数里的 render tag(arguments 流挂了 tag-echo 过滤器) #1039 invariant block is intact. Byte-exact.
  5. EOF flush / hold semantics — unchanged.
  6. Server-side history rebuild — stripAcpTags is shared: well-formed handling byte-identical; leaked degraded pairs now also drop out of rebuilds, which is the intended echo-loop breaker (see Q5).

CI status

All lanes green on head ae9eee872 (guards, docs, build-artifact, theorem, registry e2e ×2, all real-client fake lanes, e2e) except the 4 test matrix jobs (ubuntu/windows × 22/24). They fail on exactly ONE test: #2152: /__bili/overview carries the same advisory field as /__bili/status — the endpoint answered 500 because scandir <home>/.local/share/billion-context/sessions hit ENOENT on the fresh runner. This is pre-existing master breakage, not this PR: master's own latest push run (Actions run 37311580876) fails the same 4 matrix jobs, and a fix is already in flight — commit 7948d10be "fix(web): missing sessions dir reads as an empty corpus in the web index (#2152)" (branch 2026-10-05_dsh-bundle-config-slot, CI in progress). This PR touches no web/admin code. Re-run the matrix once that fix lands on master and it should go fully green.

结构化七问

  1. 是什么问题: 模型把 render-tag 的闭合名退化成我们从未枚举过的形状(</ap> </a> </p> </aph> </ck>),剥离器要求闭合名在封闭集中,退化对整体漏进可见回答,并在后续轮次反复回显放大("5-in-a-row" 爆发)。
  2. 什么原因导致的: 闭合名匹配器是封闭集,而模型真实输出是开放集;全量文本路径(PAIRED replace)与流式路径(swallow 终止符)都要求闭合名命中该封闭集。开侧一直没问题——它是合法性锚点。
  3. 怎么修复的: 只放宽闭合侧——PAIRED 闭合改为有界字母名 {1,16};新增锚定兜底仅当被吞 body 是裸 ref(回显形状)时启用。严格路径(开、独立闭合、wrapped-turn body)全部不动,用户散文标记安全([bug] 插件透传会剥掉工具调用参数里的 render tag(arguments 流挂了 tag-echo 过滤器) #1039)。
  4. 是否有回归问题: 上表六族既有行为逐项审过——无破坏。一处有意语义变更:历史中已含泄漏退化对的会话,下次重建时这些对会被剥掉(打断自增强回显环);其余字节不变。
  5. 是否破坏缓存: 纯下行变更;除受影响会话一次性移除退化对字节外,请求体字节一致(有意)。未触碰缓存键/重试/游标逻辑。
  6. 是否改了设计方向: 没有。架构、过滤器组合、双模式覆盖均不变;只是把闭合识别契约在其文档化边界内放宽。
  7. 是否引入了新的配置: 无。无新 env var、config key、CLI flag 或默认值变化。

收工判定: 可合并。代码正确、范围收敛、回归面已被测试钉住;唯一红 lane 是已存在 master 上的 #2152 web-index ENOENT 问题(修复在途 7948d10be),等它进 master 后重跑矩阵即可全绿。Category C(reasoning-as-answer + 提前停轮)按作者说明正确排除在外的——独立机制,需先拿 wire trace。

The render-tag CLOSE-name matcher was a closed acplike set, but models degrade the close into an open set (</ap>, </a>, </p>, </aph>, </ck>) in non-reasoning mode, so bare-ref spans escaped stripping and leaked into the visible answer.

Relax only the close side (PAIRED close + a bare-ref-gated lenient fallback in the streaming swallow path); keep the open side and standalone LONE_CLOSE strict so prose markup is untouched (#1039).
@ranxianglei
ranxianglei force-pushed the wt-2176-ework-daemon branch from ae9eee8 to d0b1915 Compare October 5, 2026 15:36
@ranxianglei

Copy link
Copy Markdown
Owner Author

Closing as superseded.

The unified remediation shipped via #2267 (merged, commit c564b18 - 'Unify ACP tag-echo remediation under four invariants'), which fully covers this PR's B-class degraded-close surface: my 7-case test file runs 7/7 green on #2267 and a 77/77 multi-split scan is clean (verified by @ranxianglei).

Per owner direction, closing to avoid a same-layer double-fix. The behavioral test file tests/issue2176-degraded-close.test.ts is preserved on branch wt-2176-ework-daemon @ d0b1915 and can land on master as a regression guard for #2267's fix if wanted.

C-class (empty-visible-turn -> host abort; summary-as-answer; reasoning-in-content) is tracked under the first-cause governance issue #2229.

@ranxianglei ranxianglei closed this Oct 6, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Verified the supersession, independently re-ran the preserved guard file — claim holds:

No action taken on the closed PR, nothing pushed. If you want the guard file landed on master, say so and I'll open a minimal test-only follow-up (single commit adding just that file, referencing #2267/#2176). Otherwise this thread can rest.

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.

1 participant