Repository navigation
Harden Tauri release flow - #5341
Conversation
Require managed Studio root IDs to match before attaching to existing backends, close the concurrent backend-start window, and tighten frontend Tauri detection to Tauri-specific signals.
Gate desktop backend compatibility on explicit manageability fields, add external-conflict handling for unsafe backend states, and protect update/repair paths from mutating active non-owned Studio backends. Track Tauri-owned backends with local owner metadata for verified orphan cleanup only.
Move preflight types, version checks, managed install probing, and backend probing into focused submodules while preserving behavior and keeping implementation files under the release-readiness size target.
Point the desktop updater at a same-repo desktop-latest manifest and publish that channel from non-draft desktop releases after validating the Tauri-generated latest.json.
There was a problem hiding this comment.
Code Review
This pull request introduces a backend ownership and manageability system for Unsloth Studio, allowing the desktop application to securely track and control backend processes via token-based metadata. Key improvements include a more robust server startup sequence, enhanced preflight checks for detecting port conflicts, and support for manual Linux package updates. The review feedback highlights a critical performance issue where the synchronous stop_server command blocks the UI thread, a security vulnerability regarding insecure file permissions for sensitive tokens on Windows, and an opportunity to reduce code duplication in version parsing logic.
| /// shutdown (same codepath as /api/shutdown). Falls back to SIGKILL after 5s. | ||
| /// Stop the current desktop-owned backend if this app can safely control it. | ||
| #[tauri::command] | ||
| pub fn stop_server( |
There was a problem hiding this comment.
The stop_server command is synchronous and performs blocking network I/O and thread sleeps (via stop_backend and its internal shutdown sequence). This will block the Tauri main thread, causing the UI to become unresponsive until the backend process exits or timeouts occur. This command should be defined as async so that Tauri executes it on a background thread pool.
| pub fn stop_server( | |
| pub async fn stop_server( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c3466c894a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 15d909166f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
15d9091 to
dcd8621
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dcd8621fb4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
ea06d12 to
8fb0a15
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ac211a6fea
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
ac211a6 to
ce124ed
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ce124ed136
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e159d2caf3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 85ab24daac
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| let ignored_ports: Vec<u16> = owned_port.into_iter().collect(); | ||
| block_external_conflict(&ignored_ports).await?; |
There was a problem hiding this comment.
Bypass pre-stop conflict guard when owned port is unknown
When an owned spawned backend exists but has not yet recorded reported_port (OwnedBackendHandle::port() can be None for Spawned), this builds ignored_ports as an empty list and immediately runs block_external_conflict. The probe then sees the same backend as BackendProbe::Ready and converts it into a blocking same_root_external_backend_active conflict, so the update flow returns before stop_backend_for_mutation is attempted. This makes update/repair commands fail during startup/port-validation windows even though the backend is owned by this app.
Useful? React with 👍 / 👎.
893c70d to
a1a2ad2
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 127f04bd2d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
127f04b to
a617620
Compare
a617620 to
76b0a1a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 76b0a1ac05
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…s,version}.rs PR unslothai#5341 splits studio/src-tauri/src/preflight.rs into a directory of submodules. The cmd.env_remove("UNSLOTH_STUDIO_HOME") + STUDIO_HOME calls now live in preflight/managed.rs instead of preflight.rs, so test_tauri_preflight_scrubs_studio_home_env counted zero matches in the old single-file location and failed with "assert 0 >= 2". Read whichever shape is on disk: preflight.rs at the old path plus every *.rs under preflight/ (current PR has 2 occurrences in preflight/managed.rs). The guard intent is unchanged: at least 2 env_remove calls covering run_cli_probe and probe_cli_capability, plus the single commands.rs scrub in check_install_status. Verified locally: pytest tests/test_studio_install_workspace_guard.py::test_tauri_preflight_scrubs_studio_home_env passes.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4089754678
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Resolves conflicts with #5341 (Tauri release hardening): - studio/backend/main.py: keep new supports_desktop_backend_ownership field with a one-line comment. - studio/backend/run.py: keep main's _ReadyServer / ready_event / startup_failed scaffolding; drop the trimmed server_header comment in favour of a one-line restatement next to the config call.
Conflict resolution for .github/workflows/release-desktop.yml. PR #5341 (Harden Tauri release flow) restructured the build job: - New `prepare-version` job up front owns PyPI metadata fetch + full distribution download (replaces this PR's simpler "Verify backend package is published" step -- main's version retries with backoff and downloads the actual artifacts, so the simpler check is now redundant). - New "Verify desktop updater and Linux package config" step validates the Tauri updater endpoint + refuses RPM bundling. - "Install frontend dependencies" was moved to run after the new verify step. Resolution preserves every supply-chain hardening this PR added: - workflow-level `permissions: contents: read` (build job overrides to `contents: write` for tauri-action's release creation). - `step-security/harden-runner@<sha>` in audit mode at the head of the build job's steps. - `dtolnay/rust-toolchain@29eef33...` SHA pin (= current `stable` branch tip, action default toolchain is `stable` so behaviour is identical to the old `@stable` ref). - `npm install --no-fund --no-audit` on both the Tauri CLI install and the frontend dep install (cosmetic flags only; lifecycle scripts still run as required for `vite build`). The merged step order in the build job is now: Install pinned Tauri CLI -> Verify pinned Tauri CLI -> Verify desktop updater and Linux package config (NEW) -> Install frontend dependencies (hardened) -> Install Rust stable. Verified: pytest tests/security -> 34 passed; YAML parses across every .github/workflows/*.yml; test_studio_install_workspace_guard -> 44 passed.
* studio: expose launcher capability bits on unauth /api/health PR #5375 reduced the unauthenticated /api/health response to {status, timestamp} only, on the theory that the rest of the payload was useful fingerprinting. That was too aggressive: the Tauri watchdog reads `service == "Unsloth UI Backend"` and `studio_root_id` to re-adopt its own backend across restarts (src-tauri/src/desktop_backend_owner.rs and commands.rs), and the SPA bootstrap fetches the same payload unauth to detect chat-only mode and native path lease support before any token is available (frontend src/config/env.ts and features/native-intents/use-native-readiness.ts). With the post-#5375 shape, the watchdog kills its own healthy backend, the SPA never flips out of "full Studio" mode on chat-only Linux/Windows, and the About tab shows "dev" in place of the real version. The actual fingerprint-ish fields are `version` / `studio_version` / `device_type` (and to a lesser extent the hostname inside `device_type`). `service`, `studio_root_id` (already a hex digest of the install path, not the raw path), `chat_only`, the desktop_* capability flags, and `native_path_leases_supported` do not leak the install path or version. This patch keeps the auth gate but rebalances which fields sit on each side of it: unauth service, studio_root_id, chat_only, desktop_protocol_version, desktop_manageability_version, supports_desktop_auth, supports_desktop_backend_ownership, native_path_leases_supported, desktop_owner (when present) authed + version, studio_version, device_type Existing must-change-password sessions still fall through to the base payload because get_current_subject (strict) rejects them; that matches prior behaviour. test_middleware.py is updated to pin the new contract: launcher bits present unauth, fingerprint fields present only with a valid bearer. * studio: complete launcher-bits health unauth contract on Tauri + About tab Reviewer follow-ups to the unauth /api/health launcher bits split. Tauri preflight: backend_capability_stale_reason() fell through to backend_version_stale_reason(health.version.as_deref()) when capability bits were present but version was absent. With the unauth payload now exposing service + studio_root_id + desktop_* bits but gating version behind a bearer, the desktop watchdog was reading the new payload, parsing all capability bits, then classifying the same-root backend as desktop_backend_version_missing and refusing to adopt it. A backend that exposes desktop_protocol_version=1, desktop_manageability_version>=1, supports_desktop_auth=true and supports_desktop_backend_ownership=true was introduced together with MIN_DESKTOP_BACKEND_VERSION=2026.5.3 in #5341, so a present capability bitset is itself a version-compatibility signal. Skip the version sub-check when version is None/empty; keep it for non-empty values so genuinely-too-old backends that do echo a version still get desktop_backend_version_too_old. About tab: fetchStudioVersions() did a bare fetch(apiUrl("/api/health")), which the unauth payload no longer carries version/studio_version for, so Settings -> About kept rendering "dev"/"dev" for any logged-in user. Attach Authorization: Bearer <token> when getAuthToken() returns one; fall back to bare fetch (still 200, just truncated payload) for the not-logged-in case. No new endpoint. Comment: studio_root_id is no longer a hex digest of the install path; it is an opaque per-install id written by the launcher. Updated the inline comment to match. Test: - python -m pytest studio/backend/tests/test_middleware.py::TestHealthAuthGate studio/backend/tests/test_desktop_auth.py -q -> 29 passed - npm run typecheck clean, npm run build produces fresh dist * Trigger CI rerun for flaky Mac Chat UI step
Summary
This hardens the Tauri desktop release path.
Notes
This should land after #5308 so Studio version and package version are shown separately.
The desktop app version should follow the Studio release version from #5308. The backend floor stays separate and only applies to Tauri desktop preflight.
This PR does not change install.sh or install.ps1. Native web and CLI install behavior are not forced to 2026.5.3.
The backend package 2026.5.3 should be published before public desktop release.
Validation