fix(openrouter): let a data-policy 404 fall back to another account

OpenRouter privacy settings belong to the account, so "No endpoints found
matching your data policy" on one account says nothing about another. The
resource-404 bypass still skips every cooldown, but now returns
shouldFallback: true for this case so the caller can try the next account
with the same request body. Capability mismatches stay request-scoped.
This commit is contained in:
Rafa Martins
2026-11-18 20:17:36 -03:00
committed by diegosouzapw
parent f728df8c09
commit ea246abe1c
3 changed files with 54 additions and 3 deletions

View File

@@ -404,10 +404,15 @@ export const RESOURCE_NOT_FOUND_PATTERNS = [
/\bfile-[a-z0-9_-]+\b[^\n]{0,160}\b(?:not found|does not exist)\b/i,
];
// OpenRouter privacy settings belong to the account, so this 404 says nothing about
// another account serving the same request (#19686).
const ACCOUNT_DATA_POLICY_NOT_FOUND_PATTERN =
/\bno endpoints found\b[^\n]{0,160}\bmatching your data policy\b/i;
export const CAPABILITY_OR_PREFERENCE_NOT_FOUND_PATTERNS = [
/\bno endpoints found that support\b/i,
/\bno allowed providers\b/i,
/\bno endpoints found\b[^\n]{0,160}\bmatching your data policy\b/i,
ACCOUNT_DATA_POLICY_NOT_FOUND_PATTERN,
];
/**
@@ -430,6 +435,11 @@ export function isRequestCapabilityNotFoundResponse(responseBody: unknown): bool
return CAPABILITY_OR_PREFERENCE_NOT_FOUND_PATTERNS.some((pattern) => pattern.test(body));
}
/** Whether a 404 is an account's data-policy refusal, which another account may not share. */
export function isAccountDataPolicyNotFoundResponse(responseBody: unknown): boolean {
return ACCOUNT_DATA_POLICY_NOT_FOUND_PATTERN.test(responseBodyToString(responseBody));
}
function shouldPreserveQuotaSignalsFor429(provider?: string | null): boolean {
if (!provider) return true;
return getProviderCategory(provider) === "oauth";

View File

@@ -1,11 +1,15 @@
import { isResourceNotFoundResponse } from "@omniroute/open-sse/services/errorClassifier.ts";
import {
isAccountDataPolicyNotFoundResponse,
isResourceNotFoundResponse,
} from "@omniroute/open-sse/services/errorClassifier.ts";
type HealthLogger = {
info(tag: string, message: string): void;
};
export type Resource404CooldownBypass = {
shouldFallback: false;
/** True only for an account-scoped data-policy 404: another account may serve the request. */
shouldFallback: boolean;
cooldownMs: 0;
};
@@ -20,6 +24,14 @@ export function getResource404Bypass(
logger: HealthLogger
): Resource404CooldownBypass | null {
if (status !== 404 || !isResourceNotFoundResponse(errorText)) return null;
// The request body, privacy preferences included, is resent unchanged to the next account.
if (isAccountDataPolicyNotFoundResponse(errorText)) {
logger.info(
"AUTH",
`${connectionId.slice(0, 8)} account data-policy 404; trying another account without cooldown`
);
return { shouldFallback: true, cooldownMs: 0 };
}
logger.info(
"AUTH",
`${connectionId.slice(0, 8)} request-resource 404; skipping model/account cooldown`

View File

@@ -81,3 +81,32 @@ test("#19686: getResource404Bypass bypasses cooldown for OpenRouter capability 4
assert.equal(logs.length, 1);
assert.match(logs[0], /conn-123 request-resource 404; skipping model\/account cooldown/);
});
test("#19686: a data-policy 404 skips the cooldown but lets the caller try another account", () => {
const logs: string[] = [];
const mockLogger = {
info: (_tag: string, msg: string) => {
logs.push(msg);
},
};
// OpenRouter privacy settings are per account: another account may serve the same request.
for (const body of [
"No endpoints found matching your data policy",
JSON.stringify({ error: { message: "No endpoints found matching your data policy" } }),
]) {
assert.deepEqual(getResource404Bypass(404, body, "conn-87654321-dcba", mockLogger), {
shouldFallback: true,
cooldownMs: 0,
});
assert.equal(classifyProviderError(404, body, "openrouter"), null);
}
assert.equal(logs.length, 2);
assert.match(logs[0], /conn-876 account data-policy 404/);
// A request capability mismatch stays request-scoped: no other account can serve it.
assert.deepEqual(
getResource404Bypass(404, "No endpoints found that support image input", "conn-1", mockLogger),
{ shouldFallback: false, cooldownMs: 0 }
);
});