-
Notifications
You must be signed in to change notification settings - Fork 2
fix(nexus): exclude models with unconfigured provider credentials from routed selection #1632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /** @jest-environment node */ | ||
|
|
||
| const mockGetOpenAI = jest.fn() | ||
| const mockGetGoogleAI = jest.fn() | ||
| const mockGetAzureOpenAI = jest.fn() | ||
| const mockGetLatimer = jest.fn() | ||
|
|
||
| jest.mock("@/lib/settings-manager", () => ({ | ||
| Settings: { | ||
| getOpenAI: () => mockGetOpenAI(), | ||
| getGoogleAI: () => mockGetGoogleAI(), | ||
| getAzureOpenAI: () => mockGetAzureOpenAI(), | ||
| getLatimer: () => mockGetLatimer(), | ||
| }, | ||
| })) | ||
| jest.mock("@/lib/logger", () => ({ | ||
| createLogger: () => ({ info: jest.fn(), warn: jest.fn(), error: jest.fn(), debug: jest.fn() }), | ||
| })) | ||
|
|
||
| import { getConfiguredChatProviders } from "../provider-credentials" | ||
|
|
||
| describe("getConfiguredChatProviders", () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| mockGetOpenAI.mockResolvedValue(null) | ||
| mockGetGoogleAI.mockResolvedValue(null) | ||
| mockGetAzureOpenAI.mockResolvedValue({ key: null, endpoint: null, resourceName: null }) | ||
| mockGetLatimer.mockResolvedValue(null) | ||
| }) | ||
|
|
||
| it("always includes amazon-bedrock even with no keys configured", async () => { | ||
| const configured = await getConfiguredChatProviders() | ||
| expect(configured).toEqual(new Set(["amazon-bedrock"])) | ||
| }) | ||
|
|
||
| it("includes every provider whose credential is present", async () => { | ||
| mockGetOpenAI.mockResolvedValue("sk-test") | ||
| mockGetGoogleAI.mockResolvedValue("google-key") | ||
| mockGetAzureOpenAI.mockResolvedValue({ key: "azure-key", endpoint: null, resourceName: "resource" }) | ||
| mockGetLatimer.mockResolvedValue("latimer-key") | ||
| const configured = await getConfiguredChatProviders() | ||
| expect(configured).toEqual(new Set(["openai", "google", "amazon-bedrock", "azure", "latimer"])) | ||
| }) | ||
|
|
||
| it("treats whitespace-only keys as not configured", async () => { | ||
| mockGetOpenAI.mockResolvedValue(" ") | ||
| const configured = await getConfiguredChatProviders() | ||
| expect(configured.has("openai")).toBe(false) | ||
| }) | ||
|
|
||
| it("requires both the Azure key and resource name", async () => { | ||
| mockGetAzureOpenAI.mockResolvedValue({ key: "azure-key", endpoint: null, resourceName: null }) | ||
| const configured = await getConfiguredChatProviders() | ||
| expect(configured.has("azure")).toBe(false) | ||
| }) | ||
|
|
||
| it("fails open when the credential probe throws", async () => { | ||
| mockGetOpenAI.mockRejectedValue(new Error("settings unavailable")) | ||
| const configured = await getConfiguredChatProviders() | ||
| expect(configured).toEqual(new Set(["openai", "google", "amazon-bedrock", "azure", "latimer"])) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { Settings } from "@/lib/settings-manager" | ||
| import { createLogger } from "@/lib/logger" | ||
|
|
||
| const log = createLogger({ module: "provider-credentials" }) | ||
|
|
||
| const ALL_CHAT_PROVIDERS = ["openai", "google", "amazon-bedrock", "azure", "latimer"] as const | ||
|
|
||
| /** | ||
| * Returns the lowercase provider identifiers whose credentials are configured | ||
| * (database settings with environment fallback, cached by the settings | ||
| * manager), so routing can skip models that would fail provider creation. | ||
| * | ||
| * amazon-bedrock is always included: it can authenticate through the default | ||
| * AWS credential chain (ECS/Lambda IAM roles), which cannot be probed here. | ||
| * | ||
| * Fails open — a probe failure must not take chat down, so every provider is | ||
| * treated as configured and a missing key surfaces at stream time as before. | ||
| */ | ||
| export async function getConfiguredChatProviders(): Promise<Set<string>> { | ||
| try { | ||
| const [openAiKey, googleKey, azure, latimerKey] = await Promise.all([ | ||
| Settings.getOpenAI(), | ||
| Settings.getGoogleAI(), | ||
| Settings.getAzureOpenAI(), | ||
| Settings.getLatimer(), | ||
| ]) | ||
| const configured = new Set<string>(["amazon-bedrock"]) | ||
| if (openAiKey?.trim()) configured.add("openai") | ||
| if (googleKey?.trim()) configured.add("google") | ||
| if (azure.key?.trim() && azure.resourceName?.trim()) configured.add("azure") | ||
| if (latimerKey?.trim()) configured.add("latimer") | ||
| return configured | ||
| } catch (error) { | ||
| log.warn("Provider credential probe failed; treating every provider as configured", { | ||
| error: error instanceof Error ? error.message : String(error), | ||
| }) | ||
| return new Set(ALL_CHAT_PROVIDERS) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When active Standard/Auto routing has no accessible model from a configured provider, passing only
routableModelsmeansselectRoutedTextModelcannot find the explicitly selected fallback because it searches for that fallback inside itsmodelsargument. The request therefore throwsNo accessible Nexus model is availablebefore provider creation instead of retaining the selected model and surfacing its provider-configuration error as the new comment and routing documentation specify. Keep the unconfigured fallback out of normal candidate selection, but allow it as the final non-routed fallback when no configured alternative exists.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behavior locked in with tests in 60c8140, but keeping the fail-fast rather than executing the unconfigured explicit fallback: both outcomes are errors, and running a model whose provider creation must throw reproduces the exact stream-time missing-key 500 this PR removes — a misleading mid-stream crash instead of an honest routing error. The docs carve-out applies to the paths that execute the explicit model directly (router-off without required tools, shadow retention), which are unchanged.