testlists: rebuild stale user branches onto master before pushing #1244 - #1245
Draft
aagbsn wants to merge 1 commit into
Draft
testlists: rebuild stale user branches onto master before pushing #1244#1245aagbsn wants to merge 1 commit into
aagbsn wants to merge 1 commit into
Conversation
Fixes merge conflicts on the PRs this service opens against citizenlab/test-lists (e.g. #2257: three commits from March, pushed and PR'd in August against a master that had moved on by five months of unrelated merged changes). _pull_origin_repo()/_init_repo() already keep the shared repo's own copy of master fresh on every request. The actual bug is that a user's worktree/branch is only ever cut from master *once*, the first time the account starts editing (_get_user_repo()), and is never touched again no matter how far master moves before they submit. A plain textual `git rebase` does not fix this for this workload: every edit here is a single-row append to a shared CSV (update()), and the busiest of these files (lists/global.csv, confirmed from the real repo's history) receive a steady stream of single-row-append commits from unrelated contributors. Two independent end-of-file insertions with nothing else in common are exactly what git's 3-way merge treats as a conflict - verified directly against real git, not a dulwich quirk - so replaying old commits onto a master with *any* newer, unrelated addition to the same file would still conflict, just earlier and on nearly every submission instead of rarely and on GitHub. Instead, _rebase_user_branch_onto_master() replays the account's own tracked, structured changes (read_changes_log()/write_changes_log(), already recorded per edit) directly on top of whatever lists/<cc>.csv actually contains on master right now, then hard-resets the branch onto master and commits the result. This produces a branch that differs from master by exactly this account's pending edits and nothing else, which always applies cleanly on GitHub. It's called from _push_to_repo() right before every push. This can raise CannotUpdateList or DuplicateURLError if replaying a change is genuinely impossible against master's current content (someone else already removed the exact row being deleted, or already added the exact URL being added) - a real conflict, not staleness. propose_changes() now re-raises any BaseOONIException from _push_to_repo() as-is instead of masking it behind the generic CannotProposeChanges, since "just retry" doesn't apply: retrying submit() alone hits the same conflict every time until the user reloads and reapplies their change. This also corrects the pre-existing uncommitted-changes-in-worktree error, which reuses CannotUpdateList, to surface as itself instead of as CannotProposeChanges. Also fixes a latent bug in write_changes_log(): adding then deleting the same entry within one session logged a spurious delete op even though the row never reached master, which would otherwise make the replay above fail with a false "list has changed" error. Updates test_second_users_branch_misses_first_users_merged_change (renamed to ..._picks_up_...) to assert the now-fixed behavior, per that test's own docstring, and updates test_push_refuses_when_worktree_has_uncommitted_changes for the err_cannot_update_list vs err_cannot_propose_changes change above.
aagbsn
marked this pull request as draft
August 19, 2026 08:18
Contributor
Author
|
This should be reviewed for sanity since it's a pretty big changeset |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1245 +/- ##
==========================================
+ Coverage 92.42% 93.18% +0.75%
==========================================
Files 86 79 -7
Lines 8599 7731 -868
Branches 509 468 -41
==========================================
- Hits 7948 7204 -744
+ Misses 541 437 -104
+ Partials 110 90 -20
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes merge conflicts on the PRs this service opens against citizenlab/test-lists (e.g. #2257: three commits from March, pushed and PR'd in August against a master that had moved on by five months of unrelated merged changes).
_pull_origin_repo()/_init_repo() already keep the shared repo's own copy of master fresh on every request. The actual bug is that a user's worktree/branch is only ever cut from master once, the first time the account starts editing (_get_user_repo()), and is never touched again no matter how far master moves before they submit.
A plain textual
git rebasedoes not fix this for this workload: every edit here is a single-row append to a shared CSV (update()), and the busiest of these files (lists/global.csv, confirmed from the real repo's history) receive a steady stream of single-row-append commits from unrelated contributors. Two independent end-of-file insertions with nothing else in common are exactly what git's 3-way merge treats as a conflict - verified directly against real git, not a dulwich quirk - so replaying old commits onto a master with any newer, unrelated addition to the same file would still conflict, just earlier and on nearly every submission instead of rarely and on GitHub.Instead, _rebase_user_branch_onto_master() replays the account's own tracked, structured changes (read_changes_log()/write_changes_log(), already recorded per edit) directly on top of whatever lists/.csv actually contains on master right now, then hard-resets the branch onto master and commits the result. This produces a branch that differs from master by exactly this account's pending edits and nothing else, which always applies cleanly on GitHub. It's called from _push_to_repo() right before every push.
This can raise CannotUpdateList or DuplicateURLError if replaying a change is genuinely impossible against master's current content (someone else already removed the exact row being deleted, or already added the exact URL being added) - a real conflict, not staleness. propose_changes() now re-raises any BaseOONIException from _push_to_repo() as-is instead of masking it behind the generic CannotProposeChanges, since "just retry" doesn't apply: retrying submit() alone hits the same conflict every time until the user reloads and reapplies their change. This also corrects the pre-existing uncommitted-changes-in-worktree error, which reuses CannotUpdateList, to surface as itself instead of as CannotProposeChanges.
Also fixes a latent bug in write_changes_log(): adding then deleting the same entry within one session logged a spurious delete op even though the row never reached master, which would otherwise make the replay above fail with a false "list has changed" error.
Updates test_second_users_branch_misses_first_users_merged_change (renamed to ...picks_up...) to assert the now-fixed behavior, per that test's own docstring, and updates
test_push_refuses_when_worktree_has_uncommitted_changes for the err_cannot_update_list vs err_cannot_propose_changes change above.