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
22 changes: 20 additions & 2 deletions src/lib/actions/inference-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,20 @@ function observeInferenceRouteForSelection(input: {
return observeInferenceRouteBeforeMutation(input.deps, input.gatewayName);
}

function sharedInferenceRouteChanged(
nativeProvider: boolean,
previous: OpenShellInferenceRouteObservation,
provider: string,
model: string,
): boolean {
if (nativeProvider) return false;
return (
previous.state === "unconfigured" ||
previous.route.provider !== provider ||
previous.route.model !== model
);
}

function providerBackedRouteLacksRollbackTarget(input: {
nativeProvider: boolean;
directProviderBinding: boolean;
Expand Down Expand Up @@ -1591,6 +1605,7 @@ async function runInferenceSetWithoutHostLock(
selectingNative: selectingNative && !selectingNativeLocal,
provider,
expectedAttachment: nativeProviderAuthority,
previousAttachment: previousNativeAttachment,
gatewayName: preparedRoute.gatewayName,
sandboxName,
endpointUrl: registryMetadata.endpointUrl,
Expand Down Expand Up @@ -2088,12 +2103,15 @@ async function runInferenceSetWithoutHostLock(
patched.changed,
retryingOpenClawConfigSync,
appliedProvider,
rollbackRoute?.provider !== provider,
rollbackRoute?.model !== model,
Boolean(nativeSelection.providerChanged),
nativeAttachmentChanged,
nativeLocalAttachmentChanged,
sharedInferenceRouteChanged(selectingNative, preMutationRoute, provider, model),
previousProvider !== provider,
previousModel !== model,
previousInferenceApi !== preferredInferenceApi,
(entry.endpointUrl ?? null) !== (registryMetadata.endpointUrl ?? null),
(entry.credentialEnv ?? null) !== (registryMetadata.credentialEnv ?? null),
],
expectedGatewayName,
);
Expand Down
22 changes: 14 additions & 8 deletions src/lib/actions/inference-set/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export async function prepareNativeSelection(input: {
selectingNative: boolean;
provider: string;
expectedAttachment?: NativeProviderAttachment;
previousAttachment?: NativeProviderAttachment;
gatewayName: string;
sandboxName: string;
endpointUrl?: string | null;
Expand All @@ -198,6 +199,7 @@ export async function prepareNativeSelection(input: {
}): Promise<{
attachment?: NativeProviderAttachment;
attachmentChanged: boolean;
providerChanged?: boolean;
endpointUrl?: string;
}> {
if (!input.selectingNative) return { attachmentChanged: false };
Expand Down Expand Up @@ -251,17 +253,20 @@ export async function prepareNativeSelection(input: {
hostedNativeProvider(input.provider, definition.endpointUrl)?.endpoint,
);
const target = { kind: "named", gatewayName: input.gatewayName } as const;
// Repeated selections reuse the sandbox's attached NVIDIA credential.
// Hermes host credentials use NOUS_API_KEY; OPENAI_API_KEY is its injection slot.
const credentialValue =
input.expectedAttachment &&
(!isNativeNvidiaProvider(input.provider) ||
input.previousAttachment?.providerName === input.expectedAttachment.providerName)
? null
: input.deps.resolveCredentialValue(
input.provider === "hermes-provider" ? "NOUS_API_KEY" : definition.credentialEnv,
) || null;
const ensured = await lifecycle.ensureNativeProvider({
adapter: input.deps.providerAdapter,
target,
// Hosted model selection must not rotate a gateway-shared provider credential.
// Hermes host credentials use NOUS_API_KEY; OPENAI_API_KEY is its injection slot.
credentialValue:
input.expectedAttachment && !isNativeNvidiaProvider(input.provider)
? null
: input.deps.resolveCredentialValue(
input.provider === "hermes-provider" ? "NOUS_API_KEY" : definition.credentialEnv,
) || null,
credentialValue,
...(input.expectedAttachment ? { expected: input.expectedAttachment } : {}),
...(input.expectedAttachment && !authority.read(input.gatewayName)
? { recordedSandboxName: input.sandboxName }
Expand All @@ -285,6 +290,7 @@ export async function prepareNativeSelection(input: {
return {
attachment: attached.receipt,
attachmentChanged: attached.changed,
providerChanged: !input.expectedAttachment || credentialValue !== null,
endpointUrl: attached.receipt.endpointUrl,
};
}
Expand Down
Loading