Skip to content

[Weixin] ret=-3 cron push silently fails after tokenless retry (regression from v0.14) #35062

Open

Description

@drzeast-png

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

  1. Configure a cron job delivering to Weixin (e.g., 0 7 * * *)
  2. Ensure no user message has been sent to the bot for several hours
  3. Wait for the cron job to fire at the scheduled time
  4. 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", ...)
    continue

The 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

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

  1. added
    type/bugSomething isn't working
    P2Medium — degraded but workaround exists
    comp/gatewayGateway runner, session dispatch, delivery
    comp/cronCron scheduler and job management
    on May 30, 2026
  2. alt-glitch commented on May 30, 2026

    @alt-glitch

    Related: #17228 (same family, ret=-2), #18100 (errmsg=None variant still open), #17432 (merged partial fix). PR #35066 targets this issue directly.

  3. drzeast-png commented on May 30, 2026

    @drzeast-png
    Author

    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:

    1. Live adapter (gateway's established connection): 5 retries, all fail with ret=-3 errcode=None errmsg=unknown error
    2. Standalone fallback (new connection): 5 retries, all also fail with same ret=-3

    Both paths fail identically regardless of whether a context_token is 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=-3

    iLink 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 cached context_token blocks 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:

    1. iLink to support bot-initiated pushes to inactive chats (platform change, out of our control)
    2. A workaround on the adapter side — e.g., before sending a cron push, send a dummy inbound message to 'wake up' the session
    3. Accept that cron-triggered pushes only work when the user has recently interacted with the bot, and fall back to local storage + deferred delivery on next user message

    Happy to help test if a more comprehensive fix is developed.

  4. drzeast-png commented on May 30, 2026

    @drzeast-png
    Author

    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.

  5. GottZ commented on Aug 3, 2026

    @GottZ

    This was generated by AI during triage.

    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 reported ret=-3 platform behavior.

    Related pull requests

    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 limited path 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 outbound prepare 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=-3 test must be replaced with a recognized ret=-2, errmsg="unknown error" or errcode=-14 case, and the PR must state that field evidence leaves the platform-level ret=-3 failure 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, and ret=-3 experiments 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"
    
    Loading

    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.

  6. amandawu211-beep commented on Aug 11, 2026

    @amandawu211-beep

    +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.

  7. added
    sweeper:risk-session-stateSweeper risk: may lose/corrupt/mis-associate session or context state
    sweeper:risk-message-deliverySweeper risk: may drop, duplicate, misroute, or suppress messages
    on Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/cronCron scheduler and job managementcomp/gatewayGateway runner, session dispatch, deliveryplatform/wecomWeCom / WeChat Work adaptersweeper:risk-message-deliverySweeper risk: may drop, duplicate, misroute, or suppress messagessweeper:risk-session-stateSweeper risk: may lose/corrupt/mis-associate session or context statetype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions