Skip to content

fix: warn on tool-call-shaped XML in plugin passthrough prose (#1368) - #1371

Merged
ranxianglei merged 2 commits into
masterfrom
2026-09-26_plugin-passthrough-tool-xml-warn
Sep 26, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-09-26_plugin-passthrough-tool-xml-warn

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Plugin-mode passthrough pipes (pipePluginChatWithStrip / pipePluginResponsesWithStrip, src/plugin.ts) now carry the #361 once-per-request warn-only detector that proxy mode already has (src/server.ts): when the model's prose contains tool-call-shaped XML (a tool call drafted as literal text — the #1366 shape), bili.log gets a [tag-echo] <session> plugin passthrough: response text contains tool-call XML fragment (possible tag echo; not stripped) warning.

Before this change, the same traffic in a plugin session left zero signal in the log — which is exactly why #1366 had to be attributed from a screenshot alone.

Design

Tests

New tests/plugin-passthrough-tool-xml-warn.test.ts (5 tests): openai chat pipe (literal + JSON-escaped \u003c forms), anthropic pipe, responses pipe, and a plain-prose negative — each asserts exactly one warn AND that the decoded SSE payload forwards the fragment verbatim (decoded comparison, since raw bytes carry JSON escaping).

Pre-flight (rebased onto current master, v0.1.153)

  • npm run typecheck — clean
  • npm test — 2651 tests, 0 fail, 11 skipped
  • npm run build — success incl. dist-import-annotations gate

Fixes #1368

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-26_plugin-passthrough-tool-xml-warn (927a5e7)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1371

Each push to this PR publishes a new version under the pr-1371 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1371.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] 🏷 Reviewing this PR now — it's the completed work from #1368, so I'm verifying rather than redoing: pulling branch 2026-09-26_plugin-passthrough-tool-xml-warn, cross-checking the diff against the issue's suggested fix, walking the regression surface of both passthrough pipes, and re-running typecheck + the new tests locally. CI so far: artifact/version-guard/registry-e2e/pi/codex lanes all green; the OS test matrix is still in progress. Full review conclusion coming in a follow-up comment.

…oseAcc (#1368)

The Responses pipe accumulated reasoning summary text into proseAcc only
via the filter path; chunks that never engaged the tag/marker heuristics
were forwarded to the client unaccounted, so a tool-call-shaped fragment
carried there would leave no warn. Account them at the same site as every
sibling fast path, pinned by a stream that ends after the delta so the
delta's own accounting is the only prose source.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — mergeable. I pulled the branch, re-ran the full pre-flight locally, audited every accumulation site against the client-visible text paths of all three wire shapes, and fixed one coverage gap directly on the branch (commit 927a5e73). Full CI (all 10 jobs) is green on that commit.

① Issue direction (#1368). Verified against source: containsToolCallXmlFragment existed only in proxy mode (src/server.ts:5149-5159, per-chunk raw scan) while the plugin passthrough pipes ran just the render-tag/marker-line filters — zero log signal for exactly the #1366 shape. The fix lands at the right layer: attribution-only observability, warn-only per the documented #295/#361 decision (a shape-based match cannot tell an echoed template from legitimate prose, so never strip; tool-call arguments stay byte-exact per #1039 and don't flow through prose fields anyway). One-check-at-end-of-stream keeps the per-frame hot path untouched. Direction is sound.

② Regression audit — existing behaviors touched by this diff:

  • Chat pipe (src/plugin.ts): purely additive — proseAcc declared outside the retry loop (spans degenerate-turn attempts by design), accumulated at the five existing accounting sites (fast paths ×3 protocols, pushField, flushTails). No change to filtering, retry, usage settlement, or truncation logic.
  • Responses pipe: same pattern. The responsesEventTextLength → responsesEventText refactor is behavior-preserving: identical string computation, callers still feed .length into heldVisibleChars, so the degenerate-turn gate is byte-for-byte unchanged.
  • Terminal call sites: maybeWarnProtocolFragment() runs at the same spot as maybeWarnDegenerate() in both pipes, before the truncation early-return; not called on the error path (the error itself is logged there — acceptable for a warn-only aid).
  • Function-call arguments: confirmed unmanaged in every path (OpenAI tool_calls, Anthropic input_json_delta, Responses function_call_arguments.*) — [bug] 插件透传会剥掉工具调用参数里的 render tag(arguments 流挂了 tag-echo 过滤器) #1039 invariant intact.
  • Proxy mode: its [bug] #294 残部:0.1.63(已含 #295)仍泄漏非 acp 工具调用 XML 碎片(</invoke> / </tool_call>),轮次提前终止无 tool_use #361 detector is untouched. No config schema, persistence, wire-shape, version, or cross-repo dependency changes. Both compression modes considered; the change is plugin-mode-scoped by construction.

③ Code review finding (fixed on-branch, 927a5e73): the Responses pipe's response.reasoning_summary_text.delta fast path forwarded visible prose to the client without accumulating it into proseAcc — only chunks engaging the tag/marker heuristics were accounted via the filter path. A tool-call-shaped fragment carried entirely in plain reasoning-summary deltas would reach the client with no warn, silently inconsistent with every sibling fast path (which all accumulate). One-line fix (proseAcc += v; at the fast-path write site) plus a regression test whose stream ends after the delta so the delta's own accounting is the only prose source. Verified the test has teeth: with the fix stashed it fails (0 warns instead of 1), with the fix it passes.

④ Test quality: the original 5 tests are real regression tests — each asserts exactly one warn AND decoded verbatim forwarding (decoded comparison, since raw bytes carry JSON escaping), covering literal <invoke> and double-encoded \u003c forms across openai/anthropic/responses plus a plain-prose negative. With my addition the file pins all four accumulation surfaces (chat fast+filter paths, responses delta/done-family, reasoning-summary delta).

⑤ Diff cleanliness: clean — 2 files, additive only; my review commit adds 1 line + 1 test, nothing else.

Pre-flight evidence (re-run by me on 927a5e73): typecheck clean · npm test 2652 pass / 0 fail / 11 skipped (PR's 2651 + my new test) · build success incl. dist-import-annotations gate · CI all 10 jobs success (incl. real codex/pi fake-upstream e2e lanes and hermetic registry e2e).

Behavior change flag (intended, not drift): plugin-mode sessions now emit ONE additional [tag-echo] [<session>] plugin passthrough: response text contains tool-call XML fragment (possible tag echo; not stripped) line in bili.log per request where the post-filter prose contains such a fragment. Old: no signal at all in plugin mode. Wire output is byte-identical before/after in both modes — nothing is stripped or altered.

中文摘要:修复了插件模式透传流缺少 #361 工具调用 XML 检测的观测盲区(warn-only、不动线上字节),审查中另发现并直接修掉了 Responses 推理摘要 delta 快速路径漏计 prose 的一处覆盖缺口(补了一行累加+一个可复现回归测试),全量本地验证与 CI 十项全绿,可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

深审通过(独立验证,零改动):

设计核验(#1368 = proxy 管道 #361 检测器在 plugin 管道的对齐):

实测:plugin-passthrough-tool-xml-warn 6/6(235 行,含多帧散文拼合、无散文短路、每请求一次上限)。

合并无阻塞。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,感谢独立复核。最终状态确认:PR head 927a5e73(原始实现 66fd9532 + 审查中补的 reasoning-summary delta 快速路径累加一行及回归测试),本地 typecheck / 2652 tests / build 全绿,CI 十项全绿,无其他待办。

按系统规则 Agent 不能执行合并——请你在 #1371 自行合并。

@ranxianglei
ranxianglei merged commit 7d6f48f into master Sep 26, 2026
10 checks passed
@ranxianglei
ranxianglei deleted the 2026-09-26_plugin-passthrough-tool-xml-warn branch October 15, 2026 05:32
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.

Plugin-mode passthrough lacks the #361 warn-only log for tool-call-shaped XML in model prose

1 participant