Repository navigation
[PR] fix(#2612): refuse Claude Code native compaction on the wire — bili owns compression - #2849
ranxianglei wants to merge 2 commits into
Conversation
…wns compression CC's own compaction (manual /compact, precomputed compression, auto-compact when the managed DISABLE_AUTO_COMPACT=1 block is not in force) is now refused locally with 403 before it can burn a full raw-history round-trip upstream and desync CC's transcript from the fold ledger (#2612/#2728). Escape hatch: claude.allowNativeCompaction in the config file, or BILI_ALLOW_CLAUDE_COMPACTION=1 (#2728 opt-in family, mirrors #2028 dsh).
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3159-pr.2849.f116578This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2849.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Picked up. Identified PR #2849 ( |
…test The step-C assertion accepted both 403 and 200 (a tautology — it passed under any behavior) because startServer does not hot-reload opts.allowClaudeCompaction within a lifetime. Tighten it to assert.equal(r.status, 403): this server was started without the opt-in, so it keeps refusing even after the config file flips above. The opt-in forwarding path is already covered by the fresh-server test below.
[bot] 🏷 Review 完成(PR #2849 / 分支 结论:可合(pending CI green on updated head)中文八问
我顺手修的一处(小问题直接修,已推独立标注 commit)集成测试 step C 原断言
其余各文件逐行读过:检测器用非全局正则(无 lastIndex 坑)、google 与 #1117 passthrough 明确排除在外(有文档说明)、config 解析矩阵(default OFF / file ON / env-0-beats-file / env-1 / 非"0"-enable)与 dsh 孪生完全同构。diff 干净:9 文件、无 version bump、无 lockfile/生成物连带变更、每行都与本 PR 目的相关。
判定:方向正确、无回归、测试现已有牙、diff 干净 → 可合(等更新后 head 的 CI 全绿即可人工合并)。 |
|
(ai: zhipuai-lb/glm-5.3) 陈旧票清理(第三批动作①):目标 issue #2612 已关。为避免重复劳动关闭本 PR;如判断有误请直接 reopen 并留言。 |
What
Claude Code's native compaction is now refused on the wire by default, mirroring the #1729/#2028 dsh compaction guard — one PR covering the four pieces agreed in #2612/#2728:
src/server/claude-compaction-guard.ts(new)src/server/handle.ts(after the dsh guard)DISABLE_AUTO_COMPACT=1in the managed block — already existed (applyClaudeManagedBlock); note text updated to say manual/compactis now refused instead of "survives"src/plugin-install.tsclaude.allowNativeCompaction(config file) /BILI_ALLOW_CLAUDE_COMPACTION(env)src/config.ts+ docs surfacesWhy refuse instead of letting it run
The two failure directions are both unrecoverable from bili's side:
<summary>while bili's fold ledger still anchors the raw history — an unannounced history rewrite. The three read faces split (status blocks vs what CC actually sends, search misses, decompress returns text CC can no longer place) and the session drifts into the [bug] bili claude: ACP state mismatch after CC native /compact (stale compressed block orphaned: acp_status/search_context reports no blocks, yet decompress can still retrieve by ID) | [bug] bili claude:CC 原生 /compact 后 ACP 状态失配(旧压缩块脱钩:acp_status/search_… #2728 silent-desync family./compactis exactly when things are already broken (folds lost, context re-inflated): the envelope re-sends the full raw history — multi-M tokens upstream, 400 or real money — for a summary bili would have folded for free ([bug] bili claude: #2303 draft-tail 重试把 Claude Code 自己的压缩回复(以 </summary> 结尾)当坏草稿打断,/compact 与 auto-compact 全部失败 #2612 形态ⅲ).Refusal channel = 403 API error, not text: CC renders it through its "Error during compaction" surface, the transcript stays verbatim, nothing executes. (A text reply would risk CC adopting it as the summary — the exact transcript destruction we're preventing.)
Detector contract (strict-AND) vs #2619 (either-phrase)
#2619 (merged earlier today) exempts CC compaction requests from the #2303 draft-tail retry by matching EITHER instruction phrase — fail-open by design, since a missed exemption only costs one wasted retry. The wire guard inverts the bias because it refuses a turn outright: it requires BOTH phrases, so a user legitimately asking for that output format ("summarize this, use an
<analysis>block followed by a<summary>block") is not 403'd. A reworded CC template degrades to a miss → the request forwards → #2619's exemption still protects the retry path. Defense in depth, each layer failing in the safe direction for its own blast radius.Coverage: anthropic (CC native), openai + responses (CC behind claude-code-router style installs keep the template text). Google stays out of scope (CC speaks no google wire). The #1117 passthrough lane is deliberately not guarded: it exists for unattributed in-process callers (#2709), never for external HTTP clients like CC.
Escape hatch
"claude": { "allowNativeCompaction": true }in the bili config file, orBILI_ALLOW_CLAUDE_COMPACTION=1(env wins;0forces the guard back on when the file opted out) — the claude twin ofdsh.allowDshCompaction(#2028). Opting in means accepting the desync trade documented in the config reference. Docs surfaces updated:server.yamlseed (EN+ZH),CONFIGURATION.md+CONFIGURATION.zh-CN.mdvia the generator (idempotent,check-coveragegreen).Tests
tests/issue2612-claude-compaction-guard.test.ts(12 tests):{type:"error"}envelope vs openai/responses{error:{code:"claude_compaction_refused",retryable:false}}; message names the real opt-inBILI_semantics);allowClaudeCompactionStatesourcesrequestExpectsProseSummarystays either-phrase, guard stays both-phraseallowClaudeCompaction:truelifetime forwards the envelopeRegression-checked locally:
issue2028-dsh-compaction-toggle(20+13 across the passthrough/guard files),dsh-compaction-guard,issue2612-compaction-draft-tail(#2619),issue1815-unknown-top-level-keys,plugin-agent,config-surface-guard,plugin-install-opencode,mitm,abort-rewind-cache-seam,issue2709-passthrough-compaction-guard,claude-subagent-split,issue2451/issue2432/codex-compact— all green. (claude-native.test.tshas 4 failures on this machine both with and without the branch — machine-local zone-port sticky record pins 18788 over ZONE_PORT_BASE 18787; hermetic CI unaffected.)Closes #2612 (the ⅲ direction; ⅰⅱ were fixed by #2619, already merged). Relates to #2728 (boundary work for genuinely passing compaction through stays out of scope — the documented answer is: don't).