Skip to content

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

Open
draix wants to merge 1 commit into
Tencent:mainfrom
draix:fix/sendmessage-actionable-error
Open

draix wants to merge 1 commit into
Tencent:mainfrom
draix:fix/sendmessage-actionable-error

Conversation

@draix

@draix draix commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

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. On agent-initiated outbound delivery (cron reminders, scheduled digests) the usual cause is an expired or missing context_token, which is only refreshed by a recent inbound message from the recipient; after a long idle period the bot cannot send until the user messages it again.

Fix

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.

Tests

Added end-to-end and unit tests in src/api/api.test.ts; they fail before this change and pass after. Full suite is 402/402 green and typecheck is clean.

Fixes #225

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 Tencent#225
@NewFuture

Copy link
Copy Markdown

Thank you for this diagnostics improvement. The original patch commit has been carried into and released by the current community-maintained openclaw-weixin v3.0.1 with its history preserved:

A non-zero sendMessage result now preserves a real server errmsg; when it is empty, the error explains whether a context_token was included and whether it may be missing or expired. As described in this PR, this improves diagnosis only—it does not automatically refresh or retry an expired token.

One-line in-place replacement/upgrade (requires OpenClaw >=2026.6.1; do not uninstall the official package first):

openclaw plugins install npm:openclaw-weixin --force

The plugin/channel ID and state paths are unchanged, so this normally preserves existing configuration and login state.

For clarity: the linked repository/package is a community-maintained distribution, not the official Tencent/Weixin release. This upstream Tencent PR is still open; this comment only records that its patch has shipped in the community release.

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.

sendMessage returns ret=-2 with empty errmsg when context_token expires during agent-initiated outbound delivery

2 participants