openclaw - 💡(How to fix) Fix [Bug]: Feishu embedded agent returns HTTP 401 "Invalid token" to user instead of retrying with refreshed token [1 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#56197Fetched 2026-04-08 01:43:45
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
labeled ×2

Feishu embedded agent returns raw HTTP 401 "Invalid token" error to user instead of retrying with refreshed token

Error Message

Feishu embedded agent returns raw HTTP 401 "Invalid token" error to user instead of retrying with refreshed token The embedded agent should detect the 401, trigger a token refresh, and retry the request. At minimum, it should not surface the raw HTTP error message to the end user. The 401 error is passed directly as the reply text to the Feishu user. Logs show the token refresh (config reload) occurs after the error has already been returned. The webchat session recovers after refresh, but the Feishu embedded agent continues to fail intermittently on subsequent requests. [agent/embedded] embedded run agent end: isError=true error=HTTP 401: "Invalid token"

Root Cause

Feishu embedded agent returns raw HTTP 401 "Invalid token" error to user instead of retrying with refreshed token

Fix Action

Fix / Workaround

[feishu] received message from ou_cb34... (p2p) [feishu] dispatching to agent (session=agent:main:feishu:direct:ou_cb34...) [pi-ai] request POST .../chat/completions status=401 [agent/embedded] embedded run agent end: isError=true error=HTTP 401: "Invalid token" [feishu] dispatch complete (queuedFinal=true, replies=1) [reload] config change detected; evaluating reload (models.providers.zai.models) [reload] config change applied

RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

Feishu embedded agent returns raw HTTP 401 "Invalid token" error to user instead of retrying with refreshed token

Steps to reproduce

1.Configure Feishu as a messaging channel with model routing through AutoGLM proxy (zai provider) 2.Wait for the model API's JWT token to expire (or start a new session when the token is near expiry) 3.Send any message from the Feishu client 4.The bot replies with "HTTP 401: Invalid token"

Expected behavior

The embedded agent should detect the 401, trigger a token refresh, and retry the request. At minimum, it should not surface the raw HTTP error message to the end user.

Actual behavior

The 401 error is passed directly as the reply text to the Feishu user. Logs show the token refresh (config reload) occurs after the error has already been returned. The webchat session recovers after refresh, but the Feishu embedded agent continues to fail intermittently on subsequent requests.

[feishu] received message from ou_cb34... (p2p) [feishu] dispatching to agent (session=agent:main:feishu:direct:ou_cb34...) [pi-ai] request POST .../chat/completions status=401 [agent/embedded] embedded run agent end: isError=true error=HTTP 401: "Invalid token" [feishu] dispatch complete (queuedFinal=true, replies=1) [reload] config change detected; evaluating reload (models.providers.zai.models) [reload] config change applied

OpenClaw version

2026.2.25

Operating system

Windows 10 (x64)

Install method

No response

Model

pony-alpha-2 (GLM-5-Turbo)

Provider / routing chain

zai → autoglm-api.zhipuai.cn/autoclaw-proxy/proxy/autoclaw

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

Fix Plan

To address the issue of the Feishu embedded agent returning a raw HTTP 401 "Invalid token" error instead of retrying with a refreshed token, we need to implement a token refresh mechanism that triggers before the request is sent or immediately after a 401 error is encountered. Here are the steps:

  • Modify the Token Refresh Logic: Ensure that the token refresh logic is triggered before sending a request or immediately after encountering a 401 error.
  • Implement Retry Mechanism: Implement a retry mechanism that catches the 401 error, refreshes the token, and then retries the request.
  • Handle Token Expiry: Anticipate token expiry by refreshing the token before it expires or when a 401 error is encountered.

Example Code Snippet

Here's a simplified example in Python of how you might implement a retry mechanism with token refresh:

import requests
import time

def refresh_token():
    # Logic to refresh the token
    # This is a placeholder, actual implementation depends on your token refresh API
    return "new_token"

def send_request(token, url, data):
    headers = {"Authorization": f"Bearer {token}"}
    response = requests.post(url, headers=headers, json=data)
    return response

def retry_with_refresh(token, url, data, max_retries=3):
    for attempt in range(max_retries):
        try:
            response = send_request(token, url, data)
            response.raise_for_status()  # Raise an exception for HTTP errors
            return response
        except requests.HTTPError as e:
            if e.response.status_code == 401:
                token = refresh_token()  # Refresh the token
                continue
            else:
                raise
    return None  # All retries failed

# Usage example
token = "your_initial_token"
url = "https://example.com/api/endpoint"
data = {"key": "value"}

response = retry_with_refresh(token, url, data)
if response:
    print("Request successful:", response.text)
else:
    print("All retries failed.")

Verification

To verify that the fix worked:

  • Test the scenario that previously resulted in a 401 error being returned to the user.
  • Verify that after encountering a 401 error, the request is retried with a refreshed token.
  • Check logs to ensure that the token refresh and retry mechanism are working as expected.

Extra Tips

  • Ensure that your token refresh logic is efficient and doesn't lead to unnecessary refreshes.
  • Consider implementing a backoff strategy for retries to avoid overwhelming the server with requests.
  • Always handle potential exceptions and errors that might occur during the token refresh and retry process.

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…

FAQ

Expected behavior

The embedded agent should detect the 401, trigger a token refresh, and retry the request. At minimum, it should not surface the raw HTTP error message to the end user.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING