t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Deleting a thread deletes the attachments its forks still show

Open Entrpi opened this issue 4 weeks ago • 2 comments

What happens

A fork shows its source's earlier turns by reading them from the source thread. When the source is deleted, the server queues an attachment.cleanup for every attachment in the source's messages, and the files are removed. The fork's inherited turns then show broken images and files.

Steps to reproduce (main cefb544af3)

  1. Send a prompt with an image attached (any provider that accepts images).
  2. Fork the thread from the reply.
  3. Delete the original thread.
  4. Open the fork. The inherited prompt's image no longer loads, and its file is gone from userdata/attachments.

Expected

Deleting a thread leaves the fork's history intact, including its attachments. The files go when the last thread that can show them is deleted.

Where

planThreadDeletion (apps/server/src/orchestration-v2/ThreadDeletion.ts) gets its ids from getThreadAttachmentIds, which lists the deleted thread's own files without checking for live forks that read through it. Project delete (ProjectService.ts) uses the same read.

I have a fix with a failing-first test, proven on web and Android. I can open a PR if you want one.

Entrpi avatar Nov 03 '26 08:11 Entrpi

The fix is on our fork as one commit on top of main (cefb544): 8ee2934 (compare).

It includes the failing test in ThreadFork.execution.test.ts, which fails on main for this reason. Happy to open it as a PR if you want it.

Entrpi avatar Nov 03 '26 09:11 Entrpi

Fixed by #32255, now on main: After #32255, deleting a source preserves the images and files its live forks—including nested forks—still show, and deleting the last viewer releases those files, including during concurrent thread and project deletion.

juliusmarminge avatar Nov 15 '26 05:11 juliusmarminge