Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: require managed backend for linked folders (#8536)

alkinuna1e96ece8897
diff --git a/studio/frontend/src/features/native-intents/use-native-readiness.ts b/studio/frontend/src/features/native-intents/use-native-readiness.ts
index 704ae9bc96b..9debb055d7e 100644
--- a/studio/frontend/src/features/native-intents/use-native-readiness.ts
+++ b/studio/frontend/src/features/native-intents/use-native-readiness.ts
@@ -20,13 +20,21 @@ export function useNativePathLeasesSupported(): boolean {
controller = new AbortController();
fetch(apiUrl("/api/health"), { signal: controller.signal })
.then((response) => response.json())
- .then((health) => {
+ .then(async (health) => {
if (disposed) return;
- if (health?.native_path_leases_supported === true) {
- setSupported(true);
- } else {
+ if (health?.native_path_leases_supported !== true) {
check(5000);
+ return;
}
+ // The health bit says the backend holds a key, not that it holds
+ // OURS. A survivor adopted from a dead previous app has one of its
+ // own, so the grant would fail on the signature instead. Only the
+ // app knows which backend it spawned.
+ const { invoke } = await import("@tauri-apps/api/core");
+ const usable = await invoke<boolean>("native_path_leases_usable");
+ if (disposed) return;
+ if (usable) setSupported(true);
+ else check(5000);
})
.catch(() => {
if (!disposed) check(5000);
diff --git a/studio/frontend/src/features/rag/components/linked-folders-manager.tsx b/studio/frontend/src/features/rag/components/linked-folders-manager.tsx
index d81c22adbc7..420cdd1ea08 100644
--- a/studio/frontend/src/features/rag/components/linked-folders-manager.tsx
+++ b/studio/frontend/src/features/rag/components/linked-folders-manager.tsx
@@ -72,7 +72,7 @@ export function LinkedFoldersManager({
<p className="text-xs leading-snug text-muted-foreground">
{manager.desktopSupported
? "Keep supported documents indexed as this folder changes."
- : "Existing linked folders stay synced; link new folders in the desktop app."}
+ : "Existing linked folders stay synced; linking requires the managed desktop backend."}
</p>
</div>
{scope ? (
@@ -86,7 +86,7 @@ export function LinkedFoldersManager({
title={
manager.desktopSupported
? "Choose a local folder"
- : "Requires the desktop app"
+ : "Requires the managed desktop backend"
}
>
{manager.mutating ? (
diff --git a/studio/frontend/src/features/rag/components/use-linked-folders.ts b/studio/frontend/src/features/rag/components/use-linked-folders.ts
index 075c011ff06..5f0b04499b7 100644
--- a/studio/frontend/src/features/rag/components/use-linked-folders.ts
+++ b/studio/frontend/src/features/rag/components/use-linked-folders.ts
@@ -1,7 +1,10 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-import { pickNativeDocumentFolder } from "@/features/native-intents";
+import {
+ pickNativeDocumentFolder,
+ useNativePathLeasesSupported,
+} from "@/features/native-intents";
import { isTauri } from "@/lib/api-base";
import { createScopedSingleFlightRequest } from "@/lib/single-flight-request";
import { toast } from "@/lib/toast";
@@ -36,6 +39,7 @@ export function useLinkedFolders(
const [stateScopeKey, setStateScopeKey] = useState(scopeKey);
const [loading, setLoading] = useState(true);
const [mutating, setMutating] = useState(false);
+ const nativePathLeasesSupported = useNativePathLeasesSupported();
const controllers = useRef(new Map<string, AbortController>());
const refreshGate = useRef(
createScopedSingleFlightRequest<
@@ -225,7 +229,7 @@ export function useLinkedFolders(
}, [refresh, scopeKey]);
const link = useCallback(async () => {
- if (!scopeType || !scopeId || !isTauri) return;
+ if (!scopeType || !scopeId || !isTauri || !nativePathLeasesSupported) return;
const operationScopeKey = scopeKey;
setMutating(true);
try {
@@ -251,7 +255,14 @@ export function useLinkedFolders(
} finally {
setMutating(false);
}
- }, [scopeKey, scopeType, scopeId, trackJob, onSourcesChanged]);
+ }, [
+ scopeKey,
+ scopeType,
+ scopeId,
+ nativePathLeasesSupported,
+ trackJob,
+ onSourcesChanged,
+ ]);
const run = useCallback(
async (folderId: string, mode: "sync" | "rebuild") => {
@@ -322,7 +333,7 @@ export function useLinkedFolders(
jobs: stateScopeKey === scopeKey ? jobs : {},
loading: stateScopeKey === scopeKey ? loading : true,
mutating,
- desktopSupported: isTauri,
+ desktopSupported: isTauri && nativePathLeasesSupported,
link,
sync: (folderId: string) => run(folderId, "sync"),
rebuild: (folderId: string) => run(folderId, "rebuild"),
diff --git a/studio/frontend/tests/linked-folders-lease-gate.test.ts b/studio/frontend/tests/linked-folders-lease-gate.test.ts
new file mode 100644
index 00000000000..a635a04455c
--- /dev/null
+++ b/studio/frontend/tests/linked-folders-lease-gate.test.ts
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+// Issue 8416: gated on `isTauri` alone, the picker stayed live when the app
+// attached to a backend it had not spawned, and only a spawned backend holds
+// UNSLOTH_STUDIO_NATIVE_PATH_LEASE_SECRET, so the lease came back 400. The
+// button must be dead without the capability AND `link()` must refuse anyway.
+// No React renderer here, so this asserts on source, like ~50 sibling tests.
+
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import test from "node:test";
+import { fileURLToPath } from "node:url";
+
+const HOOK = readFileSync(
+ fileURLToPath(
+ new URL("../src/features/rag/components/use-linked-folders.ts", import.meta.url),
+ ),
+ "utf8",
+);
+
+const MANAGER = readFileSync(
+ fileURLToPath(
+ new URL("../src/features/rag/components/linked-folders-manager.tsx", import.meta.url),
+ ),
+ "utf8",
+);
+
+const COMMANDS = readFileSync(
+ fileURLToPath(
+ new URL("../../src-tauri/src/commands.rs", import.meta.url),
+ ),
+ "utf8",
+);
+
+const READINESS = readFileSync(
+ fileURLToPath(
+ new URL("../src/features/native-intents/use-native-readiness.ts", import.meta.url),
+ ),
+ "utf8",
+);
+
+const PREFLIGHT = readFileSync(
+ fileURLToPath(new URL("../../src-tauri/src/preflight.rs", import.meta.url)),
+ "utf8",
+);
+
+test("the picker is gated on the backend capability, not on isTauri alone", () => {
+ assert.match(
+ HOOK,
+ /desktopSupported:\s*isTauri\s*&&\s*nativePathLeasesSupported/,
+ "desktopSupported must require the lease capability as well as Tauri",
+ );
+ assert.ok(
+ HOOK.includes("useNativePathLeasesSupported()"),
+ "the capability must come from the shared readiness hook, not a local fetch",
+ );
+});
+
+test("link() refuses without the capability, not just the button", () => {
+ const body = HOOK.slice(
+ HOOK.indexOf("const link = useCallback("),
+ HOOK.indexOf("const run = useCallback("),
+ );
+ assert.ok(body.length > 0, "link() should still exist");
+ assert.match(
+ body,
+ /if\s*\([^)]*!nativePathLeasesSupported[^)]*\)\s*return/,
+ "link() must bail before pickNativeDocumentFolder when leases are unsupported",
+ );
+ // A stale closure would restore the old behaviour once the capability flips.
+ assert.ok(
+ body.includes("nativePathLeasesSupported") &&
+ HOOK.slice(HOOK.indexOf("const link = useCallback("))
+ .includes("nativePathLeasesSupported,"),
+ "nativePathLeasesSupported must be in link()'s dependency list",
+ );
+});
+
+test("the unsupported branch names the managed backend, not the desktop app", () => {
+ // The old copy told a desktop user to use the desktop app they were already in.
+ assert.ok(
+ !MANAGER.includes("link new folders in the desktop app"),
+ "the unsupported copy must not tell a desktop user to use the desktop app",
+ );
+ assert.ok(
+ MANAGER.includes("managed desktop backend"),
+ "the unsupported copy and tooltip should name the managed backend",
+ );
+});
+
+test("the capability is read from /api/health and only latches on true", () => {
+ assert.match(
+ READINESS,
+ /native_path_leases_supported\s*!==\s*true/,
+ "an absent field on an older backend must not read as supported",
+ );
+ assert.ok(
+ READINESS.includes("useState(false)"),
+ "the hook must start unsupported, so the picker is never live before it is known",
+ );
+});
+
+test("the health bit alone does not enable the picker inside the app", () => {
+ // A survivor adopted from a dead previous app holds a lease key of its own, so
+ // it answers true while every grant this app signs fails on the signature.
+ assert.ok(
+ READINESS.includes("native_path_leases_usable"),
+ "the hook must also ask the app whether the live backend is one it spawned",
+ );
+ const gate = READINESS.slice(READINESS.indexOf("native_path_leases_usable"));
+ assert.match(
+ gate,
+ /if\s*\(usable\)\s*setSupported\(true\)/,
+ "setSupported must be reached only when the app confirms the backend is ours",
+ );
+});
+
+test("an adopted backend keeps running and only loses lease-backed actions", () => {
+ // owned_stale routes through startRepair(), which runs a network update, so a
+ // key mismatch must not force one: report the capability, leave it running.
+ assert.ok(
+ !PREFLIGHT.includes("native_path_lease_secret_not_persisted") &&
+ !PREFLIGHT.includes("native_path_lease_secret_not_shared"),
+ "an adopted survivor must not be forced stale over the lease key",
+ );
+ assert.match(
+ COMMANDS,
+ /fn native_path_leases_usable[\s\S]*?Some\(snapshot\) if !snapshot\.is_adopted/,
+ "usable must require a spawned, non-adopted backend, not merely the absence " +
+ "of an adopted one: attached_ready installs no snapshot at all",
+ );
+});
diff --git a/studio/src-tauri/src/commands.rs b/studio/src-tauri/src/commands.rs
index d96d6977569..d28b818b6dd 100644
--- a/studio/src-tauri/src/commands.rs
+++ b/studio/src-tauri/src/commands.rs
@@ -614,6 +614,24 @@ pub async fn start_backend_update(
}
/// Repair a stale managed Unsloth install.
+/// Whether a native path lease this app signs can actually be verified.
+///
+/// The key is per process, so only a backend THIS process spawned holds it. An
+/// adopted survivor and an attached terminal-started backend both advertise
+/// `native_path_leases_supported` with a key that is not ours, and the boolean
+/// cannot tell them apart, so answer from the positive fact instead. Restarting
+/// them would also work, but adoption exists so a possibly mid-training backend
+/// is not killed, and the UI's only restart path runs a network update.
+#[tauri::command]
+pub async fn native_path_leases_usable(
+ backend_state: tauri::State<'_, BackendState>,
+) -> Result<bool, String> {
+ Ok(
+ matches!(process::owned_backend_snapshot(backend_state.inner())?,
+ Some(snapshot) if !snapshot.is_adopted),
+ )
+}
+
#[tauri::command]
pub async fn start_managed_repair(
app: AppHandle,
@@ -813,8 +831,15 @@ mod tests {
} else {
String::new()
};
+ // Only an owned backend can advertise lease support; ready_health(false)
+ // stands in for a terminal-started server, which never can.
+ let leases = if include_owner {
+ r#""native_path_leases_supported":true,"#
+ } else {
+ ""
+ };
format!(
- r#"{{"status":"healthy","service":"Unsloth UI Backend","version":"2026.8.4","desktop_protocol_version":1,"desktop_manageability_version":1,"supports_desktop_auth":true,"supports_desktop_backend_ownership":true,"studio_root_id":"{ROOT_ID}"{owner}}}"#
+ r#"{{"status":"healthy","service":"Unsloth UI Backend","version":"2026.8.4","desktop_protocol_version":1,"desktop_manageability_version":1,"supports_desktop_auth":true,"supports_desktop_backend_ownership":true,{leases}"studio_root_id":"{ROOT_ID}"{owner}}}"#
)
}
diff --git a/studio/src-tauri/src/desktop_backend_owner.rs b/studio/src-tauri/src/desktop_backend_owner.rs
index 8705acf9a4c..64c47a42c0d 100644
--- a/studio/src-tauri/src/desktop_backend_owner.rs
+++ b/studio/src-tauri/src/desktop_backend_owner.rs
@@ -107,6 +107,7 @@ struct HealthDesktopOwner {
#[derive(Debug, Deserialize)]
struct HealthResponse {
version: Option<String>,
+ native_path_leases_supported: Option<bool>,
}
#[derive(Debug)]
@@ -757,9 +758,14 @@ fn ready_for_use_status(health: Option<&HealthResponse>) -> OwnedBackendReadines
let version = health
.and_then(|h| h.version.as_deref())
.filter(|v| !v.is_empty());
- match crate::preflight::backend_version_stale_reason(version) {
- Some(reason) => OwnedBackendReadiness::Stale { reason },
- None => OwnedBackendReadiness::Ready,
+ if let Some(reason) = crate::preflight::backend_version_stale_reason(version) {
+ return OwnedBackendReadiness::Stale { reason };
+ }
+ match health.and_then(|health| health.native_path_leases_supported) {
+ Some(true) => OwnedBackendReadiness::Ready,
+ _ => OwnedBackendReadiness::Stale {
+ reason: "native_path_leases_unsupported".to_string(),
+ },
}
}
@@ -777,13 +783,15 @@ async fn health_ready_status(
let Some(version) = authenticated_version else {
return Err("desktop_auth_health_unverified".to_string());
};
- return match crate::preflight::backend_version_stale_reason(Some(version)) {
- None => Ok(OwnedBackendReadiness::Ready),
- Some(reason) if reason == "desktop_backend_version_too_old" => {
+ if let Some(reason) = crate::preflight::backend_version_stale_reason(Some(version))
+ {
+ return if reason == "desktop_backend_version_too_old" {
Ok(OwnedBackendReadiness::Stale { reason })
- }
- Some(reason) => Err(reason),
- };
+ } else {
+ Err(reason)
+ };
+ }
+ return Ok(ready_for_use_status(health.as_ref()));
}
Ok(ready_for_use_status(health.as_ref()))
}
@@ -1337,7 +1345,10 @@ mod tests {
async fn authenticated_health_uses_login_bearer_and_accepts_ready_version() {
let (port, seen, server) = http_sequence_server(vec![
("200 OK", r#"{"access_token":"test-access-token"}"#),
- ("200 OK", r#"{"version":"2026.8.4"}"#),
+ (
+ "200 OK",
+ r#"{"version":"2026.8.4","native_path_leases_supported":true}"#,
+ ),
])
.await;
@@ -1354,6 +1365,31 @@ mod tests {
.contains("authorization: bearer test-access-token"));
}
+ #[tokio::test]
+ async fn authenticated_health_marks_missing_or_disabled_native_leases_stale() {
+ for health in [
+ r#"{"version":"2026.8.4"}"#,
+ r#"{"version":"2026.8.4","native_path_leases_supported":false}"#,
+ ] {
+ let (port, _, server) = http_sequence_server(vec![
+ ("200 OK", r#"{"access_token":"test-access-token"}"#),
+ ("200 OK", health),
+ ])
+ .await;
+
+ let readiness = authenticated_health_ready_status(port, "desktop-test-secret")
+ .await
+ .unwrap();
+ server.await.unwrap();
+
+ assert!(matches!(
+ readiness,
+ OwnedBackendReadiness::Stale { reason }
+ if reason == "native_path_leases_unsupported"
+ ));
+ }
+ }
+
#[tokio::test]
async fn authenticated_health_preserves_genuinely_old_version_as_stale() {
let (port, _, server) = http_sequence_server(vec![
diff --git a/studio/src-tauri/src/main.rs b/studio/src-tauri/src/main.rs
index c2986f86c41..c6ad268faf1 100644
--- a/studio/src-tauri/src/main.rs
+++ b/studio/src-tauri/src/main.rs
@@ -1537,6 +1537,7 @@ fn main() {
commands::open_models_dir,
commands::start_backend_update,
commands::start_managed_repair,
+ commands::native_path_leases_usable,
commands::cancel_pending_elevation,
commands::install_system_packages,
desktop_auth::desktop_auth,
diff --git a/studio/src-tauri/src/native_backend_lease.rs b/studio/src-tauri/src/native_backend_lease.rs
index 6e94dc19e41..b483e00cd85 100644
--- a/studio/src-tauri/src/native_backend_lease.rs
+++ b/studio/src-tauri/src/native_backend_lease.rs
@@ -78,8 +78,13 @@ pub struct NativePathLeaseResponse {
pub expires_at_ms: u64,
}
+/// Lockstep with `_MIN_LEASE_SECRET_BYTES` in
+/// `studio/backend/utils/native_path_leases.py`: a shorter secret is refused
+/// there, so a shorter one here would advertise leases the backend rejects.
+pub const MIN_LEASE_SECRET_BYTES: usize = 32;
+
pub fn new_lease_secret() -> Vec<u8> {
- rand::random::<[u8; 32]>().to_vec()
+ rand::random::<[u8; MIN_LEASE_SECRET_BYTES]>().to_vec()
}
pub fn encode_secret_env(secret: &[u8]) -> String {
diff --git a/studio/src-tauri/src/native_intents.rs b/studio/src-tauri/src/native_intents.rs
index a4b82008a6d..ad1944cceaa 100644
--- a/studio/src-tauri/src/native_intents.rs
+++ b/studio/src-tauri/src/native_intents.rs
@@ -113,6 +113,10 @@ pub struct NativeIntakeState {
lease_secret: Vec<u8>,
}
+/// Per process, and deliberately not persisted: a key on disk outlives every
+/// backend restart, and spent nonces are only remembered in memory, so a
+/// consumed lease could be replayed against a replacement inside the TTL. The
+/// adopted-survivor case is answered by `native_path_leases_usable` instead.
pub fn new_native_intake_state() -> NativeIntakeState {
NativeIntakeState {
inner: Mutex::new(NativeIntakeInner::default()),
diff --git a/studio/src-tauri/src/preflight.rs b/studio/src-tauri/src/preflight.rs
index a43bc8138b3..2e348b778a1 100644
--- a/studio/src-tauri/src/preflight.rs
+++ b/studio/src-tauri/src/preflight.rs
@@ -779,8 +779,16 @@ exit 1
fn desktop_ready_health_with_owner(root_id: &str, include_owner: bool) -> String {
let owner = desktop_owner_json(include_owner);
+ // Tied to the owner on purpose: the secret comes from the desktop spawn,
+ // so an ownerless (terminal-started) backend can never report it. Both at
+ // once describes a backend that cannot exist.
+ let leases = if include_owner {
+ r#""native_path_leases_supported":true,"#
+ } else {
+ ""
+ };
format!(
- r#"{{"status":"healthy","service":"Unsloth UI Backend","version":"2026.8.4","desktop_protocol_version":1,"desktop_manageability_version":2,"supports_desktop_auth":true,"supports_desktop_backend_ownership":true,"studio_root_id":"{root_id}"{owner}}}"#
+ r#"{{"status":"healthy","service":"Unsloth UI Backend","version":"2026.8.4","desktop_protocol_version":1,"desktop_manageability_version":2,"supports_desktop_auth":true,"supports_desktop_backend_ownership":true,{leases}"studio_root_id":"{root_id}"{owner}}}"#
)
}
@@ -866,7 +874,7 @@ exit 1
// protocol-compatible backend into a conflict the user has to kill.
let probe = probe_test_backend(
format!(
- r#"{{"status":"healthy","service":"Unsloth UI Backend","version":"2026.8.4","desktop_protocol_version":1,"desktop_manageability_version":1,"supports_desktop_auth":true,"supports_desktop_backend_ownership":true,"studio_root_id":"{EXPECTED_ROOT_ID}"{}}}"#,
+ r#"{{"status":"healthy","service":"Unsloth UI Backend","version":"2026.8.4","desktop_protocol_version":1,"desktop_manageability_version":1,"supports_desktop_auth":true,"supports_desktop_backend_ownership":true,"native_path_leases_supported":true,"studio_root_id":"{EXPECTED_ROOT_ID}"{}}}"#,
desktop_owner_json(true)
),
"401 Unauthorized",
@@ -904,6 +912,76 @@ exit 1
assert!(matches!(probe, BackendProbe::Ready { .. }));
}
+ #[tokio::test]
+ async fn terminal_started_backend_without_native_path_leases_stays_adoptable() {
+ // What EVERY terminal-started server looks like, not an edge case.
+ // Refusing it would drop the attach use-tauri-backend.ts supports on
+ // purpose, to grey out one button that use-linked-folders.ts already
+ // greys out from the same capability.
+ let probe = probe_test_backend(
+ format!(
+ r#"{{"status":"healthy","service":"Unsloth UI Backend","version":"2026.8.4","desktop_protocol_version":1,"desktop_manageability_version":2,"supports_desktop_auth":true,"supports_desktop_backend_ownership":true,"native_path_leases_supported":false,"studio_root_id":"{EXPECTED_ROOT_ID}"}}"#,
+ ),
+ "401 Unauthorized",
+ )
+ .await;
+
+ assert!(matches!(probe, BackendProbe::Ready { .. }));
+ }
+
+ #[tokio::test]
+ async fn backend_predating_the_lease_capability_field_stays_adoptable() {
+ // Absent, not false: a backend predating the field reports nothing, and
+ // Option<bool> makes that indistinguishable from `false` untested.
+ let probe = probe_test_backend(
+ format!(
+ r#"{{"status":"healthy","service":"Unsloth UI Backend","version":"2026.8.4","desktop_protocol_version":1,"desktop_manageability_version":2,"supports_desktop_auth":true,"supports_desktop_backend_ownership":true,"studio_root_id":"{EXPECTED_ROOT_ID}"}}"#,
+ ),
+ "401 Unauthorized",
+ )
+ .await;
+
+ assert!(matches!(probe, BackendProbe::Ready { .. }));
+ }
+
+ #[tokio::test]
+ async fn owned_backend_without_native_path_leases_is_stale_not_a_conflict() {
+ // A defect in our own spawn, and ours to restart, so Stale (repairable)
+ // rather than a conflict the user has to resolve by hand.
+ let probe = probe_test_backend(
+ format!(
+ r#"{{"status":"healthy","service":"Unsloth UI Backend","version":"2026.8.4","desktop_protocol_version":1,"desktop_manageability_version":2,"supports_desktop_auth":true,"supports_desktop_backend_ownership":true,"native_path_leases_supported":false,"studio_root_id":"{EXPECTED_ROOT_ID}"{}}}"#,
+ desktop_owner_json(true)
+ ),
+ "401 Unauthorized",
+ )
+ .await;
+
+ assert!(matches!(
+ probe,
+ BackendProbe::Old { reason, .. } if reason == "native_path_leases_unsupported"
+ ));
+ }
+
+ #[tokio::test]
+ async fn a_stale_version_is_still_reported_as_a_version_problem() {
+ // Ordering guard: the lease check used to run first, so a backend that
+ // really needed an update reported the wrong cause to diagnostics.
+ let probe = probe_test_backend(
+ format!(
+ r#"{{"status":"healthy","service":"Unsloth UI Backend","version":"2026.5.1","desktop_protocol_version":1,"desktop_manageability_version":2,"supports_desktop_auth":true,"supports_desktop_backend_ownership":true,"native_path_leases_supported":false,"studio_root_id":"{EXPECTED_ROOT_ID}"}}"#,
+ ),
+ "401 Unauthorized",
+ )
+ .await;
+
+ assert!(matches!(
+ probe,
+ BackendProbe::ExternalConflict { reason, .. }
+ if reason == "desktop_backend_version_too_old"
+ ));
+ }
+
#[tokio::test]
async fn stale_same_root_without_desktop_owner_is_external_conflict() {
let probe = probe_test_backend(
diff --git a/studio/src-tauri/src/preflight/backend.rs b/studio/src-tauri/src/preflight/backend.rs
index 3b81b8bad24..1ace70375fc 100644
--- a/studio/src-tauri/src/preflight/backend.rs
+++ b/studio/src-tauri/src/preflight/backend.rs
@@ -20,6 +20,7 @@ pub(super) struct BackendHealth {
desktop_manageability_version: Option<u16>,
supports_desktop_auth: Option<bool>,
supports_desktop_backend_ownership: Option<bool>,
+ native_path_leases_supported: Option<bool>,
studio_root_id: Option<String>,
desktop_owner: Option<DesktopOwnerHealth>,
version: Option<String>,
@@ -68,6 +69,9 @@ pub(super) async fn backend_health(client: &reqwest::Client, port: u16) -> Optio
let supports_desktop_backend_ownership = json
.get("supports_desktop_backend_ownership")
.and_then(|v| v.as_bool());
+ let native_path_leases_supported = json
+ .get("native_path_leases_supported")
+ .and_then(|v| v.as_bool());
let studio_root_id = json
.get("studio_root_id")
.and_then(|v| v.as_str())
@@ -91,6 +95,7 @@ pub(super) async fn backend_health(client: &reqwest::Client, port: u16) -> Optio
desktop_manageability_version,
supports_desktop_auth,
supports_desktop_backend_ownership,
+ native_path_leases_supported,
studio_root_id,
desktop_owner,
version,
@@ -163,6 +168,21 @@ fn backend_capability_stale_reason(health: &BackendHealth) -> Option<String> {
}
}
+/// Deliberately NOT part of `backend_capability_stale_reason`.
+///
+/// Only the desktop spawn sets the lease secret (`process.rs`), so this does not
+/// mean "too old to talk to", it means "this app did not start it" -- permanently
+/// true of a terminal-started backend. Folded in with the protocol bits it would
+/// make every one of those an ExternalConflict and the app would refuse to start,
+/// to fix a picker `use-linked-folders.ts` already greys out. Apply it only where
+/// a restart is ours to perform.
+fn backend_native_lease_stale_reason(health: &BackendHealth) -> Option<String> {
+ if health.native_path_leases_supported != Some(true) {
+ return Some("native_path_leases_unsupported".to_string());
+ }
+ None
+}
+
#[derive(Serialize)]
struct DesktopLoginProbe<'a> {
secret: &'a str,
@@ -179,6 +199,10 @@ pub(super) async fn probe_ownerless_spawned_backend(port: u16) -> BackendProbe {
if let Some(reason) = backend_capability_stale_reason(&health) {
return BackendProbe::Old { port, reason };
}
+ // One WE spawned: a missing secret is a defect in our own start, so restart.
+ if let Some(reason) = backend_native_lease_stale_reason(&health) {
+ return BackendProbe::Old { port, reason };
+ }
let response = client
.post(format!("http://127.0.0.1:{port}/api/auth/desktop-login"))
@@ -250,6 +274,14 @@ pub(super) async fn backend_desktop_auth_status(
BackendProbe::Old { port, reason }
};
}
+ // Owned only: ours to restart, and the restart re-injects the secret. An
+ // ownerless same-root backend is terminal-started, so blocking on it would
+ // make the app unstartable. See backend_native_lease_stale_reason.
+ if !same_root_external {
+ if let Some(reason) = backend_native_lease_stale_reason(health) {
+ return BackendProbe::Old { port, reason };
+ }
+ }
let url = format!("http://127.0.0.1:{port}/api/auth/desktop-login");
let response = client
@@ -378,6 +410,7 @@ mod tests {
desktop_manageability_version: None,
supports_desktop_auth: None,
supports_desktop_backend_ownership: None,
+ native_path_leases_supported: None,
studio_root_id: studio_root_id.map(str::to_string),
desktop_owner: None,
version: None,