Repository navigation
[PR] fix: decline the message-threads beta for Claude Code sessions bili compresses - #6918
MohammadErfan-Jabbari wants to merge 1 commit into
Conversation
…ompresses Claude Code uses Message Threads through the proxy: each continue carries only the new messages, so bili can neither nudge nor fold it (ranxianglei#2701). For a Claude Code session bili compresses, bili now answers a threads request with the 400 Anthropic gives for an unknown beta header. Claude Code drops the header and threading for the session and retries with the full history, which bili folds as usual. A session counts as one bili compresses when its bili MCP tools are on the wire, or, since Claude Code defers MCP tools behind tool search, when bili's MCP server registered its x-claude-code-session-id. Only Claude Code is declined: another Anthropic-wire client may not drop threads on the 400. Requests without bili's tools keep the threads lane. Fixes ranxianglei#6915 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(ai: vllm-qwen/qwen3.8-27b) Duplicate screening (查重): No duplicate. Searched open+closed PRs for Review of #6918 (head Direction (①): Correct. The root mechanism is real and I reproduced the asymmetry: Gate (②/③): The dual-signal gate is sound; I verified both halves are non-destructive. Wire-behaviour change: This answers some requests with a 400 instead of forwarding them — a wire change, so per §7.4 it stays at the human-review tier (the PR self-declares this). Residual risk is the client-behaviour dependency: CC 2.1.322 matches the 400 (status + message naming the header value + Tests (④): Valid, not tautological. A real CI: 1 failure of 52 checks — Rebase: The PR is 18 commits behind master (tip Docs: The Message Threads lane (#2926) is depicted only in the one-line file map Verdict: No code changes requested — the implementation is clean (named constants, doc comments explain why, no dead code, style consistent, exact 400 shape). Approve for a human reviewer to merge after (a) a rebase to current master and (b) a re-run of the flaky 八问(中文,供人工 reviewer):
判定:代码无需改动(整洁度达标)。合并前需 (a) rebase 到当前 master(落后 18 个提交,但上游改动与本 PR 插入区不重叠,应能干净合并);(b) 重跑 flaky 的 |
(ai: vllm-qwen/qwen3.8-27b) Re-verified live state first: the only red check is Diagnosis: a flake in a master-level test — not introduced by this PR.
Action taken: re-ran the failed job ( 中文八问
收工判定:本轮已完成诊断 + rerun,等 attempt 2 结果;若仍红(同签名)则按 #4599 协议升档 ci-fixes 测试硬化。 |
(ai: vllm-qwen/qwen3.8-27b) Re-run is green — flake confirmed. This confirms the diagnosis: the |
[ework] CI fix verified green ✓ |
[ework] CI fix verified green ✓ |
1 similar comment
[ework] CI fix verified green ✓ |
Fixes #6915
Problem
Claude Code sends its turns as Message Threads. After the first
create, each tool step is acontinuethat carries only the newest one or two messages, so bili can neither nudge nor fold a session it is meant to compress (#2701). Measured with a Claude Code session: 2 main-lane requests for 12 tool calls, no[plugin] [acp-usage]and no nudge line.Fix
threadsBetaToDecline(src/server/threads-lane.ts) returns themessage-threads-*token of theanthropic-betaheader when the body is a threads turn of a session bili compresses.src/server/handle.tsanswers such a request with the 400 Anthropic gives for an unknown beta header, before anything is forwarded. Claude Code 2.1.322 matches that error, drops the beta and threading for the session, and retries with the full history, which bili folds as usual. Oneinfoline per decline:[threads] declined message-threads-… for a session bili compresses ….x-claude-code-session-id), and bili compresses the session (bili's MCP tools on the wire, or, since Claude Code defers MCP tools behind tool search, a registration of that session id by bili's MCP server throughconsumePluginRegisterFor, which only reads and refreshes LRU order). Another Anthropic-wire client with bili's tools may not drop threads on the 400 and would fail every request, so it keeps the threads lane.Both compression modes
Tests
tests/claude-threads-decline.test.ts(new) drives a real proxy against a mock upstream. Positive rows: acreateand acontinuewith bili's tools are declined in Claude Code's matcher shape and never reach the upstream; the retry without threads is forwarded; a registered session whose tools are deferred is declined. Negative rows: a non-Claude-Code client with bili's tools keeps the threads lane; a threads request without bili's tools is forwarded. It fails on master and passes with the fix.claude-threads-decline,issue2701-threads-continue,mcp-native-thread,threads-laneandlane-decisions-matrixpass (135 tests), andnpm run typecheckis clean.ACP_TEST_E2E=1). This touches the request pipeline before forwarding, so the maintainers may want that lane before merge.Live result
On a private proxy with a Claude Code session (Haiku), the session was declined once, then grew 26 → 29 → 32 → 35 messages as full-history requests. The nudge fired after 25,670 tokens of growth and the model's
compressfolded about 57,000 tokens, with no rejected request besides the one intended decline. We have run this fix on our own machines since 2026-11-13.Review tier
This answers some requests with a 400 instead of forwarding them, which is a wire-behaviour change, so per §7.4 it stays with a human reviewer. No config, persistence-format or kernel change.
🤖 Generated with Claude Code