Repository navigation
Description
Bug Description
Weixin cron-initiated push silently fails with ret=-3 errcode=None errmsg=unknown error since upgrading from v0.14.
Same behavior was working in v0.14. After upgrading to v0.15, all cron jobs configured with deliver: weixin fail to deliver, even though content generation completes successfully and interactive replies work fine.
Steps to Reproduce
- Configure a cron job delivering to Weixin (e.g.,
0 7 * * *) - Ensure no user message has been sent to the bot for several hours
- Wait for the cron job to fire at the scheduled time
- Observe: content is generated but delivery fails with
ret=-3 errcode=None errmsg=unknown error
Actual Behavior
From gateway.log:
[Weixin] send chunk failed to=... attempt=1/5, retrying in 1.00s: iLink sendmessage error: ret=-3 errcode=None errmsg=unknown error
[Weixin] send chunk failed to=... attempt=2/5, retrying in 2.00s: iLink sendmessage error: ret=-3 errcode=None errmsg=unknown error
...
[Weixin] send failed to=...: iLink sendmessage error: ret=-3 errcode=None errmsg=unknown error
Note: attempt 1 correctly identifies stale session and strips token. Attempt 2 fails immediately without a session expired warning log — suggesting the retry path is bypassed.
Expected Behavior
The message should be delivered via tokenless fallback. iLink accepts tokenless sends as a degraded fallback even when the session has expired. At minimum, the root cause should be identifiable from logs.
Root Cause Analysis
In v0.14, the send_without_context_token_on_session_expiry fix (commit e105b7ac9) worked because it treated errcode=-14 as the signal and the send path tried tokenless as primary fallback.
In v0.15, the new _is_stale_session_ret helper (PR #17432) extended detection to include ret=-2 and ret=-3 with errmsg="unknown error". However, there is a logic gap in gateway/platforms/weixin.py around L1579:
if is_session_expired and not retried_without_token and context_token:
retried_without_token = True
context_token = None
self._token_store._cache.pop(...)
logger.warning("[%s] session expired for %s; retrying without context_token", ...)
continueThe tokenless retry only fires if context_token already exists. During cron-initiated pushes to a long-inactive chat, iLink may never have allocated a valid context_token in the first place. The condition context_token (truthy) is False, so the retry branch never executes and the code falls through to the generic error path — silently dropping the message.
The and context_token guard is too strict. Removing it lets the adapter attempt a tokenless send regardless of whether a cached token existed.
Related Issues
- weixin: cron-initiated push fails with iLink ret=-2 when context_token is stale (not recognized as session-expired) #17228 —
ret=-2stale session (fixed in PR fix(weixin): recognize ret=-2 errmsg='unknown error' as stale-session signal (#17228) #17432) - weixin: ret=-2 with empty errmsg also indicates stale context_token (follow-up to #17228) #18100 —
ret=-2with empty errmsg (follow-up fix) - iLink WeChat sendmessage rate limiting (ret=-2) with no built-in retry or backoff #21011 — iLink rate limiting with no retry
- WeChat (iLink) rate-limit retry storm causes gateway OOM and SIGKILL — no circuit breaker #26828 — Gateway OOM from retry storm (downstream)
Environment
- OS: macOS 26.5
- Hermes: v0.15.2 (2026.5.29) / commit
689ef5e - Python: 3.11.14
- Platform: Weixin iLink API
Suggested Fix
Remove the and context_token guard so the tokenless retry fires regardless of whether a cached token exists:
# Before (too strict):
if is_session_expired and not retried_without_token and context_token:
# After (correct):
if is_session_expired and not retried_without_token:
Activity
alt-glitch commentedon May 30, 2026
Related: #17228 (same family, ret=-2), #18100 (errmsg=None variant still open), #17432 (merged partial fix). PR #35066 targets this issue directly.
drzeast-png commentedon May 30, 2026
Follow-up: Fix is necessary but not sufficient
We tested PR #35066's proposed fix (removing
and context_token) locally on our instance, and while it's a correct change, it does not resolve the ret=-3 cron push failure.What we observed
Cron job runs at scheduled time → content generated → delivery attempted:
ret=-3 errcode=None errmsg=unknown errorBoth paths fail identically regardless of whether a
context_tokenis present or not. The tokenless retry fires correctly but iLink still returns ret=-3.The real issue is deeper
Reviewing the gateway log, we observed:
11:00:21→ Inbound message from user received successfully (via poll loop)11:00:36→ Outbound push (cron delivery) to the same chat fails with ret=-3iLink accepts replies to user-initiated messages, but rejects bot-initiated pushes to chats with no recent user activity. This is a platform-level restriction, not a token/code issue.
What this means for the fix
PR #35066 (removing
and context_token) is still a correct improvement — it handles the edge case where a stale cachedcontext_tokenblocks the tokenless fallback. But it does not fully resolve the ret=-3 cron push failure.For full cron push reliability, we would need one of:
Happy to help test if a more comprehensive fix is developed.
drzeast-png commentedon May 30, 2026
Hi team, we're still seeing ret=-3 on cron push with the current code. Our testing shows the tokenless retry in PR #35066 is a correct improvement but doesn't fully resolve the issue—iLink appears to reject bot-initiated pushes to chats without recent user activity regardless of token state. Any update on whether this will be addressed upstream? Happy to help test a more comprehensive fix if needed.
GottZ commentedon Aug 3, 2026
Summary
Eighteen PRs address or reference this Weixin reliability cluster, spanning stale-context classification, tokenless retry mechanics, genuine rate limiting, zombie polling, and
ret=-3. For #35062 specifically, #35066 is the best existing fix but only removes the no-token guard; field evidence shows tokenless retry does not fully resolve the reportedret=-3platform behavior.Related pull requests
unverified— (+15/-1) — incorporated reference: introducedret=-2, errmsg="unknown error"stale-session detection for polling and sends, and remains relevant after closure because it was cherry-picked with attribution into fix(weixin): recognize ret=-2 errmsg='unknown error' as stale-session signal (#17228) #17432 ase9b96fd05.unverified— (+45/-1) — merged reference implementation: landed fix: recognize ret=-2 as stale-session signal in Weixin adapter (#17228) #17287's classifier and seven truth-table tests, establishing the recovery baseline but not covering [Weixin] ret=-3 cron push silently fails after tokenless retry (regression from v0.14) #35062'sret=-3cause.unverified— (+16/-7) — keep open with a salvage path: its empty/None classifier addresses a sibling-2variant, while the keep_open review requires normalizing alternatemsgcontent and adding outbound and genuine-rate-limit regressions.unverified— (+27/-8) — duplicate of fix(weixin): treat empty rate-limit message as stale session #18105, closed: it implements the same empty/None classification and remains relevant only as corroborating tests and field evidence.unverified— (+34/-1709) — keep open only for focused salvage: its token-stripping idea is adjacent, but the maintainer-bot keep_open verdict requires removing twelve unrelated workflow deletions, reordering recovery before the circuit breaker, and adding current-main tests.unverified— (+27/-11) — keep open with a separate reconnect salvage path: propagating poll timeouts does not addressret=-3, and its keep_open review requires an actual fatal/reconnect transition plus replacement of contradictory sentinel coverage.unverified— (+1/-1) — rejected polling approach, closed: the contributor decision documents idle long-poll timeouts as expected, so mapping every timeout toret=-3would create false failures and must not be revived.unverified— (+8/-3) — closed genuine-throttling experiment: it lengthens exponential backoff but does not change stale-token orret=-3classification, remaining relevant only as an author-deferred alternative to fix(weixin): exponential backoff for iLink rate limiting #31132.unverified— (+59/-10) — keep open with a separate salvage path: retry hints and exponential backoff target genuine throttling, while the keep_open review requires circuit reconciliation, retained attachment-path filters, and deterministic tests.unverified— (+4/-2) — duplicate of fix(weixin): propagate asyncio.TimeoutError from _get_updates to prevent zombie connections #23529, closed: its synthetic timeout error and empty-message classifier do not rebuild the poll session or address [Weixin] ret=-3 cron push silently fails after tokenless retry (regression from v0.14) #35062's send failure.best fix— (+65/-1) — best existing fix, but partial: removingand context_tokenvalidly enables a tokenless attempt with no cached token, while its keep_open review requires replacing the unsupportedret=-3fixture and field tests show the reportedret=-3push can still fail tokenless.unverified— (+2927/-29) — closed mixed superset: the author accepted the keep_open review's classification conflict, configuration-policy violation, and circuit incompatibility, so only focused timeout, typing, or rate-limit pieces should be split out.best fix— (+45/-34) — closedret=-3partial fix: it adds-3classification and removes the token guard but mixes unrelated launchd and gateway self-stop changes, while field evidence disputes that tokenless retry solves the platform behavior.unverified— (+38/-8) — keep open with a focused sibling salvage path: its reviewed classifier covers normalizedrate limited, empty/None, andunknown error-2variants with tests, but it does not recognizeret=-3or complete [Weixin] ret=-3 cron push silently fails after tokenless retry (regression from v0.14) #35062.unverified— (+20/-5) — close as duplicate of fix(weixin): treat 'rate limited' errmsg as stale-session signal in _is_stale_session_ret #35714 despite the keep_open review on fix(weixin): detect stale context_token when iLink returns "rate limited" (#35949) #35983: the diff adds the samerate limitedclassifier through a shared helper that can also send polling into a 600-second session-expiry sleep, so preserve only its requested send/poll regression idea.unverified— (+45/-5) — close as duplicate of fix(weixin): treat 'rate limited' errmsg as stale-session signal in _is_stale_session_ret #35714 despite the keep_open review on fix(platforms): treat ret=-2 as stale session when using context_token #62386: its diff treats every token-bearing-2as stale and thereby bypasses documented genuine-frequency-limit handling, so retain only useful context-aware tests.unverified— (+63/-13) — closed overlapping empty-message fix: it duplicates fix(weixin): treat empty rate-limit message as stale session #18105/fix(weixin): treat 'rate limited' errmsg as stale-session signal in _is_stale_session_ret #35714 classification but remains relevant for durable token-deletion and end-to-end recovery tests, superseded mechanically by fix(gateway): recover from stale Weixin context tokens #74572's compare-and-delete design.unrelated— (+222/-18) — keep open with a salvage path consistent with its high-salvageability verdict: it hardens outboundprepare failedrecovery, token persistence, locking, and retry accounting, but its diff does not classify [Weixin] ret=-3 cron push silently fails after tokenless retry (regression from v0.14) #35062'sret=-3and is therefore a separate fix.Duplicates
#17287 was incorporated into #17432; #20797 and closed #73908 overlap #18105's empty/None variant, while #35983 and #62386 duplicate the earlier #35714
rate limitedpath with weaker scoping. #34216 overlaps #23529 on polling recovery, #27234 overlaps #31132 on genuine throttling, and #35283 bundles several groups but was closed for focused rework; #74572 is distinct because it targets outboundprepare failed.Suggested consolidation
Author action: rebase #35066 onto main, or split out the part that can merge; it is the best existing fix for #35062, but the unsupported
ret=-3test must be replaced with a recognizedret=-2, errmsg="unknown error"orerrcode=-14case, and the PR must state that field evidence leaves the platform-levelret=-3failure unresolved. Keep #35714 and #74572 open for their distinct salvage paths, close #35983 and #62386 as duplicates of #35714, and leave the closed polling, mixed-superset, andret=-3experiments closed rather than presenting any of them as a complete fix.Complex graph
flowchart TD classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937 classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151 classDef best stroke-width:3px,stroke:#b45309 classDef target stroke-width:3px,stroke:#4338ca I17228(["issue #17228 (closed)"]) I18100(["issue #18100 (open)"]) I23523(["issue #23523 (open)"]) I31131(["issue #31131 (open)"]) I35062(["issue #35062 (open)"]) I35713(["issue #35713 (open)"]) I62383(["issue #62383 (open)"]) P22661["PR #22661 (open)"] P35066["PR #35066 (open)"] P35666["PR #35666 (closed)"] subgraph Dup17287 ["PRs duplicating each other"] P17287["PR #17287 (closed)"] P17432["PR #17432 (merged)"] end subgraph Dup18105 ["PRs duplicating each other"] P18105["PR #18105 (open)"] P20797["PR #20797 (closed)"] end subgraph Dup23529 ["PRs duplicating each other"] P23529["PR #23529 (open)"] P23534["PR #23534 (closed)"] P34216["PR #34216 (closed)"] end subgraph Dup27234 ["PRs duplicating each other"] P27234["PR #27234 (closed)"] P31132["PR #31132 (open)"] end More["+6 more PRs not shown"] MoreI(["+2 more issues not shown"]) P17287 -.->|unverified| I35062 P17432 -.->|unverified| I35062 P18105 -.->|unverified| I35062 P20797 -.->|unverified| I35062 P22661 -.->|unverified| I35062 P23529 -.->|unverified| I35062 P23534 -.->|unverified| I35062 P27234 -.->|unverified| I35062 P31132 -.->|unverified| I35062 P34216 -.->|unverified| I35062 P35066 -->|best fix| I35062 P35666 -->|best fix| I35062 P17287 -->|fixes| I17228 P17432 -->|best fix| I17228 P22661 -.->|partial| I17228 P18105 -.->|partial| I18100 P20797 -.->|partial| I18100 P22661 -.->|partial| I18100 P23529 -.->|partial| I23523 P34216 -.->|partial| I23523 P27234 -->|best fix| I31131 P31132 -->|best fix| I31131 P22661 -.->|partial| I35713 P22661 -.->|partial| I62383 class I17228 closed class I18100 open class I23523 open class I31131 open class I35062 open class I35713 open class I62383 open class I35062 target class P17287 closed class P17432 merged class P18105 open class P20797 closed class P22661 open class P23529 open class P23534 closed class P27234 closed class P31132 open class P34216 closed class P35066 open class P35666 closed class P17432 best class P27234 best class P31132 best class P35066 best class P35666 best class More closed class MoreI closed click I17228 "https://github.com/NousResearch/hermes-agent/issues/17228" click I18100 "https://github.com/NousResearch/hermes-agent/issues/18100" click I23523 "https://github.com/NousResearch/hermes-agent/issues/23523" click I31131 "https://github.com/NousResearch/hermes-agent/issues/31131" click I35062 "https://github.com/NousResearch/hermes-agent/issues/35062" click I35713 "https://github.com/NousResearch/hermes-agent/issues/35713" click I62383 "https://github.com/NousResearch/hermes-agent/issues/62383" click P17287 "https://github.com/NousResearch/hermes-agent/pull/17287" click P17432 "https://github.com/NousResearch/hermes-agent/pull/17432" click P18105 "https://github.com/NousResearch/hermes-agent/pull/18105" click P20797 "https://github.com/NousResearch/hermes-agent/pull/20797" click P22661 "https://github.com/NousResearch/hermes-agent/pull/22661" click P23529 "https://github.com/NousResearch/hermes-agent/pull/23529" click P23534 "https://github.com/NousResearch/hermes-agent/pull/23534" click P27234 "https://github.com/NousResearch/hermes-agent/pull/27234" click P31132 "https://github.com/NousResearch/hermes-agent/pull/31132" click P34216 "https://github.com/NousResearch/hermes-agent/pull/34216" click P35066 "https://github.com/NousResearch/hermes-agent/pull/35066" click P35666 "https://github.com/NousResearch/hermes-agent/pull/35666"Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed (state tag in the node label).
Cross-PR triage: Reviewed 18 pull requests and 9 issues in this complex. Each diff was read against this issue; Assessment working set: 277 kB of PR diffs, 67 kB of issue/PR text, 38 kB of discussion (51 comments), 49 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.
amandawu211-beep commentedon Aug 11, 2026
+1, hitting same on 0.20.0. errmsg='invalid arguments' (not 'prepare failed'). 5 payload variants all return ret=-2: from_user_id='', bot_id, target, token_prefix, +ilink_user_id=me. 7 cron jobs (9:00/12:00/17:00/21:00 + 7:01/22:00 + Mon 9:30) all affected. getUpdates timeout, sendmessage ret=-2. Tokenless retry already in line 1818 but doesn't help. SOHO平台, Hong Kong/BJ TZ.