unslothai/unsloth · warning · HTTPException

Knowledge base is being deleted

Error message

Knowledge base is being deleted

What it means

_raise_if_scope_retired() returns HTTP 409 'Knowledge base is being deleted' when folder_sync.scope_retired(scope) is true: the KB's scope was retired by a delete in flight (retire_and_delete_kb marks the scope before/while removing data and stopping sync jobs). Writes to that scope — e.g. uploading a document — are rejected until deletion completes, rather than racing the deleter.

Source

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


@router.delete("/knowledge-bases/{kb_id}")
def delete_knowledge_base(kb_id: str, subject: str = Depends(get_current_subject)) -> dict:
    _require_rag()
    with _rag_unavailable_as_503():
        deleted = folder_sync.retire_and_delete_kb(kb_id)
    if not deleted:
        raise HTTPException(status_code = 404, detail = "Knowledge base not found")
    try:
        folder_sync.delete_retired_scope(store.kb_scope(kb_id))
    except Exception:
        logger.warning("failed to delete retired knowledge-base scope %s", kb_id, exc_info = True)
    return {"ok": True}


def _raise_if_scope_retired(scope: str, detail: str = "Knowledge base is being deleted") -> None:
    if folder_sync.scope_retired(scope):
        raise HTTPException(status_code = 409, detail = detail)


@router.post("/knowledge-bases/{kb_id}/documents")
async def upload_kb_document(
    kb_id: str,
    file: UploadFile | None = File(None),
    native_path_lease: str | None = Form(None, alias = "nativePathLease"),
    ocr: bool | None = Form(None),
    caption: bool | None = Form(None),
    subject: str = Depends(get_current_subject),
) -> dict:
    _require_rag()
    conn = _rag_connection()
    try:
        if store.get_kb(conn, kb_id) is None:
            raise HTTPException(status_code = 404, detail = "Knowledge base not found")
    finally:
        conn.close()

View on GitHub (pinned to 203007d190)

Solutions

  1. Do not retry: propagate 'KB is being deleted' to the UI and drop the pending upload.
  2. Close/disable upload UI for a KB as soon as its delete is initiated (optimistically mark it deleting).
  3. On 409, refresh the KB list and continue against a different KB.

Example fix

// before
if (res.status === 409) retry(500); // pointless: scope is retiring
// after
if (res.status === 409) { ui.markKbDeleting(kbId); discardPendingUpload(); return; }
Defensive patterns

Strategy: validation

Validate before calling

if (ui.kbState[kbId] === 'deleting') { abortPendingUpload(); return; } // set optimistically when delete starts

Try / catch

if (e.status === 409 && e.detail === 'Knowledge base is being deleted') { markKbDeleting(kbId); discardPendingUpload(); }

Prevention

When it happens

Trigger: Uploading a document or linking a folder to a KB that another request is currently deleting: the delete retires the scope, and any concurrent mutation to kb_scope(kb_id) hits the 409.

Common situations: Delete and upload tabs open simultaneously; automated import running while a user deletes the KB; slow scope cleanup (many documents) leaving the retired window open for seconds.

Related errors


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