AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Bug] 同一会话在不同 Responses API 模型间切换后,历史 reasoning 数据可能导致后续模型请求 400

Open C10H14N2O5 opened this issue 3 months ago • 3 comments

问题描述

在 AstrBot v4.27.3 中,同一会话先后使用不同的 OpenAI-compatible Responses API 模型时,疑似存在 Responses reasoning 历史数据跨 Provider / 模型回放时的兼容性问题。

目前能够稳定复现以下情况:

  • 清空会话上下文后,使用通过 CLIProxyAPI 接入的 gpt-5.6-luna,可以正常连续对话;
  • 在同一会话中切换至 deepseek-v4-flash 的 OpenAI-compatible Responses API,可以继续正常对话;
  • deepseek-v4-flash 至少完成一次回复后,再将同一会话切换回 gpt-5.6-luna;
  • 此时请求稳定返回 HTTP 400:Unknown parameter: 'input[2].status'
  • 如果清空该会话的上下文历史,再继续使用 gpt-5.6-luna,请求会立即恢复正常。

因此目前看起来并非 gpt-5.6-luna / CLIProxyAPI 本身无法正常使用,也不像是消息平台适配器导致,而更像是 DeepSeek Responses API 产生的某些 reasoning 历史 item 被 AstrBot 保存后,在切换至另一个 Responses API Provider 时被继续回放,而目标 Provider 不接受其中的部分字段。


初步排查

查看目前的:

astrbot/core/provider/sources/openai_responses_source.py

后发现,Responses API 返回 reasoning item 时,会通过类似以下方式进行完整序列化:

if item_type == "reasoning":
    if hasattr(item, "model_dump"):
        serialized_item = item.model_dump(mode="json", exclude_none=True)
    elif isinstance(item, dict):
        serialized_item = copy.deepcopy(item)
    else:
        serialized_item = {}

    if serialized_item:
        serialized_reasoning_items.append(serialized_item)

后续恢复上下文时,又会从保存的 reasoning state 中恢复完整 item:

restored_items = [
    item
    for item in state["items"]
    if isinstance(item, dict)
]

if restored_items:
    reasoning_items.extend(restored_items)

最终重新加入下一次 Responses 请求的 input:

response_input.extend(reasoning_items)

通过 CLIProxyAPI 的错误请求日志进一步确认,AstrBot 实际发送的 Responses API 请求中,历史 reasoning item 确实包含 status: "completed" 字段。该请求经 CLIProxyAPI 转发至目标 Responses 上游后,上游返回 Unknown parameter: 'input[5].status' ,且 input[5] 正好对应上述 reasoning item。

AstrBot 将完整 output item 保存进会话历史后,在同一会话切换到其他 Responses Provider 时,又将这个 item 原样作为下一次请求的 input 重新发送。

而当前通过 CLIProxyAPI 接入的 gpt-5.6-luna 对该 input 中的 status 字段进行校验时,会返回:

Unknown parameter: 'input[2].status'

目前已通过 CLIProxyAPI 的错误请求日志确认,AstrBot 实际发送的请求中确实包含带有 status: "completed" 的历史 reasoning item,且上游报错参数位置与该 item 一致。尚未验证 OpenAI 官方 Responses API 是否同样拒绝该字段,因此目前仅能确认该问题在上述测试链路中稳定复现。

从行为上看,这也可能不仅局限于 status 字段:如果不同 OpenAI-compatible Responses 实现返回的 reasoning item schema 存在差异,那么完整保存并跨 Provider 回放 output item 时,理论上还可能遇到其他 Provider-specific 字段的兼容性问题。


如何复现?

  1. 在 WebChat 中新建会话或清空上下文;
  2. 使用一个 OpenAI-compatible Responses API Provider(本人测试环境为通过 CLIProxyAPI 接入的 GPT-5.6);
  3. 正常发送一条消息;
  4. 不清空上下文,切换至 deepseek-v4-flash 的 Responses API,并发送一条消息;
  5. 再切回原 Responses Provider;
  6. 此时请求返回 400 Unknown parameter: 'input[N].status';
  7. 清空上下文后恢复正常。

AstrBot 版本

4.27.3

操作系统

Windows

部署方式

AstrBot Launcher

其他系统信息

  • 后端操作系统:Windows 11 家庭版 25H2,操作系统版本 26200.9168
  • Cli Proxy API 版本:v7.2.135
  • 浏览器所在系统:Windows 11 家庭中文版 25H2,操作系统版本 26200.9168
  • 浏览器:Microsoft Edge 151.0.4129.86 (正式版本) (64 位)

使用的消息平台适配器

QQ 官方机器人(WebSocket)、WebChat


错误日志

AstrBot终端日志:

[2026-08-18 10:56:33.039] [Core]
[WARN]
[v4.27.3] [runners.tool_loop_agent_runner:616]: Chat Model C10/gpt-5.6-luna request error: Error code: 400 - {'error': {'type': 'invalid_request_error', 'code': 'unknown_parameter', 'message': "Unknown parameter: 'input[2].status'.", 'param': 'input[2].status'}}

openai.BadRequestError: Error code: 400 - {
    'error': {
        'type': 'invalid_request_error',
        'code': 'unknown_parameter',
        'message': "Unknown parameter: 'input[2].status'.",
        'param': 'input[2].status'
    }
}

完整 traceback 中请求最终经过:

astrbot/core/provider/sources/openai_responses_source.py
→ _query_stream()
→ self.client.responses.create()

并由上游返回 HTTP 400。


CliProxy API Request Log(经过裁剪和脱敏处理):

=== REQUEST INFO ===
CLIProxyAPI Version: 7.2.135
URL: /v1/responses
Method: POST
Timestamp: 2026-08-18T11:18:00+08:00

=== RELEVANT REQUEST BODY ===

{
  "input": [
    {
      "type": "message",
      "role": "developer",
      "content": "<omitted>"
    },
    {
      "type": "message",
      "role": "user",
      "content": "<omitted>"
    },
    {
      "id": "<omitted>",
      "summary": [],
      "type": "reasoning",
      "content": [],
      "encrypted_content": "<omitted>"
    },
    {
      "type": "message",
      "role": "assistant",
      "content": "<omitted>"
    },
    {
      "type": "message",
      "role": "user",
      "content": "<omitted>"
    },
    {
      "id": "<omitted>",
      "summary": [],
      "type": "reasoning",
      "content": [
        {
          "text": "<omitted>",
          "type": "reasoning_text"
        }
      ],
      "status": "completed"
    },
    {
      "type": "message",
      "role": "assistant",
      "content": "<omitted>"
    }

    // remaining conversation history omitted
  ],

  "model": "gpt-5.6-luna",
  "store": false,
  "stream": true,
  "reasoning": {
    "effort": "max"
  }
}

=== UPSTREAM REQUEST ===

Upstream endpoint:
https://chatgpt.com/backend-api/codex/responses

Relevant input item:

input[5] = {
  "summary": [],
  "type": "reasoning",
  "content": [
    {
      "text": "<omitted>",
      "type": "reasoning_text"
    }
  ],
  "status": "completed"
}

=== API RESPONSE ===

HTTP 400

{
  "error": {
    "type": "invalid_request_error",
    "code": "unknown_parameter",
    "message": "Unknown parameter: 'input[5].status'.",
    "param": "input[5].status"
  }
}

辅助信息

No response

检查清单

  • [x] 我已在 Issue 列表中搜索过相关问题仍无法解决,或该问题从未被报告过。
  • [x] 我已尝试过禁用所有插件,排除了可能是因插件导致的问题。
  • [x] 我报告的问题与 AstrBot 本体相关,而非在报告某一插件的问题。
  • [x] 我已阅读并同意本项目的贡献者行为准则。
  • [ ] (可选)我愿意提交 PR 以帮助修复该问题。

C10H14N2O5 avatar Aug 18 '26 04:08 C10H14N2O5

@C10H14N2O5 排查方向完全正确。问题根源在 _parse_response 中序列化 reasoning item 时使用了 model_dump(mode="json", exclude_none=True) [1]——exclude_none=True 只过滤 None 值,但 status: "completed" 是一个有效的非 None 字符串,所以被完整保留进了会话历史。

在 _convert_chat_messages_to_response_input 恢复时 [2],这些 item 被原样还原并通过 response_input.extend(reasoning_items) 追加进下一次请求的 input [3],没有做任何字段过滤。

核心问题: DeepSeek Responses API 返回的 reasoning item 带有 status 字段,但 gpt-5.6-luna 的上游不接受 input 中 reasoning item 携带 status,故返回 Unknown parameter: 'input[N].status'。

修复思路: 在恢复 reasoning item 加入 input 之前,对字段进行白名单过滤,只保留 Responses API spec 中明确允许的字段。在 _convert_chat_messages_to_response_input 的 restored_items 处理中加入类似逻辑:

REASONING_INPUT_ALLOWED_KEYS = {"type", "id", "summary", "content", "encrypted_content"}

restored_items = [
    {k: v for k, v in item.items() if k in REASONING_INPUT_ALLOWED_KEYS}
    for item in state["items"]
    if isinstance(item, dict)
]

或者在序列化阶段(_parse_response)就只保存重放时需要的字段,而不是 model_dump 全量序列化。这样无论历史 reasoning item 来自哪个 provider,重放时都只发送对端能接受的最小 schema。

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about AstrBot with Dosu Add Dosu to your team

dosubot[bot] avatar Aug 18 '26 04:08 dosubot[bot]

hi, @C10H14N2O5 ,:)

I'd like to work on this issue. I’m following the investigation already provided in the issue, especially the reasoning item replay path and the incompatibility caused by output-only fields such as status being reused as input across different Responses API providers.

I’ll keep the fix scoped and add a regression test around the restored reasoning state behavior.

Roovelrz avatar Aug 18 '26 07:08 Roovelrz

Hi @Roovelrz , Thanks for taking this on!

One additional observation that may be useful:

I originally reproduced the issue when DeepSeek was connected directly through its native OpenAI-compatible Responses API. In that setup, the sequence GPT → DeepSeek → GPT consistently triggered the input[N].status 400 error.

However, after routing DeepSeek through CLIProxyAPI as well, so that both DeepSeek and GPT were accessed through the same Responses-compatible proxy layer, I could switch GPT → DeepSeek → GPT freely in the same conversation without triggering the error.

This makes me suspect that CLIProxyAPI is doing some normalization/filtering of the Responses payload between providers, which avoids replaying incompatible provider-specific fields.

So this can currently serve as a workaround, but the direct DeepSeek Responses → other Responses provider case still reproduces the issue.

Hope this helps with scoping the fix and regression test.

C10H14N2O5 avatar Aug 18 '26 07:08 C10H14N2O5