Skip to content

[PR] fix: openai adapter treats empty tool_calls array as absent (round-1 text loss) | 空 tool_calls 数组不再误判为工具帧,修复第一轮文本静默丢失 - #3954

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-20_empty-tool-calls-text-loss
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-20_empty-tool-calls-text-loss

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What & why

WorkBuddy-family gateways stamp EVERY streaming chunk with an empty tool_calls: [] array (plus empty sibling fields). In the openai adapter [] is truthy, so every frame was classified as a tool frame: text events lost their raw passthrough, round-1 forwarding in core.ts had nothing to emit, and the settle-time prose rescue (#1881/#1882) early-returned because an empty array absorbs no pending entries. Net effect: ALL first-round text was silently dropped at the client while finish_reason/usage looked healthy (#3926).

Fix

Single-point normalization at the classification site (src/loop/adapter-openai.ts): an empty or non-array tool_calls field is treated as absent, so such frames take the normal text path (raw passthrough). Non-empty arrays keep the tool-frame path byte-for-byte unchanged. No core.ts change needed — post-fix, "raw tool chunks buffered but pending empty" cannot occur (a non-empty array always creates pending entries).

Behavior change (disclosure)

  • Upstreams emitting tool_calls: []: round-1 streamed text now reaches the client (previously silently discarded). This restores the intended pass-through; standard upstreams (field absent/null) are unaffected.
  • Malformed non-array tool_calls values now fall back to the text path instead of throwing inside the stream parser (strictly more robust).

Verification

Closes #3926

Gateways that stamp every chunk with `tool_calls: []` (WorkBuddy /
DeepSeek-family private deployments) routed all frames into the
tool-frame branch: text events lost their raw passthrough, round-1
forwarding in core.ts found nothing to emit, and the settle-time prose
rescue early-returned with pending empty — ALL round-1 text was silently
dropped while finish_reason/usage looked healthy.

Normalize an empty (or non-array) tool_calls field to absent at the
single classification point so such frames take the normal text path.
Non-empty arrays keep the tool-frame path unchanged.

Regression pins (tests/issue3926-empty-tool-calls.test.ts): adapter-level
exact-once round-1 text + no fabricated tool calls; gate negative row for
non-empty arrays; loop-level client-boundary end-to-end pin. Verified the
new tests fail on the unfixed code and pass on this one.

Fixes #3926
@ranxianglei ranxianglei changed the title fix: openai adapter treats empty tool_calls array as absent (round-1 text loss) | 空 tool_calls 数组不再误判为工具帧,修复第一轮文本静默丢失 [PR] fix: openai adapter treats empty tool_calls array as absent (round-1 text loss) | 空 tool_calls 数组不再误判为工具帧,修复第一轮文本静默丢失 Oct 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-20_empty-tool-calls-text-loss (d2e5321)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4706-pr.3954.8f98468

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr3954.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复。 这是 #3926 的交付 PR 本身(带 ework-agent-pr 标记,已完成的工作);open/closed issue+PR 全量检索(按失败签名「empty tool_calls / round-1 text loss」与文件路径)无其他同机制在途条目——当前 open PR 列表里没有任何其他 PR 触碰 src/loop/adapter-openai.ts 的帧分类路径。

状态(初步核查):

  • head d2e532104,base master 1cec7add9;单 commit,2 文件(+162/-1):src/loop/adapter-openai.ts(+8/-1)+ 新回归套件 tests/issue3926-empty-tool-calls.test.ts(+154)。
  • CI 已绿:head 上全部 test lane(ubuntu 22/24 ×3 shards、windows 22 ×2)+ static-gates + gate/docs-sync/config-surface-guard/lock-sync 等守卫全 success;e2e/real-client lane 按门控 skip。
  • base 之后 master 前进了 177 个 commit,但 git log 1cec7add9..ab7e94105 -- src/loop/adapter-openai.ts tests/issue3926-empty-tool-calls.test.ts 为空——本 PR 触碰的两个文件在窗口内零改动,无冲突风险,无需 rebase。

正在本地做定向复核(diff 精读 + 相邻 openai 套件定向跑),结论随后按八问体例补上。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

已并入 #4590(修复本体早已由 #4466 落地,本车带其回归钉)。关单收尾;误判请 reopen。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant