Skip to content
20 changes: 19 additions & 1 deletion docs/inference/use-shared-gateway-routes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ Onboarding exits before provider or route mutation when those fields differ.

Do not run `openshell inference set` directly on a shared NemoClaw gateway because that bypasses the registry compatibility checks.

<AgentOnly variant="openclaw,hermes">

## Change the Live Route With Inference Set

Use `$$nemoclaw <name> inference set` to change a registered sandbox's provider or model outside onboarding and `connect`.

```bash
$$nemoclaw <name> inference set --provider <provider> --model <model>
```

When only the provider or model differs, the command warns immediately before it re-points the shared route.
The warning names every affected registered sandbox and its recorded provider and model.
Those sandboxes use the new live route until `connect`, onboarding, or another `inference set` command re-points it.

For the same provider name, custom endpoint, API-family, and credential environment-variable values must remain compatible.
Incomplete routes and invalid gateway bindings also stop the command before route, agent config, or registry mutation.

</AgentOnly>

## Restore a Sandbox Route When You Connect

Connect to a sandbox when you want its recorded provider and model to become live again.
Expand Down Expand Up @@ -70,7 +89,6 @@ NemoClaw fails closed when it cannot prove that a route change preserves the pro
- For a provider-global identity conflict, align the endpoint, API family, and credential environment-variable name, or remove a sandbox you no longer need.
- For incomplete legacy custom-route metadata, back up and remove the affected sandbox, then re-onboard it with an explicit endpoint and API family.
- For an invalid gateway binding, restore known-good `gatewayName` and `gatewayPort` metadata from a trusted backup, or back up and remove the sandbox before re-onboarding it.
- For a runtime `inference set` conflict, align the registered sandbox routes or remove the conflicting sandbox before retrying.

Refer to [Troubleshooting a Shared Inference Route Conflict](../../reference/troubleshooting#a-shared-inference-route-conflicts-with-another-sandbox) for the recovery commands.

Expand Down
15 changes: 12 additions & 3 deletions docs/reference/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3372,9 +3372,18 @@ Switch the active inference provider or model for a NemoClaw-managed Hermes sand

By default, the command syncs the default registered sandbox.

Each OpenShell gateway exposes one inference route to every sandbox registered on that gateway. Before changing the route, NemoClaw compares the requested provider and model with every same-gateway registry entry, including stopped sandboxes. Custom compatible routes must also have matching normalized endpoint URLs and API families. Provider-global credential environment-variable names must also match for the same provider name. If a route conflicts or a legacy custom route lacks enough endpoint or API-family metadata to prove compatibility, the command exits non-zero before changing the OpenShell route, agent config, or host registry and names the conflicting sandboxes. Align those sandboxes to the same route or remove a conflicting sandbox that you no longer need.

Onboarding and `connect` can time-share compatible provider and model routes without replacing provider-global configuration. Refer to [Use Shared Gateway Routes](../inference/manage-inference/use-shared-gateway-routes) for the onboarding warnings, compatibility fields, and status drift report.
Each OpenShell gateway exposes one inference route to every sandbox registered on that gateway.
Before changing the route, NemoClaw compares it with every same-gateway registry entry, including stopped sandboxes.
When only the provider or model differs, the command names the affected sandboxes and warns immediately before it re-points the shared route.
Those sandboxes use the new live route until `connect`, onboarding, or another `inference set` command re-points it.

For the same provider name, custom compatible routes must have matching normalized endpoint URLs and API families.
Provider-global credential environment-variable names must also match.
Endpoint, API-family, credential, incomplete-route, and invalid-gateway-binding conflicts remain fail-closed.
The command exits nonzero before changing the OpenShell route, agent config, or host registry and names the conflicting sandboxes.
Align the provider-global configuration, repair incomplete metadata, or remove a conflicting sandbox that you no longer need.

Onboarding, `connect`, and `inference set` can time-share compatible provider and model routes without replacing provider-global configuration. Refer to [Use Shared Gateway Routes](../inference/manage-inference/use-shared-gateway-routes) for route-change warnings, compatibility fields, and the status drift report.

```bash
$$nemoclaw inference set --provider <provider> --model <model> [--sandbox <name>] [--no-verify] [--endpoint-url <url>] [--credential-env <ENV>] [--inference-api <api>]
Expand Down
45 changes: 34 additions & 11 deletions src/lib/actions/inference-set-gateway-route-containment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe("runtime shared gateway route containment", () => {
expect(deps.calls.updateSandbox).not.toHaveBeenCalled();
});

it("rejects a same-gateway conflict before OpenShell, config, or registry mutation (#6315)", async () => {
it("warns and re-points a same-gateway provider/model-only route (#11890)", async () => {
const deps = createDeps({
config: {},
entries: [entry("alpha"), entry("stopped-peer")],
Expand All @@ -92,13 +92,31 @@ describe("runtime shared gateway route containment", () => {
{ provider: "nvidia-prod", model: "nvidia/model-b", sandboxName: "alpha" },
deps,
),
).rejects.toThrow("stopped-peer");
).resolves.toMatchObject({ sandboxName: "alpha", model: "nvidia/model-b" });

expect(deps.calls.captureOpenshell).not.toHaveBeenCalled();
expect(deps.calls.readSandboxConfig).not.toHaveBeenCalled();
expect(deps.calls.writeSandboxConfig).not.toHaveBeenCalled();
expect(deps.calls.updateSandbox).not.toHaveBeenCalled();
expect(deps.calls.updateSession).not.toHaveBeenCalled();
expect(deps.calls.captureOpenshell).toHaveBeenCalledWith(
[
"inference",
"set",
"-g",
"nemoclaw",
"--provider",
"nvidia-prod",
"--model",
"nvidia/model-b",
],
expect.objectContaining({ ignoreError: true }),
);
const messages = deps.calls.log.mock.calls.map(([message]) => message);
const warningIndex = messages.findIndex((message) =>
message.includes("Changing inference for 'alpha' will re-point"),
);
const mutationIndex = messages.findIndex((message) =>
message.includes("Setting OpenShell inference route"),
);
expect(warningIndex).toBeGreaterThanOrEqual(0);
expect(messages[warningIndex]).toContain("'stopped-peer' (nvidia-prod / nvidia/model-a)");
expect(warningIndex).toBeLessThan(mutationIndex);
});

it("targets the selected sandbox gateway and allows a conflicting route elsewhere (#6315)", async () => {
Expand Down Expand Up @@ -614,7 +632,7 @@ describe("runtime shared gateway route containment", () => {
expect(deps.calls.updateSandbox).not.toHaveBeenCalled();
});

it("serializes same-gateway mutations and rejects a conflicting write", async () => {
it("serializes same-gateway provider/model mutations and warns about route impact (#11890)", async () => {
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "nemoclaw-route-lock-"));
try {
const entries = [entry("route-lock-alpha"), entry("route-lock-beta")];
Expand Down Expand Up @@ -648,16 +666,21 @@ describe("runtime shared gateway route containment", () => {
),
]);

expect(results.map((result) => result.status).sort()).toEqual(["fulfilled", "rejected"]);
expect(results.map((result) => result.status)).toEqual(["fulfilled", "fulfilled"]);
expect(
deps.calls.captureOpenshell.mock.calls.filter(
([args]) => args[0] === "inference" && args[1] === "set",
),
).toHaveLength(1);
).toHaveLength(2);
expect(entries).toEqual([
expect.objectContaining({ provider: "nvidia-prod", model: "nvidia/model-a" }),
expect.objectContaining({ provider: "nvidia-prod", model: "nvidia/model-a" }),
expect.objectContaining({ provider: "anthropic-prod", model: "claude-new" }),
]);
expect(
deps.calls.log.mock.calls.some(([message]) =>
message.includes("will re-point the one shared inference route"),
),
).toBe(true);
expect(deps.calls.withGatewayRouteMutationLock).toHaveBeenCalledTimes(2);
} finally {
await fs.rm(stateDir, { recursive: true, force: true });
Expand Down
21 changes: 15 additions & 6 deletions src/lib/actions/inference-set-route-containment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import {
checkGatewayRouteCompatibility,
formatGatewayRouteConflict,
formatGatewayRouteImpactWarning,
isAdvisoryGatewayRouteConflict,
} from "../inference/gateway-route-compatibility";
import {
buildHttpsPinRouteBaseUrl,
Expand Down Expand Up @@ -92,6 +94,7 @@ export interface PreparedInferenceSetRoute {
/** Invocation-only source URL; never persisted for HTTPS-pin routes. */
preliminaryExplicitSourceEndpointUrl: string | null;
preliminaryRegistryMetadata: RegistryInferenceMetadata;
preliminaryRouteImpactWarning: string | null;
}

const CUSTOM_COMPATIBLE_CREDENTIAL_ENV: Record<string, string> = {
Expand Down Expand Up @@ -402,23 +405,25 @@ function registryMetadataForProviderSwitch(options: {
};
}

function assertGatewayRouteCompatibility(options: {
function routeImpactWarningOrThrow(options: {
gatewayName: string;
sandboxName: string;
provider: string;
model: string;
metadata: RegistryInferenceMetadata;
sandboxes: SandboxEntry[];
}): void {
}): string | null {
const compatibility = checkGatewayRouteCompatibility({
gatewayName: options.gatewayName,
sandboxName: options.sandboxName,
route: { provider: options.provider, model: options.model, ...options.metadata },
sandboxes: options.sandboxes,
});
if (!compatibility.ok) {
throw new InferenceSetError(formatGatewayRouteConflict(compatibility), 2);
if (compatibility.ok) return null;
if (isAdvisoryGatewayRouteConflict(compatibility)) {
return formatGatewayRouteImpactWarning(compatibility, "inference-set");
}
throw new InferenceSetError(formatGatewayRouteConflict(compatibility), 2);
}

export function prepareInferenceSetRoute(options: {
Expand Down Expand Up @@ -459,7 +464,7 @@ export function prepareInferenceSetRoute(options: {
session: options.session,
explicitMetadata: preliminaryExplicitMetadata,
});
assertGatewayRouteCompatibility({
const preliminaryRouteImpactWarning = routeImpactWarningOrThrow({
gatewayName,
sandboxName: options.sandboxName,
provider: options.provider,
Expand All @@ -472,6 +477,7 @@ export function prepareInferenceSetRoute(options: {
preliminaryExplicitMetadata,
preliminaryExplicitSourceEndpointUrl: explicit.sourceEndpointUrl,
preliminaryRegistryMetadata,
preliminaryRouteImpactWarning,
};
}

Expand All @@ -492,6 +498,7 @@ export async function finalizeInferenceSetRoute(options: {
explicitPreferredInferenceApi: string | null;
directProviderBinding: InferenceSetProviderBinding | null;
httpsPinProviderBinding: HttpsPinProviderBinding | null;
routeImpactWarning: string | null;
}> {
const { prepared } = options;
if (!prepared.preliminaryExplicitMetadata) {
Expand All @@ -500,6 +507,7 @@ export async function finalizeInferenceSetRoute(options: {
explicitPreferredInferenceApi: null,
directProviderBinding: null,
httpsPinProviderBinding: null,
routeImpactWarning: prepared.preliminaryRouteImpactWarning,
};
}
// Bound once per finalize call: preparation already pinned the credential env
Expand Down Expand Up @@ -602,7 +610,7 @@ export async function finalizeInferenceSetRoute(options: {
token: credentialValue,
providerType,
};
assertGatewayRouteCompatibility({
const routeImpactWarning = routeImpactWarningOrThrow({
gatewayName: prepared.gatewayName,
sandboxName: options.sandboxName,
provider: options.provider,
Expand All @@ -615,5 +623,6 @@ export async function finalizeInferenceSetRoute(options: {
explicitPreferredInferenceApi: registryMetadata.preferredInferenceApi ?? null,
directProviderBinding,
httpsPinProviderBinding,
routeImpactWarning,
};
}
2 changes: 2 additions & 0 deletions src/lib/actions/inference-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ async function runInferenceSetWithoutHostLock(
explicitPreferredInferenceApi,
directProviderBinding,
httpsPinProviderBinding,
routeImpactWarning,
} = await finalizeInferenceSetRoute({
prepared: preparedRoute,
sandboxName,
Expand Down Expand Up @@ -1194,6 +1195,7 @@ async function runInferenceSetWithoutHostLock(
}

await assertProviderCurrentBeforeSelection?.();
if (routeImpactWarning) deps.log(` ${routeImpactWarning}`);
deps.log(` Setting OpenShell inference route: ${provider} / ${model}`);
const setInferenceRoute = () =>
deps.captureOpenshell(
Expand Down
6 changes: 3 additions & 3 deletions src/lib/actions/sandbox/connect-inference-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {
checkGatewayRouteCompatibility,
GatewayRouteConflictError,
isAdvisoryProviderModelRouteConflict,
isAdvisoryGatewayRouteConflict,
} from "../../inference/gateway-route-compatibility";
import { LOCAL_INFERENCE_TIMEOUT_SECS } from "../../onboard/env";
import { resolveRegisteredRuntimeProvider } from "../../onboard/runtime-provider/selection";
Expand Down Expand Up @@ -41,7 +41,7 @@ export function canSandboxGatewayRouteRealign(
sandboxes: readonly SandboxEntry[] = registry.listSandboxes().sandboxes,
): boolean {
const result = sandboxGatewayRouteCompatibility(sandboxName, sb, gatewayName, sandboxes);
return result.ok || isAdvisoryProviderModelRouteConflict(result);
return result.ok || isAdvisoryGatewayRouteConflict(result);
}

export function buildGatewayInferenceSetArgs(
Expand Down Expand Up @@ -77,7 +77,7 @@ export function assertSandboxGatewayRouteCompatible(
gatewayName,
registry.listSandboxes().sandboxes,
);
if (!result.ok && !isAdvisoryProviderModelRouteConflict(result)) {
if (!result.ok && !isAdvisoryGatewayRouteConflict(result)) {
throw new GatewayRouteConflictError(result);
}
}
16 changes: 6 additions & 10 deletions src/lib/inference/gateway-route-compatibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
formatGatewayRouteImpactWarning,
type GatewayInferenceRoute,
isAdvisoryGatewayRouteConflict,
isAdvisoryProviderModelRouteConflict,
preflightGatewayRouteDiscovery,
} from "./gateway-route-compatibility";

Expand Down Expand Up @@ -274,13 +273,16 @@ describe("shared gateway inference route compatibility", () => {
expect(isAdvisoryGatewayRouteConflict(result as Exclude<typeof result, { ok: true }>)).toBe(
true,
);
expect(
isAdvisoryProviderModelRouteConflict(result as Exclude<typeof result, { ok: true }>),
).toBe(true);
const warning = formatGatewayRouteImpactWarning(result as Exclude<typeof result, { ok: true }>);
expect(warning).toContain("will re-point the one shared inference route");
expect(warning).toContain("'stopped-peer' (nvidia-prod / nvidia/model-a)");
expect(warning).toContain("not per sandbox");
expect(
formatGatewayRouteImpactWarning(
result as Exclude<typeof result, { ok: true }>,
"inference-set",
),
).toContain("Changing inference for 'target'");
});

it("allows different routes on different gateways (#6315)", () => {
Expand Down Expand Up @@ -416,9 +418,6 @@ describe("shared gateway inference route compatibility", () => {
expect(isAdvisoryGatewayRouteConflict(result as Exclude<typeof result, { ok: true }>)).toBe(
false,
);
expect(
isAdvisoryProviderModelRouteConflict(result as Exclude<typeof result, { ok: true }>),
).toBe(false);
});

it("does not let a model difference hide a custom endpoint conflict (#6315)", () => {
Expand All @@ -441,9 +440,6 @@ describe("shared gateway inference route compatibility", () => {
ok: false,
conflicts: [{ sandboxName: "custom-peer", reason: "custom-endpoint" }],
});
expect(
isAdvisoryProviderModelRouteConflict(result as Exclude<typeof result, { ok: true }>),
).toBe(false);
});

it.each([
Expand Down
28 changes: 9 additions & 19 deletions src/lib/inference/gateway-route-compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,25 +379,10 @@ export function isAdvisoryGatewayRouteConflict(
);
}

/**
* True only when a provider/model-only route mutation can safely reconcile the
* conflict. Provider-global endpoint, API-family, and credential changes stay
* fail-closed while another registered sandbox depends on the current identity.
*/
export function isAdvisoryProviderModelRouteConflict(
result: Exclude<GatewayRouteCompatibilityResult, { ok: true }>,
): boolean {
return (
result.conflicts.length > 0 &&
result.conflicts.every(
(conflict) => conflict.scope !== "requested" && conflict.reason === "provider-model",
)
);
}

/** Explain the single-gateway side effect immediately before route mutation. */
export function formatGatewayRouteImpactWarning(
result: Exclude<GatewayRouteCompatibilityResult, { ok: true }>,
operation: "onboard" | "inference-set" = "onboard",
): string {
const affected = [...result.conflicts]
.sort((left, right) => left.sandboxName.localeCompare(right.sandboxName))
Expand All @@ -408,9 +393,14 @@ export function formatGatewayRouteImpactWarning(
: name;
})
.join(", ");
const target = result.sandboxName
? `Onboarding '${safeDisplay(result.sandboxName)}'`
: "This onboarding run";
const target =
operation === "inference-set"
? result.sandboxName
? `Changing inference for '${safeDisplay(result.sandboxName)}'`
: "This inference change"
: result.sandboxName
? `Onboarding '${safeDisplay(result.sandboxName)}'`
: "This onboarding run";
const nextRoute = `${safeDisplay(result.route.provider)} / ${safeDisplay(result.route.model)}`;
return (
`Warning: ${target} will re-point the one shared inference route on OpenShell gateway ` +
Expand Down
Loading
Loading