Repository navigation
[PR] fix: threads-lane reforge — model-reply capture, client-shaped side-call, rejected-create cooldown - #3746
ranxianglei wants to merge 4 commits into
Conversation
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.6249-pr.3746.eac6e14This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr3746.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…es, decoder flush at stream end (#3744) Review of #3746 (Closes #3744): a completed reply carrying only signature-verified thinking blocks (or aborted before any content event) left NO mirror entry, so every later reforge rebuild hit the system-placement 400 again after each cooldown cycle. Such replies now mirror a self-describing placeholder assistant slot (SSE + JSON paths); the stream reader also flushes the TextDecoder at EOF so a trailing multi-byte character can't drop the final frame. The lane-local placement validator moves to wire-contract-fakes.ts as the shared firstAnthropicThreadsPlacementViolation export.
(ai: vllm-qwen/qwen3.8-27b) 查重结论: 不重复 — open 条目里提及 threads reforge 的只有本 PR、原始 #3744、以及无关的 #3559;上一个相关修复 #3569 已合入 master。本 PR 是 #3744 的实现线程,无并行工作。 标签: bug / claude-code / scope/kernel / p1(缺陷类;涉及 Claude Desktop 内嵌 CC 2.1.299;属上下文管理/压缩引擎域;开关打开时功能完全不可用 → p1)。 独立重审了本 PR(逐文件读 diff + 对既有行为逐项审计,未复用 issue 侧的分析)。三个修复均在代码层面验证成立;审查中另发现 一个真实缺陷、一个小缺陷、一个账本缺口,按「小问题直接修」已直接在分支上修掉(两个标注 commit,原作者署名保留):
结构化八问
行为变更披露(全部限定在 flag 之内,旧值 → 新值)
CI新 head 判定: 可合并 — 三个修复方向正确、修法到位(含我的两处补充),回归审计干净,CI 全绿。合并留给你: #3746 |
8e11fa0 to
e7c12bb
Compare
…es, decoder flush at stream end (#3744) Review of #3746 (Closes #3744): a completed reply carrying only signature-verified thinking blocks (or aborted before any content event) left NO mirror entry, so every later reforge rebuild hit the system-placement 400 again after each cooldown cycle. Such replies now mirror a self-describing placeholder assistant slot (SSE + JSON paths); the stream reader also flushes the TextDecoder at EOF so a trailing multi-byte character can't drop the final frame. The lane-local placement validator moves to wire-contract-fakes.ts as the shared firstAnthropicThreadsPlacementViolation export.
…ary side-call, cooldown on rejected create (#3744) Three defects kept the opt-in threads reforge unusable on Claude Desktop (cert-MITM, embedded CC 2.1.299, subscription OAuth): 1. Summary side-call always 429: it was hand-built with four whitelisted headers and a bili-authored system block. Rebuild it from the client's own request instead — pass every client header through except hop-by-hop / host / content-length / accept-encoding / x-bili-* / one-shot ids (x-client-request-id, anthropic-dispatch-id, x-claude-code-prompt-id), ride the captured original system verbatim (attribution + identity intact), and append the summarizer instructions to the user message. Shape proven by the local variant-B experiment in #3744. 2. Reforged create 400 "role 'system' must precede an 'assistant'": the mirror only stored client-sent deltas (user+system); mid-conversation systems were never followed by an assistant because model replies live server-side in the Thread. Capture assistant replies (text + tool_use, reassembled from SSE deltas or the JSON body; signature-verified thinking blocks excluded per #1960) so rebuilt creates satisfy the placement rule. 3. No cooldown when the swapped create is rejected: the mirror now rolls back to its pre-reforge view and arms the existing 10-min side-call cooldown, ending the summarize→rebuild→400 loop that cost 20–40s per turn. Behavior changes (opt-in feature behind BILI_ROLLOUT_ANTHROPIC_THREADS_REFORGE): - mirror size estimates rise (replies counted) → reforge triggers earlier and reflects true thread growth; - summary side-call wire shape as above; - new cooldown trigger on rejected reforged create. Docs: README en/zh note the desktop threads enablement conditions (field report, #3744). Tests: threads-lane suite extended (SSE/JSON reply capture, side-call shape+headers, placement regression both directions, rejected-create rollback+cooldown); issue2701 suite still green. Closes #3744
…es, decoder flush at stream end (#3744) Review of #3746 (Closes #3744): a completed reply carrying only signature-verified thinking blocks (or aborted before any content event) left NO mirror entry, so every later reforge rebuild hit the system-placement 400 again after each cooldown cycle. Such replies now mirror a self-describing placeholder assistant slot (SSE + JSON paths); the stream reader also flushes the TextDecoder at EOF so a trailing multi-byte character can't drop the final frame. The lane-local placement validator moves to wire-contract-fakes.ts as the shared firstAnthropicThreadsPlacementViolation export.
…t rule gate (#3744) Per #1304 the production constraint learned in bili #3744 becomes a permanent WIRE_RULES entry: WC-022 (wire anthropic, lane anthropic-threads) — a full-history Threads create 400s when any system message is not followed later by an assistant message and does not end the array. Lane-scoped enforcement stays in the lane's own fake upstream (tests/threads-lane.test.ts pins the validator both directions), with the probe row added to the laneProbes gate table.
e7c12bb to
c7cfc32
Compare
(ai: vllm-qwen/qwen3.8-27b) 上游冲突已解决:PR 分支已 rebase 到最新 master( 冲突实况:整个窗口只有一处真实文本冲突——README en/zh 的 结构化八问
判定:冲突已清除,可进入 CI→人工合并。合并仍留给你:#3746 |
# Conflicts: # README.md # README.zh-CN.md # src/server/relay.ts
Closes #3744
Three defects kept the opt-in threads reforge (
BILI_ROLLOUT_ANTHROPIC_THREADS_REFORGE=1) unusable on Claude Desktop (cert-MITM, embedded CC 2.1.299, subscription OAuth). All three were verified at code level before fixing; the reporter's local variant-B experiment is the evidence base for fix 1.Fixes
1. Summary side-call always 429. It was hand-built: four whitelisted headers plus a bili-authored system block — the upstream rejected that shape under subscription OAuth while the client's own requests passed. The side-call is now rebuilt from the client's own request: every client header passes through except hop-by-hop /
host/content-length/accept-encoding/x-bili-*/ one-shot ids (x-client-request-id,anthropic-dispatch-id,x-claude-code-prompt-id); the captured original system rides verbatim (attribution + identity intact, prefix-cache friendly); summarizer instructions move to the end of the user message. Old shape remains as fallback when no system was captured.2. Reforged create 400 —
messages.N: role 'system' must precede an 'assistant' message or end the array. The mirror only stored client-sent deltas (user+system). CC 2.1.299 sends a mid-conversationsystemeach turn, and model replies live server-side in the Thread — so rebuilt arrays wereuser system user system …, which violates the placement rule (asystemis only legal when followed by an assistant message or at array end). Assistant replies are now captured into the mirror from the response stream bili already forwards: text + tool_use reassembled from SSEcontent_block_*deltas or parsed from the JSON body;thinking/redacted_thinkingblocks are excluded (signature-verified, #1960 family). Side benefit: fold summaries now reflect what the model actually did, not just what the client sent.3. Summarize→rebuild→400 loop. When the swapped create is rejected upstream, the mirror rolls back to its pre-reforge view (the server-side thread never changed) and arms the existing 10-min side-call cooldown; subsequent over-window turns forward plain until it expires. Previously only side-call failures armed it, so a summary-success/create-rejected pair looped every turn (20–40s + a big Opus call per round).
Behavior changes (disclosed)
All inside the opt-in rollout feature — no change for anyone without
BILI_ROLLOUT_ANTHROPIC_THREADS_REFORGE=1:No config/env surface added. No
kernel/changes.Tests
tests/threads-lane.test.ts: the fake upstream now enforces the production placement rule on full-history creates (validator pinned both directions), records side-call headers, and serves SSE text/tool_use plus configurable non-stream replies. New tests: SSE reply reassembly (split deltas → text + tool_use input), non-stream capture with thinking filtered out, variant-B side-call shape/header assertions (pass-through vs stripped), CC-style mid-conversation-system placement regression (the pre-fix rebuild 400s inside the fake), rejected-create rollback + cooldown (no second side-call, fail-open continue). Existing mirror-count asserts updated for captured replies.tests/issue2701-threads-continue.test.tsunchanged and green. Local targeted runs green; full-suite verdict = CI.Docs
README en/zh: desktop threads enablement conditions appended to the #2290 known-limitation paragraph (field report from #3744, paraphrase of CC 2.1.299 minified code).