Repository navigation
Anthropic Threads lane: unified-store mirror + over-budget reforge into fresh creates (#2926, #2884) - #3332
Conversation
…and reforge over-budget continues into fresh creates (#2926) Threads state lives server-side; a continue body is delta-only no matter how big the thread grew, so the history-rewrite lever does not exist on this wire. The lane: - captures every create/continue into session_ext (threads:mirror:*), create being the client's authoritative full snapshot; - forwards all turns byte-faithfully with preflight skipped (the wire body says nothing about the real thread size — the mirror is the only budget truth); - on a continue whose mirror estimate crosses the window, with rollout feature anthropicThreadsReforge on (default 0%), swaps it for a fresh create carrying [summary, tail ring (last 3 user turns), delta] — one summarizer side-call on the client's auth, client system/tools copied byte-faithfully; the message-id chain carries the client into the new thread with zero redirection; - claims the turn before the #2648 global-scope stand-down, which used to swallow whole Claude Code threads sessions (#2884); - fails open everywhere: legacy-only storage and failed side-calls degrade to pure passthrough. Fixes #2884 (with the lane claiming threads turns ahead of the stand-down). Part of #2926.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3940-pr.3332.7b95504This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3332.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…d can't leak a stale fold point
A threads `create` is the client's authoritative snapshot, but captureThreadsTurn
spread the prior meta (`{ ...meta, shape, shapeTokens }`), carrying any earlier
foldedBefore/foldedSummary forward under the same session id. If a session id is
re-created after an earlier thread was reforged (e.g. a resume), the next reforge's
ringCutIndex treats unsummarized new-thread entries as already folded and drops them
from both the summary transcript and the tail ring — silent loss of early turns.
Reset bili's own fold tracking on create via freshMeta(); the stale fold state now
cannot survive an authoritative replace. Adds a regression test that fails without
the reset (re-create after a reforge must yield foldedBefore=0 / no summary).
Part of #2926.
The test already pulls mkdtempSync/rmSync from node:fs by name; the default `import fs` was only kept alive by a `void fs;` to satisfy the unused-import gate. Remove both.
(ai: vllm-qwen/qwen3.8-27b) PR #3332 审核结论(独立审核,非复述 issue 结论) 先说处置:我在分支上补了 2 个 commit 并已 push( 结构化八问
测试有效性(④):原 7 个都是真测试(真起 server + mock upstream,断言有牙:字节忠实 / 镜像累积 / side-call 形态 / create 换体 / system-tools 逐字 / summary 头 / delta 尾 / fail-open),非恒真。缺口:ring-cut 的「用户边界切分、tool_use/tool_result 不成对拆分」不变量未被测(现有用例全是 string content)——见下方 rollout 前置项。 rollout 开启前置(非合并阻塞,默认 0% 安全):
diff 整洁度(⑤/⑤b):原 PR diff 干净(+846/-1,每行都在目的内)。我顺手修了死代码(fs import)。遗留小注(非阻塞,建议后续):summary 请求构造里硬编码 自动合并判定:不符合 §7.4(feat + 改线/消息形态 + 会话绑定逻辑)→ 人工合并,与「human merge required」一致。 结论:可合(默认 0%,安全)。 建议 owner 现在批准合并;把上面 #2/#3 作为「开启 rollout flag」前的独立门禁步骤,而非合并前提。CI 在新 head |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.495-master.f94ee8f # this exact build
npm install -g billion-context@master # always the newest merged build
|
What
Anthropic Threads moves conversation state server-side: a
createcarries the full history once, every latercontinuecarries only a delta (previous_message_id), and the API offers no way to rewrite what already sits in the thread. bili's core lever — rewriting the resent history — therefore does not exist on this wire. Today threads turns hit the #2648 global-scope stand-down (Claude Code's main loop runs threads with a global-scope system block), forwarding byte-faithfully but with folding silently disabled for the whole session (#2884) and no path to ever shrink the thread.This PR adds the threads lane (#2926):
session_ext(threads:mirror:meta+threads:mirror:chunk:NNNN, packed under the 4 MiB per-value cap; oversized entries elided — bulk media belongs in the CAS). A create replaces the mirror (it is the client's authoritative snapshot) and captures the session "shape" (model/system/tools/max_tokens); a continue appends its delta.anthropicThreadsReforge, default 0%): when the mirror estimate (shape + summary + post-fold entries) crosses the window on a continue, bili swaps that continue for a freshcreatecarrying[summary of the folded prefix, verbatim tail ring (last 3 user turns — cut on a user-turn boundary so tool_use/tool_result pairs never split), this turn's delta]. One summarizer side-call rides the client's auth headers and the same upstream; the client's system/tools are copied byte-faithfully from the captured shape — host instructions never enter the summary. Because the message-id chain IS the thread identity, the client's next continue (echoing the new tail id) lands in the new thread with zero redirection; a late continue into the dead old thread is already handled by [Bug][claude MITM] Threads 下 bili 压缩回路在 continue 轮次全面失效:nudge 失明、mid-turn compress 400(previous_message_id already continued)、折叠只能在 create 送达 #2701 retargeting semantics.Gating
rollout.features.anthropicThreadsReforge: true/BILI_ROLLOUT_ANTHROPIC_THREADS_REFORGE=1(default 0% — capture rides along whenever the sidecar is available, the reforge swap is what the flag gates).Tests (
tests/threads-lane.test.ts, 7/7)Regression: issue2701 (10), issue833/golden-storage-render, persist-tail + storage-unified (23), tsc clean, unused-export gate clean.
Part of #2926; supersedes the stand-down half of #2888 for the threads case.
prepared by an agent under the local git identity (ranxianglei), human merge required