Skip to content

[Bug]: Feishu plugin: token invalid error (99991663) does not trigger automatic retry — requires manual gateway restart #97287

Description

@xueshenglin

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

标题

Feishu plugin: token invalid error (99991663) does not trigger automatic retry — requires manual gateway restart


问题描述 (Bug Description)

When the Feishu plugin's tenant_access_token becomes invalid (e.g. expires, clock drift, or server-side revocation), the plugin cannot send messages. Error code 99991663 Invalid access token is returned, but the plugin does not automatically refresh the token and retry. Users must manually run openclaw channels login + openclaw gateway restart to recover.

现象 (Symptoms)

  • Feishu WebSocket long connection remains active (message receiving works)
  • All outgoing messages fail with feishu[boob] final reply failed and 99991663 Invalid access token
  • Automatic recovery does not happen; manual intervention is required

根本原因 (Root Cause)

  1. The plugin caches tenant_access_token in a tokenCache Map with an expiresAt timestamp
  2. getToken() has a proactive refresh mechanism (refreshes 60 seconds before expiry)
  3. However, when the cached token becomes invalid unexpectedly (clock drift between VM and host, Feishu server-side revocation, etc.), there is no passive retry mechanism
  4. requestFeishuApi() only retries on rate-limit errors (429, 11232, 230020). Error code 99991663 is not handled → thrown immediately

影响范围 (Affected Versions)

  • OpenClaw 2026.6.10
  • Feishu plugin 2026.6.10
  • Likely all versions using the same token-caching pattern

修复建议 (Proposed Fix)

In requestFeishuApi(), add handling for token-invalid errors:

  1. Detect error codes 99991663 and 99991664
  2. Call a token-cache invalidation function (clears the cached token)
  3. Retry the request once (next call to getToken() will fetch a fresh token)
function isTokenInvalidError(error) {
    const code = error?.response?.data?.code;
    return code === 99991663 || code === 99991664;
}

async function requestFeishuApi(request, errorPrefix, options = {}) {
    // ... existing retry loop ...
    catch (error) {
        const isRateLimit = getFeishuSendRateLimitCode(error) !== void 0;
        const isTokenInvalid = isTokenInvalidError(error);
        if (isTokenInvalid && attempt === 0) {
            lastTokenInvalidError = error;
            __invalidateTokenCache();  // clear cached token
            continue;                   // retry once
        }
        if (!(attempt < FEISHU_SEND_MAX_RETRIES && isRateLimit)) {
            throw createFeishuApiError(error, errorPrefix, options);
        }
    }
}


### Steps to reproduce

---

## 复现步骤 (Steps to Reproduce)

1. Deploy OpenClaw on a VM with clock drift (VM clock behind real time)
2. Wait for the Feishu `tenant_access_token` to expire (~2 hours)
3. Send a message via Feishu
4. Message fails with `99991663 Invalid access token`
5. No auto-recovery occurs

### Expected behavior

The Feishu plugin should automatically refresh the invalid token and retry sending the message when error code 99991663 (Invalid access token) is received. No manual intervention (channels login + gateway restart) should be required.

### Actual behavior

When the cached tenant_access_token becomes invalid, all outgoing messages fail with error code 99991663 Invalid access token. The plugin does not automatically refresh the token. Manual intervention via 'openclaw channels login' and 'openclaw gateway restart' is required to recover.

### OpenClaw version

OpenClaw 2026.6.10 (aa69b12)

### Operating system

Ubuntu 24.4

### Install method

_No response_

### Model

MiniMax2.7

### Provider / routing chain

openclaw- minimax-token-plan

### Additional provider/model setup details

_No response_

### Logs, screenshots, and evidence

