Repository navigation
fix(inference): accept onboard provider aliases + guide dcode users (#6321) #6378
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 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
069db65
fix(inference): accept onboard provider aliases + guide dcode users (…
yanyunl1991 db0423a
fix(inference): guide past SSRF block on same-provider switch (#6321 …
yanyunl1991 974439e
test(inference-set): parse hostname in SSRF stub, drop if-statements …
yanyunl1991 7832449
fix(inference-set): scope same-provider hint to SSRF endpoint errors …
yanyunl1991 93e0dd3
Merge remote-tracking branch 'origin/main' into fix/inference-set-pro…
yanyunl1991 ad5205a
docs(inference): document provider aliases + same-provider switch; fi…
yanyunl1991 52699af
test(inference-set): fix dcode quoting test typing under typecheck:cl…
yanyunl1991 19e8fea
docs(inference-set): annotate facet-2 guidance design + widen tests (…
yanyunl1991 f2f89f2
test(inference-set): assert no mutation/side-effect after SSRF reject…
yanyunl1991 93baa4f
fix(inference-set): accept the onboard-established endpoint via ident…
yanyunl1991 dd4cea2
docs(inference-set): make the endpoint identity-match trust boundary …
yanyunl1991 4f005be
fix(inference): remove same-endpoint SSRF bypass; always DNS-guard su…
prekshivyas cb87b89
test(inference): correct stale identity-match comment after bypass re…
prekshivyas 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,307 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Regression coverage for #6321: | ||
| // Facet 1 — `inference set --provider anthropicCompatible` (the installer | ||
| // name onboard accepts) was rejected as unsupported; only the OpenShell | ||
| // name `compatible-anthropic-endpoint` was accepted. The two commands | ||
| // used different vocabularies for the same provider. | ||
| // Facet 3 — `inference set` on a Deep Agents (dcode / | ||
| // langchain-deepagents-code) sandbox refused with a blunt message and no | ||
| // next step. dcode bakes its model at image-build time, so the fix is an | ||
| // actionable error pointing at re-onboard. | ||
|
|
||
| import { describe, expect, it, vi } from "vitest"; | ||
| import type { ConfigValue } from "../security/credential-filter"; | ||
| import { | ||
| INFERENCE_SET_INSTALLER_PROVIDER_ALIASES, | ||
| INFERENCE_SET_SUPPORTED_PROVIDER_NAMES, | ||
| normalizeInferenceSetProvider, | ||
| runInferenceSet, | ||
| } from "./inference-set"; | ||
| import { baseSession, createDeps } from "./inference-set.test-support"; | ||
|
|
||
| // onboard's provider config is the source of truth the local alias map must | ||
| // stay in sync with. Imported here (test only — not into the inference-set hot | ||
| // path) to drive the parity check below. providers.ts is a CJS module. | ||
| import * as onboardProvidersNs from "../onboard/providers"; | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const onboardProviders: any = | ||
| (onboardProvidersNs as unknown as { default?: unknown }).default ?? onboardProvidersNs; | ||
|
|
||
| describe("normalizeInferenceSetProvider — facet 1 provider-name drift (#6321)", () => { | ||
| it("maps the installer name onboard uses to its OpenShell provider name", () => { | ||
| expect(normalizeInferenceSetProvider("anthropicCompatible")).toBe( | ||
| "compatible-anthropic-endpoint", | ||
| ); | ||
| expect(normalizeInferenceSetProvider("build")).toBe("nvidia-prod"); | ||
| expect(normalizeInferenceSetProvider("openai")).toBe("openai-api"); | ||
| expect(normalizeInferenceSetProvider("custom")).toBe("compatible-endpoint"); | ||
| expect(normalizeInferenceSetProvider("ollama")).toBe("ollama-local"); | ||
| }); | ||
|
|
||
| it("is case-insensitive and trims whitespace on the installer key", () => { | ||
| expect(normalizeInferenceSetProvider(" AnthropicCompatible ")).toBe( | ||
| "compatible-anthropic-endpoint", | ||
| ); | ||
| expect(normalizeInferenceSetProvider("BUILD")).toBe("nvidia-prod"); | ||
| }); | ||
|
|
||
| it("passes OpenShell provider names through unchanged", () => { | ||
| for (const name of INFERENCE_SET_SUPPORTED_PROVIDER_NAMES) { | ||
| expect(normalizeInferenceSetProvider(name)).toBe(name); | ||
| } | ||
| }); | ||
|
|
||
| it("passes an unrecognized provider through unchanged (validation still rejects it later)", () => { | ||
| expect(normalizeInferenceSetProvider("totally-made-up")).toBe("totally-made-up"); | ||
| }); | ||
|
|
||
| it("every installer alias resolves to a supported OpenShell provider name (drift guard)", () => { | ||
| const supported = new Set<string>(INFERENCE_SET_SUPPORTED_PROVIDER_NAMES); | ||
| for (const [alias, resolved] of Object.entries(INFERENCE_SET_INSTALLER_PROVIDER_ALIASES)) { | ||
| expect( | ||
| supported.has(resolved), | ||
| `${alias} -> ${resolved} not in SUPPORTED_PROVIDER_NAMES`, | ||
| ).toBe(true); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe("runInferenceSet accepts the installer provider name — facet 1 (#6321)", () => { | ||
| it("does not reject `anthropicCompatible` as unsupported", async () => { | ||
| // Reporter's exact command shape: onboard with anthropicCompatible, then | ||
| // switch with the same name. The provider must normalize to | ||
| // compatible-anthropic-endpoint and reuse durable endpoint metadata rather | ||
| // than hit "Unsupported provider 'anthropicCompatible'". | ||
| const deps = createDeps({ | ||
| config: { | ||
| agents: { defaults: { model: { primary: "inference/anthropic/model-a" } } }, | ||
| models: { providers: { inference: { api: "anthropic-messages", models: [] } } }, | ||
| }, | ||
| entry: { | ||
| name: "alpha", | ||
| agent: "openclaw", | ||
| provider: "compatible-anthropic-endpoint", | ||
| model: "anthropic/model-a", | ||
| endpointUrl: "https://inference-api.nvidia.com/v1", | ||
| credentialEnv: "COMPATIBLE_ANTHROPIC_API_KEY", | ||
| preferredInferenceApi: "anthropic-messages", | ||
| }, | ||
| session: baseSession({ | ||
| provider: "compatible-anthropic-endpoint", | ||
| model: "anthropic/model-a", | ||
| endpointUrl: "https://inference-api.nvidia.com/v1", | ||
| credentialEnv: "COMPATIBLE_ANTHROPIC_API_KEY", | ||
| preferredInferenceApi: "anthropic-messages", | ||
| }), | ||
| }); | ||
|
|
||
| await expect( | ||
| runInferenceSet( | ||
| { provider: "anthropicCompatible", model: "anthropic/model-b", noVerify: true }, | ||
| deps, | ||
| ), | ||
| ).resolves.toBeTruthy(); | ||
|
|
||
| // The persisted provider must be the normalized OpenShell name, not the | ||
| // installer alias, so the sandbox registry stays canonical. | ||
| expect(deps.calls.updateSandbox.mock.calls.at(-1)).toEqual([ | ||
| "alpha", | ||
| expect.objectContaining({ provider: "compatible-anthropic-endpoint" }), | ||
| ]); | ||
| }); | ||
|
|
||
| it("still rejects a genuinely unsupported provider name", async () => { | ||
| const deps = createDeps({ | ||
| config: { agents: { defaults: { model: { primary: "inference/nvidia/model-a" } } } }, | ||
| entry: { name: "alpha", agent: "openclaw" }, | ||
| }); | ||
| await expect( | ||
| runInferenceSet({ provider: "totally-made-up", model: "nvidia/model-a" }, deps), | ||
| ).rejects.toThrow(/Unsupported provider 'totally-made-up'/); | ||
| }); | ||
| }); | ||
|
|
||
| describe("runInferenceSet dcode refusal message — facet 3 (#6321)", () => { | ||
| it("points Deep Agents users at re-onboard instead of a dead-end refusal", async () => { | ||
| const deps = createDeps({ | ||
| config: { agents: { defaults: { model: { primary: "inference/nvidia/model-a" } } } }, | ||
| entry: { name: "dcode-sb", agent: "langchain-deepagents-code" }, | ||
| }); | ||
|
|
||
| await expect( | ||
| runInferenceSet( | ||
| { provider: "nvidia-prod", model: "nvidia/model-a", sandboxName: "dcode-sb" }, | ||
| deps, | ||
| ), | ||
| ).rejects.toThrow(/re-onboard with the new selection/); | ||
|
|
||
| // The message keeps the original "supports OpenClaw and Hermes" statement | ||
| // for compatibility with anything matching on it, and adds the dcode hint. | ||
| await expect( | ||
| runInferenceSet( | ||
| { provider: "nvidia-prod", model: "nvidia/model-a", sandboxName: "dcode-sb" }, | ||
| deps, | ||
| ), | ||
| ).rejects.toThrow(/supports OpenClaw and Hermes sandboxes/); | ||
| }); | ||
|
|
||
| it("does NOT add the dcode hint for other unsupported agents", async () => { | ||
| const deps = createDeps({ | ||
| config: { agents: { defaults: { model: { primary: "inference/nvidia/model-a" } } } }, | ||
| entry: { name: "spark-sb", agent: "spark" }, | ||
| }); | ||
| await expect( | ||
| runInferenceSet( | ||
| { provider: "nvidia-prod", model: "nvidia/model-a", sandboxName: "spark-sb" }, | ||
| deps, | ||
| ), | ||
| ).rejects.toThrow(/supports OpenClaw and Hermes sandboxes; 'spark-sb' uses 'spark'\.$/); | ||
| }); | ||
| }); | ||
|
|
||
| describe("runInferenceSet SSRF-block guidance — facet 2 (#6321)", () => { | ||
| // A stand-in DNS-pinning guard: rejects any URL whose host resolves internal | ||
| // (mirrors rewriteConfigUrlsWithDnsPinning blocking an RFC1918 address). | ||
| function ssrfGuard() { | ||
| return vi.fn(async (value: ConfigValue): Promise<ConfigValue> => { | ||
| if (String(value).includes("inference-api.nvidia.com") || String(value).includes("10.")) { | ||
| throw new Error( | ||
| `URL hostname "inference-api.nvidia.com" resolves to private/internal address "10.48.203.205". This could expose internal services to the sandbox.`, | ||
| ); | ||
| } | ||
| return value; | ||
| }); | ||
| } | ||
|
|
||
| it("keeps the SSRF guard AND adds an actionable hint when the sandbox is already on this provider", async () => { | ||
| // The reporter's case: a sandbox onboarded on compatible-endpoint against an | ||
| // internal Hub. `inference set --endpoint-url <internal>` still (correctly) | ||
| // trips the SSRF guard — but the message now tells the operator they can | ||
| // omit --endpoint-url to switch only the model. | ||
| const deps = createDeps({ | ||
| config: { agents: { defaults: { model: { primary: "inference/nvidia/model-a" } } } }, | ||
| entry: { | ||
| name: "alpha", | ||
| agent: "openclaw", | ||
| provider: "compatible-endpoint", | ||
| model: "nvidia/model-a", | ||
| credentialEnv: "COMPATIBLE_API_KEY", | ||
| preferredInferenceApi: "openai-completions", | ||
| }, | ||
| rewriteConfigUrlsWithDnsPinning: ssrfGuard(), | ||
| }); | ||
|
|
||
| const attempt = runInferenceSet( | ||
| { | ||
| provider: "compatible-endpoint", | ||
| model: "nvidia/model-b", | ||
| endpointUrl: "https://inference-api.nvidia.com/v1", | ||
| noVerify: true, | ||
| }, | ||
| deps, | ||
| ); | ||
| // Guard still fires (no security relaxation) ... | ||
| await expect(attempt).rejects.toThrow( | ||
| /endpoint-url is not allowed:.*private\/internal address/, | ||
| ); | ||
| // ... but the message now guides toward the working same-provider path. | ||
| await expect(attempt).rejects.toThrow(/already configured for 'compatible-endpoint'/); | ||
| await expect(attempt).rejects.toThrow(/omit --endpoint-url/); | ||
| }); | ||
|
|
||
| it("switches the model WITHOUT --endpoint-url on a same-provider sandbox (the guided path works, guard never runs)", async () => { | ||
| // Proves the hint's advice is real: dropping --endpoint-url reuses the | ||
| // established route and the model switch succeeds without touching the guard. | ||
| const deps = createDeps({ | ||
| config: { | ||
| agents: { defaults: { model: { primary: "inference/nvidia/model-a" } } }, | ||
| models: { providers: { inference: { api: "openai-completions", models: [] } } }, | ||
| }, | ||
| entry: { | ||
| name: "alpha", | ||
| agent: "openclaw", | ||
| provider: "compatible-endpoint", | ||
| model: "nvidia/model-a", | ||
| credentialEnv: "COMPATIBLE_API_KEY", | ||
| preferredInferenceApi: "openai-completions", | ||
| }, | ||
| rewriteConfigUrlsWithDnsPinning: ssrfGuard(), | ||
| }); | ||
|
|
||
| await expect( | ||
| runInferenceSet( | ||
| { provider: "compatible-endpoint", model: "nvidia/model-b", noVerify: true }, | ||
| deps, | ||
| ), | ||
| ).resolves.toBeTruthy(); | ||
| // No --endpoint-url supplied → the SSRF guard is never consulted. | ||
| expect(deps.calls.rewriteConfigUrlsWithDnsPinning).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("does NOT add the same-provider hint when switching to a DIFFERENT provider (bare SSRF error stands)", async () => { | ||
| // entry.provider is nvidia-prod; the operator is switching to | ||
| // compatible-endpoint with an internal URL. There is no established route to | ||
| // fall back to, so the guard's bare message stands with no "omit" hint. | ||
| const deps = createDeps({ | ||
| config: { agents: { defaults: { model: { primary: "inference/nvidia/model-a" } } } }, | ||
| entry: { | ||
| name: "alpha", | ||
| agent: "openclaw", | ||
| provider: "nvidia-prod", | ||
| model: "nvidia/model-a", | ||
| }, | ||
| rewriteConfigUrlsWithDnsPinning: ssrfGuard(), | ||
| }); | ||
|
|
||
| const attempt = runInferenceSet( | ||
| { | ||
| provider: "compatible-endpoint", | ||
| model: "nvidia/model-b", | ||
| endpointUrl: "https://inference-api.nvidia.com/v1", | ||
| noVerify: true, | ||
| }, | ||
| deps, | ||
| ); | ||
| await expect(attempt).rejects.toThrow( | ||
| /endpoint-url is not allowed:.*private\/internal address/, | ||
| ); | ||
| await expect(attempt).rejects.not.toThrow(/omit --endpoint-url/); | ||
| }); | ||
| }); | ||
|
|
||
| describe("installer alias parity with onboard provider config — facet 1 drift guard (#6321)", () => { | ||
| it("matches onboard's getEffectiveProviderName for every shared provider key", () => { | ||
| // Bind the local alias map to onboard's source of truth: for every installer | ||
| // key onboard accepts that resolves to a provider inference set supports, | ||
| // normalizeInferenceSetProvider must produce the exact same OpenShell name. | ||
| // If onboard renames a provider or adds an alias, this fails until the local | ||
| // map is updated — closing the drift gap CodeRabbit / the PR advisor flagged. | ||
| const supported = new Set<string>(INFERENCE_SET_SUPPORTED_PROVIDER_NAMES); | ||
| const aliasKeys: string[] = Object.keys( | ||
| onboardProviders.NON_INTERACTIVE_PROVIDER_ALIASES ?? {}, | ||
| ); | ||
| const directKeys: string[] = Array.from( | ||
| (onboardProviders.NON_INTERACTIVE_PROVIDER_KEYS ?? new Set()) as Iterable<string>, | ||
| ); | ||
| const onboardKeys = [...new Set([...aliasKeys, ...directKeys])]; | ||
| // Sanity: onboard exposes a non-trivial key set (guards against an import | ||
| // that silently resolved to an empty object). | ||
| expect(onboardKeys.length).toBeGreaterThan(5); | ||
|
|
||
| const checked: string[] = []; | ||
| for (const key of onboardKeys) { | ||
| const canonical = onboardProviders.NON_INTERACTIVE_PROVIDER_ALIASES?.[key] ?? key; | ||
| const onboardResolved: string | null = onboardProviders.getEffectiveProviderName(canonical); | ||
| if (!onboardResolved || !supported.has(onboardResolved)) continue; // not an inference-set target | ||
| checked.push(key); | ||
| expect( | ||
| normalizeInferenceSetProvider(key), | ||
| `inference set must map onboard key '${key}' to '${onboardResolved}'`, | ||
| ).toBe(onboardResolved); | ||
| } | ||
| // We actually exercised a meaningful set (anthropicCompatible, build, etc.). | ||
| expect(checked.length).toBeGreaterThan(3); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.