openclaw - 💡(How to fix) Fix Bug: WeChat context_token not loaded in isolated sessions and Gateway CLI [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#63172Fetched 2026-04-09 07:57:31
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
commented ×1

Root Cause

  • restoreContextTokens() is only called during Gateway daemon startup (when startAccount is called)
  • Gateway CLI and isolated sessions spawn NEW processes that do NOT call restoreContextTokens()
  • The context_token file exists but is never loaded into memory for these new processes

Fix Action

Fix / Workaround

Temporary Workaround for Users

Code Example

restoreContextTokens: restored 1 tokens for account=b66e0b53888f-im-bot

---

[runtime] setWeixinRuntime called, runtime set successfully
sendWeixinOutbound: contextToken missing for to=o9cq8033CGRzv8xhE8IUzxhipFYs@im.wechat

---

// In send.ts or channel.ts, before sending:
if (!getContextToken(accountId, userId)) {
  restoreContextTokens(accountId);
}
RAW_BUFFERClick to expand / collapse

Bug Report: WeChat context_token not loaded in isolated sessions and Gateway CLI

Problem Summary

WeChat messages fail to send when using:

  1. Gateway CLI (openclaw message send --channel openclaw-weixin)
  2. Isolated sessions (cron jobs with sessionTarget: "isolated")

Both show: contextToken missing for to=<user_id>, sending without context

Root Cause

  • restoreContextTokens() is only called during Gateway daemon startup (when startAccount is called)
  • Gateway CLI and isolated sessions spawn NEW processes that do NOT call restoreContextTokens()
  • The context_token file exists but is never loaded into memory for these new processes

Evidence from Logs

Gateway daemon (22:11:44):

restoreContextTokens: restored 1 tokens for account=b66e0b53888f-im-bot

Gateway CLI (06:51:53):

[runtime] setWeixinRuntime called, runtime set successfully
sendWeixinOutbound: contextToken missing for [email protected]

The CLI sets up the runtime but never loads context_token from file.

Verification

ComponentProcess Typecontext_tokenResult
Gateway daemonLong-running✅ Loaded at startup✅ Send success
Gateway CLINew process❌ Not loaded❌ Send fail
Isolated sessionNew process❌ Not loaded❌ Send fail

Suggested Fix

Option 1: Call restoreContextTokens() when isolated session sends WeChat message

// In send.ts or channel.ts, before sending:
if (!getContextToken(accountId, userId)) {
  restoreContextTokens(accountId);
}

Option 2: Load context_token file when setWeixinRuntime is called in CLI/isolated sessions

Temporary Workaround for Users

  • Send a message to the WeChat bot first, which triggers Gateway daemon to get a fresh context_token
  • Gateway daemon auto-reply will work correctly
  • But isolated sessions (cron jobs) still cannot send WeChat messages

Files Affected

  • openclaw-weixin/src/messaging/inbound.js - restoreContextTokens() function
  • openclaw-weixin/src/messaging/send.ts - message sending logic
  • openclaw-weixin/src/channel.ts - channel initialization

Context Token File Path

~/.openclaw/openclaw-weixin/accounts/<account-id>.context-tokens.json

This file persists correctly. The issue is purely that new processes don't read it.

Impact

This bug prevents:

  • Cron jobs from sending WeChat notifications
  • CLI-based WeChat messaging from working

Only Gateway daemon auto-replies (triggered by user inbound messages) work correctly.

Steps to Reproduce

  1. Set up WeChat channel with openclaw-weixin plugin
  2. Start Gateway daemon: openclaw gateway start
  3. Send a message to WeChat bot (to get context_token)
  4. Try sending via CLI: openclaw message send --channel openclaw-weixin --target <user_id> --message "test"
  5. Check logs: grep contextToken /tmp/openclaw/openclaw-$(date +%Y-%m-%d).log
  6. You will see: contextToken missing for to=<user_id>, sending without context

extent analysis

TL;DR

Call restoreContextTokens() before sending WeChat messages in isolated sessions and Gateway CLI to load the context token.

Guidance

  • Identify the processes that spawn new instances without calling restoreContextTokens(), such as Gateway CLI and isolated sessions.
  • Modify the code to call restoreContextTokens() before sending WeChat messages in these processes, as suggested in the send.ts or channel.ts files.
  • Verify that the context token is loaded correctly by checking the logs for the restoreContextTokens message.
  • Consider implementing a temporary workaround, such as sending a message to the WeChat bot first, to trigger the Gateway daemon to get a fresh context token.

Example

// In send.ts or channel.ts, before sending:
if (!getContextToken(accountId, userId)) {
  restoreContextTokens(accountId);
}

Notes

The issue is specific to new processes spawned by Gateway CLI and isolated sessions, which do not call restoreContextTokens() to load the context token. The suggested fix and temporary workaround should address this issue, but may require further testing and verification.

Recommendation

Apply workaround: Call restoreContextTokens() before sending WeChat messages in isolated sessions and Gateway CLI. This should resolve the issue of missing context tokens in new processes.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING