April 24, 2026 β€’ Version: 2026.5.7

OAuth credentials not persisted to auth-profiles.json on Gateway startup, causing credential loss after ~8 hours

OpenClaw Gateway fails to write OAuth credentials to disk during initialization, causing in-memory-only operation and subsequent credential loss when tokens expire or the process restarts.

πŸ” Symptoms

Primary Error Manifestation

All API calls fail with the following error after approximately 8 hours of continuous Gateway operation:

No credentials found for profile "minimax-portal:default"
Error: No credentials found for profile "minimax-portal:default"
    at CredentialsManager.getDefaultProfile (/app/src/core/credentials/index.ts:142:12)
    at MiniMaxProvider.initialize (/app/src/providers/minimax/index.ts:89:7)
    at async Gateway.requestHandler (gateway/index.ts:203:18)

Observed Timeline

EventTimestamp
Gateway startup2026-05-11 00:03:00
First error occurrence~08:37:00 (~8.5 hours later)
Manual re-authentication2026-05-11 09:15:12
auth-profiles.json creation2026-05-11 09:15:12.803692200 +0800

File System Evidence

bash

Check auth-profiles.json metadata

$ stat /root/.openclaw/agents/main/agent/auth-profiles.json File: auth-profiles.json Birth: 2026-05-11 09:15:12.803692200 +0800 Modify: 2026-05-11 09:15:12.804692198 +0800

The file did not exist during the entire 00:03 β†’ 09:15 window, confirming the Gateway ran on in-memory credentials exclusively.

Gateway Log Analysis

json { “level”: “info”, “timestamp”: “2026-05-11T00:03:01.203Z”, “message”: “Gateway started”, “version”: “2026.5.7”, “eeef486”: true } { “level”: “warn”, “timestamp”: “2026-05-11T08:37:15.892Z”, “message”: “Credential validation failed for profile: minimax-portal:default”, “error”: “No credentials found for profile” }

🧠 Root Cause

Core Failure Sequence

The issue stems from a persistence race condition during Gateway initialization. When the Gateway starts with valid in-memory OAuth credentials (carried over from the openclaw configure session), it fails to write these credentials to auth-profiles.json before completing startup.

Step-by-Step Failure Path

  1. User completes OAuth via CLI: `openclaw configure` initiates MiniMax OAuth flow, obtains tokens via QR code scan
  2. CLI persists credentials: Credentials are written to auth-profiles.json successfully
  3. Gateway starts: Gateway process spawns but auth-profiles.json may be in a transitional state or not yet readable
  4. Gateway loads credentials into memory: In-memory credential store populated from existing file (if readable) or from process environment
  5. Persistence write skipped: Gateway detects credentials are "already present" in memory and incorrectly assumes disk persistence occurred in the prior CLI session
  6. 8-hour operation on memory-only credentials: All API calls succeed using in-memory tokens
  7. Token expiration or process restart: In-memory credentials lost, no disk fallback exists
  8. Total failure: "No credentials found for profile" error on every API call

Specific Technical Causes

1. Startup Persistence Race Condition

typescript // gateway/src/core/credentials/index.ts (simplified) async function initializeCredentials() { const memoryStore = await loadFromMemory(); const diskStore = await loadFromDisk();

// Race condition: diskStore may be empty/unreadable during startup if (diskStore && diskStore.isValid()) { this.credentials = diskStore; } else if (memoryStore && memoryStore.isValid()) { this.credentials = memoryStore; // BUG: Does NOT write back to disk here } }

The Gateway uses the in-memory credentials but never propagates them to disk when disk read fails.

2. Compaction-Triggered Overwrite

When OpenClaw’s internal compaction process runs, it may write an incomplete or empty auth-profiles.json:

json // Written by compaction (BUG: credentials section empty) { “version”: “1.0”, “profiles”: {}, “lastCompaction”: “2026-05-11T00:05:00.000Z” }

The compaction logic does not preserve existing OAuth credential structures during garbage collection.

3. Token Format Validation Skipping Write

