-
Notifications
You must be signed in to change notification settings - Fork 3.1k
perf(policy): batch onboarding preset application #3502
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b701032
perf(policy): batch onboarding preset application
cv 4c07771
refactor(onboard): move preset sync out of entrypoint
cv e9a9ef0
Merge branch 'main' into perf/batch-onboard-policy-presets
cv e07e69c
fix(policy): preserve mixed preset apply order
cv 420f28d
Merge remote-tracking branch 'origin/perf/batch-onboard-policy-preset…
cv 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| const policies: typeof import("../policy") = require("../policy"); | ||
| const { waitUntil }: typeof import("../core/wait") = require("../core/wait"); | ||
|
|
||
| function waitForPolicyMutation(description: string, mutate: () => boolean | void): void { | ||
| let lastError: Error | null = null; | ||
| const success = waitUntil(() => { | ||
| try { | ||
| const result = mutate(); | ||
| if (result === false) { | ||
| lastError = new Error(`${description} returned false`); | ||
| return false; | ||
| } | ||
| return true; | ||
| } catch (err) { | ||
| const error = err instanceof Error ? err : new Error(String(err)); | ||
| lastError = error; | ||
| if (!error.message.includes("sandbox not found")) { | ||
| throw err; | ||
| } | ||
| return false; | ||
| } | ||
| }, 10, 2000); | ||
|
|
||
| if (!success) { | ||
| throw lastError || new Error(`${description} timed out`); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Reconcile the sandbox's currently-applied preset list with the user's | ||
| * target selection: | ||
| * - remove presets in `applied` but not in `target` (narrow) | ||
| * - apply presets in `target` but not in `applied` (widen) | ||
| * - leave unchanged presets untouched (no wasteful re-apply) | ||
| */ | ||
| function syncPresetSelection( | ||
| sandboxName: string, | ||
| applied: string[], | ||
| target: string[], | ||
| accessByName: Record<string, string> | null = null, | ||
| ): void { | ||
| const targetSet = new Set(target); | ||
| const appliedSet = new Set(applied); | ||
| const deselected = applied.filter((name) => !targetSet.has(name)); | ||
| const newlySelected = target.filter((name) => !appliedSet.has(name)); | ||
|
|
||
| for (const name of deselected) { | ||
| waitForPolicyMutation(`removePreset(${name})`, () => policies.removePreset(sandboxName, name)); | ||
| } | ||
|
|
||
| if (!accessByName) { | ||
| const builtInPresetNames = new Set(policies.listPresets().map((preset) => preset.name)); | ||
| const builtInNewlySelected = newlySelected.filter((name) => builtInPresetNames.has(name)); | ||
| const remainingNewlySelected = newlySelected.filter((name) => !builtInPresetNames.has(name)); | ||
|
|
||
| if (builtInNewlySelected.length > 0 && remainingNewlySelected.length === 0) { | ||
| waitForPolicyMutation(`applyPresets(${builtInNewlySelected.join(",")})`, () => | ||
| policies.applyPresets(sandboxName, builtInNewlySelected), | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| for (const name of newlySelected) { | ||
| waitForPolicyMutation(`applyPreset(${name})`, () => policies.applyPreset(sandboxName, name)); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| for (const name of newlySelected) { | ||
| const options = { access: accessByName[name] }; | ||
| waitForPolicyMutation(`applyPreset(${name})`, () => | ||
| policies.applyPreset(sandboxName, name, options), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export { syncPresetSelection, waitForPolicyMutation }; | ||
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
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.
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.