fix: #3346 clean up orphaned messages in delete_branch#3526
Open
kimnamu wants to merge 1 commit into
Open
Conversation
This was referenced May 29, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3346.
delete_branch()removes the branch'smessage_structurerows but never cleans up the underlying messages, so messages that were only referenced by the deleted branch stay in the messages table indefinitely.The session already has a well-factored
_cleanup_orphaned_messages_sync()helper (the same oneadd_items()relies on for its failure path), so this fix simply calls it after the structure rows are deleted — no new deletion logic, just the missing call site. The log line now also reports how many orphaned messages were removed.Before / After
delete_branch("feature")with branch-only messagesmessage_structurerows deleted, but the messages stay inmessages_tableforever_cleanup_orphaned_messages_sync()helperDeleted branch 'feature': N message entries, M usage entriesDeleted branch 'feature': N structure entries, M usage entries, K orphaned messages removedTest
Adds
test_delete_branch_cleans_up_orphaned_messages, a regression test that creates a branch-only message, deletes the branch, and asserts the orphaned message is gone while the shared message remains.