-
-
Notifications
You must be signed in to change notification settings - Fork 69.5k
Auth profile order reverts on gateway restart / API calls overwrite CLI-set order #45516
Description
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
- Configure two Anthropic auth profiles (
anthropic:defaultandanthropic:secondary) - Set order:
openclaw models auth order set --agent main --provider anthropic anthropic:default anthropic:secondary - Verify file has correct order ✅
- Wait for any API call (or trigger one manually)
- 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:
- Hot-reload the running gateway's in-memory auth store (preferred), or
- At minimum, the gateway should re-read
auth.orderfromopenclaw.jsonon 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 startThis 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