Clean up orphaned messages when deleting a branch#3478
Open
Doondi-Ashlesh wants to merge 1 commit into
Open
Conversation
delete_branch was removing rows from turn_usage and message_structure but leaving behind message rows in the messages table that belonged exclusively to the deleted branch. Those rows were invisible to queries since get_items joins through message_structure, but they kept accumulating on disk with each branch deletion. The existing _cleanup_orphaned_messages_sync helper already handles this correctly by checking for messages with no remaining structure references. This just calls it as part of the delete transaction before committing. Added a regression test that verifies branch-only messages are removed and shared messages are preserved after deletion.
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
delete_branchwas removing rows fromturn_usageandmessage_structurebut leaving behind the corresponding rows in the messages table that belonged exclusively to the deleted branch. Those rows were invisible to any query sinceget_itemsjoins throughmessage_structure, but they kept accumulating on disk with each branch deletion.The existing
_cleanup_orphaned_messages_synchelper already does the right thing: it finds messages with no remaining references inmessage_structureand removes them. This just calls it inside the same transaction before the final commit, so shared messages (referenced by other branches) are preserved and exclusive ones are removed atomically.Test plan
Added
test_delete_branch_removes_orphaned_messageswhich:All 38 tests in
test_advanced_sqlite_session.pypass. No regressions in the wider suite.Issue number
Closes #3346
Checks
make lintandmake format