openclaw - 💡(How to fix) Fix OAuth refresh error surfaced to user on every message even when access token is valid [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#60029Fetched 2026-04-08 02:37:17
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
commented ×1cross-referenced ×1

Every time a user sends a message, they receive:

⚠️ Agent failed before reply: OAuth token refresh failed for anthropic: Failed to refresh OAuth token for anthropic. Please try again or re-authenticate.

The error appears even when the access token has 6-8 hours remaining (verified via auth-profiles.jsonexpires field).

The agent still responds correctly after the error (fallback works), but the error message is sent to the user first, creating a poor UX.

Error Message

Bug: OAuth token refresh error surfaced to user on every message even when access token is still valid

The error appears even when the access token has 6-8 hours remaining (verified via auth-profiles.jsonexpires field). The agent still responds correctly after the error (fallback works), but the error message is sent to the user first, creating a poor UX. 5. The error is surfaced to the user via agent-runner.runtime-DEDCwJ0o.js line 632 as "Agent failed before reply"

  • If refresh fails but access token is still valid, the error should NOT be surfaced to the user
  1. Observe error message before the actual response None found. The error persists regardless of:

Root Cause

  1. auth-profiles-bVW1e9Dr.js line 258: if (Date.now() < cred.expires) should skip refresh when token is valid
  2. However, probe-anthropic-* sessions are spawned periodically and trigger refresh independently
  3. The refresh request to https://platform.claude.com/v1/oauth/token returns HTTP 403 from Cloudflare when called from a VPS/server IP
  4. This is a known issue: Anthropic's OAuth token refresh endpoint blocks non-browser (server) IPs via Cloudflare
  5. The error is surfaced to the user via agent-runner.runtime-DEDCwJ0o.js line 632 as "Agent failed before reply"

Fix Action

Workaround

None found. The error persists regardless of:

  • Switching accounts
  • Cleaning dead auth profiles from agents
  • Restarting gateway
  • Fresh OAuth token with 8h remaining

Code Example

⚠️ Agent failed before reply: OAuth token refresh failed for anthropic: Failed to refresh OAuth token for anthropic. Please try again or re-authenticate.
RAW_BUFFERClick to expand / collapse

Bug: OAuth token refresh error surfaced to user on every message even when access token is still valid

Environment

  • OpenClaw version: 2026.4.2 (d74a122)
  • OS: Ubuntu 22.04 (VPS)
  • Node: v22.22.0
  • Provider: Anthropic (OAuth subscription, NOT API key)
  • Channels: Discord + Telegram

Description

Every time a user sends a message, they receive:

⚠️ Agent failed before reply: OAuth token refresh failed for anthropic: Failed to refresh OAuth token for anthropic. Please try again or re-authenticate.

The error appears even when the access token has 6-8 hours remaining (verified via auth-profiles.jsonexpires field).

The agent still responds correctly after the error (fallback works), but the error message is sent to the user first, creating a poor UX.

Root cause analysis

  1. auth-profiles-bVW1e9Dr.js line 258: if (Date.now() < cred.expires) should skip refresh when token is valid
  2. However, probe-anthropic-* sessions are spawned periodically and trigger refresh independently
  3. The refresh request to https://platform.claude.com/v1/oauth/token returns HTTP 403 from Cloudflare when called from a VPS/server IP
  4. This is a known issue: Anthropic's OAuth token refresh endpoint blocks non-browser (server) IPs via Cloudflare
  5. The error is surfaced to the user via agent-runner.runtime-DEDCwJ0o.js line 632 as "Agent failed before reply"

Expected behavior

  • If the access token is still valid (Date.now() < expires), no refresh should be attempted
  • If refresh fails but access token is still valid, the error should NOT be surfaced to the user
  • Probe sessions should not trigger user-facing errors

Steps to reproduce

  1. Connect Anthropic OAuth account via openclaw onboard
  2. Deploy on a VPS/cloud server (not residential IP)
  3. Send any message via Discord or Telegram
  4. Observe error message before the actual response

Related issues

  • #34117 (OAuth token refresh failure)
  • #44616 (OAuth refresh token rotation issue)

Workaround

None found. The error persists regardless of:

  • Switching accounts
  • Cleaning dead auth profiles from agents
  • Restarting gateway
  • Fresh OAuth token with 8h remaining

extent analysis

TL;DR

Modify the OAuth token refresh logic to skip refresh when the access token is still valid and suppress error messages when the refresh fails but the access token remains valid.

Guidance

  • Review the auth-profiles-bVW1e9Dr.js file, specifically line 258, to ensure the condition if (Date.now() < cred.expires) correctly skips token refresh when the token is valid.
  • Investigate modifying the agent-runner.runtime-DEDCwJ0o.js file, line 632, to prevent surfacing the "Agent failed before reply" error to the user when the access token is still valid, despite the refresh failure.
  • Consider implementing a check to prevent probe-anthropic-* sessions from triggering token refresh independently, potentially by adding a flag or condition to skip refresh during these sessions.
  • Examine the Cloudflare configuration for the Anthropic OAuth token refresh endpoint to understand the IP blocking behavior and potential workarounds.

Example

// Example of modified refresh logic in auth-profiles-bVW1e9Dr.js
if (Date.now() < cred.expires) {
  // Token is still valid, skip refresh
  return;
} else {
  // Token has expired, attempt refresh
  // ...
}

Notes

The provided workaround attempts may not be comprehensive, and further investigation into the Anthropic OAuth token refresh endpoint and Cloudflare configuration may be necessary to resolve the issue.

Recommendation

Apply a workaround by modifying the OAuth token refresh logic and error handling to suppress user-facing errors when the access token is still valid, as the root cause is related to Cloudflare blocking server IPs and the issue persists across different accounts and setups.

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

  • If the access token is still valid (Date.now() < expires), no refresh should be attempted
  • If refresh fails but access token is still valid, the error should NOT be surfaced to the user
  • Probe sessions should not trigger user-facing errors

Still need to ship something?

×6

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

Back to top recommendations

TRENDING