Skip to content

fix: auto auth profile override should not bias profile ordering - #25534

Closed
taw0002 wants to merge 1 commit into
openclaw:mainfrom
taw0002:fix/auto-auth-profile-preferred-bias
Closed

taw0002 wants to merge 1 commit into
openclaw:mainfrom
taw0002:fix/auto-auth-profile-preferred-bias

Conversation

@taw0002

@taw0002 taw0002 commented Feb 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two related bugs in auth profile rotation that cause auto-selected fallback profiles (e.g., API key) to be used instead of higher-priority profiles (e.g., manual OAuth) even when those profiles are available.

Bug 1: preferredProfile passed for auto overrides (run.ts)

resolveAuthProfileOrder() received preferredProfile: preferredProfileId regardless of whether the source was user or auto. When set, resolveAuthProfileOrder moves the preferred profile to the front of the candidate list. This means an auto-selected anthropic:default (API key) gets front-of-queue treatment, bypassing manual OAuth profiles.

Fix: Only pass preferredProfile when the override source is user (explicitly user-locked).

Bug 2: No re-evaluation when higher-priority profiles exit cooldown (session-override.ts)

resolveSessionAuthProfileOverride() kept the current auto-selected profile as long as it wasn't in cooldown itself. It never checked whether a higher-priority profile had exited cooldown and become available again. So once the session fell back to API key, it stayed there until compaction or new session.

Fix: Added a check — when the current auto-selected profile is not the highest priority in the configured order, scan for any higher-priority profile that's now available (not in cooldown) and switch to it.

Tests

  • Added 2 new test cases to session-override.test.ts:
    • Re-selects higher-priority profile when it exits cooldown
    • Stays on current profile when higher-priority profiles are still in cooldown

Fixes #25510

Greptile Summary

Fixes two related bugs in auth profile rotation that prevented higher-priority profiles (like manual OAuth) from being used when they became available again after cooldown periods.

  • Bug 1: run.ts previously passed preferredProfile for both user and auto override sources. This caused auto-selected profiles to get front-of-queue treatment via resolveAuthProfileOrder, bypassing the configured priority order. Fixed by only passing preferredProfile for user-locked profiles.
  • Bug 2: session-override.ts never re-evaluated higher-priority profiles after they exited cooldown. Once a session fell back to a lower-priority profile (e.g., API key), it stayed there until compaction or new session. Fixed by adding logic to scan for available higher-priority profiles when the current profile is not the highest priority.
  • Added comprehensive test coverage for both scenarios (re-selecting when higher-priority exits cooldown, staying when still in cooldown)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-targeted fixes for specific bugs with clear logic improvements. Both fixes have strong test coverage and follow the existing code patterns. The distinction between lockedProfileId (user) vs preferredProfileId (user or auto) in run.ts is now properly handled, and the re-evaluation logic in session-override.ts is straightforward with proper boundary checks
  • No files require special attention

Last reviewed commit: e064b4d

When authProfileIdSource is 'auto', the preferredProfile param was still
passed to resolveAuthProfileOrder(), causing it to move the auto-selected
profile (e.g., API key fallback) to the front of the candidate list. This
bypassed the configured manual-first OAuth priority order.

Also add higher-priority re-evaluation in resolveSessionAuthProfileOverride:
when the current auto-selected profile is lower priority and a higher-priority
profile has exited cooldown, switch back to it instead of staying pinned.

Fixes openclaw#25510
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Feb 24, 2026
@taw0002

taw0002 commented Feb 26, 2026

Copy link
Copy Markdown
Contributor Author

Has merge conflicts — going to close and rebase if I still need this fix.

@taw0002 taw0002 closed this Feb 26, 2026
@dotmilk

dotmilk commented Feb 28, 2026

Copy link
Copy Markdown

@taw0002 running into similar things, is this still an issue for you?

@taw0002

taw0002 commented Feb 28, 2026

Copy link
Copy Markdown
Contributor Author

Yes just don't know if it's a priority and don't want to waste time if it isnt going to be reviewed and merged. I'll rebase and try one more time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: auto auth profile override can bypass manual-first key rotation and pin API key fallback

2 participants