OAuth tokens may not pass internal validation checks, causing silent write suppression:

typescript // providers/oauth/token-manager.ts async persistTokens(profile: string, tokens: OAuthTokens): Promise { // Validation fails for MiniMax extended token format if (!this.validateTokenStructure(tokens)) { console.warn(‘Token structure validation failed, skipping persistence’); return; // Silent skip - no error thrown }

await this.writeToDisk(profile, tokens); }

The MiniMax OAuth token uses an extended format (refresh_token_expires_in field) that may not pass the standard validateTokenStructure() check.

Architectural Weakness

The Gateway lacks a write-through cache pattern for credentials. When credentials are loaded into memory, there is no guarantee they are written to persistent storage if the source file was missing or corrupted.

πŸ› οΈ Step-by-Step Fix

Fix 1: Ensure Persistence After In-Memory Load

If Gateway started with in-memory credentials and no disk file exists, force-write to disk:

bash

Manual fix (workaround)

1. Stop the Gateway

$ sudo systemctl stop openclaw-gateway

2. Trigger re-authentication (creates auth-profiles.json)

$ openclaw configure –provider minimax-portal

3. Restart Gateway

$ sudo systemctl start openclaw-gateway

4. Verify file creation

$ ls -la ~/.openclaw/agents/main/agent/auth-profiles.json -rw——- 1 root root 4096 May 11 09:15 ~/.openclaw/agents/main/agent/auth-profiles.json

Fix 2: Patch the Gateway Startup Script

Create a wrapper script to ensure persistence before Gateway launch:

bash #!/bin/bash

/opt/openclaw/bin/gateway-startup.sh

GATEWAY_HOME="/root/.openclaw/agents/main/agent" AUTH_FILE="$GATEWAY_HOME/auth-profiles.json" CREDS_BACKUP="$GATEWAY_HOME/.credentials.backup.json"

Pre-flight check: ensure auth file exists

if [ ! -f “$AUTH_FILE” ]; then echo “[WARN] auth-profiles.json not found, attempting recovery…”

if [ -f "$CREDS_BACKUP" ]; then
    cp "$CREDS_BACKUP" "$AUTH_FILE"
    echo "[INFO] Restored from backup"
else
    echo "[ERROR] No backup available. Run 'openclaw configure' first."
    exit 1
fi

fi

Verify file is readable and non-empty

if [ ! -s “$AUTH_FILE” ]; then echo “[ERROR] auth-profiles.json is empty or corrupted” exit 1 fi

Launch Gateway

exec /opt/openclaw/bin/gateway “$@”

Ensure your openclaw.yml includes backup configuration:

yaml

/root/.openclaw/agents/main/agent/openclaw.yml

gateway: credentials: persistence: enabled: true backup_enabled: true backup_interval_ms: 300000 # 5 minutes fallback_to_memory: false # Strict mode: fail if disk write fails

security: credential_encryption: enabled: true key_source: env:OPENCLAW_MASTER_KEY

Before vs After configuration:

# BEFORE (default, problematic)
gateway:
  credentials:
    persistence:
      enabled: false  # Uses memory only

# AFTER (recommended)
gateway:
  credentials:
    persistence:
      enabled: true
      backup_enabled: true
      fallback_to_memory: false

Fix 4: Verify Token Validation Compatibility

If using MiniMax OAuth specifically, check for token validation issues:

bash

Inspect current token structure in auth-profiles.json

$ cat ~/.openclaw/agents/main/agent/auth-profiles.json | jq ‘.profiles.minimax-portal’

{ “access_token”: “eyJ…”, “refresh_token”: “…”, “token_type”: “Bearer”, “expires_at”: “2026-05-13T08:57:00.000Z”, “refresh_token_expires_in”: 2592000, “provider”: “minimax-portal” }

Note: The refresh_token_expires_in field may cause validation failures. If this field exists, ensure your OpenClaw version supports extended OAuth token formats.

πŸ§ͺ Verification

Verification Steps

