Repository navigation
fix(tools): accept JSON-encoded messages in send_message_to_user - #10709
Open
rudycelekli wants to merge 2 commits into
Open
rudycelekli wants to merge 2 commits into
rudycelekli wants to merge 2 commits into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/tools/message_tools.py" line_range="227-228" />
<code_context>
+ # Some models send the array as a JSON-encoded string, especially
+ # for long multi-line text.
+ try:
+ messages = json.loads(messages)
+ except json.JSONDecodeError:
+ pass
if not isinstance(messages, list) or not messages:
</code_context>
<issue_to_address>
**Invalid messages raise exceptions**
When the JSON string exceeds Python’s nesting or integer-conversion limits, `json.loads(messages)` raises `RecursionError` or `ValueError`, which the `JSONDecodeError` handler does not catch. `call_local_llm_tool` propagates the exception instead of returning the invalid-messages error.
Catch `RecursionError` and `ValueError` alongside `JSONDecodeError` so these inputs reach the existing invalid-messages check.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and a JSON-encoded array now reaches the existing send flow, so if it is decoded into the wrong content, a message may be sent to the session and cannot be recalled by reverting. Reverting stops future sends through this path but does not undo messages already delivered.
Blocking findings: astrbot/core/tools/message_tools.py:228
This branch has not been deployed
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.
Fixes #7961
Some models (reported with MiniMax, also seen with other OpenAI-compatible providers) send the
messagesargument ofsend_message_to_useras a JSON-encoded string instead of an array, typically when the text is long and multi-line:SendMessageToUserTool.call()only accepted alist, so it returnederror: messages parameter is empty or invalid.. The model then had to retry, and in cron jobs the first delivery attempt failed.Modifications / 改动点
astrbot/core/tools/message_tools.py: whenmessagesis a string, tryjson.loadsbefore validating. If the string is not valid JSON, the existing error is returned unchanged. The decoded value goes through the same per-item validation as before.tests/unit/test_message_tools.py: one test for a JSON-encoded string containing newlines and escaped quotes, and one test showing that a non-JSON string is still rejected without sending anything.This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
ruff format/ruff checkpass.Checklist / 检查清单
Summary by Sourcery
Accept JSON-encoded message arrays in
send_message_to_userwhile preserving validation for invalid input.Bug Fixes:
send_message_to_userto accept JSON-encoded message arrays from compatible models, including long multi-line content.Tests:
Review follow-up (2026-10-26)
Fixed decoder boundary handling: catch
ValueError(which includesJSONDecodeError) andRecursionError, letting both reach the existing invalid-messages return before component construction or sending. Added actual deeply nested JSON and oversized integer inputs, with assertions that no message send occurs. Before: 2 failed / 42 passed; after: all 44 tests intests/unit/test_message_tools.pypass. Whole-repository Ruff lint/format checks pass. Local Python 3.13.5 validation; hosted Python 3.12 CI remains separate. No live message delivery.