```shell

Impact and severity

No response

Additional information

No response

Activity

  1. clawsweeper commented on Jun 27, 2026

    @clawsweeper
    Contributor

    Codex review: this still needs some work.

    Summary
    Current main still lacks rejected-token recovery, and an open maintainer-owned closing PR owns the repair.

    Reproducibility: Current CardKit source proves that a still-unexpired rejected token remains cached and subsequent operations can reuse it without recovery; no live Feishu reproduction was run.

    Root-cause cluster
    Relationship: canonical
    Canonical: #97287
    Summary: This issue remains the canonical rejected-token recovery report, with an open maintainer-owned candidate repair.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Next step
    Resolve conflicts and complete the authenticated SDK/CardKit recovery proof for #122193 before landing it.

    Review details

    Best possible solution:

    Land the existing repair after conflict resolution and authenticated proof establish bounded recovery at both token owners.

    Do we have a high-confidence way to reproduce the issue?

    Current CardKit source proves that a still-unexpired rejected token remains cached and subsequent operations can reuse it without recovery; no live Feishu reproduction was run.

    Is this the best way to solve the issue?

    Recovery belongs at the SDK and CardKit token owners, as the existing PR proposes, rather than clearing an unrelated global cache in the message retry wrapper.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • Authenticated recovery remains unproven under the existing PR's explicit landing hold.
    • The repair branch conflicts with current main and needs integration that preserves current request-authority checks.
    • The requested treatment of 99991664 needs separate error-contract justification; the existing repair targets 99991663.

    Codex review notes: model internal, reasoning medium; reviewed against 5d36e6431693.

    Label changes

    Label changes:

    No label changes.

    Label justifications:

    • P1: Rejected cached credentials can interrupt an established Feishu reply workflow until scheduled refresh or manual recovery.
    • impact:message-loss: Outgoing replies and streaming-card writes can fail while inbound connectivity remains healthy.
    • impact:auth-provider: The failure concerns recovery from invalid cached tenant access tokens.
    Evidence reviewed

    What I checked:

    • Current CardKit defect: getToken returns a cached token until its refresh threshold; requestCardKit dispatches once and releases the response without invalidating a rejected token or replaying the operation. (extensions/feishu/src/streaming-card.ts:107, 5d36e6431693)
    • Message retry boundary: requestFeishuApi handles rate limits and selected transient failures but has no token-invalid recovery; normal sends reach it through sendFeishuMessage. (extensions/feishu/src/comment-shared.ts:116, 5d36e6431693)
    • SDK ownership distinction: createFeishuClient caches Lark clients by account and supplies a transport that dispatches requests without plugin-owned token recovery; SDK-internal recovery was not independently verified. (extensions/feishu/src/client.ts:420, 5d36e6431693)
    • Open closing PR blocks cleanup: fix(feishu): recover invalid tenant tokens #122193 explicitly closes this issue and remains open, draft, unmerged, and conflicted. Its body and vincentkoc's discussion retain authenticated Feishu/CardKit proof as an explicit pre-landing hold. (cdae50296233)
    • Reporter corroboration: wzg0911 reports the same failure and describes a local passive-refresh workaround; that discussion is corroboration rather than verified live proof.
    • Feature history: The original CardKit streaming addition introduced the expiry-based token cache. Subsequent streaming work includes vincentkoc's final-delivery changes and extensive transport and lifecycle refactoring by steipete. Local historical blob reads failed; REST history and the introduction patch supplied attribution evidence. (extensions/feishu/src/streaming-card.ts, 65be9ccf63f3)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge; those execution lanes are retired.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

    Reviewed November 8, 2026, 2:08 PM ET / 19:08 UTC.

  2. added
    P2Normal backlog priority with limited blast radius.
    impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.
    impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.
    no-staleExclude from stale automation
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    on Jun 27, 2026
  3. 62 remaining items

  4. added
    clawsweeper:intake:bugPreliminary submission classification; full source review pending.
    and removed
    clawsweeper:intake:bugPreliminary submission classification; full source review pending.
    on Oct 16, 2026
  5. added
    clawsweeper:intake:bugPreliminary submission classification; full source review pending.
    and removed
    clawsweeper:intake:bugPreliminary submission classification; full source review pending.
    on Oct 27, 2026
  6. added
    clawsweeper:intake:bugPreliminary submission classification; full source review pending.
    and removed
    clawsweeper:intake:bugPreliminary submission classification; full source review pending.
    on Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority user-facing bug, regression, or broken workflow.bugSomething isn't workingclawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions