Don't mutate the caller's managed map in BuildPlans#89
Open
Soph wants to merge 1 commit into
Open
Conversation
BuildPlans passed the caller's managed map straight to addPruneCandidates, which inserts prune candidates — so a --prune plan mutated a map the caller still owns. BuildReplicationPlans already copied defensively. Copy inside the prune branch in both (the only mutation happens there), so neither touches the caller's map and the two functions stay symmetric. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Entire-Checkpoint: f3b681dacd36
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.
Problem
BuildPlanspassed the caller'smanagedmap straight intoaddPruneCandidates, which inserts prune candidates. So a--pruneplan mutated a map the caller still owns (and may reuse).BuildReplicationPlansalready copied defensively, so the two diverged.Fix
Copy
managedinside theif cfg.Pruneblock in both functions — that's the only place the map is mutated, so neither touches the caller's map, both stay symmetric, and the copy is skipped entirely when not pruning.Tests
TestBuildPlansDoesNotMutateManagedMapruns a--pruneplan with a stale target ref, confirms it's planned for deletion (prune actually ran), and asserts the caller'smanagedmap is unchanged (the prune candidate landed only in the copy).🤖 Generated with Claude Code
Note
Low Risk
Localized defensive copy in plan builders with a regression test; behavior for prune/delete plans is unchanged aside from fixing unintended map mutation.
Overview
BuildPlanswith--pruneno longer mutates the caller’smanagedmap. Prune candidates fromaddPruneCandidatesare applied only on acopyManagedTargetscopy, matchingBuildReplicationPlans.BuildReplicationPlansnow copiesmanagedonly whencfg.Pruneis set (it previously copied on every call). Both builders share the same rule: no copy when not pruning, copy before the only mutation when pruning.Adds
TestBuildPlansDoesNotMutateManagedMapto assert a stale ref gets a delete plan while the caller’smanagedmap stays length 1 with no leaked prune entry.Reviewed by Cursor Bugbot for commit cf4957c. Configure here.