Skip to content

[Bug]: Kimi k2p5 (anthropic-messages): "Unexpected event order: message_start before message_stop" — chat unusable #57523

Closed as not planned
BingqingLyu/openclaw
#1999

Description

@kanmanhu-less

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

Summary

When using Kimi with model k2p5 via the Anthropic Messages–compatible streaming path (anthropic-messages), OpenClaw fails on assistant runs with:

Unexpected event order, got message_start before receiving "message_stop"

This comes from the @anthropic-ai/sdk stream parser when the upstream SSE sequence is invalid (e.g. a new message_start arrives before the previous assistant message received message_stop). The Control UI shows the equivalent event order / stream sequence error. Restarting the gateway, refreshing the page, or opening a new session does not reliably fix it once the failure pattern appears.

The issue persisted across OpenClaw upgrades (currently on 2026.3.28). The same setup had worked normally for roughly one month before the failures began.

Environment

  • OpenClaw: 2026.3.28 (f9b1079) — openclaw --version
  • Node.js: v22.22.0
  • Host: Windows with WSL2 (userland paths under /home/...)
  • Model / provider (effective): k2p5, provider kimi (Kimi Coding / Anthropic-compatible endpoint as configured by OpenClaw)
  • Install: npm install -g openclaw@latest

Steps to reproduce

  1. Configure Kimi Coding API credentials in OpenClaw (Kimi Code / Kimi for Coding product).
  2. Select k2p5 (UI may show kimi/k2p5 or equivalent).
  3. Open Control UI web chat and send a normal user message.
  4. Observe the failure in the UI banner and in gateway logs (embedded_run_agent_end with assistant_error).

Actual behavior

  • Assistant run ends with isError: true and the error text above.
  • Chat cannot complete a turn; error repeats on subsequent attempts.

Expected behavior

  • Streaming completes with a well-formed message_stop sequence, or the client falls back safely.
  • A single bad stream should not leave the session permanently broken; session transcript repair should drop incomplete tool-call blocks (e.g. streaming-only partialJson) so the next request does not cascade into repeated stream errors.

Gateway log excerpt (redacted)

Log file: /tmp/openclaw/openclaw-2026-03-30.log (JSON lines).

Representative embedded_run_agent_end event :

{
  "subsystem": "agent/embedded",
  "event": "embedded_run_agent_end",
  "tags": ["error_handling", "lifecycle", "agent_end", "assistant_error"],
  "runId": "<run-id>",
  "isError": true,
  "error": "Unexpected event order, got message_start before receiving \"message_stop\"",
  "failoverReason": null,
  "model": "k2p5",
  "provider": "kimi",
  "rawErrorPreview": "Unexpected event order, got message_start before receiving \"message_stop\"",
  "rawErrorHash": "sha256:e52189f5ca9c"
}

### Steps to reproduce

1. Start OpenClaw 2026.2.17 using the configuration attached to this issue.
2. In the affected chat, send a Telegram thread reply (reply in the same conversation flow you normally use).
3. Check whether a reply is posted, and in the attached gateway logs confirm the line indicating “target for reply not found” (or the equivalent English message in your log).



### Expected behavior

On 2026-02-10, the same agent successfully posted replies in the same Telegram topic using the same workflow. The expected behavior is that replies continue to be delivered in that topic under the same configuration.



### Actual behavior

No reply was posted to that topic. The attached gateway logs show a “target for reply not found” error at 14:23:08 UTC.

### OpenClaw version

2026.3.13、2026.3.28

### Operating system

Windows 11 + WSL2

### Install method

npm install -g openclaw

### Model

kimi-coding/k2p5

### Provider / routing chain

openclaw -> https://api.kimi.com/coding/(Anthropic-compatible)

### Additional provider/model setup details

_No response_

### Logs, screenshots, and evidence

