Repository navigation
fix: anthropic legacy-completion stream error emits a well-formed block lifecycle with index (#2689) - #2691
Conversation
…ck lifecycle with index (#2689) Strict clients (ZCode) validate every SSE frame against the Anthropic schema and rejected the whole turn on the #870 in-band error frame: a bare content_block_delta with no numeric index and no owning content_block_start. - legacyCompletionChunk anthropic branch now mirrors the compress-loop adapter's #413 pattern: synthesize message_start when the stream never began, then content_block_start/delta/stop at the caller's next free block index; message_delta gains stop_sequence + usage (adapter parity). - emitStreamError takes an optional LegacyAnthropicState {blockIndex, messageStarted}; defaults model a fresh stream (index 0, synthesize start), so the relay call sites need no change. - plugin.ts #870 call site passes blocksForwarded as the next free index and a new sawMessageStart flag (set where the first attempt's message_start is dispatched, after the retryFraming gate that consumes the retry's own). - Regression tests: emitter-level shape pins in proxy-stream-error.test.ts, pipe-level next-free-index pin in plugin-empty-turn-retry.test.ts.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2910-pr.2691.a158e91This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2691.tgz
npm install -g packageInstall instructions are refreshed on each push. |
Review hygiene (小问题直接修): dc8259b flipped the visible error text from the base file's \u274C escape to a literal UTF-8 ❌ byte sequence. Runtime output is byte-identical either way; reverting removes one unrelated line from the diff so every hunk maps to the block-lifecycle fix. No behavior change.
[bot] 🏷 PR #2691 review 完成(修 #2689)。已对照 live master 做可合入性校验、跑定向验证、并顺手修掉一处 diff 噪音后推回。结论:可合(wire/message-shape 变更,按 §7.4 走人工合并,不 auto-merge)。 审查动作与证据
① 方向关(审原 issue):根因定位正确——在产出点 ② 回归关(既有行为清点)
③ 代码关
④ 测试关:断言有牙——emitter 级用游标钉死 6 事件顺序 + 逐帧 ⑤ diff 整洁度:发现一处与本 PR 目的无关的行—— 行为变更披露(确认 PR 所述,旧 → 新)
已知残留(同一机制的另一处产出点,非本 PR 引入、非回归) 结构化八问
判定:修复到位、测试钉住、diff 已收敛、可干净合入当前 master。等你人工合并 #2691 —— wire/message-shape 变更按 §7.4 属人工项,我不 auto-merge。CI 全量交远程把关。 |
|
ci失败 另外 |
…rts gate The type is used only inside src/stream-error.ts; callers pass structurally-typed object literals so no module imports the name. The leading 'export' tripped the INTERNAL_ONLY unused-exports guard and red CI. Dropping it makes the type module-private. No behavior change.
[bot] 🏷 两件事都处理好了。 ① CI 失败 —— 已修好并确认变绿根因(不是测试挂了):PR 原提交 为什么整轮红、而非某条测试红: 修法:去掉那个 CI 确认(对
即:挡路的守卫已绿,被它连带跳过的全量套件已恢复实际运行并通过(ubuntu 两个 Node 版本),CI 恢复健康。 ② 已知残留(relay.ts:1410 中途流)能否直接修 —— 不建议顺手修,建议拆 follow-up这轮我把上一轮基于推断的部分读代码坐实了:
我的明确建议:不要并进本 PR。它是 #2689 同一机制的另一处产出点,按粒度策略挂在 #2689 名下当一个待办 facet,不另开 issue。等你拍板:若你想现在就做,我开一个小的 follow-up PR(方向就是上面 (iii)——把 判定:CI 已修绿、全量套件恢复运行并通过(ubuntu 两版本);残留维持「已知、非回归、极窄」定性,建议拆 follow-up 不进本 PR。本 PR 本身可合(wire/message-shape 变更,按 §7.4 仍需你人工合并)。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.243-master.a645bf7 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Closes #2689
修了什么
legacyCompletionChunk()的 anthropic 分支发裸content_block_delta(无数字index、无content_block_start/stop)——严格校验宿主(ZCode)整轮拒绝该帧。#870 路径(src/plugin.ts:2030)硬编码"completion",使其成为默认可达缺陷。修复沿用 compress-loop adapter 的 #413 既有纪律(「content block 永不孤儿」):
src/stream-error.ts:anthropic 分支补齐全生命周期content_block_start → content_block_delta → content_block_stop → message_delta → message_stop;index由调用点传入(客户端已见块数 = 下一个可用索引);若该流还没发过message_start,先合成一个 start 帧。message_delta对齐 adapter 的buildTerminal:补stop_sequence: null与零 usage。emitStreamError增加可选参数LegacyAnthropicState { blockIndex?, messageStarted? };默认建模新流(index 0 + 合成 start),relay.ts 两个调用点因此无需改动。src/plugin.ts:Plugin passthrough leaves the client an empty turn when the model echoes a render tag #870 调用点传blocksForwarded;新增sawMessageStart标志(在 retryFraming 门后的 dispatch 处置位——retry 自己的 message_start 在那里被消费,不计入)。行为变更(旧 → 新)
[裸 delta, message_delta{stop_reason}, message_stop]变为[start(N), delta(N), stop(N), message_delta{stop_reason, stop_sequence:null, usage:0}, message_stop],N = 客户端已见块数(该路径下 ≥1)。宽松客户端看到的错误文本不变;严格客户端从整轮拒绝变为接受。compat.streamErrorShape="completion"+ anthropic):原为裸 delta + 终结帧;现为[合成 message_start, block 0 全生命周期, 终结帧]——新流首次完全合规。message_delta增加stop_sequence: null+ 零 usage(严格 schema 要求字段)。默认
errorShape="protocol"路径与其他协议分支不变。无新增配置项、无 kernel 变更、无持久化格式变更。回归测试
tests/proxy-stream-error.test.ts:emitter 级形状钉住——全生命周期顺序、三个块帧共享同一数字 index、默认状态合成 start / mid-stream 不重开、message_delta字段精确匹配。tests/plugin-empty-turn-retry.test.ts:pipe 级钉住——anthropic echo-only 双退化轮驱动真实 Plugin passthrough leaves the client an empty turn when the model echoes a render tag #870 路径,断言每个 delta 带数字 index、错误块有 owning start/stop、其 index 等于已转发 distinct 块数(不复用)。本地验证:typecheck + build 绿;定向套件 43/43(
proxy-stream-error/plugin-empty-turn-retry/issue2303-draft-tail)。全量套件交 CI。合并判定
wire/message-shape 变更(两模式均涉)→ 按 §7.4 需人工合并,不走 auto-merge。
判断说明