Skip to content

Kimi Code CLI 前台子代理立即超时故障报告 #4943

Closed

Description

@LeafLIU210

你运行的 Kimi Code 版本是?

2.6.0

你使用的是哪个开放平台/订阅?

kimi.com coding plan

你使用的是哪个模型?

kimi-3.1-pro

你的电脑平台是?

windows 11 x64

你遇到了什么问题?

问题摘要

在 Windows 上使用 Kimi Code CLI 2.6.0 的非交互模式 kimi --prompt 时,主代理可以正常完成模型请求并调用 Agent 工具,但前台子代理会在启动后几十毫秒内被取消,统一返回:

status: failed
stop_reason: timed_out
subagent error: Agent timed out after 0 hours.
[partial output] none — the subagent wrote no text in this run before it ended.

该问题同时出现在完整实现任务的 coder 子代理和不读写任何文件的最小 explore 健康检查中。三次 Agent 工具调用的报告耗时分别为 66 ms(首次实现调用)、17 ms(恢复调用)和 103 ms(最小健康检查)。恢复原 coder 子代理也立即失败。显式设置 KIMI_SUBAGENT_TIMEOUT_MS=7200000 后问题仍可复现,因此不是简单的超时时间过短。

环境

  • Kimi Code CLI:2.6.0,native 安装
  • 操作系统:Microsoft Windows 10.0.26200,x64
  • 导出清单中的平台标识:win32 x64
  • Node.js 运行时标识:24.15.0
  • Shell:C:\Program Files\Git\bin\bash.exe
  • 工作目录:D:/PYTHON/osta_certificate
  • 模型:kimi-code/k3.1-pro,主代理和子代理均使用该模型
  • kimi doctor:config.toml 与 tui.toml 均显示 OK
  • 两个会话的 wire protocol:1.5

复现步骤?

最小复现

在 Git Bash 中执行:

KIMI_SUBAGENT_TIMEOUT_MS=7200000 kimi --prompt '这是一次只读的子代理健康检查。请同步调用一次 explore 子代理,让它仅返回 subagent-ok,不要读取或修改任何文件;收到后原样返回该文本。'

主代理实际发起的工具调用为:

Agent(
  subagent_type="explore",
  run_in_background=false,
  prompt="这是一次只读健康检查。不要读取或修改任何文件,也不要调用任何工具。仅返回以下文本,不要添加任何其他内容:subagent-ok"
)

预期:子代理返回 subagent-ok,主代理收到后原样输出。

实际:子代理没有返回任何文本,Agent 工具在 103 ms 后以 timed_out 失败;主代理随后如实报告未收到结果。

对应导出:exports/health-check-session.zip,会话 session_6e7afca5-ac55-4886-8b95-d8b27fbe9626。

原始故障与时间线

对应导出:exports/story-4.2-session.zip,会话 session_dccb621e-b882-4ca2-b18f-d985e42f3113。

主代理按照工作流同步启动一个 coder 子代理,要求读取故事规范并完成实现。底层 agents/main/wire.jsonl 记录如下:

  1. 2026-11-14 17:57:51.251 UTC:首次 Agent 工具调用。
  2. 17:57:51.283 UTC:subagent.spawned,runInBackground=false。
  3. 17:57:51.284 UTC:subagent.started。
  4. 17:57:51.317 UTC:subagent.cancelled。
  5. 17:57:51.318 UTC:工具返回 Agent timed out after 0 hours,durationMs=66。
  6. 17:57:57.385 UTC:使用 Agent(resume="agent-0", prompt="continue") 恢复同一子代理。
  7. 17:57:57.387 UTC:恢复实例启动。
  8. 17:57:57.402 UTC:恢复实例被取消。
  9. 17:57:57.403 UTC:再次返回相同错误,durationMs=17。

子代理自己的 agents/agent-0/wire.jsonl 显示:初始化和 step.begin 后立即出现 turn.cancel、turn.ended(reason=cancelled) 和 prompt.aborted;没有助手响应或工具调用。会话日志中存在子代理的 llm request,但没有对应的 llm response。与此同时,主代理的多次模型请求均正常收到响应。

独立健康检查的关键记录:

  • 2026-11-14 18:02:27.040 UTC:同步调用 explore。
  • 18:02:27.119 UTC:子代理启动。
  • 18:02:27.142 UTC:子代理被取消。
  • 18:02:27.144 UTC:工具返回相同错误,durationMs=103。

已排除或尚未确定的事项

已确认:

  • 故障发生在前台 Agent 子代理的启动/超时/取消路径;不是子代理执行任务过久。
  • 原任务和最小健康检查均在首个子代理模型响应前失败。
  • 显式设置正向 KIMI_SUBAGENT_TIMEOUT_MS=7200000 没有消除故障。
  • CLI 配置校验正常,主代理模型请求正常。
  • 这不是项目 PowerShell 脚本的 3600 秒停滞阈值触发;目标进程在两分钟左右已正常退出,而子代理实际只运行了几十毫秒。

尚未确定:

  • CLI 内部具体哪段源码或哪个状态转换把前台子代理错误地判定为零小时超时。
  • 是否影响其他模型、其他 CLI 版本或交互式 TUI;本次未验证这些组合。
  • 是否能通过持久化 [subagent] timeout_ms 配置绕过;本次仅验证了环境变量覆盖无效,未修改用户配置。

影响

依赖同步子代理的实现和独立审查工作流无法执行。每次失败都会要求主代理恢复子代理或停止任务,造成自动化批次无法完成。

另有一个独立的项目批处理问题:pwsh/run-stories-2.4-5.7.ps1 只检查 CLI 进程退出码,因此将已明确写入 status: blocked / no subagents 的故事计为成功并继续下一故事。该问题放大了故障影响,但不是子代理立即超时的根因。相关日志和脚本仅作为上下文附上。

附件

  • exports/story-4.2-session.zip:原始 coder 调用与恢复失败的完整官方会话导出。
  • exports/health-check-session.zip:最小 explore 健康检查的完整官方会话导出。
  • project-evidence/001-story-4.2.log:外层批处理捕获的故事日志。
  • project-evidence/batch.log:批次将失败故事按退出码 0 结束并进入下一故事的记录。
  • project-evidence/status.json:该批次留下的状态快照。
  • project-evidence/run-stories-2.4-5.7.ps1:相关批处理脚本原文。
  • manifest.json:附件用途、大小及 SHA-256。

两个会话导出均使用 --no-include-global-log。其中的 logs/kimi-code.log 是对应会话自己的日志,不是全局诊断日志。导出未包含 CLI 配置文件。高置信度凭据模式扫描未发现私钥、API token 或已填写的凭据字段。

期望的行为是什么?

No response

补充信息

kimi-subagent-failure-report-20261115-020852.zip

Contribution

  • 我愿意自己提交修复此 bug 的 PR(请先等待维护者在本 issue 中批准)

Activity

  1. added
    bug
    on Nov 14, 2026
  2. shenxingy commented on Nov 14, 2026

    @shenxingy

    I reproduced this on Linux x64 (Kimi Code CLI 2.6.0, kimi-code/k3.1-pro, print mode) and traced it to a single cause in the 2.6.0 bundle.

    Cause

    1. In print mode, applyPrintModeConfigDefaults() runs fillSectionDefault(config, SUBAGENT_SECTION, "timeoutMs", 0). It does the same for SWARM_SECTION. This only writes to memory, and only when the user has not set a value. It sits next to bashTaskTimeoutS = 0 and maxStepsPerTurn = 0, so 0 seems to mean "no limit" here.
    2. SubagentTool takes resolveSubagentTimeoutMs(config), which returns config.get("subagent")?.timeoutMs ?? 72e5. That value is now 0, and the tool passes it straight to setTimeout(() => { timedOut = true; controller.abort("Timed out") }, timeoutMs). With 0, the abort fires on the next event-loop tick. That is why the subagent is cancelled within tens of milliseconds (your 17/66/103 ms) and the error reads "timed out after 0 hours".
    3. The swarm path already treats 0 as "no timer": AgentRunBatch.linkAttemptSignals arms no timer when task.timeout <= 0. Only SubagentTool disagrees.

    Linux checks:

    • 2026-11-14, the same call to the explore subagent:
      • with no setting, it fails with Agent timed out after 0 hours;
      • with KIMI_SUBAGENT_TIMEOUT_MS=600000 kimi -p ..., it completes and returns the file contents.
    • 2026-11-13, a custom subagent with no env var: with [subagent] / timeout_ms = 7200000 in ~/.kimi-code/config.toml, it completes.

    We did not test Windows, so we don't know why the env var has no effect there. The config file goes through a different path, so it is worth trying on Windows:

    [subagent]
    timeout_ms = 7200000

    Suggested fix: in SubagentTool, skip setTimeout when timeoutMs <= 0, the same way the swarm path does. Alternatively, print mode could stop writing 0 into subagent.

    Related: #3187 (print mode does not honour bash_task_timeout_s = 0 either).

  3. added a commit that references this issue on Nov 15, 2026
  4. LeafLIU210 commented on Nov 15, 2026

    @LeafLIU210
    Author

    Update from the reporter on Windows 11 x64 with Kimi Code CLI 2.6.0:

    I have confirmed that the positive-timeout workaround resolves the immediate subagent failures on my machine.

    I appended the following to C:\Users\Leaf_\.kimi-code\config.toml:

    [subagent]
    timeout_ms = 7200000

    Verification results:

    1. My original PowerShell batch workflow now runs the foreground coder implementation subagent successfully. The subsequent independent review subagents also return their findings normally.
    2. The minimal foreground explore health check now completes and returns subagent-ok.

    This confirms that setting a positive persistent timeout prevents print mode from applying subagent.timeoutMs = 0, thereby avoiding the unconditional setTimeout(..., 0) failure path described in #4868.

    One clarification: the successful health check was run with both the persistent config entry and KIMI_SUBAGENT_TIMEOUT_MS=7200000 present. Therefore, it does not independently prove that the environment-variable-only workaround works on Windows. The workaround confirmed here is the positive value in config.toml.

    The underlying zero-timeout handling has been addressed in main by #4868. My installed 2.6.0 build still requires this positive-timeout workaround.

    I am closing this issue as completed because the root cause has been identified and fixed upstream, and the workaround has been verified on my side. Thank you for the analysis and fix. @shenxingy

  5. LeafLIU210 commented on Nov 15, 2026

    @LeafLIU210
    Author

    Update from the reporter on Windows 11 x64 with Kimi Code CLI 2.6.0:

    I have confirmed that the positive-timeout workaround resolves the immediate subagent failures on my machine.

    I appended the following to C:\Users\Leaf_\.kimi-code\config.toml:

    [subagent]
    timeout_ms = 7200000

    Verification results:

    1. My original PowerShell batch workflow now runs the foreground coder implementation subagent successfully. The subsequent independent review subagents also return their findings normally.
    2. The minimal foreground explore health check now completes and returns subagent-ok.

    This confirms that setting a positive persistent timeout prevents print mode from applying subagent.timeoutMs = 0, thereby avoiding the unconditional setTimeout(..., 0) failure path described in #4868.

    One clarification: the successful health check was run with both the persistent config entry and KIMI_SUBAGENT_TIMEOUT_MS=7200000 present. Therefore, it does not independently prove that the environment-variable-only workaround works on Windows. The workaround confirmed here is the positive value in config.toml.

    The underlying zero-timeout handling has been addressed in main by #4868. My installed 2.6.0 build still requires this positive-timeout workaround.

    I am closing this issue as completed because the root cause has been identified and fixed upstream, and the workaround has been verified on my side. Thank you for the analysis and fix. @shenxingy

  6. shenxingy commented on Nov 15, 2026

    @shenxingy

    On the environment-variable question: KIMI_SUBAGENT_TIMEOUT_MS=7200000 on its own cannot help in print mode, because 7200000 is the registered default. A value from the environment is not a userValue, and isUnset in agent/task/printDefaults.ts treats an effective value equal to the default as unset, so applyPrintModeConfigDefaults writes 0 over it. Any other positive value is kept (600000 worked on Linux), as is any value in config.toml. After #4868 this no longer fails, but KIMI_SUBAGENT_TIMEOUT_MS=7200000 kimi -p still gets no limit instead of two hours.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions