unslothai/unsloth · warning · ValueError

Folder was concurrently removed

Error message

Folder was concurrently removed

What it means

Raised when, after INSERT (or its IntegrityError on a duplicate) and commit, re-selecting the row by path returns None. The path column is UNIQUE, so the only way the row vanishes between commit and SELECT is another connection DELETEing it concurrently — studio uses per-call SQLite connections, so a remove_scan_folder racing an add_scan_folder_with_status for the same path triggers this. It signals a lost race, not corruption.

Source

Thrown at studio/backend/hub/storage/scan_folders.py:178

            return dict(existing), False
        inserted = False
        try:
            conn.execute(
                "INSERT INTO scan_folders (path, created_at) VALUES (?, ?)",
                (normalized, now),
            )
            conn.commit()
            inserted = True
        except sqlite3.IntegrityError:
            pass
        fallback_sql = (
            "SELECT id, path, created_at FROM scan_folders WHERE path = ? COLLATE NOCASE"
            if is_win
            else "SELECT id, path, created_at FROM scan_folders WHERE path = ?"
        )
        row = conn.execute(fallback_sql, (normalized,)).fetchone()
        if row is None:
            raise ValueError("Folder was concurrently removed")
        return dict(row), inserted
    finally:
        conn.close()


def add_scan_folder(path: str) -> dict:
    """Add a readable directory for the local OS user; not a multi-user sandbox."""
    row, _ = add_scan_folder_with_status(path)
    return row


def remove_scan_folder(id: int) -> bool:
    # sqlite INTEGER is signed 64-bit; ids outside that range cannot exist.
    if not -(2**63) <= id < 2**63:
        return False
    conn = get_connection()
    try:
        _ensure_schema(conn)

View on GitHub (pinned to 203007d190)

Solutions

  1. Retry the add if the folder should exist — the race is timing-dependent and a retry will succeed when no delete is in flight.
  2. Serialize add/remove calls for the same path client-side (disable the remove button until add settles).
  3. Treat as informational if the intent was removal anyway: the folder ended up unregistered either way.
Defensive patterns

Strategy: retry

Try / catch

for attempt in range(2):
    try:
        row, inserted = add_scan_folder_with_status(path)
        break
    except ValueError as e:
        if "concurrently removed" in str(e) and attempt == 0:
            continue  # lost an add/remove race; safe to retry
        raise

Prevention

When it happens

Trigger: Two API calls in flight simultaneously: POST /scan-folders {path} and DELETE /scan-folders {id} for the same path; the DELETE's commit lands between the add's commit and its re-select.

Common situations: UI allowing rapid add-then-remove clicks with in-flight requests; automation scripts adding and pruning folders; retry storms from a flaky client.

Related errors


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