Repository navigation
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 354c4701aa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (next && source === "auto" && order.length > 1) { | ||
| const currentIndex = order.indexOf(next); | ||
| if (currentIndex > 0) { | ||
| const higherPriority = order.slice(0, currentIndex).find( | ||
| (pid) => !isProfileInCooldown(store, pid) |
There was a problem hiding this comment.
Skip higher-priority override after explicit rotation
The new re-evaluation in resolveSessionAuthProfileOverride runs for every auto-sourced choice, including cases where next was intentionally advanced by pickNextAvailable (new-session rotation or compaction-driven rotation). In a simple healthy order like [p1, p2] with current p1, this block rewrites next from p2 back to p1, so rotation is effectively canceled and selection stays pinned to the first profile. This check should only run when we kept the current fallback (the “higher-priority exited cooldown” case), not after an intentional rotation step.
Useful? React with 👍 / 👎.
Greptile SummaryThis PR fixes two related bugs in auth profile rotation that prevented higher-priority profiles (OAuth) from being used when available, favoring lower-priority fallbacks (API keys). Changes:
Logic correctness: The fix correctly addresses both bugs. The run.ts change prevents auto-selected profiles from biasing the order, and the session-override.ts change ensures sessions upgrade to higher-priority profiles when available. Confidence Score: 4/5
Last reviewed commit: 354c470 |
354c470 to
90ffa3c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 90ffa3c9ef
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @@ -348,7 +348,7 @@ export async function runEmbeddedPiAgent( | |||
| cfg: params.config, | |||
| store: authStore, | |||
| provider, | |||
| preferredProfile: preferredProfileId, | |||
| preferredProfile: params.authProfileIdSource === "user" ? preferredProfileId : undefined, | |||
There was a problem hiding this comment.
Preserve inferred user overrides when source is missing
Only passing preferredProfile when authProfileIdSource === "user" drops backward-compatible behavior for sessions that have authProfileOverride but no authProfileOverrideSource. resolveSessionAuthProfileOverride explicitly infers that case as user-selected and returns early (src/agents/auth-profiles/session-override.ts:110-119), so after this change runEmbeddedPiAgent can ignore that explicit profile and start from a different candidate whenever multiple profiles exist. This creates an upgrade regression for legacy session entries unless undefined source is treated as inferred-user (or otherwise preserved) instead of non-preferred.
Useful? React with 👍 / 👎.
f67c93a to
cbc591b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cbc591b197
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (next && source === "auto" && order.length > 1 && !intentionallyRotated) { | ||
| const currentIndex = order.indexOf(next); | ||
| if (currentIndex > 0) { | ||
| const higherPriority = order | ||
| .slice(0, currentIndex) |
There was a problem hiding this comment.
Avoid reverting intentional rotation on subsequent turns
Fresh evidence beyond the earlier thread: this re-evaluation still executes on the next invocation, and resolveSessionAuthProfileOverride is called for each message (src/auto-reply/reply/get-reply-run.ts:446), so intentionallyRotated only protects the current call. If a new session intentionally rotates from p1 to p2, the next non-new turn (isNewSession=false) will immediately switch back to p1 whenever it is available, which collapses the intended auto round-robin persistence and reintroduces ordering bias.
Useful? React with 👍 / 👎.
cbc591b to
4ae7dea
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ae7deae2a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!cooldownUntilByProfileBeforeOrder.has(profileId)) { | ||
| continue; | ||
| } | ||
| if (!isProfileInCooldown(store, profileId)) { |
There was a problem hiding this comment.
Restrict higher-priority reselection to actual cooldown expiry
Using cooldownUntilByProfileBeforeOrder.has(profileId) as the only gate means any historical cooldownUntil value (including long-expired entries) is treated as a reason to override the current auto profile. When a session intentionally rotates to a lower-priority healthy profile (for example on isNewSession), the next non-new turn can immediately snap back to the first profile solely because that higher profile once had cooldown metadata, so rotation persistence becomes dependent on stale history rather than a real just-ended cooldown event.
Useful? React with 👍 / 👎.
Two related bugs in auth profile rotation: 1. preferredProfile passed for auto overrides (run.ts): resolveAuthProfileOrder received preferredProfile regardless of whether the source was user or auto. Auto-selected profiles (e.g., API key fallback) got front-of-queue treatment, bypassing higher-priority profiles (e.g., OAuth). Fix: only pass preferredProfile when source is user or inferred-user (legacy sessions without explicit source). 2. No re-evaluation when higher-priority profiles exit cooldown (session-override.ts): once a session fell back to a lower-priority profile, it stayed there even after the higher-priority profile exited cooldown. Fix: check for available higher-priority profiles on each resolution, but only when not intentionally rotating (new session or post-compaction). Fixes openclaw#25510
4ae7dea to
6f6bd6b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6f6bd6bfef
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } else if (source === "auto") { | ||
| const best = pickFirstAvailable(); | ||
| if (best && order.indexOf(best) < order.indexOf(current)) { | ||
| next = best; | ||
| } |
There was a problem hiding this comment.
Preserve auto rotation across subsequent session turns
Avoid re-selecting pickFirstAvailable() unconditionally for source === "auto" here, because on the message after an intentional rotation (isNewSession or compaction), this branch immediately snaps next back to the first profile in order and undoes the rotation. In a healthy two-profile order [p1, p2], a new-session rotation to p2 is reverted to p1 on the very next non-new turn, so the session cannot stay on its rotated profile long enough to get the intended round-robin behavior.
Useful? React with 👍 / 👎.
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
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., OAuth) even when those profiles are available.
Bug 1: preferredProfile passed for auto overrides (run.ts)
resolveAuthProfileOrder()receivedpreferredProfile: preferredProfileIdregardless of whether the source wasuserorauto. When set,resolveAuthProfileOrdermoves the preferred profile to the front of the candidate list. This means an auto-selectedanthropic:default(API key) gets front-of-queue treatment, bypassing OAuth profiles.Fix: Only pass
preferredProfilewhen the override source isuser.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.Fix: When the current auto-selected profile is not the highest-priority in the order, scan for any higher-priority profile that's now available.
Tests
Added 2 new test cases to
session-override.test.ts:Fixes #25510
Replaces #25534 (which had merge conflicts)