Skip to content

fix(weixin): add retry mechanism for sendMessage ret=-2 errors#371

Open
chenhg5 wants to merge 1 commit intomainfrom
fix/issue-365-weixin-sendmessage-retry
Open

fix(weixin): add retry mechanism for sendMessage ret=-2 errors#371
chenhg5 wants to merge 1 commit intomainfrom
fix/issue-365-weixin-sendmessage-retry

Conversation

@chenhg5
Copy link
Copy Markdown
Owner

@chenhg5 chenhg5 commented Mar 29, 2026

Summary

  • Add retry mechanism (3 attempts) for sendMessage when ilink API returns ret=-2
  • Refresh context_token between retries to handle expired tokens
  • Add 100ms delay between message chunks to avoid rate limiting
  • Add 500ms delay between retries for temporary failures
  • Add more detailed logging including content_len for debugging

Root Cause

When ilink API returns ret=-2, it typically indicates:

  • context_token expired or invalid
  • temporary rate limiting

Previously, cc-connect would immediately fail without retry, causing partial message delivery.

Changes

  • weixin.go: Add sendChunkWithRetry with retry logic and chunk delay
  • media_outbound.go: Add sendSingleItemWithRetry for media messages
  • client.go: Add content_len to error logging for better debugging

Test plan

  • go build ./... passes
  • go vet ./... passes
  • go test ./platform/weixin/... passes
  • Manual test: send long messages that get split into chunks
  • Manual test: verify retry works when context_token expires

🤖 Generated with Claude Code

Fixes #365

When ilink API returns ret=-2, it typically indicates:
- context_token expired or invalid
- temporary rate limiting

This fix adds:
- Retry mechanism (3 attempts) for sendMessage when ret=-2 is returned
- context_token refresh between retries
- Delay between message chunks (100ms) to avoid rate limiting
- Delay between retries (500ms) for temporary failures
- More detailed logging including content_len for debugging

Fixes #365

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chenhg5
Copy link
Copy Markdown
Owner Author

chenhg5 commented Mar 30, 2026

QA review: Ready to merge

Well-structured retry mechanism for weixin API failures.

Review summary:

Minor observation: Retry logic duplicates between sendChunkWithRetry and sendSingleItemWithRetry - could consider extracting to a helper in a follow-up PR, but not a blocker.

Good fix for a real production issue.

@chenhg5
Copy link
Copy Markdown
Owner Author

chenhg5 commented Apr 1, 2026

LGTM! Solid retry mechanism for weixin sendMessage failures.

✅ Implementation:

  • sendChunkWithRetry and sendSingleItemWithRetry handle ret=-2 errors with 3 retries
  • Context token refresh between retries
  • 100ms chunk delay and 500ms retry delay for rate limiting

✅ Root cause handling: ret=-2 typically indicates expired context_token or rate limiting - retry with fresh token is the correct approach.

✅ Logging: Added content_len for debugging which is helpful.

✅ CI: All checks pass.

Ready for merge.

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.

[Bug] 个人微信(weixin)场景下回复已生成但 sendMessage 被拒,导致微信侧回复不完整/后半段丢失

2 participants