-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(rebuild): reuse OpenShell gateway credential when host env is empty #3918
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
Closed
ssam18
wants to merge
8
commits into
NVIDIA:main
from
ssam18:fix/3895-rebuild-reuse-gateway-credential
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
514effc
fix(rebuild): reuse OpenShell gateway credential when host env is empty
ssam18 08b0edc
Merge branch 'main' into fix/3895-rebuild-reuse-gateway-credential
ssam18 8cda768
Merge branch 'main' into fix/3895-rebuild-reuse-gateway-credential
ssam18 0b87520
Merge branch 'main' into fix/3895-rebuild-reuse-gateway-credential
ssam18 13500c3
refactor(onboard): extract gateway-reuse logic into a focused module
ssam18 7ad73a4
fix(rebuild): distinguish gateway lookup errors and guard mutable end…
ssam18 57c111e
Merge branch 'main' into fix/3895-rebuild-reuse-gateway-credential
ssam18 33ce8c8
Merge branch 'main' into fix/3895-rebuild-reuse-gateway-credential
ssam18 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
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,88 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| // Issue 3895. Sandbox rebuild calls back into onboard --resume after the | ||
| // host shell has been closed, so NVIDIA_API_KEY and friends are no longer | ||
| // in process.env even though the original onboard registered the provider | ||
| // in the OpenShell gateway. Re-running upsertProvider with an empty env | ||
| // would overwrite the gateway-stored credential, so this helper short | ||
| // circuits the upsert when the gateway already holds the credential and | ||
| // the host has nothing to contribute. | ||
|
|
||
| import type { ProbeRecovery } from "../validation-recovery"; | ||
| import type { ValidationClassification } from "../validation"; | ||
|
|
||
| export type UpsertResult = { ok: boolean; status?: number; message?: string }; | ||
|
|
||
| export type UpsertOutcome = | ||
| | { kind: "ok" } | ||
| | { kind: "retry" } | ||
| | { kind: "selection" } | ||
| | { kind: "exit"; code: number }; | ||
|
|
||
| export type RecoveryChoice = "credential" | "retry" | "selection" | "model" | string; | ||
|
|
||
| export interface InferenceProviderUpsertSpec { | ||
| provider: string; | ||
| providerType: string; | ||
| credentialEnv: string; | ||
| endpointUrl: string | null; | ||
| env: Record<string, string>; | ||
| credentialValue: string | null; | ||
| label: string; | ||
| helpUrl: string | null; | ||
| } | ||
|
|
||
| export interface InferenceProviderUpsertHandlers { | ||
| upsertProvider: ( | ||
| name: string, | ||
| type: string, | ||
| credentialEnv: string, | ||
| baseUrl: string | null, | ||
| env: Record<string, string>, | ||
| ) => UpsertResult; | ||
| providerExistsInGateway: (name: string) => boolean; | ||
| isMutableEndpointProvider: (name: string) => boolean; | ||
| isNonInteractive: () => boolean; | ||
| promptValidationRecovery: ( | ||
| label: string, | ||
| classification: ProbeRecovery, | ||
| credentialEnv: string, | ||
| helpUrl: string | null, | ||
| ) => Promise<RecoveryChoice>; | ||
| classifyApplyFailure: (message: string) => ValidationClassification; | ||
| } | ||
|
|
||
| export async function reuseGatewayOrUpsertInferenceProvider( | ||
| spec: InferenceProviderUpsertSpec, | ||
| handlers: InferenceProviderUpsertHandlers, | ||
| ): Promise<UpsertOutcome> { | ||
| if ( | ||
| !spec.credentialValue && | ||
| !handlers.isMutableEndpointProvider(spec.provider) && | ||
| handlers.providerExistsInGateway(spec.provider) | ||
| ) { | ||
| return { kind: "ok" }; | ||
| } | ||
| const result = handlers.upsertProvider( | ||
| spec.provider, | ||
| spec.providerType, | ||
| spec.credentialEnv, | ||
| spec.endpointUrl, | ||
| spec.env, | ||
| ); | ||
| if (result.ok) return { kind: "ok" }; | ||
| console.error(` ${result.message}`); | ||
| if (handlers.isNonInteractive()) { | ||
| return { kind: "exit", code: result.status || 1 }; | ||
| } | ||
| const retry = await handlers.promptValidationRecovery( | ||
| spec.label, | ||
| handlers.classifyApplyFailure(result.message ?? ""), | ||
| spec.credentialEnv, | ||
| spec.helpUrl, | ||
| ); | ||
| if (retry === "credential" || retry === "retry") return { kind: "retry" }; | ||
| if (retry === "selection" || retry === "model") return { kind: "selection" }; | ||
| return { kind: "exit", code: result.status || 1 }; | ||
| } |
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
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.