Repository navigation
fix: dsh 增量标记与 body 原子落位,补单飞行守卫——并发会话不再可能裸发增量体丢历史 - #3378
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3997-pr.3378.d106b03This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3378.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…ending incremental entry (#3378 align) The PR's own comment promised 'keep the pending entry for the marker'd response still in flight', but all four ack collectors deleted the entry unconditionally right after the lookup. A concurrent full-resend request's plain 200 (no seq header) arriving first would consume the entry, so the marker'd response's ack was lost: the client's sinceSeq lagged, the next turn replanned already-applied messages into the delta, the server answered 409, and #3377's recovery reset to a full resync — self-healing degradation, but it defeats the single-flight design this PR adds. Invariant relied on: src/incremental-lane.ts installs a writeHead wrap that stamps x-bili-applied-seq on every diverted response that reaches forward(); every lane-written rejection (400/409/503) is emitted before that wrap and therefore never carries the header. So 200-without-seq is provably a foreign response: keep the entry (bounded by the existing 30s TTL); every other status keeps its previous consumption semantics. Regression test: dsh seam test step 2b feeds a foreign 200 before the marker'd response and asserts the next turn still plans a clean delta.
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复。本 PR(原子盖章+单飞行,closes #3370)与它 stack 其上的 #3377(409/503 恢复,closes #3369)、以及并行的 #3340(per-request turn-id 键控 pending map,closes #3329)是三个不同修复。但本 PR 第 2 部分(单飞行守卫)与 #3340 命中同一根因,存在机制交叠与合并顺序问题——见文末「重点提示」,这是本次 review 最需要你拍板的地方。 结构化八问
重点提示(需你拍板):与 #3377 / #3340 的协调
建议(按此顺序推进,请确认):① 先合 #3377(base);② 合本 PR——原子盖章是 #3370 真正修复(静默丢历史,高优先)、单飞行作 #3340 落地前的过渡止损;③ 把 #3340 修绿合入,其 turn-id 键控取代单飞行守卫,届时用一个 follow-up 小 PR 删掉 dsh 里已冗余的单飞行检查(或并入 #3340 rebase)。三个 PR 都落在 dsh/omp/opencode 的 onResponse + pending-map 同一批热文件上,属热文件竞争,需显式排好顺序再逐个合。 已做的动作
判定原子盖章部分成立、测试有牙(CI 全绿),可在 #3377 之后合入——它修的是静默丢历史的高优先缺陷。单飞行守卫作为过渡止损可保留,但须待 #3340 定去留后再决定删/留,不建议在未定 #3340 之前把整 PR 当作最终闭环合入。等你对上面三步顺序点头。 |
(ai: vllm-qwen/qwen3.8-27b) Review 完成:可合(待 CI 绿);合并顺序 #3377 → #3378(stacked,祖先关系已验证)。 独立重走了完整机制链(两个 PR 的 diff 逐行读 + 服务端 结构化八问1. 是什么问题 2. 什么原因导致的 3. 影响范围与严重程度 4. 怎么修复的
5. 是否有回归问题 6. 是否破坏缓存 7. 是否改了设计方向 8. 是否引入了新的配置 行为变更清单(旧 → 新,全部在 rollout 门后,当前暗)
审核发现并已直接修复的缺陷(commit
|
(ai: vllm-qwen/qwen3.8-27b) 跟进(接上一轮 review):我上一轮标记的那个残留——「单飞行守卫本身不充分:onResponse 顶部无条件 核对了 098cabf(刚推到分支上,标题 "...must not consume the pending incremental entry (#3340 align)")。它把四个 ack collector(dsh/omp/opencode/pi)里 一处可选小 nit(功能无差,不强求):seq 校验口径不一致——dsh 用 #3340 协调点仍成立:本分支仍是「URL 键控 pending map + 单飞行守卫」;#3340(per-request turn-id 键控,closes #3329)落地后会取代单飞行守卫、让整类 URL 串号问题消失。#3340 当前 CI 红(test ubuntu/node22/shard2 失败),未就绪。三步顺序建议不变:#3377 → 本 PR(#3378)→ 修绿并合 #3340(届时用一个 follow-up 删掉已冗余的单飞行检查)。 现状:PR head = 098cabf,mergeable = true,新 head 的 CI 跑中(暂无失败)。上一轮结论更新为:原子盖章 + 单飞行守卫 + ack 消费修正三者都已就位且方向正确,待新 head CI 转绿、你对合并顺序点头即可推进。PR 由你合(人工动作,我不会合)。 |
(ai: vllm-qwen/qwen3.8-27b) 更新:pushed head |
…flight + TTL on the ack stash native-intercept.ts:698-700) and marker stamping (state.headersFor, called at :705) across a single closure-level boolean shared by EVERY session in the process. Two concurrent model requests crossing that microtask boundary interleaved: R1.beforeSend armed the flag -> R2.beforeSend -> R2.headersFor consumed it -> R1.headersFor found it disarmed and R1's delta body shipped with NO marker. The proxy forwarded the delta-only messages verbatim (incrementalTurnBodyShape is only consulted under the marker, handle.ts:146-152), so the model answered with no conversation history — silent wrong answers, not an error. - The marker now rides init.headers from the conversion itself (omp pattern): new Headers(init.headers).set(x-bili-plugin-turn, "1") right where init.body is swapped, atomic in the same hook invocation. withHeaders merges headersFor's own stamps on top, so the marker and the body can never part ways. headersFor's armed-flag branch is gone. - Single-flight guard (omp-native.ts:104-106 pattern): while a marker'd request for the same URL awaits its ack, later requests ride the normal pipeline — their acks could otherwise collide with the pending entry keyed by the shared model endpoint URL. Pending entries carry at: Date.now() and expire after 30s (matches omp/opencode). - Test seams: _stateBeforeSendForTest/_stateOnResponseForTest exposed alongside _stateHeadersForTest; the dsh mock proxy serves the /__bili/plugin/turn feature probe (turnEnabled flag). Tests: new #3370 dsh test drives the seams end-to-end — marker+body atomic on the same init, headersFor carries no marker, single-flight leaves an overlapping request untouched, ack advances the next plan to a real delta. Existing suites re-run green: native-intercept 58/58, incremental-lane 17/17, opencode/omp incremental + recovery suites, tsc clean. The dsh test nulls BILI_PROVIDER_REWRITES/BILLION_CONTEXT_PLUGIN (hermetic pattern from the #1772 suite) so it runs on hosts whose shell is itself behind a bili proxy. Stacked on #3377 (409/503 recovery rewired the onResponse arms this test also drives). Closes #3370
…ending incremental entry (#3378 align) The PR's own comment promised 'keep the pending entry for the marker'd response still in flight', but all four ack collectors deleted the entry unconditionally right after the lookup. A concurrent full-resend request's plain 200 (no seq header) arriving first would consume the entry, so the marker'd response's ack was lost: the client's sinceSeq lagged, the next turn replanned already-applied messages into the delta, the server answered 409, and #3377's recovery reset to a full resync — self-healing degradation, but it defeats the single-flight design this PR adds. Invariant relied on: src/incremental-lane.ts installs a writeHead wrap that stamps x-bili-applied-seq on every diverted response that reaches forward(); every lane-written rejection (400/409/503) is emitted before that wrap and therefore never carries the header. So 200-without-seq is provably a foreign response: keep the entry (bounded by the existing 30s TTL); every other status keeps its previous consumption semantics. Regression test: dsh seam test step 2b feeds a foreign 200 before the marker'd response and asserts the next turn still plans a clean delta.
098cabf to
1ccb554
Compare
|
ai: zhipuai-lb/glm-5.3 Rebase 完成(#3377 已并入 master 后的冲突已解),现 HEAD = 冲突解法:dsh 对「单飞行 vs #3340」阻塞的立场(按 reviewer 三步顺序执行,供 owner 拍板):
合并仍留给人类;CI 绿后即可按顺序推进。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.493-master.cfe5769 # this exact build
npm install -g billion-context@master # always the newest merged build
|
opencode-native.ts had the same claim-before-guard order as dsh/omp (planIncrementalTurn with the harvested msgIds at :979, the #3378 single-flight guard below it). A guard-blocked turn burned its harvested ids the same way; hoist the guard above the planning call. alignedMsgIdsForWire() is a pure read of the harvest map, so it is safe to keep inline in the (now post-guard) plan call. Regression test mirrors the dsh one: blocked attempt must not burn the ids; after the seed acks, the retry still pins them (pre-fix: actual undefined).
…he turn A turn that the guard discards had already claimed its msgIds client-side (all-or-nothing, #4491). The burned ids were never released, so the host's retry of the same turn lost the whole msgIds field and the server pinned those rows to content-derived identity — the exact host/server divergence #4834 just fixed, self-inflicted here by the client lanes themselves. Hoist the #3370/#3378 single-flight guard above planIncrementalTurn in both native lanes (dsh, omp). The guard only reads the pending-ack table, so the reorder changes nothing for the guard itself; planning now only happens for turns that will actually be dispatched. Regression test: a guard-blocked delta attempt must not burn its ids — after the seed acks, the retry still pins msgIds (pre-fix: the field is silently dropped).
opencode-native.ts had the same claim-before-guard order as dsh/omp (planIncrementalTurn with the harvested msgIds at :979, the #3378 single-flight guard below it). A guard-blocked turn burned its harvested ids the same way; hoist the guard above the planning call. alignedMsgIdsForWire() is a pure read of the harvest map, so it is safe to keep inline in the (now post-guard) plan call. Regression test mirrors the dsh one: blocked attempt must not burn the ids; after the seed acks, the retry still pins them (pre-fix: actual undefined).
ai: zhipuai-lb/glm-5.3
什么坏了(#3370)
dsh 把增量转换(
beforeSend,在 native-intercept 里被 await)和标记盖章(headersFor,稍后另一次调用)拆在一个进程级共享布尔的两端。同一进程里两个并发模型请求(两个聊天窗口,或聊天+后台标题生成)跨过这个微任务边界就会交错:R1 置位 → R2 置位(仍 true)→ R2 的 headersFor 消费掉(false)→ R1 的 headersFor 看到 false → R1 的增量体不带标记直发。代理端标记分流要求x-bili-plugin-turn存在(handle.ts:146-152),没有它,只含新消息的 delta 被当普通请求原样转发——模型在零历史状态下静默答错,不是报错。修复(向 omp/opencode 模式收敛)
init上盖(new Headers(init.headers).set(marker),紧挨init.body交换),同一钩子调用内完成;withHeaders只在 init.headers 之上叠加 headersFor 自己的键,标记与 body 再无分家可能。headersFor 的消费分支删除。测试
sinceSeq前进、只含新消息)。/__bili/plugin/turn探测端点;_stateBeforeSendForTest/_stateOnResponseForTest两个测试 seam。BILI_PROVIDER_REWRITES/BILLION_CONTEXT_PLUGIN(沿用dsh.bundle.patch.yml禁用自动压缩在 web profile 下静默失效 #1772 套件的封闭模式),否则 shell 本身在 bili 后面的机器上planNativeDsh直接 off、apply 空转。Stacked on #3377(409/503 恢复重写了本测试同样驱动的 onResponse 分支),合并顺序:#3377 → 本 PR。
Closes #3370。来自 #3331 区间审查(D-H1)。