Skip to content

Fix/sendmessage response check and tool result truncation#183

Open
aalinyu wants to merge 2 commits into
Tencent:mainfrom
aalinyu:fix/sendmessage-response-check-and-tool-result-truncation
Open

Fix/sendmessage response check and tool result truncation#183
aalinyu wants to merge 2 commits into
Tencent:mainfrom
aalinyu:fix/sendmessage-response-check-and-tool-result-truncation

Conversation

@aalinyu

@aalinyu aalinyu commented May 28, 2026

Copy link
Copy Markdown

Summary

  • Parse sendMessage API response body: check ret / errcode and throw on non-zero values, catching silent failures where the HTTP request succeeds but the WeChat backend returns an error.
  • Truncate tool result echoes: the deliver callback now identifies kind === "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:

  1. Some messages return HTTP 200 from sendMessage but never reach the WeChat user. The sendMessage function was discarding the response body, making it blind to backend-level ret / errcode errors.
  2. When the AI invokes tools like 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

File Change
src/api/types.ts Add ret / errcode / errmsg fields to SendMessageResp
src/api/api.ts Parse sendMessage response JSON; throw Error when ret !== 0; gracefully degrade on non-JSON responses
src/messaging/process-message.ts Accept deliveryCtx?.kind in deliver; truncate non-error tool results to 120 chars

linyu.wang and others added 2 commits May 28, 2026 14:45
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant