Repository navigation
fix: make chain-integrity recognition header-only by default (#1683) - #1690
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1645-pr.1690.a5775a0This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1690.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…ill switch (#1690 review fix)
[bot] 🏷 Review complete — mergeable (human merge; not auto-merge eligible: default flip + new config field + hot file ① 原 issue(方向关)— pass#1683 floor-2 triage already verified the mechanism ( ② 回归审查(逐项既有行为)
③ 代码One call site for ④ 测试有效性Real teeth: default-mode tests assert BOTH "processed" (compress tool present) AND "no ⑤ diff 整洁度9 files, every line on-purpose, single linear commit, no whitespace churn, no version bump. ✅ Fixed in passing (direct commit on the branch): One semantic to confirm (flagging, not blocking): the switches are now fully independent — 一句话中文摘要:审了让 chain-integrity 出站盖章改为默认关闭的 PR——方向与 owner 拍板一致、入站检测/强制行为未动且四条 wire 均验证默认无 carrier、测试断言有牙可兜底、diff 干净、CI 13/13 全绿,顺手修了一个过时的测试名(E5 标题),可以合并。 |
The <bili-chain .../> checkpoint carrier sits in a model-visible slot (trailing user message on openai/responses, trailing text part on anthropic/google), so models read it as phantom input and burn tokens commenting on it (#1683). And scanning the request body for a checkpoint marker false-positives on CCR/file-introduced text and model-echoed tags. So by default ONLY the x-bili-hop header drives chain recognition; both body-marker behaviors are opt-in and decoupled from each other and from the header path: - Egress emission: new `chainEgressStamp` / BILI_CHAIN_STAMP, default OFF. The stampOutbound call-site gate now requires it === true. - Inbound body-content detection: `chainContentDetection` / BILI_CHAIN_CONTENT default flipped ON -> OFF in loadOptions (first-processor-wins body-marker passthrough + advisory artifact-seed). x-bili-hop passthrough unaffected. Old -> new: processed requests were always stamped + recognized foreign body-markers; now neither unless opted in. Header-based chains unchanged. Closes #1683
c4e897e to
e5c94fc
Compare
What
The
<bili-chain …/>chain-integrity checkpoint carrier was stamped onto every request bili processes as a model-visible message — a trailingusermessage on OpenAI/Responses, a trailing text part on Anthropic/Google. The terminal model reads the messages array, so it treated the empty carrier as phantom/untrusted user input and burned tokens commenting on it each turn (~40–60 tokens + per-turn derailment). Reported in #1683 (Claude Code → cc-switch → bili → claude-opus-5, v0.1.172).Follow-up (owner direction after the egress fix): the body-marker heuristics false-positive on real content — CCR/file-introduced text and model-echoed tags can look like a checkpoint — so by default ONLY the
x-bili-hopheader should drive chain recognition. Both body-marker paths (egress emission + inbound body-content detection) are now opt-in.Root cause
Not "the tag leaks" — the tag was intended to be there. The carrier contract (#1357/#1395/#1421) was designed to satisfy exactly two constraints — survive transit through middleboxes + pass upstream role-alternation validation — and never considered that the terminal model reads the same messages array. No position is simultaneously transit-surviving, validation-passing, and model-invisible:
prompt_cache_key);parseChainCheckpoint;And separately, scanning the request BODY for a checkpoint marker is a heuristic over user/model content — it cannot distinguish a real foreign checkpoint from CCR/file text or a model-echoed tag. So the body marker is not a reliable recognition signal either. The fix makes both body-marker behaviors opt-in and keeps the header as the default signal.
Change
Two independent default flips, each behind its own opt-in, decoupled from each other and from the header path:
src/server.ts: the gate at thestampOutboundcall site now requiresopts.chainEgressStamp === trueinstead ofopts.chainContentDetection !== false. New configchainEgressStamp(envBILI_CHAIN_STAMP=1), default OFF.src/config.ts:loadOptionsnow resolveschainContentDetectionto false when unset (was true); envBILI_CHAIN_CONTENT=1/ file"chainContentDetection": trueopts back in. This disables both the first-processor-wins body-marker passthrough and the advisory artifact-seed; thex-bili-hopheader path is independent of this flag and is unchanged.opts.chainContentDetection !== false, so production (which always funnels throughloadOptions) gets the concretefalse; direct-opts unit tests that omit the flag still seeundefined → on, which is why the enabled-path regression coverage keeps running.Config surface
Owner-gated area, flagged per policy. Two rows change:
chainEgressStampfalse(new)BILI_CHAIN_STAMP=1chainContentDetectionfalse(wastrue)BILI_CHAIN_CONTENT=1chainContentDetectionused one switch for several concerns (inbound body recognition + egress emission). [Bug]Chain-integrity checkpoint tag<bili-chain …/>is injected as a visible trailing user-role message — models read it as phantom user input and burn tokens commenting on it #1683 needs emission independent of recognition, and the owner needs body-recognition off by default while the header stays on. One boolean cannot express all of that.BILI_CHAIN_STAMP=1andBILI_CHAIN_CONTENT=1(or the file equivalents) to restore body-stamp emission + body-marker recognition exactly as before.Behavior change (old → new)
<bili-chain …/>carrier, and a foreign body-marker triggered first-processor-wins passthrough (both wheneverchainContentDetection !== false, which defaulted on).x-bili-hopheader. Body-marker recognition and body-stamp emission are each restored by their own env/file flag.x-bili-hopbyte-exact passthrough · plugin-mode sessions: #1421 outbound chain stamps accumulate in the model-visible transcript (+1 user message per request) #1542 stripping of stale embedded carriers · Compression metadata reaches the transcript and the model answers it instead of the user (long sessions stall) #1634 output-side echo filtering · self-exemption / digest logic.x-bili-hoploses the digest-verified body-stamp fallback until it opts in. Single-bili deployments and any relay whose hop header survives are unaffected.Tests
tests/issue1683-chain-egress-off.test.ts: default opts → processed openai and google outbounds carry NO carrier (kernel did run);chainEgressStamp:true→ stamp restored (verdictvalid); body-detection on → a valid external checkpoint forwards byte-identical; body-detection off (new default) → a foreign body-carrier is processed, not passed through;x-bili-hopheader alone → byte-identical passthrough even with body-detection off.tests/issue1086-chain-self-exemption.test.tsT9/T9b: T9 pinschainContentDetectiondefault-OFF precedence (unset→false,=1→true,=0→false, filetrue→true, env wins over file); T9b pinschainEgressStampthe same way.tests/chain-checkpoint-step2.test.tsT3 andtests/chain-checkpoint-step3.test.tsE3/E4/E6 pass{ chainEgressStamp: true }to keep asserting the (now opt-in) re-stamp path; step2 rig gained overrides plumbing.tests/issue1542-chain-embedded-strip.test.tssplit into default (polluted body → zero carriers reach the LLM) and opt-in (stripped + one fresh trailing carrier), both modes.Pre-flight (local):
npm run typecheckclean ·npm test3249 tests / 3237 pass / 0 fail / 12 gated skips ·npm run buildOK.Closes #1683