Repository navigation
[PR] OpenAI adapter: treat empty tool_calls array as absent so text isn't dropped (#4466) - #4469
ranxianglei wants to merge 1 commit into
Conversation
Gateways that emit `tool_calls: []` on every chunk (e.g. Tencent CodeBuddy against copilot.tencent.com) made frameToolCalls truthy, so all text was routed into the tool-call absorb path; settle then bailed early (pending stayed empty) and round-1 text without raw forwards nothing -> empty stream. Treat a length-0 array as absent, matching the guard already present in filterRealToolFragments in the same file. Adds tests/issue4466-empty-toolcalls.test.ts: the pure-text and minimal-repro streams now reach the client; a negative control confirms a real non-empty tool call is still absorbed and replayed verbatim.
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.5364-pr.4469.7988f31This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr4469.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复。 本 PR 是 #4466 的修复 PR;按失败签名(空 标签:bug / scope/wiring / p1(原有 pr 标签保留)—— 请求管道 wire 帧误分类,受影响网关完全拿不到正文(可用性停摆)故 p1;波及面是任意 OpenAI-wire 客户端而非特定宿主车道,不打客户端标签。 审核结论(独立复审)拉取 PR head 结构化八问
回归清点(改动路径上的既有行为)
另扫了 测试有效性与 diff 整洁度
CI 状态(写此评论时)静态门禁已全绿(mysql-contract / config-surface-guard / unused-exports / test-import-graph success;e2e·theorem 按门控 skip);30 个 check 中 12 个 test shard 仍在跑,暂无红项。若后续 shard 变红我会跟进补报。 行为变更披露(旧→新):旧—— 判定:审核通过。单模块修复 + 回归钉 + teeth 验证过的负向对照,未触碰 kernel/config/persistence/wire-form/security;CI 全量绿后即可合(合并按规矩由人来执行)。 |
(ai: vllm-qwen/qwen3.8-27b) CI 终态更新(补上上一条留的尾巴):PR head
最终判定维持上一条结论:审核通过,CI 全量绿已达成,可合(合并按规矩由人来执行)。 |
Closes #4466
What
The OpenAI chat-completions adapter treated any truthy
delta.tool_callsas a tool-call frame. An empty array[]is truthy in JS, so gateways that emit"tool_calls": []on every chunk of a plain text response (reproduced against Tencent CodeBuddy /copilot.tencent.com) routed all text into the tool-call absorb path and dropped it — the client got an empty stream (Model returned no valid response).Root cause
src/loop/adapter-openai.ts:For
tool_calls: [],frameToolCallsis[](truthy), so the chunk is buffered intorawToolChunksfor settle-time raw replay. ButsettleToolCallsbails early (if (pending.size === 0) return) because the empty arrays never populatedpending, and round-1 text events carry noraw(which core.ts forwards nothing for). Net effect: zero client-visible bytes. NotefilterRealToolFragmentsin the same file already guarded this correctly (!tcs || tcs.length === 0); the two checks were inconsistent.Fix
Treat a length-0 array as absent:
Such chunks now fall through to the normal text/reasoning path and reach the client. Real (non-empty) tool calls are untouched.
Behavior change (old → new)
delta.tool_callsis a truthy value — including an empty array — was classified as a tool-call frame; its text was buffered and then dropped when no real tool call arrived → empty stream for affected gateways.tool_callsarray is treated as absent; the chunk flows through the normal text/reasoning path and its content reaches the client. Non-emptytool_callsbehave exactly as before.tool_calls: []on every chunk; without it those clients could get no model output at all through bili.Verification
tests/issue4466-empty-toolcalls.test.ts:tool_calls: []on every chunk → text reaches the client (was empty pre-fix);openai-reasoning-content,openai-toolcall-finish-reason,issue589-usage-frame(29 tests) andtypecheck. Full-suite verdict deferred to CI on the pushed head.Scope / gates
Single-module fix in
src/loop/adapter-openai.ts; nokernel/change, no config surface change, no persistence/version/wire-format change, no security surface. Full regression via remote CI.