unslothai/unsloth · error · HTTPException

Dropped file could not be read.

Error message

Dropped file could not be read.

What it means

In the native-path attach flow, after the lease verifies, the backend opens grant.canonical_path to copy the file into the managed uploads root. If open() or the streaming read raises OSError (file deleted, permissions changed, I/O error, unreadable removable media), it is converted to HTTP 400 'Dropped file could not be read.' — the lease was valid but the bytes are gone.

Source

Thrown at studio/backend/routes/rag.py:188

            lease,
            operation = "attach",
            expected_kind = "attachment",
            expected_path_type = "file",
            allowed_suffixes = sorted(config.UPLOAD_EXTS),
        )
    except NativePathLeaseError as exc:
        raise HTTPException(status_code = 400, detail = str(exc)) from exc

    filename = _sanitize_filename(grant.canonical_path.name)
    try:
        with open(grant.canonical_path, "rb") as source:
            return _persist_upload_stream(
                source,
                filename,
                empty_detail = "Dropped file is empty.",
            )
    except OSError as exc:
        raise HTTPException(status_code = 400, detail = "Dropped file could not be read.") from exc


def _resolve_document_upload(
    file: UploadFile | None, native_path_lease: str | None
) -> tuple[str, str]:
    if native_path_lease:
        return _save_native_path_upload(native_path_lease)
    if file is None:
        raise HTTPException(status_code = 400, detail = "No file was provided.")
    return _save_upload(file)


def _remove_stored_upload(stored_path: str | None) -> None:
    """Best-effort cleanup for files saved by _save_upload."""
    if not stored_path:
        return
    try:
        uploads = os.path.realpath(str(rag_uploads_root()))

View on GitHub (pinned to 203007d190)

Solutions

  1. Verify the file still exists and is readable (os.access(path, R_OK)) right before upload and re-drop if not.
  2. Re-mount / re-attach the external media and repeat the drop.
  3. Copy the file to a local stable location before dropping if it lives on flaky storage.

Example fix

# before
drop_file('/mnt/usb/report.pdf')  # USB unplugged -> 400
# after
import os
if not os.access('/mnt/usb/report.pdf', os.R_OK):
    raise SystemExit('Re-attach the drive, then drop the file again')
Defensive patterns

Strategy: try-catch

Validate before calling

import os
if not os.path.isfile(path) or not os.access(path, os.R_OK):
    raise RuntimeError('file unreadable; re-select it')

Try / catch

if (res.status === 400 && detail === 'Dropped file could not be read.') { promptReDrop(); }

Prevention

When it happens

Trigger: File removed, renamed, locked (Windows), on unmounted external media, or with read permission revoked between the user dropping it and the backend opening it.

Common situations: User drops a file from a USB drive that gets disconnected; antivirus/quarantine removes the file; the file lives in a synchronized folder that renames it during upload; macOS sandbox denies read after the lease.

Related errors


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