Skip to content

Auth profile order reverts on gateway restart / API calls overwrite CLI-set order #45516

@lodekeeper

Description

@lodekeeper

Bug

openclaw models auth order set writes the correct order to ~/.openclaw/agents/<agentId>/agent/auth-profiles.json, but the running gateway overwrites it on the next saveAuthProfileStore() call (triggered by any API call that updates usage stats, cooldowns, or lastGood).

Root Cause

In src/agents/auth-profiles/store.ts, resolveAuthProfileOrder() uses:

const storedOrder = findNormalizedProviderValue(store.order, providerKey);
const configuredOrder = findNormalizedProviderValue(cfg?.auth?.order, providerKey);
const explicitOrder = storedOrder ?? configuredOrder;

The in-memory store.order takes priority over cfg.auth.order. When the CLI command writes to the file, it does not update the running gateway's in-memory runtimeAuthStoreSnapshots. The next saveAuthProfileStore() call then persists the stale in-memory order back to disk, reverting the CLI change.

Steps to Reproduce

  1. Configure two Anthropic auth profiles (anthropic:default and anthropic:secondary)
  2. Set order: openclaw models auth order set --agent main --provider anthropic anthropic:default anthropic:secondary
  3. Verify file has correct order ✅
  4. Wait for any API call (or trigger one manually)
  5. Check file again — order is reverted to the previous in-memory state ❌

Gateway restart also reverts, because:

  • Running gateway overwrites the file before the restart kills it
  • New gateway loads the (now-reverted) file

Expected Behavior

openclaw models auth order set should either:

  1. Hot-reload the running gateway's in-memory auth store (preferred), or
  2. At minimum, the gateway should re-read auth.order from openclaw.json on startup and use it as authoritative over the persisted store order

Workaround

Stop the gateway before setting the order, then start it:

openclaw gateway stop
openclaw models auth order set --agent main --provider anthropic anthropic:default anthropic:secondary
openclaw gateway start

This ensures the file is written while no gateway process can overwrite it, and the fresh gateway loads the correct order into memory.

Environment

  • OpenClaw v2026.3.12 (6472949)
  • Two Anthropic static token profiles
  • Linux x64, Node v22.19.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions