Fix/sendmessage response check and tool result truncation#183
Open
aalinyu wants to merge 2 commits into
Open
Conversation
Two fixes for the WeChat channel outbound delivery: 1. sendMessage now parses the API response body and throws on non-zero ret/errcode, catching silent failures where the HTTP request succeeds but the WeChat backend returns an error. 2. Tool result payloads sent as chat-visible messages are truncated to 120 chars (non-error only). Previously, web_search results of 5000+ chars were echoed verbatim, flooding the chat and pushing the actual AI reply out of view. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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
sendMessageAPI response body: checkret/errcodeand throw on non-zero values, catching silent failures where the HTTP request succeeds but the WeChat backend returns an error.delivercallback now identifieskind === "tool"payloads and truncates non-error tool results exceeding 120 characters, preventing large web_search results from flooding the chat.Root cause
Two issues were observed in the WeChat channel:
sendMessagebut never reach the WeChat user. ThesendMessagefunction was discarding the response body, making it blind to backend-levelret/errcodeerrors.web_search, raw search results (4,500–8,000 chars each) are echoed as visible chat messages. A single multi-tool turn can emit 17 messages in 48 seconds, burying the AI's final reply under a wall of tool output.Changes
src/api/types.tsret/errcode/errmsgfields toSendMessageRespsrc/api/api.tssendMessageresponse JSON; throwErrorwhenret !== 0; gracefully degrade on non-JSON responsessrc/messaging/process-message.tsdeliveryCtx?.kindindeliver; truncate non-error tool results to 120 chars