```shell

Impact and severity

No response

Additional information

No response

Activity

  1. added
    bug
    on Mar 30, 2026
  2. added
    regression
    on Mar 30, 2026
  3. charles0-0 commented on Mar 30, 2026

    @charles0-0

    same question

  4. ingozy commented on Mar 30, 2026

    @ingozy

    I'm experiencing the same issue. My OpenClaw version is 3.13, and I'm using the kimi-coding/k2p5 model. This suddenly started happening after 11:50 today (March 30th) — everything was working fine before that.
    My colleague is using the same API key with OpenClaw version 3.2, and it's working normally for them.

  5. XHJ-Studio commented on Mar 30, 2026

    @XHJ-Studio

    I'm experiencing the exact same error!

    My setup:

    OpenClaw version: 2026.3.13 (different from the reporter - I haven't upgraded to 2026.3.28 yet)
    Model: kimi-coding/k2p5
    Issue started: First appeared today (2026-03-30)
    Key difference:
    My configuration was working perfectly for a long time before this. The error started appearing suddenly today with no updates or configuration changes on my end.

    Error message matches exactly:

    This looks more like a temporary issue on Kimi API's side rather than an OpenClaw version-specific problem, because:

    Different versions (2026.3.13 and 2026.3.28) are both affected
    Both started experiencing the issue today (2026-03-30)
    Both were working normally for an extended period before
    Hope the team can investigate the Kimi API compatibility issue soon!

  6. jiahello commented on Mar 30, 2026

    @jiahello

    use model "kimi code" got the same error "Unexpected event order, got message_start before receiving "message_stop"
    v2026.3.28

  7. VipMason commented on Mar 30, 2026

    @VipMason

    same question

  8. easy8in commented on Mar 30, 2026

    @easy8in

    same question

  9. lsh1994 commented on Mar 30, 2026

    @lsh1994

    同样的问题

  10. aprilandjan commented on Mar 30, 2026

    @aprilandjan

    It worked sereral hours ago, and failed right now, without any changes in openclaw nor its configuration. might be kimi api backend issues 🤔

  11. Little-Initiate commented on Mar 30, 2026

    @Little-Initiate

    Same. This suddenly started happening around 11:50 today (March 30th) — everything was working fine before that. And I had tried v3.28 and v3.24, neither of them worked properly.
    BTW, I had also send this issue to Kimi Code's officials.

  12. cyijun commented on Mar 30, 2026

    @cyijun

    3.13 met this too. Only kimi claw is fine

  13. easy8in commented on Mar 30, 2026

    @easy8in

    That's right, it was 11:50 this morning. (Only WSL's OpenClaw, MacBook's OpenClaw were successful, and Ubuntu 24's OpenClaw was successful.)

  14. Little-Initiate commented on Mar 30, 2026

    @Little-Initiate

    Seems like v2.26 dont have this problem. I can chat with Kimi k2p5(Kimi coding) on openclaw tui.

  15. fishel-feng commented on Mar 30, 2026

    @fishel-feng

    Same issue, and I didn’t make any changes.

  16. 28 remaining items

  17. ironbox360 commented on Mar 30, 2026

    @ironbox360

    My Temporary Workaround for Kimi-Code Connection Issues

    Run the command: openclaw onboard

    Select Custom Provider and use the following parameters:

    Base URL: https://api.kimi.com/coding/
    Compatibility: Anthropic-compatible
    Model ID: kimi-coding (doesn't matter)

    Caution: "This workaround will store the apiKey in plain text within the openclaw.json file."

    │
    ◇  Model/auth provider
    │  Custom Provider
    │
    ◇  API Base URL
    │  https://api.kimi.com/coding/
    │
    ◇  How do you want to provide this API key?
    │  Paste API key now
    │
    ◇  API Key (leave blank if not required)
    │  sk-kimi-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    │
    ◇  Endpoint compatibility
    │  Anthropic-compatible
    │
    ◇  Model ID
    │  kimi-coding
    │
    ◇  Verification successful.
    │
    ◇  Endpoint ID
    │  custom-api-kimi-com
    │
    ◇  Model alias (optional)
    │  kimi-code-temp
    Configured custom provider: custom-api-kimi-com/kimi-coding

    Then modify "reasoning" to true,, "contextWindow" to 262144, and "maxTokens" to 32768 ,
    And the result is as the following.

      "models": {
        "mode": "merge",
        "providers": {
          "custom-api-kimi-com": {
            "baseUrl": "https://api.kimi.com/coding/",
            "apiKey": "sk-kimi-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "api": "anthropic-messages",
            "models": [
              {
                "id": "k2",
                "name": "k2 (Custom Provider)",
                "reasoning": true,
                "input": [
                  "text"
                ],
                "cost": {
                  "input": 0,
                  "output": 0,
                  "cacheRead": 0,
                  "cacheWrite": 0
                },
                "contextWindow": 262144,
                "maxTokens": 32768
              }
            ]
          }
        }
      },
  18. lolydleo commented on Mar 30, 2026

    @lolydleo

    Perhaps it's a problem with the Kimi K2.5 model; I encountered the same issue using Kimi Code K2.5. However, the problem disappeared after switching to DeepSeek.

  19. yadnuses commented on Mar 30, 2026

    @yadnuses

    Perhaps it's a problem with the Kimi K2.5 model; I encountered the same issue using Kimi Code K2.5. However, the problem disappeared after switching to DeepSeek.

    yes,i try switching to deepseek, the problem are disappear

  20. mazaruz commented on Mar 30, 2026

    @mazaruz

    My Temporary Workaround for Kimi-Code Connection Issues

    Run the command: openclaw onboard

    Select Custom Provider and use the following parameters:

    Base URL: https://api.kimi.com/coding/ Compatibility: Anthropic-compatible Model ID: kimi-coding (doesn't matter)

    Caution: "This workaround will store the apiKey in plain text within the openclaw.json file."

    │
    ◇  Model/auth provider
    │  Custom Provider
    │
    ◇  API Base URL
    │  https://api.kimi.com/coding/
    │
    ◇  How do you want to provide this API key?
    │  Paste API key now
    │
    ◇  API Key (leave blank if not required)
    │  sk-kimi-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    │
    ◇  Endpoint compatibility
    │  Anthropic-compatible
    │
    ◇  Model ID
    │  kimi-coding
    │
    ◇  Verification successful.
    │
    ◇  Endpoint ID
    │  custom-api-kimi-com
    │
    ◇  Model alias (optional)
    │  kimi-code-temp
    Configured custom provider: custom-api-kimi-com/kimi-coding
    

    This one works for me.

  21. Qrym commented on Mar 30, 2026

    @Qrym

    I was hitting the "Unexpected event order" error with Kimi k2p5 on v2026.3.13. I suspect it might be related to me dumping a huge chunk of text into it earlier, probably made the request body balloon and messed up the SSE stream parsing.

    Tried rolling back to v2026.3.2 and so far it's looking good, no more errors and responses are coming through fine.

  22. heyAyushh commented on Mar 30, 2026

    @heyAyushh
  23. pepsykolya commented on Mar 30, 2026

    @pepsykolya

    Window 11, WSL, Ubuntu 24, OpenClaw 2026.3.13 & openclaw-lark 2026.3.18

    1. cd ~/.openclaw/agents/main/agent (rm models.json & rm auth-profiles.json)
    2. cd ~/.openclaw/agents/main/session (rm all files)
    3. cd ~/.opencalw/
    4. editor openclaw.json

    "models": {
    "mode": "merge",
    "providers": {
    "kimi-coding": {
    "baseUrl": "https://api.kimi.com/coding/",
    "apiKey": "sk-kimi-xxx", // important 重要!!! 重要!!! 重要!!!
    "api": "anthropic-messages",
    "models": [
    I was succeed!!!

    I love u!!!

  24. easy8in commented on Mar 30, 2026

    @easy8in

    Windows 11、WSL、Ubuntu 24、OpenClaw 2026.3.13 和 openclaw-lark 2026.3.18

    1. cd ~/.openclaw/agents/main/agent (rm models.json & rm auth-profiles.json)
    2. cd ~/.openclaw/agents/main/session(删除所有文件)
    3. cd ~/.opencalw/
    4. 编辑器 openclaw.json

    "models": {
    "mode": "merge",
    "providers": {
    "kimi-coding": {
    "baseUrl": "https://api.kimi.com/coding/",
    "apiKey": "sk-kimi-xxx", // important 重要!!! 重要!!! 重要!!!
    "api": "anthropic-messages",
    "models": [
    我成功了!!!

    我刚花时间重新配置了一遍,还是不行,完全无法对话。
    这是我的配置
    "providers": {
    "kimi-coding": {
    "baseUrl": "https://api.kimi.com/coding/",
    "apiKey": "sk-kimi-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "api": "anthropic-messages",
    "models": [
    {
    "id": "k2p5",
    "name": "Kimi for Coding",
    "reasoning": true,
    "input": [
    "text",
    "image"
    ],
    "cost": {
    "input": 0,
    "output": 0,
    "cacheRead": 0,
    "cacheWrite": 0
    },
    "contextWindow": 262144,
    "maxTokens": 32768
    }
    ]
    },

  25. easy8in commented on Mar 31, 2026

    @easy8in

    Window 11, WSL, Ubuntu 24, OpenClaw 2026.3.13 & openclaw-lark 2026.3.18

    1. cd ~/.openclaw/agents/main/agent (rm models.json & rm auth-profiles.json)
    2. cd ~/.openclaw/agents/main/session (rm all files)
    3. cd ~/.opencalw/
    4. editor openclaw.json

    "models": {
    "mode": "merge",
    "providers": {
    "kimi-coding": {
    "baseUrl": "https://api.kimi.com/coding/",
    "apiKey": "sk-kimi-xxx", // important 重要!!! 重要!!! 重要!!!
    "api": "anthropic-messages",
    "models": [
    I was succeed!!!

    not working can u please give me your all config details

    Update: It works when delete

        "headers": {
          "User-Agent": "claude-code/0.1.0"
        },
    

    my config:

    "models": {
        "mode": "merge",
        "providers": {
          "kimi-coding": {
            "baseUrl": "https://api.kimi.com/coding/",
            "apiKey": "sk-kimi-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "api": "anthropic-messages",
            "models": [
              {
                "id": "k2p5",
                "name": "Kimi for Coding",
                "reasoning": true,
                "input": [
                  "text",
                  "image"
                ],
                "cost": {
                  "input": 0,
                  "output": 0,
                  "cacheRead": 0,
                  "cacheWrite": 0
                },
                "contextWindow": 262144,
                "maxTokens": 32768
              }
            ]
          },
    ..............
  26. fishel-feng commented on Mar 31, 2026

    @fishel-feng

    It seems to be resolved already. I didn’t change any configuration. I received a push from Corn this morning, and now I can talk to it normally.

  27. kanmanhu-less commented on Mar 31, 2026

    @kanmanhu-less
    Author

    目前有两个Kimi相关的问题困扰着我们。

    1. 空工具调用(之前已合并到主分支)- fix(kimi): 在格式错误的参数修复路径中保留有效的 Anthropic 兼容工具调用参数 #54491
    2. Kimi 编码 API - [Bug]: Kimi k2p5 (anthropic-messages): "意外的事件顺序:message_start 在 message_stop 之前" — 聊天功能无法使用 #57523 (评论)

    同样的问题我都遇到了,第一个我通过回滚版本到3.13解决了,应该是3.28增加了参数但是kimi没有适配,第二个问题昨天晚上kimi应该也已经修复了,我昨晚22:00左右使用已经恢复了

  28. steipete commented on Apr 25, 2026

    @steipete
    Contributor

    Closing this as not reproducible on current main after Codex review.

    Issue appears to have been a transient Kimi Coding upstream streaming outage on March 30, 2026, not a persistent OpenClaw mainline regression. Current main also contains guardrails that turn this parser failure into a retryable user-facing error and avoid cascading transcript repair damage from aborted/errored tool-call turns.

    What I checked:

    • Issue discussion points to an upstream outage window, not a version-specific core regression: Multiple reporters said the exact same failure started suddenly on March 30, 2026 around 11:50 with no local OpenClaw/config changes, across v2026.3.13 and v2026.3.28. Later comments from fishel-feng and the original reporter said the problem recovered without configuration changes by March 31, 2026.
    • Current main rewrites the raw stream-order parser failure into a generic retry message: formatAssistantErrorText now catches invalid Anthropic stream ordering errors and returns a safe user-facing retry message instead of surfacing the raw message_start/message_stop parser text. (src/agents/pi-embedded-helpers/errors.ts:1072, c65aa1d2a6e5)
    • UI-facing sanitizer applies the same invalid-stream rewrite: sanitizeUserFacingText also recognizes the same invalid event-order error and rewrites it to the same retry copy, so the raw parser message no longer leaks through chat/UI surfaces on current main. (src/agents/pi-embedded-helpers/sanitize-user-facing-text.ts:409, c65aa1d2a6e5)
    • Transcript repair already avoids cascading synthetic tool results for aborted or errored assistant turns: Current repairToolUseResultPairing explicitly skips synthesizing missing tool results when an assistant turn ended with stopReason === "error" or "aborted", which reduces the follow-on transcript corruption the report called out. (src/agents/session-transcript-repair.ts:536, c65aa1d2a6e5)
    • Transcript repair also drops malformed/incomplete tool-call blocks: Current repairToolCallInputs drops raw tool-call blocks that are missing input, id, or allowed tool names before replay, covering another class of broken partial stream artifacts. (src/agents/session-transcript-repair.ts:319, c65aa1d2a6e5)
    • Release notes already document the invalid-stream-order mitigation: The changelog entry says OpenClaw now replaces raw message_start/message_stop invalid stream-order provider errors with a safe retry message. (CHANGELOG.md:2253, c65aa1d2a6e5)

    Review notes: reviewed against c65aa1d2a6e5.

  29. locked as resolved and limited conversation to collaborators on Apr 28, 2026
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

    bugregression

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions