Repository navigation
fix(chain-echo): strip echoed bili-chain carriers from model-visible paths - #1584
ranxianglei wants to merge 3 commits into
Conversation
…paths (#1565) A bare <bili-chain digest="sha256:<hex>"/> checkpoint stamp leaking into model-visible context gets echoed back verbatim by models: visible tag chatter, polluted history, and completed turns that end up empty once the echo is removed. Root fixes, all gated behind the existing BILI_CHAIN_CONTENT switch (no new config surface): - src/loop/chain-echo-filter.ts (new): streaming-tolerant echo-span machine for <bili-chain>/<bili-chain-processed> carriers (well-formed plus the three observed malformed variants, truncated-at-EOF, broken-attrs swallow, byte-split invariant), one-shot walkers for all four wire shapes, byte-exact echoed-input item removal, and post-verdict history scrubbing (assistant prose stripped, user text kept+counted, tool args/results untouched). - adapters (openai/responses/anthropic/google): nest the filter into the existing tag/marker stream filters; report chainEcho on done. - loop/core.ts: an echo-only terminal turn (zero visible output, no reasoning, but a stripped carrier) fires the existing one-shot continuation retry alongside sawThinking; genuinely bare turns remain untouched. - adapter-responses: response.completed echoing the request back loses its byte-exact carrier input items (near-variants preserved). - server.ts: the stampOutboundWithTag result feeds chainCarrierTag into pickAdapter and the non-stream rewriters; inbound history scrub runs in each prepare lane only when the request continues into this instance's pipeline (chainSkip relays stay byte-verbatim); verdict matrix unchanged. - plugin.ts: both plugin pipes and the non-stream JSON pipe get the same treatment (count-only telemetry; retry latch via the existing sawStrippedEcho flag). - non-stream rewriters (stream.ts / stream-openai / stream-google / stream-responses): chain-echo stripping + carrier-item removal. - tests: tests/chain-echo.test.ts (new: unit machine incl. split-at-every-byte-position property, walker parity, exact-vs-near input removal, history scrub, P0-1 integration) and degenerate-retry E1/E2 pins. Fixes #1565
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1515-pr.1584.7813706This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1584.tgz
npm install -g packageInstall instructions are refreshed on each push. |
pipePluginResponsesWithStrip gained a chainCarrier param for P0-1 (response.input echo removal), but none of its three call sites in forward() passed it, so the removal was dead code on the plugin-mode streaming path. Wire chainCarrierTag at all three sites.
…d anthropic done yield
Review complete (supersedes the earlier ack). Full verdict below. ① Direction gate (原 issue): PASS. The PR implements #1565's prescribed plan point-for-point: P0-1 byte-exact carrier removal from echoed ② Regression audit — existing behaviors carried by the touched paths, each checked against pre-change code:
③ Code review — found and fixed directly (pushed to the PR branch):
Flagged, not fixed (author/owner call): ④ Test validity: strong. ⑤ Diff cleanliness: tight after the two nits — 19 files, every line serves #1565; no whitespace churn, no unrelated files, no lockfile drift. Verification: CI was fully green on Verdict: mergeable once CI is green on the updated head — the pushed commits are +3 lines of wiring (activating tested logic) plus whitespace. Item 3 ( 中文摘要:审查了 #1584(剥离模型回显的 bili-chain 载体):实现方向与 #1565 方案完全一致,回归面逐项清点无意外;我已在 PR 分支直接补两个 commit——把 P0-1 的 carrier 参数接到三个 plugin 管道调用点(此前是死代码)+ 修正两处缩进错位;另指出两点待你定夺: |
What & why
#1565: when the bare
<bili-chain digest="sha256:<hex>"/>checkpoint stamp (added by #1421's cross-instance content checkpointing) leaks into model-visible context, models echo it back verbatim — visible tag chatter, polluted history, and completed turns that end up empty once the echo is stripped.This fix makes the proxy own the echo lifecycle instead of requiring users to disable chain checkpoints (
BILI_CHAIN_CONTENT=0):src/loop/chain-echo-filter.ts— streaming-tolerant echo-span machine for<bili-chain>/<bili-chain-processed>carriers: well-formed spans plus the three malformed variants observed in bug(chain-checkpoint): 裸戳记进入模型上下文后被复述,并可能造成可见污染与空完成轮 #1565 (leading space inside quotes, non-hex byte, space after=), truncated-at-EOF openings, broken-attr openings (swallowed to close), with a split-at-every-byte-position invariant (streamed deltas ≡ whole-text strip). Plus one-shot walkers for all four wire shapes, byte-exact echoed-input item removal, and post-verdict history scrubbing.chainEchoon done.sawThinking. Genuinely bare turns remain untouched (pinned by test E2).response.completedechoing the request back loses its byte-exact carrier input items (near-variants preserved verbatim).stampOutboundWithTag's result feedschainCarrierTaginto pickAdapter and the non-stream rewriters; inbound history scrub runs in each prepare lane only when the request continues into this instance's pipeline (chainSkip relays stay byte-verbatim); verdict matrix unchanged.sawStrippedEchoflag).stream.ts/stream-openai/stream-google/stream-responses) — chain-echo stripping + carrier-item removal.tests/chain-echo.test.ts(unit machine incl. split property, walker parity, exact-vs-near input removal, history scrub, P0-1 integration) + degenerate-retry E1/E2 pins.BILI_CHAIN_CONTENTrows in CONFIGURATION.md / CONFIGURATION.zh-CN.md and the config.ts doc comment updated from stale "advisory-only since bug(chain): ACP tag literals in normal history can permanently force fresh proxy sessions into passthrough #1357" wording to current stamp/detect/enforce semantics.Behavior changes (old → new)
response.completedechoing request inputUnchanged: verdict matrix (valid / recent-mismatch / stale / invalid), carrier format & digest, parser, retry nudge text, all thresholds, tool-call argument bytes (#1039), and tag-free SSE/JSON bytes (chain probes skip
response.input, so frames without echoes are never rebuilt).Config surface
None added. The existing
BILI_CHAIN_CONTENT=0/"chainContentDetection": falseremains the escape hatch and disables stamping AND detection; the docs are corrected to state that (they previously described pre-#1421 advisory-only behavior). No new env var, CLI flag, or config field.Pre-flight (rebased onto master @ v0.1.166)
npm run typecheck✅npm test✅ 3051 pass / 0 fail / 12 skip (+17 new tests vs base)npm run build✅tests/e2e/e2e-codex.test.ts: local zero-token preflight (E2E_CHECK=1) passes; the full run could not be executed locally because the local sglang upstream was down at commit time (connection refused on the e2e port). This diff touches request-pipeline hot files, so CI's e2e job will run it automatically.Fixes #1565