openclaw - 💡(How to fix) Fix [Bug] Codex OAuth token fails in isolated cron/heartbeat sessions — atob URL-safe base64 issue [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#76211Fetched 2026-05-03 04:40:42
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
2
Author
Timeline (top)
closed ×1commented ×1

Error Message

[codex] agent run error: FailoverError: Failed to extract accountId from token at extractAccountId (pi-ai/dist/providers/openai-codex-responses.js) at streamOpenAICodexResponses

Root Cause

  1. The Codex access token is a valid JWT containing chatgpt_account_id
  2. In the main interactive session, extractAccountId() correctly decodes the JWT
  3. In isolated cron/heartbeat sessions, the same token fails to decode
  4. Root cause: The JWT payload uses URL-safe base64 characters (- and _) which are standard for JWT but break when atob() is called directly in the browser-like isolated session runtime
  5. The main session apparently has a different code path that handles URL-safe base64, while the isolated session uses raw atob() which doesn't handle -/_ characters

Fix Action

Fix / Workaround

All cron jobs must use minimax/MiniMax-M2.7 as a workaround since Codex cannot run in isolated sessions. Users who prefer Codex for flat-rate pricing cannot use it for automated jobs.

Code Example

[codex] agent run error: FailoverError: Failed to extract accountId from token
    at extractAccountId (pi-ai/dist/providers/openai-codex-responses.js)
    at streamOpenAICodexResponses

---

// Replace raw atob() with:
const base64 = payload.replace(/-/g, '+').replace(/_/g, '/');
const json = JSON.parse(atob(base64));
RAW_BUFFERClick to expand / collapse

Bug Description

OpenAI Codex (codex/gpt-5.5) fails with Failed to extract accountId from token when used in isolated cron or heartbeat sessions, despite working correctly in the main interactive session.

Environment

  • OpenClaw: 2026.4.29 (a448042)
  • Platform: macOS (Darwin 25.2.0, Apple Silicon)
  • Node.js: v22.22.1
  • Auth: OAuth via ChatGPT account

Steps to Reproduce

  1. Authenticate Codex via openclaw models auth login (interactive browser flow)
  2. Create a cron job using codex/gpt-5.5
  3. Wait for cron to fire — job fails with Failed to extract accountId from token

Actual Behavior

[codex] agent run error: FailoverError: Failed to extract accountId from token
    at extractAccountId (pi-ai/dist/providers/openai-codex-responses.js)
    at streamOpenAICodexResponses

Root Cause Analysis

  1. The Codex access token is a valid JWT containing chatgpt_account_id
  2. In the main interactive session, extractAccountId() correctly decodes the JWT
  3. In isolated cron/heartbeat sessions, the same token fails to decode
  4. Root cause: The JWT payload uses URL-safe base64 characters (- and _) which are standard for JWT but break when atob() is called directly in the browser-like isolated session runtime
  5. The main session apparently has a different code path that handles URL-safe base64, while the isolated session uses raw atob() which doesn't handle -/_ characters

Related Issues

  • #36604 (closed, Mar 2026) — Cron jobs fail with Codex fallback
  • #57275 (closed, Apr 2026) — OAuth login fails in TUI with same error
  • #70201 (closed, Apr 2026) — codex/gpt-5.4 imageModel fails with same error

Suggested Fix

The extractAccountId() function in openai-codex-responses.js should use a base64 decoder that handles URL-safe characters (replacing - with + and _ with /) instead of relying on atob() directly. For example:

// Replace raw atob() with:
const base64 = payload.replace(/-/g, '+').replace(/_/g, '/');
const json = JSON.parse(atob(base64));

Alternatively, add a session option to pass the main session's authenticated OAuth context to isolated cron/heartbeat sessions.

Impact

All cron jobs must use minimax/MiniMax-M2.7 as a workaround since Codex cannot run in isolated sessions. Users who prefer Codex for flat-rate pricing cannot use it for automated jobs.

extent analysis

TL;DR

Update the extractAccountId() function in openai-codex-responses.js to handle URL-safe base64 characters.

Guidance

  • Verify that the issue is indeed caused by the atob() function not handling URL-safe base64 characters by checking the JWT payload for - and _ characters.
  • Replace the atob() function with a custom base64 decoder that handles URL-safe characters, as suggested in the issue.
  • Consider adding a session option to pass the main session's authenticated OAuth context to isolated cron/heartbeat sessions as an alternative solution.
  • Test the updated extractAccountId() function with a sample JWT payload containing URL-safe base64 characters to ensure it correctly extracts the accountId.

Example

const base64 = payload.replace(/-/g, '+').replace(/_/g, '/');
const json = JSON.parse(atob(base64));

Notes

The suggested fix assumes that the issue is indeed caused by the atob() function not handling URL-safe base64 characters. If the issue persists after applying the fix, further investigation may be necessary.

Recommendation

Apply the workaround by updating the extractAccountId() function to handle URL-safe base64 characters, as this is a targeted fix that addresses the root cause of the issue.

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Bug] Codex OAuth token fails in isolated cron/heartbeat sessions — atob URL-safe base64 issue [1 comments, 2 participants]