fix: Handle rate_limit_event message to avoid MessageParseError#605
Open
liangzhang-keepmoving wants to merge 1 commit intoanthropics:mainfrom
Open
fix: Handle rate_limit_event message to avoid MessageParseError#605liangzhang-keepmoving wants to merge 1 commit intoanthropics:mainfrom
liangzhang-keepmoving wants to merge 1 commit intoanthropics:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the issue where the SDK would crash with
MessageParseError: Unknown message type: rate_limit_eventwhen the Claude Code CLI emits arate_limit_eventmessage.Root Cause
The CLI emits a
rate_limit_eventmessage at session start on every run, but the SDK's_read_messages()method inquery.pywas passing all messages to the stream, including informational events that shouldn't be parsed as SDK messages.Fix
Added a
continuestatement forrate_limit_eventmessages in_read_messages(), similar to howcontrol_cancel_requestis handled. This skips the informational event and prevents it from reaching the message parser.Changes
src/claude_agent_sdk/_internal/query.pyto add a case forrate_limit_eventmessagesTesting
The fix has been tested locally and resolves the issue where the SDK would crash with
MessageParseErrorwhen the CLI emits arate_limit_eventmessage.This change ensures that the SDK can properly handle the
rate_limit_eventmessage type, which is emitted by the CLI on every session start, without crashing.Fixes #603 and #601