Skip to content

Commit 266039f

Browse files
author
Jordi
committed
fix(auth-profiles): break self-reinforcing session auth override loop
When a session falls back to a different provider (e.g. minimax → deepseek), the session entry stores the fallback provider's auth profile override (e.g. deepseek:default) with source 'auto'. On subsequent turns, resolveSessionAuthProfileOverride builds the auth profile order from the current run's provider (deepseek), not the agent's configured default model provider (minimax). Since deepseek:default is valid for deepseek's auth order, it's never re-evaluated against the agent's actual default model, creating a self-reinforcing loop. Fix: when source === 'auto', also include the agent's configured default model provider's auth profiles in the order list. This ensures the resolver can find and prefer the default model's auth profile when it's available, breaking the loop. Fixes #85126
1 parent ff79299 commit 266039f

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

src/agents/auth-profiles/session-override.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { SessionEntry } from "../../config/sessions/types.js";
22
import type { OpenClawConfig } from "../../config/types.openclaw.js";
33
import { createLazyImportLoader } from "../../shared/lazy-promise.js";
4+
import { resolveAgentConfig, resolveSessionAgentId } from "../agent-scope.js";
45
import {
56
isConfiguredAwsSdkAuthProfileForProvider,
67
isStoredCredentialCompatibleWithAuthProvider,
@@ -161,6 +162,34 @@ export async function resolveSessionAuthProfileOverride(params: {
161162
current = undefined;
162163
}
163164

165+
// When the override was set automatically (via fallback) and the current
166+
// run's provider differs from the agent's configured default model provider,
167+
// include the default provider's auth profiles in the order list. This
168+
// prevents a fallback from permanently locking the session to the fallback
169+
// provider's auth profile (https://github.com/openclaw/openclaw/issues/85126).
170+
if (source === "auto") {
171+
const sessionAgentId = resolveSessionAgentId({ config: cfg, sessionKey });
172+
const agentCfg = resolveAgentConfig(cfg, sessionAgentId);
173+
const rawModel: string | { primary?: string } | undefined =
174+
agentCfg?.model ?? cfg.agents?.defaults?.model;
175+
const agentPrimary =
176+
typeof rawModel === "string"
177+
? rawModel
178+
: rawModel && typeof rawModel === "object" && "primary" in rawModel
179+
? (rawModel as { primary: string }).primary
180+
: undefined;
181+
if (agentPrimary) {
182+
const agentProvider = agentPrimary.split("/")[0];
183+
if (agentProvider && agentProvider !== provider) {
184+
const agentOrder = resolveAuthProfileOrder({ cfg, store, provider: agentProvider });
185+
if (agentOrder.length > 0) {
186+
// Prepend default provider's order so it's preferred over the fallback's
187+
order.splice(0, order.length, ...new Set([...agentOrder, ...order]));
188+
}
189+
}
190+
}
191+
}
192+
164193
if (order.length === 0) {
165194
return undefined;
166195
}

0 commit comments

Comments
 (0)