Repository navigation
Incremental turns: POST /__bili/plugin/turn — native clients send only the delta (#3248) - #3253
Conversation
Native-mode clients stop resending full history: turn 1 seeds the canonical (unified messages table), later turns send only the delta (including the previous assistant reply, client-owned). The lane assembles the full anthropic body and re-enters the proxy pipeline in-process (module-local forward, no loopback hop) — the session is the client's own conversation id, so incremental and full-resend traffic share one session, one fold ledger, one canonical, and may interleave freely (mode switch needs no ceremony). - Strict ack contract: x-bili-applied-seq header; 409 seq-mismatch / turn-in-flight force a client resync (sinceSeq realign or resync:true full seed); crash window = resync, the client stays the source of truth until it prunes (threads-lane model). - Canonical = kernel BiliMessage core form — exactly the rows the unified messages table already holds (rawTail ingest #3007 + watermark #3166 feed it from normal traffic too). Cold rebuild after restart / LRU eviction replays the table; malformed rows are a 409, never a silent truncation. - Sticky system prompt (session_ext inc:system), cache-control marks persisted (inc:cache-marks), anthropic request params via allowlist, plugin capability headers forwarded, /__bili/ loopback gate via the shared adminGateDenial. - Requires storage.unified shadow|full (503 legacy-only). v1 keeps the O(full) pipeline walk over the assembled prefix (zero-hit, cheap); the server-authored prefix fast path is tracked on #3248. Tests: tests/incremental-lane.test.ts (seed/delta/assembly, 409 + resync recovery, cold rebuild from the table, session interop, sticky system, turn-in-flight, request-param allowlist, legacy 503).
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3761-pr.3253.584c1fcThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3253.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 收到。这是 #3248 phase 2(增量 turn lane)的交付 PR,分支 查重:不重复——open/closed 里检索 "incremental"、"/__bili/plugin/turn"、"sinceSeq",只有这一条增量 lane 的在途工作(#3248 主线),无并行重复 PR/分支。 正在按 PR review 规范走完整审查(原 issue 方向 → 回归清点 → 代码 → 测试有效性 → diff 整洁度),稍后按结构化八问给结论。CI 状态一并核对中。 |
- PLUGIN.md: manifest.capabilities.turn does not exist in the plugin manifest (capabilities object has externalSummary + fork only) — state that detection is by endpoint + 503 instead of claiming a capability. - PLUGIN.md v1 caveats: document the append-only resync behavior — a diverged-canonical resync appends rows beside the stale ones, so a cold rebuild answers 409 until one more resync (durable replacement tracked on #3248). - CHANGELOG.md: 'interoping' -> 'interleaving'. Review fix-ups for PR #3253 (no code changes).
(ai: vllm-qwen/qwen3.8-27b) 审核结论(结构化八问)1. 是什么问题:功能 PR——#3248 的 phase 2。native 客户端(dsh/pi 等自持全量历史的宿主)不再每轮重发整段历史,只发增量+游标;服务端在 unified messages 表里维护 canonical 全量,拼出完整 anthropic body 后进程内重入管线,上游照旧只收折叠快照。 2. 什么原因导致的:不适用(需求实现)。动机:#3248 把 #2926 threads-lane 的"客户端发增量、服务端持权威历史"模式泛化到 native 车道。 3. 影响范围与严重程度:纯新增面——新端点 4. 怎么修复的(设计要点):canonical = 管线本来就在写的 kernel BiliMessage core 行(rawTail ingest #3007 + watermark #3166),无第二套存储,全量重发的会话切过来直接可用;会话身份故意不命名空间化——合成请求携带客户端自己的 5. 是否有回归问题:审过触碰路径的既有行为,逐项——
两个边界发现(均不拦合并):
6. 是否破坏缓存:否。组装 body 走标准管线(system 字节稳定、acp_summary 锚位不变);cacheControls 从存储行经 7. 是否改了设计方向:否。纯增量式 lane,沿用 #2926 既定模式,架构/边界/数据流无转向。一个观察供 owner 决定:PR 正文 8. 是否引入了新的配置:无新 env/config/CLI key。端点可用性复用既有 验证证据
判定可合并——待 |
Windows CI (test shards, node 22+24) failed teardown with 'EBUSY: resource busy or locked, unlink ...sessions\index.db': the harness closed the proxy and upstream but never the store's SQLite handle, and Windows cannot delete a directory while index.db is open. closeQuietly() is the documented seam for exactly this (persist.ts); the storage-unified suite already uses it. POSIX masked it because unlink of an open file succeeds there.
…ds slice past the rejected branch External review of #3253 found the persistence gap: a resync replaces the canonical in memory, but the unified messages table is append-only — the stale branch's rows stayed, so a cold rebuild served the longer row union and answered 409 until the client resynced once more (one extra round per restart). Fix: handleIncrementalTurn records the table row count at resync time (session_ext key 'inc:base-seq') AFTER flushing the outgoing branch's pending save, and readCanonicalFromStore slices rows past that epoch — the rejected branch keeps its append-only audit copy without polluting the served canonical. Legacy-only storage degrades to the previous full-union read (warn once). Test: divergent resync survives a cold restart without a 409 loop — seed an old branch, resync to an edited one, restart, next delta serves the edited branch (3 messages, no old-branch leakage).
|
Review finding ① (divergent-resync persistence gap) is now fixed in-PR (2ec6b40): a |
The concurrent-turn test settled the first request with a 40ms sleep against a 150ms upstream delay. Under load (observed locally on the review box: 1 failure in 4 runs, then clean), the first request can reach inFlight after the second is already issued, flipping the expected 'turn-in-flight' into 'seq-mismatch'. Widen both margins (120ms settle / 800ms delay) so the overlap no longer depends on scheduler luck.
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.443-master.360abaa # this exact build
npm install -g billion-context@master # always the newest merged build
|
Closes #3248 (phase 2: the incremental lane proper; phase 1's hash fast-path turned out to be subsumed — see notes).
What
Native-mode hosts that keep their own full local history (dsh, pi, future omp lanes) stop resending it:
sinceSeq: 0+ fullmessages[]seeds the canonical.forward, no loopback hop). Same session (the client's ownx-bili-plugin-conversation), same fold ledger, same nudges/tools — incremental and full-resend traffic interleave freely; a mode switch needs no ceremony.Contract
200= upstream body streamed through +x-bili-applied-seq(canonical length after the delta) — echo as next turn'ssinceSeq.409 {error: "seq-mismatch"|"turn-in-flight", serverSeq}— client recovers by realigningsinceSeqorresync: truefull seed. Strict:sinceSeqmust equal the server's canonical length;0against a populated canonical is a mismatch, never a silent replace.503— lane runs legacy-only; the canonical log lives in the unified messages table (storage.unifiedshadow|full).system(omit = keep last; session_extinc:system), anthropic request params via allowlist, plugin capability headers forwarded,/__bili/loopback gate via the sharedadminGateDenial.Why it is this shape
rawTailingest (Unified store holds the raw conversation tail (#2960 ⑤) #3007) + watermark (fix: per-session ingest watermark — storage saves cost O(new messages), not O(full log) (#3133) #3166) feed the unified messages table from normal traffic too, so the lane replays exactly what persistence already holds — no second storage, and a conversation that ran in full-resend mode already has its canonical on disk (switching mid-conversation just works, both directions).Tests
tests/incremental-lane.test.ts(8): seed→delta assembly asserted at the upstream; 409 + resync recovery; cold rebuild from the unified table after pool+cache reset; session-interop (same session id as normal traffic); sticky system; turn-in-flight; request-param allowlist (incl.request.messagessmuggling rejected); legacy 503. Regressions: plugin-fork + memory-diagnostics + storage-unified (64), golden-storage-render + issue833 + wire-contract (10), tsc clean, unused-export gate clean.Prepared by an agent under the local git identity (ranxianglei), human merge required.