From fe8a7b2e812895a3d5c1270177136a5fc1ced69f Mon Sep 17 00:00:00 2001 From: Will Curran Date: Fri, 23 Oct 2026 16:13:59 -0700 Subject: [PATCH 1/3] fix(inference): preserve no-change outcomes for native repeats --- src/lib/actions/inference-set.ts | 21 +++++++++++++++++++-- src/lib/actions/inference-set/native.ts | 19 +++++++++++-------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/lib/actions/inference-set.ts b/src/lib/actions/inference-set.ts index 4469b15dc64..570463a04a5 100644 --- a/src/lib/actions/inference-set.ts +++ b/src/lib/actions/inference-set.ts @@ -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; @@ -2088,12 +2102,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, ); diff --git a/src/lib/actions/inference-set/native.ts b/src/lib/actions/inference-set/native.ts index 84d963d65df..d490a7e0abe 100644 --- a/src/lib/actions/inference-set/native.ts +++ b/src/lib/actions/inference-set/native.ts @@ -198,6 +198,7 @@ export async function prepareNativeSelection(input: { }): Promise<{ attachment?: NativeProviderAttachment; attachmentChanged: boolean; + providerChanged?: boolean; endpointUrl?: string; }> { if (!input.selectingNative) return { attachmentChanged: false }; @@ -251,17 +252,18 @@ export async function prepareNativeSelection(input: { hostedNativeProvider(input.provider, definition.endpointUrl)?.endpoint, ); const target = { kind: "named", gatewayName: input.gatewayName } as const; + // 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. + const credentialValue = + input.expectedAttachment && !isNativeNvidiaProvider(input.provider) + ? 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 } @@ -285,6 +287,7 @@ export async function prepareNativeSelection(input: { return { attachment: attached.receipt, attachmentChanged: attached.changed, + providerChanged: !input.expectedAttachment || credentialValue !== null, endpointUrl: attached.receipt.endpointUrl, }; } From d302b1521029e6c4906094b922f851efb5c6628b Mon Sep 17 00:00:00 2001 From: Will Curran Date: Mon, 26 Oct 2026 08:54:53 -0700 Subject: [PATCH 2/3] fix(inference): reuse attached NVIDIA provider credentials Signed-off-by: Will Curran --- src/lib/actions/inference-set/native.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/lib/actions/inference-set/native.ts b/src/lib/actions/inference-set/native.ts index d490a7e0abe..4f7871e82ce 100644 --- a/src/lib/actions/inference-set/native.ts +++ b/src/lib/actions/inference-set/native.ts @@ -252,14 +252,13 @@ export async function prepareNativeSelection(input: { hostedNativeProvider(input.provider, definition.endpointUrl)?.endpoint, ); const target = { kind: "named", gatewayName: input.gatewayName } as const; - // Hosted model selection must not rotate a gateway-shared provider credential. + // Model selection must not rotate a gateway-shared provider credential. // Hermes host credentials use NOUS_API_KEY; OPENAI_API_KEY is its injection slot. - const credentialValue = - input.expectedAttachment && !isNativeNvidiaProvider(input.provider) - ? null - : input.deps.resolveCredentialValue( - input.provider === "hermes-provider" ? "NOUS_API_KEY" : definition.credentialEnv, - ) || null; + const credentialValue = input.expectedAttachment + ? null + : input.deps.resolveCredentialValue( + input.provider === "hermes-provider" ? "NOUS_API_KEY" : definition.credentialEnv, + ) || null; const ensured = await lifecycle.ensureNativeProvider({ adapter: input.deps.providerAdapter, target, From 2a8ff094a3372ba1bc37bf712ca9f2eba4ec74b3 Mon Sep 17 00:00:00 2001 From: Will Curran Date: Mon, 26 Oct 2026 12:50:01 -0700 Subject: [PATCH 3/3] fix(inference): preserve credential updates for new selections Signed-off-by: Will Curran --- src/lib/actions/inference-set.ts | 1 + src/lib/actions/inference-set/native.ts | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib/actions/inference-set.ts b/src/lib/actions/inference-set.ts index 570463a04a5..bf9b8a181b8 100644 --- a/src/lib/actions/inference-set.ts +++ b/src/lib/actions/inference-set.ts @@ -1605,6 +1605,7 @@ async function runInferenceSetWithoutHostLock( selectingNative: selectingNative && !selectingNativeLocal, provider, expectedAttachment: nativeProviderAuthority, + previousAttachment: previousNativeAttachment, gatewayName: preparedRoute.gatewayName, sandboxName, endpointUrl: registryMetadata.endpointUrl, diff --git a/src/lib/actions/inference-set/native.ts b/src/lib/actions/inference-set/native.ts index 4f7871e82ce..9591f961aff 100644 --- a/src/lib/actions/inference-set/native.ts +++ b/src/lib/actions/inference-set/native.ts @@ -188,6 +188,7 @@ export async function prepareNativeSelection(input: { selectingNative: boolean; provider: string; expectedAttachment?: NativeProviderAttachment; + previousAttachment?: NativeProviderAttachment; gatewayName: string; sandboxName: string; endpointUrl?: string | null; @@ -252,13 +253,16 @@ export async function prepareNativeSelection(input: { hostedNativeProvider(input.provider, definition.endpointUrl)?.endpoint, ); const target = { kind: "named", gatewayName: input.gatewayName } as const; - // Model selection must not rotate a gateway-shared provider credential. + // 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 - ? null - : input.deps.resolveCredentialValue( - input.provider === "hermes-provider" ? "NOUS_API_KEY" : definition.credentialEnv, - ) || null; + 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,