Repository navigation
Studio: add a Sandbox settings tab with a Windows MXC opt-in and one-click host preparation - #12215
Conversation
…tings when the environment is silent
…ith the Windows controls
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…he host prep job test by loop count
…imports left unused by the move
# Conflicts: # studio/backend/tests/conftest.py
When the MXC runtime is missing, the Windows section now has an Install runtime button instead of asking to rerun the installer. It runs the same unelevated install_mxc_prebuilt.py call setup.ps1 makes, one run at a time, never beside Prepare this PC, and resets the probe caches when it ends. On Windows that cannot run MXC (not x64, or older than build 26100) the section shows one note saying so instead of controls that cannot work.
# Conflicts: # studio/frontend/src/features/settings/settings-dialog.tsx
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 01960493e2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| needed = mxc_policy.dacl_fallback_enabled() and enabled() | ||
| try: | ||
| return hold() | ||
| except ReadGrantError: | ||
| if needed: | ||
| raise | ||
| return None |
There was a problem hiding this comment.
Refuse unleased launches while grants remain deferred
When the switch is already off while workload A keeps recorded ACLs alive, needed is false; if workload B then cannot create its lease—for example because the lease directory became unwritable or the record lock times out—this branch suppresses the error and B still launches. Since the old ACL can make wxc-exec skip its temporary grant, A's release can then see no lease for B and revoke the ACL underneath it. Fresh evidence after the prior fix is this conditional suppression of ReadGrantError; it should refuse the launch whenever recorded or deferred grants may still exist.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: a lease only fails to record when Studio's own lease folder is unwritable or a revocation outlasts the grant timeout plus 60 s, and refusing every launch with the switch off on that path would take tools away from users who never turned the grants on.
| try: | ||
| mxc_runtime.installation_identity() | ||
| except Exception: # noqa: BLE001 - no runtime yet |
There was a problem hiding this comment.
Treat a missing host-prep binary as an incomplete runtime
When wxc-exec.exe remains valid but its companion wxc-host-prep.exe is missing or corrupt, this reports the runtime as installed because installation_identity() validates only selected_runtime(). Consequently windows_runtime_plan() refuses the repair operation as “already installed” and the status UI hides the install button, while Prepare this PC later fails when acquire_host_prep() validates the missing artifact. Validate both installed executables here so the one-click installer remains available for this partially damaged installation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: both executables come from the same verified package and every installer that ships them writes them together, so this needs a damaged install; Prepare this PC then fails with the integrity error rather than running anything.
| def _live_leases() -> int: | ||
| try: | ||
| entries = list(_leases_dir().iterdir()) | ||
| except OSError: | ||
| return 0 |
There was a problem hiding this comment.
Defer revocation when lease enumeration fails
If the lease directory cannot be enumerated while a workload still has an open lease—for example because of a transient filesystem or permission error—returning zero makes revoke_recorded() conclude that no workloads are running and remove the read ACLs underneath that workload. An unreadable lease directory is an unknown safety state and must defer revocation rather than be treated as empty.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: the lease folder lives in Studio's own home, so a missing folder means no leases and an unreadable one needs the user to break Studio's own permissions while a call runs.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 01960493e2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| with _lock: | ||
| if _current is not None and _current.state == "running": | ||
| return _current |
There was a problem hiding this comment.
Serialize host preparation across Studio processes
When two Studio backend processes share the same installation, each has its own _lock and _current, so both can pass this check and launch the elevated preparation simultaneously. This can present duplicate UAC prompts and run the multi-minute system-drive ACL propagation twice at once; the repository already accounts for sibling Studio processes in the grant/settings paths, so this operation also needs an inter-process lease or lock rather than only process-local state.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: two concurrent prepare jobs need two Studio backends running on the same home at once, which is not a supported setup, and each would still need its own UAC approval before anything elevated runs.
| with _sandbox_status_lock: | ||
| cached, generation = _sandbox_status_cache, _sandbox_status_generation | ||
| if not refresh and cached is not None and time.monotonic() < cached[0]: |
There was a problem hiding this comment.
Invalidate older status builds when forcing a refresh
With two owner tabs or concurrent API requests, a normal cache-miss build can start before a forced refresh and finish after it. Both capture the same generation here, so the older non-forced build is still allowed to overwrite the cache at line 4769, causing subsequent requests for the next 30 seconds to receive the pre-refresh verdict even though Refresh already completed. A forced refresh should advance the status generation or otherwise prevent builds that began before it from publishing afterward.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: the forced refresh returns its own fresh build to the tab that asked, so the race only leaves another concurrent reader with a status at most 30 s old, which the next refresh or settings change replaces.
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…md fallback on Windows (#12272) * Studio: install or prepare the OS sandbox from Settings with one fixed setup plan per host * Studio: rename the permission modes, offer OS sandbox setup from the picker, and show setup in Settings > Sandbox Ask every time, Auto-approve, Full access in sandbox and Bypass permissions replace the old labels; the stored values are unchanged and the labels move to i18n in all 12 locales. Picking Full access in sandbox on a computer without a working OS sandbox opens a setup dialog (install, copy the command, or use it anyway) instead of switching. Settings > Sandbox shows the install command and a Linux install row, and can install the Windows MXC runtime. * Studio: ask before a risky Python or Terminal call in Run automatically when no OS sandbox is on, and warm the sandbox check at startup One shared approval decision replaces the three loop copies. Under permission mode off the route arms the confirm gate only on a stream carrying the control frames, and the loop then asks only for a high-risk python or terminal call whose cached capability is not OS isolated. The cached answer never blocks on a probe; a startup warm-up and a stale-while-revalidate probe cache keep the first call and the 15 minute recheck off the request path. GET /api/sandbox/capability reports the cached answer to any signed-in user. * Studio: offer the sandbox setup to the local owner in the capability and status reads, and use the new mode names in backend messages * Studio: sandbox setup dialog waits out a pending check, offers Retry, asks for Windows consent only when needed, shows why a setup failed, and installs the Windows runtime without an administrator prompt * Studio: refuse an unasked risky call when the sandbox stopped working, pin every elevated setup step, and check the sandbox before answering after setup * Studio: keep a reset from being undone by an in-flight launch, report a running setup on the prepare route, give PowerShell a command it can run, and translate the dictation menu label * Studio: pin an x64 host in the Windows setup plan tests * Studio: pin an x64 host once in the Windows setup plan fixture * Studio: tell the owner at this computer to run the setup command when Unsloth cannot ask for the password * Studio: launch strictly from the prompt decision already made, and keep Windows setup commands with host paths to the owner * Studio: run the Terminal isolated on cmd whenever bash fails under MXC and cmd passes * Studio: size the setup dialog and Sandbox tab text with the UI font tokens * Studio: let picking Full access in sandbox again reopen the setup when there is no OS sandbox * Studio: run the two POSIX binary path tests of the setup plan on POSIX hosts only * Studio: cancel a pending Full access in sandbox pick on any later mode change * Studio: keep an explicit confirm_tool_calls=false in Full access in sandbox unprompted, and stop the chat sending it * Studio: trim the sandbox setup and permission mode comments * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Studio: expect the install-and-profile command when bwrap is missing on an AppArmor-restricted host * Studio: keep a runtime-only or Linux setup job out of the Windows prepare row * Studio: keep the sandbox capability unknown until both tools have an answer, and never offer setup on an unknown one * Studio: run the Linux sandbox setup directly when Unsloth already runs as root, and never hand back a different running setup * Studio: judge bwrap by the launcher's trust check when planning the Linux sandbox setup * Studio: let host preparation join only the chained Windows setup, and keep an older isolation check from overwriting a newer one * Studio: cache only the latest sandbox capability read, so an older one finishing last cannot replace it * Studio: drop a cached sandbox pass when the backend refuses at preparation * Studio: keep the per-account scan folder test off the macOS folder deny list * Studio: update tests for the renamed Bypass permissions message and the sandbox capability router, and wait for the level to land before reloading in the chat UI test * Studio: drop the sandbox capability stub once the chat UI permission checks finish The stub stayed on the page for the rest of the chat UI run. An intercepted page keeps no HTTP cache, and on Windows the later sign-out step wedged on the /login load until the watchdog fired. Unroute it after the level checks, the same way the chat settings stub is released. * Point the missing MXC runtime note at Install runtime in every locale * Reword the Terminal profile comment for the any-failure cmd fallback * Sandbox setup: say what is wrong once, and say the sandbox is ready after a Linux install * Run automatically: keep the no-sandbox check on saved chats and managed engines - Durable chat runs persisted confirm_tool_calls=False for Run automatically, which the replay read as an explicit opt-out, so the ask-before-risky-calls check never armed in normal Studio chats. Drop the forced value when saving. - The vLLM/SGLang tool loop now arms the same check as the other loops. - The picker hook and the setup dialog apply only their newest capability read, so a slow older answer cannot undo a newer one. - Saving a sandbox setting or finishing Prepare this PC drops the cached capability the chat picker reads. - pkexec setup on Alpine runs BusyBox as its sh applet. * Run automatically: apply at once when the sandbox is already known to work The pick waited for a forced live probe even when the cached answer said the OS sandbox works, so on a slow host the menu looked unresponsive for seconds. The backend checks isolation on every call either way. * Sandbox tab on Windows: no repeated MXC paragraph, plain setup reason While the Windows section shows what to do (install the runtime, turn the sandbox on, prepare this PC), the Python and Terminal rows keep only their badge, and on Windows they never repeat the generic MXC remediation text. The setup reason says the PC needs its administrator step instead of naming MXC's internal step ids. * Spell out why the POSIX-only sandbox plan tests skip * Format the sandbox plan test skips --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
… bar rework (#12763) Main is over the startup budget: 6,278.6 KB raw / 1,879.0 KB transfer against 6,237.3 / 1,867.2. Built commit by commit from #12347, no single import is responsible: #12347 itself left 2.9 KB transfer over, the Sandbox settings tab (#12215) added 16.4 KB raw / 4.5 KB transfer, #12735 2.9 KB raw, and the rest is spread over the other merges, all in the eager chat, index and settings chunks. Put back the margin the previous raises chose (210.8 KB raw, 65.1 KB transfer).
On Windows, OS isolation for tool calls (MXC) could only be turned on with environment variables:
UNSLOTH_MXC_ALLOW_DACL_FALLBACK=1, plus runninginstall_mxc_prebuilt.py --prepare-hostfrom an elevated shell, again after every restart. That is out of reach for Unsloth Desktop users. With #12121 and #12164 the cost is now +66 to +271 ms per call, so this PR puts it in Settings.What changes
New owner-only Settings > Sandbox tab:
install_mxc_prebuilt.pycallsetup.ps1makes, so nobody has to rerun the installer. No administrator prompt is involved. The switches appear once it is installed.wxc-host-prepflow (UAC prompt) as a background job and shows the result (succeeded, declined, failed with the last output lines).The switches only fill in what the environment leaves open: when
UNSLOTH_MXC_ALLOW_DACL_FALLBACKorUNSLOTH_MXC_PERSISTENT_READ_GRANTSis set, it decides exactly as before, and the row is locked with a note naming the variable. Nobody who does not touch the tab sees a change.Who can do what
Host, no proxy headers (the same check the local bootstrap page uses, now shared fromutils/client_ip.py). The UAC prompt appears on that computer, so a remote browser, or one relayed by a local reverse proxy or tunnel, is refused with a message saying where to do it.Backend
utils/mxc_isolation_settings.py: the two saved switches in the owner's settings store, with a 1 s cache and a generation counter so a read that started before a save cannot republish the old value. The opt-in reads as off on any error; the grants switch keeps its default (on).mxc_policy.dacl_fallback_enabled()andmxc_read_grants.enabled(): environment first, then the saved switch.sandbox_setup_plan.py/sandbox_setup_job.py: the runtime install as one fixed operation (windows-runtime; nothing from the request reaches the command line), one run at a time, never beside Prepare this PC, probe caches reset on finish.GET/POST /api/settings/sandbox/setup. The status reportsruntime_unsupported(archorbuild).mxc_host_prep_job.py: one preparation at a time, started throughutils.process_lifetime, never killed mid-run (it changes ACLs); on finish the MXC probe cache, the Terminal profile memo and the status cache are dropped.routes/settings.py:GET/PUT /api/settings/sandboxandGET/POST /api/settings/sandbox/prepare. Status is built off the event loop and cached for 30 s;refresh=truere-probes. Reading status never triggers UAC.Results
GitHub
windows-latest(Server 2025, build 26100), MXC runtime installed byinstall_mxc_prebuilt.pyonly: no host preparation and no manual grants. The real routes with the owner's session, the real settings store, job, probes and tools:prepare-system-drive,prepare-null-devicecmd_isolatedgit --versionos_isolated(MXC), git 2.55.0UNSLOTH_MXC_ALLOW_DACL_FALLBACK=0setLinux: backend suites 2093 passed (MXC, sandbox, settings, the new routes and job, bootstrap loopback, origin and rate-limit tests). Frontend: typecheck,
i18n:check:strict, and the Sandbox, settings visibility and desktop menu tests (35) pass.After merging the latest
main(owner-only Full access from #12604, the shorter permission menu from #12630): the MXC, sandbox, settings, bootstrap and loopback suites pass locally (1960 passed), and the frontend typecheck,i18n:check:strictand the Sandbox tab tests pass.Not covered
NUL(the cmd probe from Studio: run the isolated Windows Terminal on cmd.exe with stock git when Git Bash cannot start in MXC #12164 does not exercise the null device). The tab shows Administrator setup "Needed" in that state; tightening the probe is a follow-up.Screenshots
Merge base (
57937d2) vs this branch (8ce5b91), two isolated installs built from each tree, opened from the sidebar Settings cog.Linux (this host's user namespaces are restricted, so both tools fall back to software safeguards and say why):
The Windows section only renders when the backend runs on Windows, so the next ones are the same Linux build driven through its real clicks (Install runtime, the switch, Prepare this PC), with the sandbox routes answering what the Windows end-to-end run returned at each step. Runtime missing, with the new Install runtime button:
After Install runtime, switching on and Prepare this PC: both tools on MXC, Terminal in cmd.exe, Administrator setup Done:
The whole click path as a recording:
The same rows on a real Windows Server 2025 runner (no replayed routes, real runtime install and preparation) are in #12272, which carries this tab.