From 957ace9ca7e2204cbbb2d842a4381b96f6a9e9c6 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 22:46:11 -0400 Subject: [PATCH] fix(automerge): key replaySupersedeOntoBase claim by prior_copy so re-adoption replays the base merge Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/fixed-15225.md | 1 + ...automerge_adoption_readopt_journal_test.go | 21 ++++++++++++++++++ .../automerge/automerge_contributor_adopt.go | 22 +++++++++++-------- 3 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 changelog.d/fixed-15225.md diff --git a/changelog.d/fixed-15225.md b/changelog.d/fixed-15225.md new file mode 100644 index 0000000000..41bc9afbda --- /dev/null +++ b/changelog.d/fixed-15225.md @@ -0,0 +1 @@ +- Re-adopting a pull request after the hive closed its earlier copy now merges the base branch into the new copy again, so the fresh copy no longer opens with the conflict the first adoption had resolved ([#15225](https://github.com/hivecommons/hive/issues/15225)). diff --git a/src/pkg/github/automerge/automerge_adoption_readopt_journal_test.go b/src/pkg/github/automerge/automerge_adoption_readopt_journal_test.go index ab9a224dbb..fda498e7af 100644 --- a/src/pkg/github/automerge/automerge_adoption_readopt_journal_test.go +++ b/src/pkg/github/automerge/automerge_adoption_readopt_journal_test.go @@ -144,6 +144,27 @@ func TestAdoptionReadoptAfterClosedCopyIsNotJournalReplayed(t *testing.T) { // The journal replays the PR-create claim and hands back a copy that is // closed: the adoption claims a fresh copy rather than reading the replay // as a failure and clearing the adoption. +func TestAdoptionReadoptReplaysBaseMergeKeyedByPriorCopy(t *testing.T) { + h, jb, done, adopted := adoptAt074Journaled(t) + defer done() + h.adopt.setSuperseder(90, "closed", false) + h.api.reset() + h.clock.advance(adoptCheckInterval) + h.observe(adoptPR(7, "aaa", append(adopted, "needs-rebase")...), "check-failing:unit") + var replay effects.Claim + for _, c := range jb.claims { + if c.Kind == effects.KindBranchPush && c.Inputs["reason"] == "supersede-replay" { + replay = c + } + } + if got := replay.Inputs["prior_copy"]; got != "90" { + t.Fatalf("supersede-replay claim prior_copy = %q, want 90 (claims %v)", got, jb.claims) + } + if len(h.adopt.merges) != 1 || h.adopt.merges[0] != "hive/adopt-7<-v5" { + t.Fatalf("base not merged on re-adoption: %v", h.adopt.merges) + } +} + func TestAdoptionJournalReplayOfClosedCopyOpensFreshCopy(t *testing.T) { h, jb, done, adopted := adoptAt074Journaled(t) defer done() diff --git a/src/pkg/github/automerge/automerge_contributor_adopt.go b/src/pkg/github/automerge/automerge_contributor_adopt.go index 6773ba9c40..bd89d74d2b 100644 --- a/src/pkg/github/automerge/automerge_contributor_adopt.go +++ b/src/pkg/github/automerge/automerge_contributor_adopt.go @@ -807,12 +807,7 @@ func (c *Engine) supersedeAdoptedPR(ctx context.Context, store *stagelabels.Stor if stored, ok := store.Get(key); ok && stored.AdoptedBy > 0 && stored.AdoptOrphanedBy == stored.AdoptedBy { priorCopy = stored.AdoptedBy } - claimInputs := func(prior int, inputs map[string]string) map[string]string { - if prior > 0 { - inputs["prior_copy"] = strconv.Itoa(prior) - } - return inputs - } + claimInputs := priorCopyInputs // resignedTip stays "" when the branch falls back to the unsigned // contributor head; the body then keeps the manual DCO repair steps. var resignedTip string @@ -860,7 +855,7 @@ func (c *Engine) supersedeAdoptedPR(ctx context.Context, store *stagelabels.Stor // The head is red on a conflict: opening the copy as-is would just // move the conflict. Replay the base onto the hive branch first; a // git conflict is terminal for this head (one note, 07x reason). - conflicted, n, err := c.replaySupersedeOntoBase(ctx, store, key, obs, branch, now) + conflicted, n, err := c.replaySupersedeOntoBase(ctx, store, key, obs, branch, priorCopy, now) if err != nil || conflicted { return n, err } @@ -976,12 +971,12 @@ func AdoptionSupersedeConflictComment(obs stageObservation, branch string, files // recorded as supersede-conflict so the request is consumed and the 07x // reason names it, and one note is posted. Other API failures return the // error with the attempt already recorded by the caller. -func (c *Engine) replaySupersedeOntoBase(ctx context.Context, store *stagelabels.Store, key string, obs stageObservation, branch string, now time.Time) (conflicted bool, comments int, err error) { +func (c *Engine) replaySupersedeOntoBase(ctx context.Context, store *stagelabels.Store, key string, obs stageObservation, branch string, priorCopy int, now time.Time) (conflicted bool, comments int, err error) { owner, repo, number := obs.Owner, obs.Repo, obs.Number var status int _, err = effects.Execute(ctx, c.mutation, effects.Claim{ Repo: owner + "/" + repo, Kind: effects.KindBranchPush, Target: branch, Actor: "stage_labels", - Inputs: map[string]string{"pr": strconv.Itoa(number), "head_sha": obs.HeadSHA, "base": obs.BaseRef, "reason": "supersede-replay"}, + Inputs: priorCopyInputs(priorCopy, map[string]string{"pr": strconv.Itoa(number), "head_sha": obs.HeadSHA, "base": obs.BaseRef, "reason": "supersede-replay"}), }, func(ctx context.Context) (effects.Result, error) { commit, resp, apiErr := c.gh.Repositories.Merge(ctx, owner, repo, &gh.RepositoryMergeRequest{ Base: gh.Ptr(branch), @@ -1018,6 +1013,15 @@ func (c *Engine) replaySupersedeOntoBase(ctx context.Context, store *stagelabels return true, 1, nil } +// priorCopyInputs keys a claim by the closed copy it follows, so a +// re-adoption is not answered by the first adoption's journal entry. +func priorCopyInputs(prior int, inputs map[string]string) map[string]string { + if prior > 0 { + inputs["prior_copy"] = strconv.Itoa(prior) + } + return inputs +} + // adoptionReplayedPRNumber reads the PR number from a pull_request_create // provenance URL (…/pull/N); 0 when there is none. func adoptionReplayedPRNumber(provenance string) int {