{"record":{"id":"9d3e3a70336162aa","repo":"unslothai/unsloth","slug":"native-path-grant-is-required-9d3e3a","errorCode":null,"errorMessage":"Native path grant is required.","messagePattern":"Native path grant is required\\.","errorType":"validation","errorClass":"NativePathLeaseError","httpStatus":400,"severity":"error","filePath":"studio/backend/utils/native_path_leases.py","lineNumber":169,"sourceCode":"        try:\n            yield\n        finally:\n            _SCRUB_REFCOUNT -= 1\n            if _SCRUB_REFCOUNT == 0 and _SCRUB_SAVED_SECRET is not None:\n                os.environ[LEASE_SECRET_ENV] = _SCRUB_SAVED_SECRET\n                _SCRUB_SAVED_SECRET = None\n\n\ndef verify_native_path_lease(\n    lease: str | None,\n    *,\n    operation: str,\n    expected_kind: str | None = None,\n    expected_path_type: str | None = None,\n    allowed_suffixes: Iterable[str] | None = None,\n) -> NativePathGrant:\n    if not lease:\n        raise NativePathLeaseError(\"Native path grant is required.\")\n\n    secret = _decode_secret()\n    payload_b64, signature_b64 = _split_lease(lease)\n    expected_signature = hmac.new(\n        secret,\n        payload_b64.encode(\"ascii\"),\n        hashlib.sha256,\n    ).digest()\n    supplied_signature = _b64decode(signature_b64)\n    if not hmac.compare_digest(expected_signature, supplied_signature):\n        raise NativePathLeaseError(\"Native path grant signature is invalid.\")\n\n    payload = _decode_payload(payload_b64)\n    _validate_payload(payload, operation = operation, expected_kind = expected_kind)\n\n    path = Path(str(payload[\"canonical_path\"]))\n    _reject_network_or_device_path(path)\n    try:","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/utils/native_path_leases.py#L151-L187","documentation":"verify_native_path_lease() was called with a falsy lease value (None or empty string). The backend requires a signed native path grant (issued by the Tauri/Rust desktop shell) before it will touch any user-selected filesystem path; a missing grant means the request never went through the managed file-picker flow.","triggerScenarios":"Any backend API that accepts a nativePathLease parameter being called with lease=None, lease omitted from the request payload, or an empty string — e.g. a frontend form that submitted before the desktop dialog returned a grant, a test/CI harness calling the endpoint directly, or a client that dropped the lease field during serialization.","commonSituations":"Running the studio backend outside the Tauri desktop app (no grant issuance possible), frontend code that reads the grant from state before the native dialog resolves, JSON payloads where the lease key is misspelled, or replaying a captured request without the lease header/field.","solutions":["Ensure the desktop file-picker flow completes and its returned grant string is forwarded verbatim as the lease argument.","Check the frontend state/serialization: confirm the lease field is present, non-empty, and not renamed between the dialog callback and the API call.","If you are calling the endpoint from tests or a non-desktop context, obtain a lease from the Tauri shell or mock verify_native_path_lease instead of passing None.","Guard the call with native_path_leases_supported() and show a 'managed desktop backend required' message when it returns False."],"exampleFix":"// before\nresult = import_native_gguf(path=selected_path, lease=None)\n\n# after\nif not lease:\n    raise ValueError(\"Select a file in the desktop dialog first; it returns the required grant.\")\nresult = import_native_gguf(path=selected_path, lease=lease)","handlingStrategy":"validation","validationCode":"def require_lease(lease):\n    if not isinstance(lease, str) or not lease.strip():\n        raise HTTPBadRequest(\"Native path grant is required; re-select the file in the desktop dialog.\")\n    return lease","typeGuard":"def is_lease_string(value: object) -> bool:\n    return isinstance(value, str) and len(value) > 0","tryCatchPattern":"try:\n    grant = verify_native_path_lease(lease, operation=OP)\nexcept NativePathLeaseError as exc:\n    if \"grant is required\" in str(exc):\n        return error_response(400, \"Please select a file first.\")\n    raise","preventionTips":["Treat the lease as mandatory request state: validate presence before calling verify.","Disable submit actions in the UI until the native dialog has returned a grant.","Feature-detect with native_path_leases_supported() and route users to non-native flows when unsupported."],"tags":["desktop","tauri","file-picker","validation"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}