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
2 changes: 1 addition & 1 deletion open-sse/executors/cliproxyapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export class CliproxyapiExecutor extends BaseExecutor {
input.log?.warn?.("CPA", `CLIProxyAPI rate limited: ${response.status}`);
}

return { response, url, headers, transformedBody };
return { response, url, headers, transformedBody, transport: "cliproxyapi" as const };
}

/**
Expand Down
11 changes: 8 additions & 3 deletions open-sse/handlers/chatCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,9 @@ export async function handleChatCore({
// and delegate so the existing call sites stay byte-identical.
const recordKeyHealthStatus = (
status: number,
creds: Record<string, unknown> | null | undefined
): void => recordKeyHealthStatusFor(status, creds, log);
creds: Record<string, unknown> | null | undefined,
transport?: string
): void => recordKeyHealthStatusFor(status, creds, log, transport);

const persistCodexQuotaState = async (headers: Record<string, string> | null, status = 0) => {
const currentConnectionId = getCurrentConnectionId();
Expand Down Expand Up @@ -2988,7 +2989,11 @@ export async function handleChatCore({
rawResult._executionCredentials?.connectionId &&
rawResult._executionCredentials?.apiKey
) {
recordKeyHealthStatus(status, rawResult._executionCredentials);
recordKeyHealthStatus(
status,
rawResult._executionCredentials,
rawResult.transport
);
}
releaseRawResultAccountSemaphore =
typeof rawResult._accountSemaphoreRelease === "function"
Expand Down
7 changes: 6 additions & 1 deletion open-sse/handlers/chatCore/keyHealth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ type KeyHealthLog = {
export function recordKeyHealthStatus(
status: number,
creds: Record<string, unknown> | null | undefined,
log?: KeyHealthLog
log?: KeyHealthLog,
transport?: string
): void {
// CLIProxyAPI owns a shared external credential pool. Its auth failures cannot be
// attributed to the native OmniRoute connection selected before proxy dispatch.
if (transport === "cliproxyapi") return;

const connId = creds?.connectionId as string | undefined;
if (!connId) return;

Expand Down
10 changes: 9 additions & 1 deletion open-sse/handlers/chatCore/upstreamTimeouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,15 @@ export function normalizeExecutorResult(
url?: string;
headers?: Record<string, string>;
transformedBody?: unknown;
transport?: string;
}
): { response: Response; url: string; headers: Record<string, string>; transformedBody: unknown } {
): {
response: Response;
url: string;
headers: Record<string, string>;
transformedBody: unknown;
transport?: string;
} {
if (result instanceof Response) {
return { response: result, url: "", headers: {}, transformedBody: null };
}
Expand All @@ -116,6 +123,7 @@ export function normalizeExecutorResult(
url: result.url || "",
headers: result.headers || {},
transformedBody: result.transformedBody ?? null,
transport: result.transport,
};
}

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/chatcore-key-health.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,9 @@ test("non-401 / non-2xx status does not touch key health", () => {
recordKeyHealthStatus(500, creds(conn), noopLog);
assert.equal(getAllKeyHealth()[`${conn}:primary`], undefined);
});

test("CPA pool failures do not poison the selected native connection key", () => {
const conn = "kh-cpa-pool-isolation";
recordKeyHealthStatus(401, creds(conn), noopLog, "cliproxyapi");
assert.equal(getAllKeyHealth()[`${conn}:primary`], undefined);
});
Loading