{"record":{"id":"0c20626a18d691a2","repo":"unslothai/unsloth","slug":"native-path-grants-require-the-managed-desktop-bac","errorCode":null,"errorMessage":"Native path grants require the managed desktop backend.","messagePattern":"Native path grants require the managed desktop backend\\.","errorType":"validation","errorClass":"NativePathLeaseError","httpStatus":400,"severity":"error","filePath":"studio/backend/utils/native_path_leases.py","lineNumber":268,"sourceCode":"        for variant in {path, path.replace(\"/\", \"\\\\\"), path.replace(\"\\\\\", \"/\")}:\n            if variant:\n                redacted = redacted.replace(variant, \"<native_path>\")\n    return redacted\n\n\ndef _decode_secret() -> bytes:\n    global _CACHED_LEASE_SECRET\n    if _CACHED_LEASE_SECRET is not None:\n        return _CACHED_LEASE_SECRET\n    with _SECRET_INIT_LOCK:\n        if _CACHED_LEASE_SECRET is not None:\n            return _CACHED_LEASE_SECRET\n        with _NATIVE_PATH_ENV_LOCK:\n            encoded = os.environ.get(LEASE_SECRET_ENV)\n            if encoded is None and _SCRUB_SAVED_SECRET is not None:\n                encoded = _SCRUB_SAVED_SECRET\n        if not encoded:\n            raise NativePathLeaseError(\"Native path grants require the managed desktop backend.\")\n        try:\n            secret = _b64decode(encoded)\n        except Exception as exc:\n            raise NativePathLeaseError(\"Native path grant secret is invalid.\") from exc\n        if len(secret) < _MIN_LEASE_SECRET_BYTES:\n            raise NativePathLeaseError(\"Native path grant secret is invalid.\")\n        _CACHED_LEASE_SECRET = secret\n        return secret\n\n\ndef _split_lease(lease: str) -> tuple[str, str]:\n    if not isinstance(lease, str):\n        raise NativePathLeaseError(\"Native path grant has an invalid format.\")\n    try:\n        lease.encode(\"ascii\")\n    except UnicodeEncodeError as exc:\n        raise NativePathLeaseError(\"Native path grant has an invalid format.\") from exc\n    parts = lease.split(\".\")","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/utils/native_path_leases.py#L250-L286","documentation":"The lease-signing secret is absent: neither the UNSLOTH_STUDIO_NATIVE_PATH_LEASE_SECRET environment variable nor the temporarily scrubbed copy (_SCRUB_SAVED_SECRET) is set. That secret is installed only by the managed Tauri desktop launcher, so its absence means the process is not running under the managed desktop backend.","triggerScenarios":"Starting the studio backend manually (python -m, uvicorn, pytest) outside the Tauri shell; a child process spawned via run_without_native_path_secret() (which deliberately deletes the env var) later attempting lease verification; the env var name misspelled or stripped by a supervisor/unit file; or the secret scrub window (native_path_secret_removed_for_child_start) covering the verification call.","commonSituations":"Local dev servers, CI test runs, Docker deployments, or multiprocessing workers where the desktop launcher never ran; systemd/launchd configs that whitelist specific env vars; or code that spawns inference/training workers via run_without_native_path_secret and those workers try to re-verify a lease forwarded from the parent.","solutions":["If you need lease support, run the backend under the managed Tauri desktop app so it injects the secret.","Use native_path_leases_supported() to feature-detect and disable native-path flows (fall back to regular uploads) when the secret is absent.","If a child worker needs to verify leases, pass the verified NativePathGrant (or the resolved path result) from the parent instead of re-verifying inside a worker that had the secret scrubbed.","For dev/test, set UNSLOTH_STUDIO_NATIVE_PATH_LEASE_SECRET to a base64url-encoded >=32-byte random value matching your signing harness."],"exampleFix":"# before\ngrant = verify_native_path_lease(lease, operation=\"read\")  # raises in child workers\n\n# after\nif not native_path_leases_supported():\n    raise UnsupportedEnvironmentError(\"Native file access needs the managed desktop backend.\")\ngrant = verify_native_path_lease(lease, operation=\"read\")","handlingStrategy":"type-guard","validationCode":"from utils.native_path_leases import native_path_leases_supported\n\nif not native_path_leases_supported():\n    return error_response(501, \"Native file access requires the managed desktop app.\")","typeGuard":"native_path_leases_supported  # built-in feature check; returns False instead of raising","tryCatchPattern":"try:\n    grant = verify_native_path_lease(lease, operation=OP)\nexcept NativePathLeaseError as exc:\n    if \"require the managed desktop backend\" in str(exc):\n        return error_response(501, \"Run inside the desktop app to use native file access.\")\n    raise","preventionTips":["Feature-detect with native_path_leases_supported() at startup and disable native-path UI.","Never re-verify leases in workers spawned via run_without_native_path_secret — verify in the parent and pass the resolved path/grant.","In dev/test, inject a valid base64url >=32-byte secret via the documented env var."],"tags":["environment","desktop","tauri","configuration"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}