openclaw - ✅(Solved) Fix [Bug] Streaming error "Unexpected event order, got message_start before receiving message_stop" with Claude Opus 4.6 via MyClaw — error message visible in Telegram chat [1 pull requests, 3 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#55408Fetched 2026-04-08 01:39:53
View on GitHub
Comments
3
Participants
1
Timeline
7
Reactions
0
Author
Participants
Timeline (top)
commented ×3cross-referenced ×2closed ×1locked ×1

Every agent response via Claude models (MyClaw provider) triggers an Unexpected event order, got message_start before receiving "message_stop" error that is displayed as a visible error message in the Telegram chat. This makes the chat essentially unusable — every reply from the agent is followed by a red error notification.

Affects all Claude models tested (claude-opus-4.6 and claude-sonnet-4.6). Not yet tested on non-Claude models.

Error Message

Every agent response via Claude models (MyClaw provider) triggers an Unexpected event order, got message_start before receiving "message_stop" error that is displayed as a visible error message in the Telegram chat. This makes the chat essentially unusable — every reply from the agent is followed by a red error notification. {"subsystem":"agent/embedded", "event":"embedded_run_agent_end", "tags":["error_handling","lifecycle","agent_end","assistant_error"], "isError":true, "error":"Unexpected event order, got message_start before receiving "message_stop"", "model":"claude-opus-4.6", "provider":"myclaw"} {"subsystem":"agent/embedded", "event":"embedded_run_agent_end", "isError":true, "error":"Unexpected event order, got message_start before receiving "message_stop"", "model":"claude-sonnet-4.6", "provider":"myclaw"} This error repeats for every single response from the agent, regardless of model. 3. Agent responds correctly BUT an error message appears in the Telegram chat: Unexpected event order, got message_start before receiving "message_stop" 4. Repeat for every message — error appears every time No error message should appear in the Telegram chat. Even if the streaming event order is unexpected, the error should be handled gracefully and silently (or logged internally only). An error notification is sent to the Telegram chat after every agent response, making the chat unusable.

  • The error likely originates from MyClaw sending a malformed SSE stream (sending message_start before the previous stream is closed with message_stop)
  • OpenClaw should handle this case gracefully without exposing the error to the end user in the chat

Root Cause

Every agent response via Claude models (MyClaw provider) triggers an Unexpected event order, got message_start before receiving "message_stop" error that is displayed as a visible error message in the Telegram chat. This makes the chat essentially unusable — every reply from the agent is followed by a red error notification.

Affects all Claude models tested (claude-opus-4.6 and claude-sonnet-4.6). Not yet tested on non-Claude models.

PR fix notes

PR #55999: fix(telegram): sanitize invalid stream-order errors

Description (problem / solution / changelog)

Summary

  • treat invalid provider stream-order failures as a safe retryable user-facing error
  • cover both assistant-error formatting and explicit user-facing sanitization paths
  • add unreleased changelog credit for the original reporter and maintainer follow-up

Validation

  • pnpm test -- src/agents/pi-embedded-helpers.formatassistanterrortext.test.ts src/agents/pi-embedded-helpers.sanitizeuserfacingtext.test.ts
  • pnpm build

Fixes #55408 Related #55399

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/agents/pi-embedded-helpers.formatassistanterrortext.test.ts (modified, +9/-0)
  • src/agents/pi-embedded-helpers.sanitizeuserfacingtext.test.ts (modified, +11/-0)
  • src/agents/pi-embedded-helpers/errors.ts (modified, +20/-0)

Code Example

{"subsystem":"agent/embedded", "event":"embedded_run_agent_end", "tags":["error_handling","lifecycle","agent_end","assistant_error"], "isError":true, "error":"Unexpected event order, got message_start before receiving \"message_stop\"", "model":"claude-opus-4.6", "provider":"myclaw"}

---

{"subsystem":"agent/embedded", "event":"embedded_run_agent_end", "isError":true, "error":"Unexpected event order, got message_start before receiving \"message_stop\"", "model":"claude-sonnet-4.6", "provider":"myclaw"}
RAW_BUFFERClick to expand / collapse

Description

Every agent response via Claude models (MyClaw provider) triggers an Unexpected event order, got message_start before receiving "message_stop" error that is displayed as a visible error message in the Telegram chat. This makes the chat essentially unusable — every reply from the agent is followed by a red error notification.

Affects all Claude models tested (claude-opus-4.6 and claude-sonnet-4.6). Not yet tested on non-Claude models.

Environment

  • OpenClaw: 2026.3.24 (cff6dc9)
  • OS: Linux 6.8.0-106-generic (x64), Node v22.22.1
  • Channel: Telegram
  • Models affected: claude-opus-4.6, claude-sonnet-4.6
  • Provider: myclaw
  • Gateway mode: local (supervisord)

Log Evidence

{"subsystem":"agent/embedded", "event":"embedded_run_agent_end", "tags":["error_handling","lifecycle","agent_end","assistant_error"], "isError":true, "error":"Unexpected event order, got message_start before receiving \"message_stop\"", "model":"claude-opus-4.6", "provider":"myclaw"}
{"subsystem":"agent/embedded", "event":"embedded_run_agent_end", "isError":true, "error":"Unexpected event order, got message_start before receiving \"message_stop\"", "model":"claude-sonnet-4.6", "provider":"myclaw"}

This error repeats for every single response from the agent, regardless of model.

Steps to Reproduce

  1. Configure OpenClaw with any Claude model via MyClaw provider
  2. Send any message via Telegram
  3. Agent responds correctly BUT an error message appears in the Telegram chat: Unexpected event order, got message_start before receiving "message_stop"
  4. Repeat for every message — error appears every time

Expected Behavior

No error message should appear in the Telegram chat. Even if the streaming event order is unexpected, the error should be handled gracefully and silently (or logged internally only).

Actual Behavior

An error notification is sent to the Telegram chat after every agent response, making the chat unusable.

Notes

  • The error likely originates from MyClaw sending a malformed SSE stream (sending message_start before the previous stream is closed with message_stop)
  • OpenClaw should handle this case gracefully without exposing the error to the end user in the chat
  • Also reported to MyClaw as a potential upstream streaming issue
  • Not yet tested with non-Claude models (Gemini, GPT) to determine if it is Claude-specific or a general MyClaw gateway issue

Related

  • #54695 (STT not working)
  • #54696 (TTS delivered as MP3 instead of voice)

extent analysis

Fix Plan

To resolve the Unexpected event order, got message_start before receiving "message_stop" error, we need to modify the OpenClaw code to handle the malformed SSE stream from MyClaw gracefully. Here are the steps:

  • Modify the embedded_run_agent_end function to catch and log the error internally instead of sending it to the Telegram chat.
  • Implement a retry mechanism to handle the case where message_start is received before message_stop.
  • Update the error handling to silently ignore the error and continue processing the agent response.

Example code changes:

// Catch and log the error internally
try {
    // Existing code to handle agent response
} catch (error) {
    if (error.message === 'Unexpected event order, got message_start before receiving "message_stop"') {
        console.error('Error handling agent response:', error);
    } else {
        throw error;
    }
}

// Implement a retry mechanism
const maxRetries = 3;
let retries = 0;
while (retries < maxRetries) {
    try {
        // Existing code to handle agent response
        break;
    } catch (error) {
        if (error.message === 'Unexpected event order, got message_start before receiving "message_stop"') {
            retries++;
            console.error('Retry ', retries, ' failed. Retrying...');
        } else {
            throw error;
        }
    }
}

// Update error handling to silently ignore the error
if (error.message === 'Unexpected event order, got message_start before receiving "message_stop"') {
    console.error('Error handling agent response:', error);
    // Continue processing the agent response
} else {
    throw error;
}

Verification

To verify that the fix worked, follow these steps:

  1. Apply the code changes and restart the OpenClaw service.
  2. Test the agent response via Telegram.
  3. Verify that the error message no longer appears in the Telegram chat.
  4. Check the logs to ensure that the error is being caught and logged internally.

Extra Tips

  • Monitor the logs to ensure that the error is not occurring frequently and adjust the retry mechanism as needed.
  • Consider implementing a more robust error handling mechanism to handle other potential errors that may occur.
  • Test the fix with non-Claude models to determine if the issue is specific to Claude models or a general MyClaw gateway issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING