Repository navigation
fix: anthropic global-scope gate — narrow predicate + default threads-lane passthrough cap (#2884) - #2888
fix: anthropic global-scope gate — narrow predicate + default threads-lane passthrough cap (#2884)#2888ranxianglei wants to merge 4 commits into
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3257-pr.2888.329179bThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2888.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR #2888 review 结论(rebased onto master 结构化八问:
验证证据(本地定向,全量留给 CI):rebase 到当前 master Review 顺手小修(已推 PR 分支,独立 commit 判定:可合(§7.4:wire 行为变更属 human-merge 类,请手动合并 #2888 )。分支落后 master 一个提交但文件零重叠,本地 rebase 已证干净,GitHub mergeable=true。合并后建议在你的 CC 环境观察一个真实主会话:预期日志出现正常注入(不再每 turn 一条 "global-scope system passthrough"),且 |
…nd-down (#2884) #2650 whole-request passthrough fired on ANY system block carrying cache_control.scope:"global". That stood down Claude Code main-conversation requests wholesale -- their main loop carries unmarked tools plus a global breakpoint mid-system that upstream accepts WITH extra unmarked tools ahead -- silently disabling compression there (no inject / nudge / fold). The decision was also evaluated per request, so one threads create/continue pair could mix raw and injected forwards -> upstream 400 thread_fingerprint_mismatch. Narrow the gate to the shapes WC-016 actually rejects: stand down only when the request carries NO tools OR the global breakpoint sits on system[0]. Make it thread-granular -- computed at the thread create and inherited by every continue through session.metadata -- so a single upstream thread never mixes raw and injected forwards. Regression tests: CC main-convo shape keeps compress injection; thread-granular stand-down and inject inheritance across truncated continues.
The #2650 repair line in WC-016's provenance still described the gate as "whole-request passthrough when any SYSTEM block pins scope:global". That gate was narrowed in the preceding commit (#2884) to globalScopeRequiresStandDown (NO tools OR global-on-system[0]) and made thread-granular. Add a short refinement note so the ledger documents the live gate accurately. No wire constraint changed; goldens do not pin provenance text.
…er cap, #2884) #2888 restored Claude Code main-conversation compression by narrowing the global-scope stand-down predicate and making the inject/passthrough decision thread-granular. But both rely on a shape assumption -- the client's own unmarked tools plus a mid-system scope:"global" breakpoint survive upstream WITH bili's extra unmarked tools rendered ahead -- that was never proven against the real upstream (the e2e tests run against a permissive fake). An unproven assumption that 400s the whole Claude Code conversation is worse than "works but doesn't compress". Per owner decision, land a temporary cap on top of #2888 instead of shipping the unproven injection by default: - Any anthropic request carrying a `thread` field (create AND continue alike) now forwards byte-for-byte by DEFAULT: no tool injection, no nudge, no system/tools/cache_control rewrite. Non-threaded global-scope requests are unaffected and keep the #2888 narrowed predicate + thread stickiness intact. - BILI_ANTHROPIC_THREADS_INJECT=1 opts back into full #2888 behavior (forensics / capturing a real post-injection 200 -- the evidence bar that lifts the cap). - Visibility: the first passthrough per session logs WARN (then info), and /__bili/status + /__bili/overview expose `anthropicThreadsLane` so a user can discover bili is not compressing this lane. Tests: new byte-for-byte passthrough regression (acceptance item 1); the two thread-field #2884 tests now set the opt-in env to exercise the full logic; the non-thread CC-main test stays in default mode. WC-016 ledger unchanged (the wire rule is unchanged; only bili's gate becomes more conservative). Closes #2884
…2884) En + zh. Env-only by design (transient forensic toggle slated for deletion when the cap ships), deliberately no config-file key. Documents the default byte-for-byte passthrough of the anthropic threads lane, the opt-in escape hatch, and the /__bili/status `anthropicThreadsLane` field.
37ce311 to
3a9f3da
Compare
|
Closing — superseded by #3332 (the Anthropic Threads lane, tracking #2926). #3332 claims every threads create/continue via The one surviving piece — the narrowed non-threads stand-down predicate — is dropped too, deliberately: it permits injection under the same "client tools + mid-system global survive upstream with bili's extra tools" shape assumption that motivated the cap and #3332 (never proven against a real upstream), and #2884's data showed no non-threads client hitting this path (dsh/pi/codex passthrough = 0). Keeping it would ship an unproven behavior change for a case with no observed demand; dropping it leaves the non-threads path at today's #2650 behavior (zero change). Net effect: non-threads anthropic path unchanged from master; the Claude Code threads path is fixed properly by #3332 (capture + reforge) rather than waved through. Trivially reopenable if the non-threads predicate is wanted back. |
Summary
Fixes Claude Code compression breakage from #2650's over-broad global-scope passthrough, per @ranxianglei's direction on #2884. Two layers:
scope:"global"breakpoint on system[0]. The inject/passthrough decision is made at threadcreateand inherited by everycontinue, so one upstream thread never mixes raw and injected forwards (which causedthread_fingerprint_mismatch).threadfield (create AND continue alike) now forwards byte-for-byte by default — no tool injection, no nudge, no system/tools/cache_control rewrite. Rationale: layer 1 restores Claude Code main-conversation compression only under a shape assumption (the client's own unmarked tools + a mid-systemscope:"global"breakpoint survive upstream with bili's extra unmarked tools rendered ahead) that was never proven against the real upstream — the e2e tests run against a permissive fake. An unproven assumption that could 400 an entire Claude Code conversation is worse than "works but doesn't compress". So we ship the conservative default and keep the full logic behind an opt-in until a real post-injection 200 is captured. Endgame tracked in [Tracking] SQLite-backed threads-lane compression (endgame for the #2884 cap) #2926.Behavior change (old → new)
toolspresent +scope:"global"mid-system)BILI_ANTHROPIC_THREADS_INJECT=1→ injects (full #2888 logic)scope:"global"on system[0])thread_fingerprint_mismatchVisibility (owner req ②)
/__bili/statusand/__bili/overviewexposeanthropicThreadsLane: { mode, compression, optInEnv, issue }so a user can discover bili isn't compressing this lane. (There is no literalbili statusCLI subcommand today; these endpoints + the log are the status surface.)Config surface (owner-gated)
New env var
BILI_ANTHROPIC_THREADS_INJECT(default unset = cap active). Env-only by design: a transient forensic toggle slated for deletion the moment the cap lifts, deliberately NOT given a config-file key. Owner-directed in #2884. Documented in CONFIGURATION.md (en + zh), hand-written env table (not the generated twin table).Changes
src/server/prepare-anthropic.ts:isThreadsWireRequest()+ cap gate (byte-for-byte forward, WARN-once) ahead of the existingresolveGlobalScopeStandDowngate; thread stickiness viasession.metadata.anthropicGlobalStandDown.src/knobs.ts:threadsInject()(env-only).src/server/admin.ts:anthropicThreadsLanefield on/__bili/status+/__bili/overview.tests/e2e-anthropic.test.ts: new byte-for-byte passthrough regression (acceptance ①); the two thread-field [Bug][claude MITM] The global-scope passthrough in #2650 lets the entire Claude Code main conversation pass through unprocessed, rendering compression completely non-functional on Claude Code (Note: inconsistent injection within the same Thread causes fingerprint mismatch) | [Bug][claude MITM] #2650 的 global-scope 放行把 Claude Code 主对话整条放行,Claude Code 上压缩完全失效(附:同一 Thread 注入不一致导致 fingerprint mismatch) #2884 tests set the opt-in env to exercise full logic; non-thread CC-main test stays default-mode.tests/wire-contract-fakes.ts: WC-016 provenance note (wire rule unchanged; bili's gate more conservative).CONFIGURATION.md(+zh): document the opt-in.Verification
Rebased onto master
9972ff2df; typecheck ✓, build ✓, targeted suites green on the rebased head: e2e-anthropic 10/10, wire-contract 18/18 (WC-016 intact), side-lane-invariants 8/8, advisory-endpoint-parity + build-info ✓. Full suite left to CI.Acceptance mapping (owner's 盖子版 checklist)
threadrequests — regression test asserts tools/system/messages deepEqual inbound./__bili/statusfield.Deferred: observer-mode ingestion (acceptance ⑤)
Per owner note "若改动面大,PR 里说明后可二期": the durable substrate for threads-lane compression is the unified SQLite store (#2671), not ephemeral session-state. Building observer writes into session-state now would be throwaway, and running the kernel pipeline purely to observe risks diverging session state from the raw-forwarded wire. Tracked in #2926 alongside the endgame.
Closes #2884