Files
OmniRoute/src/lib/tokenHealthCheckProxyGuard.ts
Diego Rodrigues de Sa e Souza 5d1f4687eb fix(sse): fail closed on background token-refresh for dead proxy pools (#13470) (#13793)
Merged in the 2026-09-16 sweep of the maintainer's own open PRs, at the owner's explicit instruction. No push was made to the PR branch: the merge took the head as the owning session left it (verified OPEN, non-draft and MERGEABLE against the release tip immediately before merging).
2026-09-16 06:12:59 -03:00

25 lines
1.2 KiB
TypeScript

import { resolveProxyForConnection } from "@/lib/db/settings";
import { hasBlockingProxyAssignment } from "@/lib/db/proxies";
/**
* #13470: fail-closed guard for the token-health-check sweep, mirroring the #6246
* contract the interactive chat/executor path enforces via
* `safeResolveProxy`/`hasBlockingProxyAssignment` (src/sse/handlers/chatHelpers.ts).
* Before this guard, the sweep called `resolveProxyForConnection` directly and a
* connection whose assigned proxy pool had gone fully dead resolved silently to
* direct/env-proxy egress — leaking the refresh-token exchange on the real IP.
* Callers must skip (log + return) rather than throw: this sweeps many connections
* per tick and one blocked connection must not abort the rest.
*/
export async function resolveGuardedProxyConfig(
connectionId: string,
provider?: string
): Promise<{ proxyConfig: unknown; blocked: boolean }> {
const resolved = (await resolveProxyForConnection(connectionId)) as { proxy?: unknown } | null;
const proxyConfig = resolved?.proxy ?? null;
if (!proxyConfig && hasBlockingProxyAssignment(connectionId, provider)) {
return { proxyConfig: null, blocked: true };
}
return { proxyConfig, blocked: false };
}