t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Deleting a source thread removes the HTML page a kept fork still shows

Open SouthCarpet opened this issue 1 month ago • 0 comments

Before submitting

  • [x] I searched existing issues and did not find a duplicate. (#23703 covers message attachments on mobile and leaves HTML ownership unchanged; #10774 and #10872 cover memory at startup.)
  • [x] I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Have an agent publish a page with html_render.
  2. Fork the thread after that turn.
  3. In the source thread, publish a second page in a later turn.
  4. Delete the source thread.
  5. Open the inherited page in the fork.

Expected behavior

The fork keeps the page it shows in its inherited history. Pages the source rendered after the fork point are removed with the source.

Actual behavior

The inherited page fails with AssetAttachmentNotFoundError. Its only HTML file was removed by the source's cleanup.

Checked on main 7873f53ada:

  • apps/server/src/htmlRender/HtmlRender.ts:420 creates the attachment id from the rendering thread and line 436 writes the single HTML file.
  • apps/server/src/orchestration-v2/ProjectionStore.ts:1388 keeps inherited items with their original ids; lines 1451 and 1494 build the fork's history from the source's runs. Inherited items are derived through forkedFrom, not copied into the fork's rows.
  • ProjectionStore.ts:5342 and :7205 (getThreadAttachmentIds) select render ids through threadHtmlRenderAttachmentIds.
  • apps/server/src/attachmentStore.ts:138 selects by the id's thread segment: ownership decides, not whether another live thread still references the id. The comment says this preserves source pages when a fork is deleted, which it does; the opposite order is not covered.
  • apps/server/src/orchestration-v2/ThreadDeletion.ts:235 schedules the cleanup; ResourceCleanupService.ts:104 removes the file; apps/server/src/assets/AssetAccess.ts:657 returns the error when the file is missing.

Deleted threads keep their rows with deleted_at set, so the fork's inherited history still resolves, only the file is gone.

Impact

Minor bug or occasional failure. The result is data loss: the published page cannot be recovered.

Version or commit

main at 7873f53ada; also present in 0.1.4-nightly.20261027.3770.

Environment

Windows 11, desktop app as host. Any provider that publishes a page; web, desktop and mobile read the same attachment id.

Workaround

None. Do not delete a source thread whose forks show its pages.

Proposed rule

Remove a rendered document only when no other live thread still references its attachment id. The source deleted first keeps the file for the fork; the last fork deleted removes it; a page rendered after the fork point goes with the source; nested forks and captured MCP App pages follow the same rule. I have this implemented on a branch (SQLite and memory stores, bounded to the thread's fork family through lineage.rootThreadId, with tests for both stores and the ordering cases) and can open a pull request if that is useful.

SouthCarpet avatar Oct 27 '26 18:10 SouthCarpet