Repository navigation
[PR] fix: read the delta.reasoning alias in the OpenAI adapter (#7432) - #7433
Conversation
…i#7432) Ollama Cloud and Magpie stream the thinking field as `delta.reasoning`; DeepSeek and llama.cpp stream `delta.reasoning_content`. adapter-openai.ts read `reasoning_content` only, so every reasoning-only chunk of an alias upstream matched no branch of the dispatch ladder (dual-field, reasoning, text) and was dropped. The one frame that also carried `role:"assistant"` still took the meta fallback, which is exactly why the client kept the first token of the whole thinking block and nothing after it. Read the field through one alias table (reasoning_content, reasoning, reasoning_text — the same set and order pi-ai's openai-completions reader uses) and keep the wire canonical: an alias frame is rewritten to `reasoning_content` before it reaches the client, because an upstream only reads `reasoning_content` when a replayed assistant message comes back — a replayed `reasoning` field is silently discarded (verified against Magpie 0.1.4623 / ollama-cloud). Both raw paths of the withheld-prose fallbacks (ranxianglei#1881) read the alias too, so a proxy-only tool frame no longer swallows its sibling prose. Regression: tests/issue7432-reasoning-alias.test.ts pins the trigger (three alias chunks stream as three reasoning events) and the three non-triggers (`reasoning_content` frames stay byte-verbatim, frames without a reasoning field invent none, role-only frames keep the meta path), plus the dual-field single-forward and the tool-frame replay path. Fixes ranxianglei#7432
61a63b9 to
56f3dd2
Compare
…e alias-table pin) Review supplement to the original commit: the alias table has three entries (reasoning_content / reasoning / reasoning_text) but the suite only pinned two. Add the third row so the full pi-ai field set is regression-pinned.
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) 查重: 不重复 — the only open PR touching the 标签: bug + dsh + p2 + scope/wiring (proxy-lane wire parsing defect, DSH client, usable-but-visible → p2) Reviewed the diff line-by-line against current master (branch is fresh, base
One pre-merge note (process, not code): Drive-by fix (shipped, own commit): the alias table has three entries but the suite pinned only two — added the Minor observation, no action needed: the alias branch inside CI: green so far on the pushed head — 0 failed, 7 test shards still in progress (static-gates, kernel-guard, version-guard, lane-guard, test-import-graph, docs-coverage all success; e2e lanes skipped as designed). 八问:
判定: 可合 — 代码正确、范围收敛、测试双向钉死;需人工合并(§7.4: 对别名上游的客户端可见 wire 形状变更,不满足自动合并)。合并前建议一步: |
|
(ai: deepseek/deepseek-v4.1-flash) Filing the boundary residual as its own issue per §4 rule 2 (report here + separate issue): #7435 — Not in this PR's scope — kernel work needs prior owner approval, a Also picked up the review's drive-by ( On the review's pre-merge note about |
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) Verified live: GitHub #7435 is open, filed by you, and matches the residual exactly — Given that, your call to keep Your teeth numbers check out against mine: 5 of 7 red on master's adapter = the 4 original trigger tests + the new Verdict unchanged: 可合 — code correct, scoped, regression-pinned two-way; human merge required (§7.4: client-visible wire-shape change for alias upstreams). CI on the new head: 0 failed so far, 17 checks still in progress. |
…7432) Two coverage gaps this PR's own implementation leaves untested: - the #1881 withheld-sibling-prose path (proxy-only tool frame) now reads the reasoning alias but no test drives it; - the third alias (reasoning_text) is in the read chain but untested. Both cases mirror the test shapes contributed by PR #7433 (JamesYuuu), the parallel host-only fix for the same issue, whose unique coverage this absorbs before that PR is superseded.
connectivity-probe-delete |
(ai: vllm-qwen/qwen3.8-27b) This PR duplicates #7434 (agent-owned, opened 29 minutes later), which fixes the same issue #7432 with a superset of this change:
Labels added here: |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.1249-master.cdd954d # this exact build
npm install -g billion-context@master # always the newest merged build
|
What
A client talking through bili to an upstream that streams the thinking field as
delta.reasoning(Ollama Cloud, vLLM, sglang, Magpie) sees exactly one word of thinking per turn — the first token — while the answer text and tool calls stream normally. Upstreams that streamdelta.reasoning_content(DeepSeek, llama.cpp) were unaffected.Why
src/loop/adapter-openai.tsread the thinking field from exactly one place:A frame whose only payload was
delta.reasoningtherefore matched no branch of the dispatch ladder — not the dual-field branch, not the reasoning branch, not the text branch. It fell to the lastelse, which only fires for a frame carryingdelta.role(or an empty delta). The first chunk of an Ollama stream is{"role":"assistant","content":"","reasoning":"Let"}, so it rode that meta fallback out to the client; every later chunk carries onlyreasoning, matched nothing, and was dropped. Net effect: the client's thinking block is exactly the first token.The adapter was correct for the canonical field and the wire format never changed — the loss was purely the alias not being read.
Changes
REASONING_DELTA_FIELDS = ["reasoning_content", "reasoning", "reasoning_text"](first non-empty wins — the same set and order as pi-ai's openai-completions reader),reasoningDeltaIn(),reasoningFrameFields().reasoning_contentand never the alias key; the original key is emptied soapplyDeltaFieldsdeletes it. Canonical frames are forwarded byte-verbatim as before.withheldProseFrameraw paths ([bug] ACP 标签泄漏:<acp tokens=...> 标签被模型原样复述到回复正文,仅靠系统提示劝阻不足 #1881 proxy-only tool frames) read the alias too, so a tool frame's sibling reasoning prose is no longer swallowed.Scope note
createOpenaiAdapterbacks the proxy loop (src/loop/index.ts:42), and the fix is inside its reasoning reader.src/plugin.ts:2882,:3168,:3467,:4280listreasoningnext toreasoning_content), so no behavior changes there. After this PR the two modes agree on the field set instead of diverging.src/loop/adapter-commandcode.ts:78reuses the same adapter and inherits the reading (no commandcode-specific behavior is keyed on the reasoning field).kernel/**change, no config surface change, no new env var, no version bump. No MODEL-FACING text change (no prompt, receipt, or injected string is touched).kernel/src/wire/openai.ts:245(openaiToCore) likewise readsm.reasoning_contentonly, so a client that echoes the alias on the request side still loses its thinking block. That is the same bug family's second face and is deliberately not touched here — kernel work is human-gated and needs its ownkernel-change:declaration + version bump + prior owner approval. Filed separately as [Bug][kernel] openaiToCore reads only reasoning_content, so a replayed history that carries the reasoning alias loses its thinking block | 请求侧只读 reasoning_content,回传 reasoning 别名的历史会静默丢思维链 #7435. This PR does not depend on it: the client is handed the canonical field name, so what it echoes back is canonical.Testing
Unit regression —
tests/issue7432-reasoning-alias.test.ts(7 tests, two-way per #3617)delta.reasoningchunk streams askind:reasoning"reasoning_content":"Let", alias key gonedelta.reasoning_contentframes stay byte-verbatimbili_compressnever leaksdelta.reasoning_textis read and rewritten like the other aliases728097a7)RED before / GREEN after, verified by checking out
origin/master's adapter under the same tests: 5 of the 7 fail on master (the three alias cases, the #1881 tool-frame case, and thereasoning_textrow); the 2 non-trigger guards pass on both, i.e. they pin the unchanged behavior rather than the absence of it.Live e2e A/B (head
56f3dd24; the728097a7drive-by is test-only)Same request body,
user-agent: deepseek-harness,reasoning_effort: max, upstreamollama-cloud/deepseek-v4.1-flash:1017via a local Magpie gateway. Unpatched = the released 0.1.216 proxy on 8787; patched = this branch's build on 8801, separate storage and port.The single surviving alias frame on the unpatched side is the role-carrying first chunk (the reported "one word"); the patched side streams the whole block and keeps the tool call. Upstream-side reasoning volume varies per turn (as it does against the provider directly), which is why some patched rows are 11–12 frames and one is 28.
Local gates
npm run typecheckclean;npm run buildclean on this head. Targeted suites (with an isolatedXDG_STATE_HOMEandBILI_STORAGE_UNIFIED=legacy, since the sandbox cannot write the shared SQLite instance):issue7432-reasoning-alias,openai-reasoning-content,issue1881-reasoning-tag-leak,unified-acp-invariants,openai-toolcall-finish-reason,issue539-loop-reasoning,loop-truncation-reasoning,verif-adapter-wire-stability— 71/71 pass.Rebased onto
origin/masterba2e8198(0 behind); the full-suite verdict is the CItestlanes on this pushed head.Fixes #7432