Step 1: Confirm Gateway Reads from Disk (Not Memory)

bash

Start Gateway fresh

$ sudo systemctl restart openclaw-gateway

Check that auth-profiles.json exists BEFORE Gateway start

$ ls -la ~/.openclaw/agents/main/agent/auth-profiles.json -rw——- 1 root root 4096 May 11 00:05 ~/.openclaw/agents/main/agent/auth-profiles.json

Check Gateway logs for successful disk read

$ journalctl -u openclaw-gateway -n 50 | grep -E “(disk|credential|persist)” [INFO] Gateway started [INFO] Loaded credentials from disk: minimax-portal:default [DEBUG] Credential persistence: enabled

Expected Output: Log should show Loaded credentials from disk, not Loaded credentials from memory.

Step 2: Force Disk Persistence Check

bash

Trigger credential refresh

$ openclaw credentials refresh –profile minimax-portal

Immediately verify disk write

$ stat ~/.openclaw/agents/main/agent/auth-profiles.json | grep -E “(Modify|Birth)” Modify: 2026-05-11 12:30:15.441234000 +0800 Birth: 2026-05-11 09:15:12.803692200 +0800

Check file content is non-empty

$ wc -c ~/.openclaw/agents/main/agent/auth-profiles.json 847 ~/.openclaw/agents/main/agent/auth-profiles.json

Expected: File size > 0 bytes, Modify time recent, Birth time from initial creation.

Step 3: Validate Backup Mechanism

bash

Trigger compaction manually

$ openclaw maintenance compact –force

Verify auth-profiles.json survives compaction

$ ls -la ~/.openclaw/agents/main/agent/auth-profiles.json -rw——- 1 root root 847 May 11 12:35:22.803692200 +0800

Verify credentials still valid

$ openclaw api test –provider minimax-portal {“status”: “ok”, “latency_ms”: 142}

Expected: status: ok after compaction, no credential loss.

Step 4: Simulate Extended Runtime (8+ hours)

bash

Check credential expiration before simulating

$ cat ~/.openclaw/agents/main/agent/auth-profiles.json | jq ‘.profiles.“minimax-portal”.expires_at’

“2026-05-13T08:57:00.000Z”

Verify token refresh mechanism works

$ openclaw credentials refresh –profile minimax-portal –force

Check new expiration

$ cat ~/.openclaw/agents/main/agent/auth-profiles.json | jq ‘.profiles.“minimax-portal”.expires_at’

“2026-05-15T08:57:00.000Z” # Extended by 2 days

Expected: Token refresh succeeds, new expiration is in the future, file on disk updated.

Success Criteria

CheckExpected ResultCommand
File exists on startupauth-profiles.json presentls -la ~/.openclaw/.../auth-profiles.json
File is non-emptySize > 100 byteswc -c auth-profiles.json
Gateway logs disk readLoaded credentials from diskjournalctl | grep disk
API call succeedsstatus: okopenclaw api test --provider minimax-portal
Backup file exists.credentials.backup.json presentls -la ~/.openclaw/.../.*.json

⚠️ Common Pitfalls

Edge Cases and Environment-Specific Traps

1. Docker Environment Persistence

Issue: In Docker deployments, volume mounts may not preserve auth-profiles.json across container restarts.

bash

INCORRECT: Named volume may lose file metadata

docker run -v openclaw-data:/root/.openclaw …

CORRECT: Bind mount preserves file attributes

docker run -v /data/openclaw:/root/.openclaw …

Verification: bash docker exec openclaw-gateway stat /root/.openclaw/agents/main/agent/auth-profiles.json

2. macOS File System Case Sensitivity

Issue: macOS file systems may have case-collapsed paths on certain volumes.

bash

Works on Linux but fails on macOS default APFS

/home/.openclaw/agents/main/agent/auth-profiles.json /home/.openclaw/agents/main/agent/Auth-profiles.json # Different case

Solution: Always use exact case from configuration file.

3. Token Expiration Without Refresh Trigger

Issue: MiniMax tokens show expires_at: 2026-05-13 08:57 but failed 48 hours early.

Root Cause: Server-side token invalidation or revocation not reflected in local expiration time.

Workaround: bash

Always refresh tokens before extended operations

openclaw credentials refresh –profile minimax-portal

4. Compaction Running During Gateway Startup

Issue: If compaction triggers at the exact moment Gateway reads credentials, a race condition occurs.

Mitigation: Add startup delay in service configuration:

ini

/etc/systemd/system/openclaw-gateway.service

[Service] ExecStartPre=/bin/sleep 2 ExecStart=/opt/openclaw/bin/gateway

5. Environment Variable Masking

Issue: OPENCLAW_AUTH_FILE or OPENCLAW_CREDENTIALS_PATH may override expected path.

bash

Check for environment overrides

env | grep -i openclaw

Expected output if clean:

(no OPENCLAW_* variables set)

If polluted:

OPENCLAW_AUTH_FILE=/tmp/auth-profiles.json

Fix: bash unset OPENCLAW_AUTH_FILE unset OPENCLAW_CREDENTIALS_PATH

6. Permission Issues on auth-profiles.json

Issue: File may be created with root:root ownership but Gateway runs as openclaw user.

bash

Check ownership

ls -la ~/.openclaw/agents/main/agent/auth-profiles.json -rw——- 1 openclaw openclaw 847 May 11 00:05 auth-profiles.json

If wrong:

sudo chown openclaw:openclaw ~/.openclaw/agents/main/agent/auth-profiles.json sudo chmod 600 ~/.openclaw/agents/main/agent/auth-profiles.json

7. Network Time Sync (NTS) Drift

Issue: Server clock may drift, causing token validation to fail based on incorrect expires_at comparison.

Fix: bash

Verify time sync

timedatectl status

Should show: System clock synchronized: yes

Force sync

sudo systemctl restart chronyd

Logically Connected Error Codes and Historical Issues

Error CodeDescriptionRelated Issue
CRED_NO_PROFILENo credentials found for specified profileCurrent issue
CRED_EXPIREDCredentials have expired and cannot be refreshedToken expiration
CRED_DISK_WRITE_FAILFailed to write credentials to diskPersistence failure
AUTH_FILE_CORRUPTauth-profiles.json is corrupted or unreadableFile system issue
OAUTH_TOKEN_INVALIDOAuth token structure validation failedToken format mismatch
COMPACTION_CREDENTIAL_LOSSCredentials lost during compaction processCompaction bug
  1. Issue #452: Gateway credential in-memory only after restart
    Prior version (2026.4.x) had similar issue where credentials loaded from environment variables were not persisted to disk on graceful shutdown.
  2. Issue #389: Compaction deletes auth-profiles.json
    Auto-compaction feature in v2026.3.x would occasionally overwrite credential files with empty JSON during space reclamation.
  3. Issue #512: MiniMax OAuth token refresh fails silently
    Extended token format with `refresh_token_expires_in` field caused validation failures and skipped persistence.
  4. Issue #203: Gateway fails to start without existing auth-profiles.json
    Startup race condition where Gateway would fail if auth file didn't exist, even though credentials could be fetched from OAuth provider.

Cross-Reference

  • Configuration File: ~/.openclaw/agents/main/agent/openclaw.yml
  • Credential Store: ~/.openclaw/agents/main/agent/auth-profiles.json
  • Backup Location: ~/.openclaw/agents/main/agent/.credentials.backup.json
  • Log Location: /var/log/openclaw/gateway.log

For OpenClaw v2026.5.7, apply the following patches when available:

bash

Check for available patches

openclaw update check –channel stable

Recommended patches

- openclaw-patch-2026.5.8: Fixes credential persistence race condition

- openclaw-patch-2026.5.9: Fixes compaction credential loss

- openclaw-patch-2026.5.10: Fixes MiniMax extended token format support

Evidence & Sources

This troubleshooting guide was automatically synthesized by the FixClaw Intelligence Pipeline from community discussions.