Skip to content

[Bug][kernel] openaiToCore reads only reasoning_content, so a replayed history that carries the reasoning alias loses its thinking block | 请求侧只读 reasoning_content,回传 reasoning 别名的历史会静默丢思维链 #7435

Closed

Description

@JamesYuuu

Description

TL;DR — kernel/src/wire/openai.ts:245 的 openaiToCore 只读 m.reasoning_content。客户端把历史 assistant 消息的思维链回传成别名 reasoning(Ollama Cloud / vLLM / sglang / Magpie 这类 OpenAI-wire 形状)时,core 里产生 0 条 reasoning 消息,coreToOpenai 再回传的 assistant 只剩 ["role","content","tool_calls"] —— 思维链在请求侧被静默丢弃,无日志、无 400。

这是 #7432 的第二面:响应侧的 delta.reasoning 丢帧已由 PR #7433(src/loop/adapter-openai.ts)修复,请求侧属于 kernel 边界,按 §7.1「一 issue 一 scope」拆到本 issue 单独跟踪。

复现(proxy 模式,实测)

  1. 构造一轮 assistant 历史消息:带 tool_calls,思维链分别放在 reasoning_content 与 reasoning 两种字段名下。
  2. 调用 kernel 的 openaiToCore → coreToOpenai 往返(探针直接 node --import tsx 在仓库里跑)。
  3. 结果:
assistant 历史字段 core reasoning 消息数 回传 assistant 的 keys reasoning_content
reasoning_content: "…" 1 ["role","content","tool_calls"] + 该字段 保留
reasoning: "…" 0 ["role","content","tool_calls"] null(字段整个消失)

上游侧同样只认规范名:同一份请求体回传 reasoning_content → 上游 200 且正常复用思维链;回传 reasoning → 上游 200 但 reasoning 帧为 0(静默丢弃,实测于 Magpie 0.1.4623 / ollama-cloud deepseek-v4.1-flash:1017)。所以读取侧接受别名、写出侧必须保持 reasoning_content,两侧都改成别名反而更糟。

根因(按 master kernel/src/wire/openai.ts)

// :245
const rawReasoning = m.reasoning_content;
const fieldPresent = typeof rawReasoning === "string";
const fieldReasoning = fieldPresent ? rawReasoning : "";
let reasoning = fieldReasoning;

别名不读,于是只有 :258 的 splitDemotedThinking(text) 内联回落( thinking / <thinking> / ```thinking)能救回思维链 —— 它处理的是**内联进 content** 的形态,救不了**独立字段**的形态。fieldPresent` / `blankEcho`(:268)同样只看规范名,别名键连"空字段要回显"的语义都拿不到。

为什么必须在 kernel 修(host 侧解决不了)

wire 形状契约(请求侧 OpenAI message → core 的规范化)属于 kernel 边界:openaiToCore 是两条车道(plugin / proxy)共用的唯一解析入口,bili 的 src/ 侧若要补这个别名,只能在请求体进 kernel 前做一次 JSON 层重写 —— 那正是 §7.3 点名的"在错误的层做过滤"的 mask,别名明天换个形状(reasoning_text)就再破一次。

建议修法

  1. 读入侧走一张别名表 reasoning_content → reasoning → reasoning_text(取第一个「存在且非空」的字符串,与 pi-ai openai-completions 的 reasoningFields 同序),命中别名时归一进 reasoningContent;
  2. fieldPresent / blankEcho 按命中的那个字段名判定(别名键存在但为空 → 同样 reasoningPresent,回传仍写 reasoning_content);
  3. 写出侧(coreToOpenai flusher :408-437)保持 reasoning_content 不变;
  4. 回归测试双向断言(Test Blind Spot Retrospective: Reinforcing Negative Assertion Discipline, Tightening Fake Upstream Strictness, Thin Inst | 测试盲区复盘:补反向断言纪律、假上游严格化、薄安装冒烟、形态矩阵与生命周期覆盖 #3617 gate test discipline):触发(别名历史 → 1 条 reasoning core,回传字段为 reasoning_content)+ 不触发(reasoning_content 历史往返逐字节不变、无 reasoning 字段的历史不新增字段)。

Kernel Boundary 声明

本 issue 只做定位与提案,未包含实现。按 Kernel Boundary 规则 1,实现需要一个说明"host 侧为什么解决不了"的 issue(本 issue)+ owner 预先批准,PR 在 body 写 kernel-change: <reason>、bump kernel/package.json(当前 0.0.201)、并同时推演 plugin / proxy 两种模式;合并走 human-only review 档。

bili version

0.1.216(commit 6a641f378);kernel 0.0.201

Usage mode

Proxy mode (client manually points its base URL at bili)

Client and version

DeepSeek Harness 0.2.2-rc.5(内置 @earendil-works/pi-ai 1.3.0);api: openai-completions

Operating system

macOS 27.2.1 (arm64)

Upstream and model

Magpie 网关 127.0.0.1:3425 → Ollama Cloud https://ollama.com/v1 · deepseek-v4.1-flash:1017

关联

Activity

  1. ranxianglei commented on Nov 21, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    🔶 需要决策

    查重:不重复。本 issue 是 #7432(响应侧 delta.reasoning 丢帧,已由 PR #7433 修复)的请求侧对应面——openaiToCore 只读 reasoning_content,回传 reasoning 别名的历史会静默丢思维链。已检索 open+closed 的 issue/PR,无其他条目覆盖这个请求侧 kernel 缺陷。

    背景一句话:kernel 的 OpenAI wire 解析入口 openaiToCore(kernel/src/wire/openai.ts:245)只读规范字段 reasoning_content;当客户端把历史 assistant 消息的思维链回传成别名 reasoning(Ollama Cloud / vLLM / sglang / Magpie 这类 OpenAI-wire 形状)时,core 里产生 0 条 reasoning 消息,coreToOpenai 回传的 assistant 只剩 ["role","content","tool_calls"]——思维链在请求侧被静默丢弃,无日志、无 400。

    已验证(master 1e357bf2d,与 reporter 版本 6a641f378 该函数逐字节一致):

    assistant 历史字段 core reasoning 数 回传 assistant keys reasoning_content
    reasoning_content(规范) 1 ["role","content","tool_calls","reasoning_content"] 保留 ✓
    reasoning(别名) 0 ["role","content","tool_calls"] 字段整个消失(bug 复现)
    无 reasoning 字段 0 ["role","content","tool_calls"] 不新增 ✓

    待决问题:这是 kernel 边界改动(openaiToCore 是 plugin/proxy 两条车道共用的唯一解析入口),按 Kernel Boundary 规则 1 需要 owner 预先批准才能动 kernel/**。是否批准按下述方案实现?

    选项:

    我的推荐:A。打到根因(kernel wire 规范化本应接受别名),未来兼容,且 human-only review 档把关合并;PR 会写 kernel-change: <reason>、bump 版本、并推演 plugin / proxy 两种模式。

    不决定的默认行为:issue 保持 open(needs-decision 标签),kernel 不动,bug 持续——用 reasoning 别名的客户端思维链在请求侧静默丢失。响应侧(PR #7433)已修,不受影响。

    triage 标签(已打):bug + scope/kernel + p2 + deepseek-harness。两点说明:

    • 严重度标 p2(能用但思维链静默丢失,非「不能用」/非持久数据丢失/非缓存泄露);若 owner 认为属「数据丢失类」应升 p1,我可改标。
    • 客户端标签用了 deepseek-harness(reporter 的 DeepSeek Harness 0.2.2-rc.5),而非 issue 建议的 dsh——repo 有专门的 deepseek-harness 标签,更精确。

    版本勘误:reporter 报的 kernel 版本是 0.0.201,但其 release commit 6a641f378 实际是 0.0.198、master 是 0.0.200——该函数逐字节一致,不影响判定。

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions