Skip to content

Studio: delete a chat's uploaded documents when the chat is deleted - #11233

Merged
Lyxot merged 2 commits into
unslothai:mainfrom
NilayYadav:delete-thread-rag-documents
Sep 18, 2026
Merged

Lyxot merged 2 commits into
unslothai:mainfrom
NilayYadav:delete-thread-rag-documents

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Documents added with Chat with Files stayed on disk and in the database after their chat was deleted. They kept showing up under Settings > Data > Uploaded files, pointing at a chat that no longer existed. Clear all chats left them behind too.

Deleting a chat, Clear all chats and deleting a project now also remove the documents that belonged to those chats, including the stored file. Documents in other chats are not touched.

Tested in Studio with two chats that each had a document. Before, both documents stayed after deleting a chat and after Clear all chats. After, only the deleted chat's document is removed, and Clear all chats leaves nothing behind.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

…ts tests

Delete a thread's archived turns and uploaded documents from one loop so the recreated-thread cutoff is decided once, pin multi-document, index-row and cross-chat isolation in the cleanup tests, and generalize the shared scope-deletion docstrings.
@Lyxot

Lyxot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Thanks, the fix is right. I pushed one small follow-up commit (a58ee27) on top:

  • _remove_thread_documents was a copy of _remove_conversation_archives, so every delete route made two calls. Both are now one _remove_thread_rag_data loop that decides the recreated-thread cutoff once, then deletes archived turns and uploaded documents in separate try blocks.
  • Tests: the chat-delete case uploads two documents, the chunk count reads raw chunks / chunks_fts rows so index leftovers are caught, and the project case checks a non-member chat's upload survives.
  • Docstrings in the shared scope-delete helpers no longer describe archives only.

No behavior change beyond the original PR.

@Lyxot

Lyxot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Codex review on a staging copy of this PR (at a58ee27): Didn't find any major issues. Lyxot#58 (comment)

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Deleting a chat, clearing all chats, or deleting a project now removes that chat's uploads (rows, index entries and the stored file), scoped to the chat and confined to the uploads root. Merges cleanly with current main and the related backend tests pass; the two CI failures are unrelated (runner missing browser libs, MoE LoRA test).

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed that on main routes/chat_history.py only clears archived turns on delete, so a chat's uploads stay in rag.db and under the uploads root and keep listing in the Data settings; the scoping and the recreated-thread cutoff here look right, will get this reviewed.

@Lyxot
Lyxot merged commit fd51e60 into unslothai:main Sep 18, 2026
47 of 49 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…nslothai#11233)

* Studio: remove a chat's uploaded documents when the chat is deleted

* refactor(studio): fold thread RAG cleanup into one pass and tighten its tests

Delete a thread's archived turns and uploaded documents from one loop so the recreated-thread cutoff is decided once, pin multi-document, index-row and cross-chat isolation in the cleanup tests, and generalize the shared scope-deletion docstrings.

---------

Co-authored-by: Lyxot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants