unslothai/unsloth · error · NativePathLeaseError

Native path grant has the wrong path type.

Error message

Native path grant has the wrong path type.

What it means

The caller passed expected_path_type to verify_native_path_lease() and the grant's embedded path_type ('file' or 'directory') doesn't match it. Each API endpoint admits only one shape of grant — a file-upload endpoint requires a 'file' grant, a folder-picking endpoint a 'directory' grant — so this blocks replaying a grant against the wrong kind of operation.

Source

Thrown at studio/backend/utils/native_path_leases.py:218

    identity_options = _identity_options(payload)
    grant = NativePathGrant(
        operation = str(payload["operation"]),
        canonical_path = resolved,
        path_kind = str(payload["path_kind"]),
        path_type = str(payload["path_type"]),
        source_kind = str(payload["source_kind"]),
        token_id_hash = str(payload["token_id_hash"]),
        display_label = str(payload.get("display_label") or resolved.name),
        expires_at_ms = _required_int(payload, "expires_at_ms"),
        size_bytes = _optional_int(payload.get("size_bytes")),
        modified_ms = _optional_int(payload.get("modified_ms")),
        device_id = identity_options[0][0] if identity_options else None,
        file_id = identity_options[0][1] if identity_options else None,
    )

    if expected_path_type and grant.path_type != expected_path_type:
        raise NativePathLeaseError("Native path grant has the wrong path type.")
    suffixes = tuple(s.lower() for s in (allowed_suffixes or ()))
    if suffixes and resolved.suffix.lower() not in suffixes:
        raise NativePathLeaseError("Native path grant has an unsupported file type.")

    current_identity = _validate_current_stat(grant, identity_options)
    if current_identity is not None:
        grant = replace(grant, device_id = current_identity[0], file_id = current_identity[1])
    _consume_nonce(str(payload["nonce"]), grant.expires_at_ms)
    _remember_native_path_for_redaction(str(resolved), grant.display_label)
    return grant


def display_label_for_native_path(value: str | None) -> str | None:
    if not value:
        return value
    with _REDACTION_LOCK:
        return _NATIVE_PATH_LABELS.get(value, value)

View on GitHub (pinned to 203007d190)

Solutions

  1. Make the picker mode match the endpoint: open the file dialog for endpoints expecting path_type='file', the directory dialog for 'directory'.
  2. Store leases per-purpose in the frontend instead of one shared variable so a directory grant can't be sent to a file endpoint.
  3. After the dialog returns, sanity-check the grant's semantics (which dialog produced it) before enabling the submit action.
  4. If writing a new endpoint, pass expected_path_type explicitly so mismatches fail loudly.

Example fix

# before
verify_native_path_lease(lease, operation="import_weights", expected_path_type="file")  # lease came from directory picker

# after
lease = await native_dialog.pick_file(dialog="gguf")  # file picker, not folder picker
verify_native_path_lease(lease, operation="import_weights", expected_path_type="file")
Defensive patterns

Strategy: validation

Validate before calling

# Client-side: only enable the file action when the grant came from the file dialog
assert dialog_mode == "file" before submitting to an endpoint documented as file-type.

Try / catch

try:
    grant = verify_native_path_lease(lease, operation=OP, expected_path_type="file")
except NativePathLeaseError as exc:
    if "wrong path type" in str(exc):
        return error_response(400, "This action needs a single file, not a folder.")
    raise

Prevention

When it happens

Trigger: Calling an endpoint with a directory-selection grant where a file grant is required (or vice versa); frontend reusing a stored lease from a different picker dialog; passing expected_path_type="file" while the user picked a folder in a directory-mode dialog.

Common situations: Shared lease state in the frontend where multiple pickers write to the same variable; copy-pasted call sites where the picker mode (file vs directory) doesn't match the API's expected_path_type; UI regressions that open the wrong dialog variant for the action.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/d0d53ace6659c0fd. Report an issue: GitHub.