openclaw - 💡(How to fix) Fix [Bug]: OAuth login fails with "Failed to extract accountId from token" in TUI (openai-codex) [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#57275Fetched 2026-04-08 01:51:42
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
labeled ×2cross-referenced ×1

Using OpenClaw with OAuth login (not API key), the TUI fails to send messages and repeatedly outputs:

"Failed to extract accountId from token"

This happens immediately when attempting to chat.

Error Message

Result: Error "Failed to extract accountId from token" appears for every message and chat does not work After sending a message in the TUI, no response is generated. Instead, the following error is repeatedly shown: The session remains connected but stuck in an error state, and all subsequent messages produce the same error.

Root Cause

Using OpenClaw with OAuth login (not API key), the TUI fails to send messages and repeatedly outputs:

"Failed to extract accountId from token"

This happens immediately when attempting to chat.

RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

Description

Using OpenClaw with OAuth login (not API key), the TUI fails to send messages and repeatedly outputs:

"Failed to extract accountId from token"

This happens immediately when attempting to chat.

Steps to reproduce

  1. Install OpenClaw via npm (Windows)
  2. Authenticate using OAuth (browser login flow)
  3. Set model to openai-codex (e.g. openai-codex/gpt-5.4-codex)
  4. Run: openclaw tui
  5. Type any message (e.g. "hi")

Expected behavior

Chat should work normally in TUI after successful OAuth login.

Actual behavior

Each message results in: "Failed to extract accountId from token"

No responses are generated.

Environment

  • OS: Windows
  • Install: npm global install
  • OpenClaw version: 2026.3.11
  • Auth method: OAuth (NOT API key)
  • Model: openai-codex/gpt-5.x-codex

Notes

  • The OAuth token appears to be opaque (not JWT format with 3 parts), so accountId extraction fails.
  • Related commits/PRs suggest fixes for this behavior, but unclear if included in this version.
  • Downgrading OpenClaw does not resolve the issue.

Steps to reproduce

  1. Install OpenClaw globally via npm
  2. Run openclaw tui
  3. Complete OAuth login in the browser when prompted
  4. Set model to openai-codex/gpt-5.3-codex (or any openai-codex model)
  5. Start a new session in TUI
  6. Type a message (e.g. "hi")

Result: "Failed to extract accountId from token" is shown and no response is returned

  1. Install OpenClaw via npm (Windows environment)
  2. Run openclaw tui
  3. Authenticate using OAuth (browser login flow)
  4. Confirm model is set to an openai-codex model
  5. Enter a message in the TUI

Result: Error "Failed to extract accountId from token" appears for every message and chat does not work

Expected behavior

Chat should work normally in the TUI after successful OAuth login, and messages should receive responses from the selected Codex model without errors.

Actual behavior

After sending a message in the TUI, no response is generated. Instead, the following error is repeatedly shown:

"Failed to extract accountId from token"

The session remains connected but stuck in an error state, and all subsequent messages produce the same error.

OpenClaw version

all

Operating system

windowz

Install method

npm global

Model

openai-codex/gpt-5.1-codex, openai-codex/gpt-5.2-codex, openai-codex/gpt-5.4-codex

Provider / routing chain

openclaw -> openai-codex (OAuth)

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 resolve the "Failed to extract accountId from token" error, we need to modify the token extraction logic in OpenClaw to handle opaque OAuth tokens.

Here are the steps:

  • Update the tokenExtractor function to handle opaque tokens.
  • Add a fallback mechanism to extract the accountId from the token response.

Code Changes

// Update tokenExtractor function
function tokenExtractor(tokenResponse) {
  // Check if token is opaque
  if (!tokenResponse.accessToken.includes('.')) {
    // Fallback to extract accountId from token response
    return extractAccountIdFromResponse(tokenResponse);
  }
  // Existing logic to extract accountId from JWT token
  const decodedToken = decodeJwtToken(tokenResponse.accessToken);
  return decodedToken.accountId;
}

// Add fallback function to extract accountId from token response
function extractAccountIdFromResponse(tokenResponse) {
  // Assuming the accountId is available in the token response
  return tokenResponse.accountId;
}

Verification

To verify the fix, follow these steps:

  • Install the updated OpenClaw version.
  • Run openclaw tui and complete the OAuth login.
  • Set the model to an openai-codex model.
  • Start a new session in TUI and enter a message.
  • Verify that the chat works normally and messages receive responses from the selected Codex model without errors.

Extra Tips

  • Ensure that the tokenResponse object contains the accountId property.
  • If the accountId is not available in the token response, modify the extractAccountIdFromResponse function accordingly.
  • Test the updated OpenClaw version with different openai-codex models to ensure the fix works across all models.

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

Chat should work normally in the TUI after successful OAuth login, and messages should receive responses from the selected Codex model without 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