Repository navigation
fix: passthrough anthropic requests carrying a global-scope system block (#2648) - #2650
Conversation
…ock (#2648) Claude Desktop's Code tab routes through bili via cert-MITM in proxy mode. Its notification / title / classification side calls pin their system blocks to cache_control.scope:"global". Anthropic renders tools BEFORE system, so the six ACP tools bili injects (narrower scope) land ahead of a global block and the request 400s upstream ("scope:global … found after content with a narrower cache scope"). Key the stand-down on the invariant actually being violated — a global-scope system block — rather than on "no tools": a tool-less conversation can still grow large and be compressed, so gating soft-compression off on tool absence would be wrong (and breaks the compress round-trip regression test). Healthy main turns use ephemeral/unscoped system and keep full compression; only genuine global-scope side calls are forwarded untouched, mirroring the auto-mode classifier bypass (#353). Regression test pins the boundary: a global-scope request gains no ACP tools / compress prompt and keeps its breakpoint verbatim, while the existing tool-less round-trip test still exercises injection (guards against over-broadening).
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2865-pr.2650.44c6affThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2650.tgz
npm install -g packageInstall instructions are refreshed on each push. |
PR #2650 review 完成。在 查重:open+closed 检索 结构化八问
测试有效性(④)新 e2e 测试有牙:按名断言注入工具缺席、compress prompt 缺席、global 断点 verbatim 存活、SSE 完整到 client。过宽防护由既有 tool-less round-trip(:301)+ #353(:333)+ #1092 salvage(:415)覆盖。CI:head commit 全部 check success,仅 diff 整洁度(⑤)2 文件 +61/-0(src 18 / test 43),每行都服务于本 PR 目的;base 新鲜、无其他 open PR 同文件竞争。干净。 发现处置
两件待你拍板的事(PR 正文自列)
判定:可合(human merge;F1/#2653 不阻塞,class 2 决策独立跟进)。 |
补充:head |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.233-master.df40d87 # this exact build
npm install -g billion-context@master # always the newest merged build
|
The summary line still stated the over-strict reading (#2650 era): any unmarked or narrower-scope content ahead of a global breakpoint is a 400. #2884's traffic evidence contradicts it — the Claude Code main loop carries 56 unmarked tools + unmarked system[0..1] ahead of its global breakpoint on system[2] and is accepted upstream. Restate the constraint at the observed boundary: the 400 trigger is tools present + global on system[0] (upstream's own 'not a true prefix when tools are present' note); unmarked predecessors of a deeper global are accepted. Provenance already carried the refinement; no gate, fake, or golden changed.
…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.
Closes #2648
What & why
Claude Desktop's Code tab reaches bili through cert-MITM in proxy mode (no native lane → no
x-bili-plugin). Its auxiliary side calls — notification / title / classification classifiers — pin theirsystemblocks tocache_control.scope:"global". Anthropic renderstoolsbeforesystem, so the six ACP tools bili injects (narrower scope) land ahead of a global block → upstream rejects with:This is class 1 of the two 400 families reported in #2648. Class 2 (
thread_fingerprint_mismatch) is a separate mechanism (bili has no Threads awareness) and is deliberately out of scope here — see "Pending owner decision" below.Fix (P1)
In
src/server/prepare-anthropic.ts, forward the request untouched when any system block carriescache_control.scope:"global"— no ACP tools, no Compression Philosophy block, no nudge, no cache marks. This mirrors the existing auto-mode classifier bypass (#353): the gate sits at the decision point (removes the tool-injection producer), not by filtering payload in transit, so it holds if the same root cause resurfaces in another shape.The trigger is keyed on the invariant actually being violated (a global-scope system block), not on "no tools": a tool-less conversation can still grow large and be compressed, so gating soft compression off on tool absence would be wrong — and it breaks the existing compress round-trip regression test. Healthy main turns use ephemeral/unscoped system and keep full compression; only genuine global-scope side calls are stood down for. The preflight hard-limit backstop still runs afterward (same code path #353 takes).
Regression test
tests/e2e-anthropic.test.ts: a global-scope request gains no ACP tools / compress prompt and keeps its breakpoint verbatim; the existing tool-less round-trip test still exercises injection (guards against over-broadening the gate). Targeted suite 6/6 pass; typecheck clean. Full suite left to CI.Behavior-change disclosure (owner policy 2026-09-22)
scope:"global"block are forwarded verbatim (no injection). No behavior change for any request without a global-scope system block — the overwhelming common case, including all healthy CC main-loop turns.Structured eight-question
scope:"global"时,注入的非 global 工具成为更窄前缀 → 400。Pending owner decision (class 2 — NOT in this PR)
thread_fingerprint_mismatch(class 2) stems from bili having no Threads awareness: it re-injects on every continue, and when the client omits tools/system on a continue (relying on server inheritance) the fingerprint mismatches. Fixing it needs a Thread lifecycle model — three options (A: stand down entirely on thethread:field; B: per-thread consistent canonical injection; C: replay-as-create on mismatch). This is a wire/message-shape change → human-gated (§7.4), so it stays out of this bugfix pending your call. I recommend shipping A now + filing B/C as a dedicated follow-up issue.Note (docs, user-reported — not independently verified here)
#2648 also reports that cert-MITM routing now works on Claude Desktop 2.31226.1 / CC 2.1.295 (host sets
NODE_USE_ENV_PROXY=1; settings-envHTTPS_PROXYhonored), which supersedes #2290's zero-CONNECT conclusion for that version. Since this is the reporter's observation and I can't reproduce Desktop here, I have not promoted it into CONFIGURATION.md / README yet — flagging for your confirmation before I touch the docs surface.