Skip to content

fix(api): make sendMessage failures actionable on empty errmsg - #8

Merged
NewFuture merged 1 commit into
mainfrom
upstream/pr-230-sendmessage-actionable-error
Jul 23, 2026
Merged

NewFuture merged 1 commit into
mainfrom
upstream/pr-230-sendmessage-actionable-error

Conversation

@NewFuture

Copy link
Copy Markdown
Owner

Upstream source

Exact mirror of Tencent/openclaw-weixin#230 by @draix.

  • Original branch: draix/openclaw-weixin:fix/sendmessage-actionable-error
  • Original base: cef0bfc390393f716903e16d50408118047f87e0
  • Preserved head: da9efec952286a63df432808ceb6323fd67fc751
  • Current target base at mirror creation: 4feec89ff2b40c93578a96f6325bdd536ad9d38e
  • Commit history and authorship are unchanged.

Upstream intent

Make sendMessage failures actionable when the backend returns a nonzero ret with an empty errmsg.

Local review status

This exact mirror merges cleanly into the current target and its API tests, typecheck, and build pass, but it remains a Draft until these findings are addressed:

  • blank-error failures are classified as token expiry solely from context_token presence, although the same return code can represent rate limits, media failures, or unrelated backend errors;
  • a non-string errmsg reaches .trim() and throws a TypeError, masking the useful ret value.

The follow-up should preserve ret, type-guard backend fields, and provide neutral guidance when the cause is ambiguous. Original discussion remains on the upstream PR.

When `sendMessage` fails with a non-zero `ret` the server often returns an
empty `errmsg` (commonly `ret=-2`), so the thrown error was
`sendMessage ret=-2 errmsg=(none)` — impossible to act on. The most common
cause on agent-initiated outbound delivery (cron reminders, scheduled
digests) is an expired or missing `context_token`: it is only refreshed by a
recent inbound message from the recipient, so after a long idle period the
bot cannot send until the user messages it again.

Add `describeSendMessageFailure`, which passes through a real server errmsg
but, when it is empty, reports the likely cause and whether a `context_token`
was included in the request. No behavior change on success or when the server
provides an error detail.

Refreshing the token automatically is not possible from the bot side (it
depends on inbound user activity), so this focuses on diagnosability.

Fixes #225
@NewFuture
NewFuture marked this pull request as ready for review July 23, 2026 02:10
@NewFuture
NewFuture merged commit bda416c into main Jul 23, 2026
@NewFuture
NewFuture deleted the upstream/pr-230-sendmessage-actionable-error branch July 24, 2026 01:11
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.

2 participants