[Bug] Responses API (/coding/v1/responses): k3.1-pro intermittently splits one tool call into many function_call items with empty name/call_id, next request fails with 400

未关闭
#5,335 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
22/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
typescript
领域
api, backend

调研方向

This is a server-side streaming/assembly bug on the Responses endpoint, not a CLI bug, and the payload names no source file — so the first step is to find the code that builds and emits response.output_item.done events and the final response.completed output array, then check where a single tool call's argument deltas are turned into output items. Reproduce with the curl loop in the issue against https://api.kimi.ai/coding/v1/responses using the supplied request.json, counting function_call items with empty name/call_id; 0 is correct. Done means the same loop stays at 0 and one tool call yields exactly one function_call item with complete arguments. Because the failure is intermittent (5/38) and lives in the model-serving path, expect maintainer triage before any patch.

由索引模型根据 Issue 内容生成。

描述

What version of Kimi Code is running?

Not a CLI problem: this is the Coding Plan Responses API. Seen from Codex CLI 0.172.0 and reproduced with plain curl. (Kimi Code CLI on the same machine is 2.6.3 and is not involved.)

Which open platform/subscription were you using?

Kimi Code subscription, https://api.kimi.ai/coding/v1/responses

Which model were you using?

k3.1-pro (reasoning.effort: "max", stream: true, parallel_tool_calls: true)

What platform is your computer?

Darwin 27.2.0 arm64 arm

What issue are you seeing?

On the Coding Plan Responses endpoint (POST https://api.kimi.ai/coding/v1/responses), k3.1-pro intermittently returns one tool call split into many function_call output items. The first item has the tool name, the call_id and arguments: "{". The following items have empty name and call_id and each carries a fragment of the arguments, with an empty assistant message item between every two of them.

Codex CLI stores these items in the conversation, and the next request is rejected with:

{"error":{"code":"invalid_request_error","message":"Invalid request: an assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages: exec_command:0","type":"invalid_request_error"}}

After that the session cannot continue: every further request carries the same history and gets the same 400.

The broken output is produced by the API itself. It reproduces with plain curl, without Codex.

Codex was configured exactly as in the official guide (https://www.kimi.com/code/docs/en/third-party-tools/codex).

What a broken response looks like

response.output_item.done events of one broken response, in order (the model asked for three parallel exec_command calls; only the first is shown):

output_index= 0 reasoning
output_index= 1 message        text='Выполняю три команды параллельно.'
output_index= 2 function_call  name='exec_command' call_id='exec_command_0_0da4b78e' arguments='{'
output_index= 3 message        text=''
output_index= 4 function_call  name=''             call_id=''                        arguments='"cmd": "cat README.md'
output_index= 5 message        text=''
output_index= 6 function_call  name=''             call_id=''                        arguments='"'
output_index= 7 message        text=''
output_index= 8 function_call  name=''             call_id=''                        arguments=', "workdir": "/tmp'
output_index= 9 message        text=''
output_index=10 function_call  name=''             call_id=''                        arguments='"'
output_index=11 message        text=''
output_index=12 function_call  name=''             call_id=''                        arguments=', "yield_time_ms": 10000'
output_index=13 message        text=''
output_index=14 function_call  name=''             call_id=''                        arguments=', "max_output_tokens": 20000'
output_index=15 message        text=''
output_index=16 function_call  name=''             call_id=''                        arguments='}'
output_index=17 message        text=''
output_index=18 function_call  name='exec_command' call_id='exec_command_1_f6dbc57f' arguments='{'
...

That response had 50 output items for 3 tool calls. The output array of the final response.completed event contains the same 50 items, so this is not only a streaming artifact.

A well-formed response to the same request has 5 items: reasoning, message, and three function_call items with complete arguments such as {"cmd":"cat README.md","workdir":"/tmp","yield_time_ms":10000,"max_output_tokens":20000}.

How often

All trials on 2026-11-24, same request sent repeatedly:

Request Broken / trials
The request below (7 function tools), Russian prompt 5 / 38
Same request, the prompt translated to English 1 / 24
Same prompt, 10 function tools (the 7 below plus Codex's three goal tools) 2 / 13
The full request Codex sends (17 tool entries, about 27K input tokens) 2 / 10
Same prompt with 1 to 4 tools 0 / 69

Identical requests give a well-formed response on one attempt and a broken one on the next. Every attempt used a fresh prompt_cache_key.

In every broken response the arguments are written with a space after the colon ("cmd": "...") and the fragments end exactly where a JSON string opens or closes, or between two key/value pairs. Well-formed responses appear in both the compact and the spaced style.

Response ids of broken responses

  • resp_wNrh2p0hdt7QussigIwd72my (2026-11-24 06:06:48 UTC)
  • resp_E8NTSxhUsQdOHR6boqBD9Chu (2026-11-24 06:08:23 UTC)
  • resp_keWA0KZho5m215AL8kgMUpJa (2026-11-24 06:09:09 UTC)
  • resp_W9hIqTqBTWhG0TUMYKxPgtAQ (2026-11-24 06:09:31 UTC)
What steps can reproduce the bug?

Save the request below as request.json, then:

for i in $(seq 1 30); do
  curl -sN https://api.kimi.ai/coding/v1/responses \
    -H "Authorization: Bearer $KIMI_API_KEY" -H "Content-Type: application/json" \
    -H "Accept: text/event-stream" -H "User-Agent: codex_exec/0.172.0" -H "originator: codex_exec" \
    -d @request.json \
  | grep '^data:' | sed 's/^data: *//' \
  | jq -c 'select(.type=="response.output_item.done" and .item.type=="function_call") | [.item.name, .item.call_id]' \
  | grep -c '^\["",""\]'
done

Each line is the number of function_call items with an empty name and call_id in one response. 0 is a well-formed response; a broken one prints a larger number, for example 21.

request.json
{
 "model": "k3.1-pro",
 "stream": true,
 "input": [
  {
   "type": "message",
   "role": "user",
   "content": [
    {
     "type": "input_text",
     "text": "Скажи одну короткую фразу, затем в этом же ответе вызови exec_command три раза параллельно: `cat README.md`, `git status --short --branch`, `ls -la`. В каждом вызове укажи workdir \"/tmp\", yield_time_ms 10000 и max_output_tokens 20000."
    }
   ]
  }
 ],
 "tools": [
  {
   "type": "function",
   "name": "exec_command",
   "description": "Runs a command in a PTY, returning output or a session ID for ongoing interaction.",
   "strict": false,
   "parameters": {
    "type": "object",
    "properties": {
     "cmd": {
      "type": "string",
      "description": "Shell command to execute."
     },
     "justification": {
      "type": "string",
      "description": "User-facing approval question for `require_escalated`; omit otherwise."
     },
     "login": {
      "type": "boolean",
      "description": "Request login-shell startup. Omit to inherit."
     },
     "max_output_tokens": {
      "type": "number",
      "description": "Output token budget. Defaults to 10000 tokens; larger requests may be capped by policy."
     },
     "prefix_rule": {
      "type": "array",
      "description": "Reusable approval prefix for `cmd`, only with `sandbox_permissions: \"require_escalated\"`; for example [\"git\", \"pull\"].",
      "items": {
       "type": "string"
      }
     },
     "sandbox_permissions": {
      "type": "string",
      "description": "Per-command sandbox override. Defaults to `use_default`; use `require_escalated` for unsandboxed execution.",
      "enum": [
       "use_default",
       "require_escalated"
      ]
     },
     "shell": {
      "type": "string",
      "description": "Shell binary to launch. Defaults to the user's default shell."
     },
     "tty": {
      "type": "boolean",
      "description": "True allocates a PTY for the command; false or omitted uses plain pipes."
     },
     "workdir": {
      "type": "string",
      "description": "Working directory for the command. Defaults to the turn cwd."
     },
     "yield_time_ms": {
      "type": "number",
      "description": "Wait before yielding output. Defaults to 10000 ms; effective range is 250-30000 ms."
     }
    },
    "required": [
     "cmd"
    ],
    "additionalProperties": false
   }
  },
  {
   "type": "function",
   "name": "list_mcp_resources",
   "description": "Lists resources provided by MCP servers. Resources allow servers to share data that provides context to language models, such as files, database schemas, or application-specific information. Prefer resources over web search when possible.",
   "strict": false,
   "parameters": {
    "type": "object",
    "properties": {
     "cursor": {
      "type": "string",
      "description": "Opaque cursor from a previous list_mcp_resources call; omit for the first page."
     },
     "server": {
      "type": "string",
      "description": "MCP server name. Omit to list resources from every configured server."
     }
    },
    "additionalProperties": false
   }
  },
  {
   "type": "function",
   "name": "list_mcp_resource_templates",
   "description": "Lists resource templates provided by MCP servers. Parameterized resource templates allow servers to share data that takes parameters and provides context to language models, such as files, database schemas, or application-specific information. Prefer resource templates over web search when possible.",
   "strict": false,
   "parameters": {
    "type": "object",
    "properties": {
     "cursor": {
      "type": "string",
      "description": "Opaque cursor from a previous list_mcp_resource_templates call; omit for the first page."
     },
     "server": {
      "type": "string",
      "description": "MCP server name. Omit to list resource templates from every configured server."
     }
    },
    "additionalProperties": false
   }
  },
  {
   "type": "function",
   "name": "read_mcp_resource",
   "description": "Read a specific resource from an MCP server given the server name and resource URI.",
   "strict": false,
   "parameters": {
    "type": "object",
    "properties": {
     "server": {
      "type": "string",
      "description": "MCP server name exactly as configured. Must match the 'server' field returned by list_mcp_resources."
     },
     "uri": {
      "type": "string",
      "description": "Resource URI to read. Must be one of the URIs returned by list_mcp_resources."
     }
    },
    "required": [
     "server",
     "uri"
    ],
    "additionalProperties": false
   }
  },
  {
   "type": "function",
   "name": "write_stdin",
   "description": "Writes characters to an existing unified exec session and returns recent output.",
   "strict": false,
   "parameters": {
    "type": "object",
    "properties": {
     "chars": {
      "type": "string",
      "description": "Bytes to write to stdin. Defaults to empty, which polls without writing."
     },
     "max_output_tokens": {
      "type": "number",
      "description": "Output token budget. Defaults to 10000 tokens; larger requests may be capped by policy."
     },
     "session_id": {
      "type": "number",
      "description": "Identifier of the running unified exec session."
     },
     "yield_time_ms": {
      "type": "number",
      "description": "Wait before yielding output. Non-empty writes default to 250 ms and cap at 30000 ms; empty polls wait 5000-300000 ms by default."
     }
    },
    "required": [
     "session_id"
    ],
    "additionalProperties": false
   }
  },
  {
   "type": "function",
   "name": "request_user_input",
   "description": "Request user input for one to three short questions and wait for the response. This tool is only available in Plan mode.",
   "strict": false,
   "parameters": {
    "type": "object",
    "properties": {
     "questions": {
      "type": "array",
      "description": "Questions to show the user. Prefer 1 and do not exceed 3",
      "items": {
       "type": "object",
       "properties": {
        "header": {
         "type": "string",
         "description": "Short header label shown in the UI (12 or fewer chars)."
        },
        "id": {
         "type": "string",
         "description": "Stable identifier for mapping answers (snake_case)."
        },
        "options": {
         "type": "array",
         "description": "Provide 2-3 mutually exclusive choices. Put the recommended option first and suffix its label with \"(Recommended)\". Do not include an \"Other\" option in this list; the client will add a free-form \"Other\" option automatically.",
         "items": {
          "type": "object",
          "properties": {
           "description": {
            "type": "string",
            "description": "One short sentence explaining impact/tradeoff if selected."
           },
           "label": {
            "type": "string",
            "description": "User-facing label (1-5 words)."
           }
          },
          "required": [
           "label",
           "description"
          ],
          "additionalProperties": false
         }
        },
        "question": {
         "type": "string",
         "description": "Single-sentence prompt shown to the user."
        }
       },
       "required": [
        "id",
        "header",
        "question",
        "options"
       ],
       "additionalProperties": false
      }
     }
    },
    "required": [
     "questions"
    ],
    "additionalProperties": false
   }
  },
  {
   "type": "function",
   "name": "view_image",
   "description": "View a local image file from the filesystem when visual inspection is needed. Use this for images already available on disk.",
   "strict": false,
   "parameters": {
    "type": "object",
    "properties": {
     "path": {
      "type": "string",
      "description": "Local filesystem path to an image file."
     }
    },
    "required": [
     "path"
    ],
    "additionalProperties": false
   }
  }
 ],
 "tool_choice": "auto",
 "parallel_tool_calls": true,
 "reasoning": {
  "effort": "max"
 },
 "store": false,
 "include": [
  "reasoning.encrypted_content"
 ]
}

The tool definitions are the ones Codex CLI sends for exec_command, write_stdin, view_image, request_user_input and the three MCP resource tools.

What is the expected behavior?

One function_call output item per tool call, with its name, call_id and complete arguments, and no empty message items between them.

Additional information
主要语言
TypeScript
星标
8.3k
派生
1.4k
平均合并
12 小时 6 分钟
30 天内合并 PR
596

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

MoonshotAI/kimi-code 的其他 Issue

查看 MoonshotAI/kimi-code 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。