Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions open-sse/executors/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export type ExecuteInput = {
clientHeaders?: Record<string, string> | null;
/** Callback to persist tokens that are proactively refreshed during execution. */
onCredentialsRefreshed?: (newCredentials: ProviderCredentials) => Promise<void> | void;
/** When true, skip the intra-URL 429 retry in execute() so the caller handles fallback. */
skipUpstreamRetry?: boolean;
};

export type CountTokensInput = {
Expand Down Expand Up @@ -526,6 +528,7 @@ export class BaseExecutor {
extendedContext,
upstreamExtraHeaders,
clientHeaders,
skipUpstreamRetry = false,
}: ExecuteInput) {
const fallbackCount = this.getFallbackCount();
let lastError: unknown = null;
Expand Down Expand Up @@ -936,6 +939,7 @@ export class BaseExecutor {

// Intra-URL retry: if 429 and we haven't exhausted per-URL retries, wait and retry the same URL
if (
!skipUpstreamRetry &&
response.status === HTTP_STATUS.RATE_LIMITED &&
(retryAttemptsByUrl[urlIndex] ?? 0) < BaseExecutor.RETRY_CONFIG.maxAttempts
) {
Expand All @@ -955,7 +959,7 @@ export class BaseExecutor {
log?.warn?.("AUTH", `401 on ${url} - API key may be invalid`);
}

if (this.shouldRetry(response.status, urlIndex)) {
if (!skipUpstreamRetry && this.shouldRetry(response.status, urlIndex)) {
log?.debug?.("RETRY", `${response.status} on ${url}, trying fallback ${urlIndex + 1}`);
lastStatus = response.status;
continue;
Expand All @@ -969,7 +973,7 @@ export class BaseExecutor {
log?.warn?.("TIMEOUT", `Fetch timeout after ${this.getTimeoutMs()}ms on ${url}`);
}
lastError = err;
if (urlIndex + 1 < fallbackCount) {
if (!skipUpstreamRetry && urlIndex + 1 < fallbackCount) {
log?.debug?.("RETRY", `Error on ${url}, trying fallback ${urlIndex + 1}`);
continue;
}
Expand Down
3 changes: 3 additions & 0 deletions open-sse/handlers/chatCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ export async function handleChatCore({
comboExecutionKey = null,
disableEmergencyFallback = false,
cachedSettings = null,
skipUpstreamRetry = false,
}) {
let { provider, model, extendedContext } = modelInfo;
// apiFormat is an optional custom-model marker injected by getModelInfo for
Expand Down Expand Up @@ -3170,6 +3171,7 @@ export async function handleChatCore({
upstreamExtraHeaders: buildUpstreamHeadersForExecute(modelToCall),
clientHeaders: buildExecutorClientHeaders(clientRawRequest?.headers, userAgent),
onCredentialsRefreshed,
skipUpstreamRetry,
});
trace("post_executor", { status: res?.response?.status });

Expand Down Expand Up @@ -3661,6 +3663,7 @@ export async function handleChatCore({
upstreamExtraHeaders: buildUpstreamHeadersForExecute(retryModelId),
clientHeaders: buildExecutorClientHeaders(clientRawRequest?.headers, userAgent),
onCredentialsRefreshed,
skipUpstreamRetry: isCombo,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: skipUpstreamRetry: isCombo disables executor-level retries for ALL combo requests, not just those with failoverBeforeRetry: true.

This means combos without failoverBeforeRetry will also skip the executor's intra-URL retry logic (BaseExecutor.RETRY_CONFIG). For example, if an upstream provider returns a transient 500, the executor won't retry that URL even if the combo config would normally allow retries.

If the combo layer is intended to fully own retry behavior, this is fine. But if non-fobr combos should still benefit from executor-level retries as a safety net, this should be:

Suggested change
skipUpstreamRetry: isCombo,
skipUpstreamRetry: isCombo && skipUpstreamRetry,

This way, executor retries are only skipped when both conditions are met: it's a combo request AND skipUpstreamRetry was explicitly passed as true (i.e., failoverBeforeRetry is enabled).

});

if (retryResult.response.ok) {
Expand Down
8 changes: 8 additions & 0 deletions open-sse/services/accountFallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,14 @@ export function shouldMarkAccountExhaustedFrom429(
);
}

/**
* Clear all in-memory model lockouts and failure state (for tests / full reset).
*/
export function clearAllModelLockouts(): void {
modelLockouts.clear();
modelFailureState.clear();
}

/**
* Check if a specific model on a specific account is locked
* @returns {boolean}
Expand Down
Loading