From 49a7da888f38c7358a95170f21e2886aa31a8ccd Mon Sep 17 00:00:00 2001 From: Danathar Date: Thu, 5 Nov 2026 16:36:29 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix(adoption):=20refuse=20a?= =?UTF-8?q?=20fixer=20push=20that=20undoes=20the=20adopted=20PR's=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit projectbluefin/utah#1091: the adopted fixer re-added the 25 triage entries the PR removed (a75a567), leaving a docs-only diff, and announced "sweep will merge when green". - automerge: each hive push on an in-place adoption is checked before the head is taken; if the PR's three-dot diff keeps less than half of the lines it changed, park 085 (adoption-fixer-reverts-pr) with one note and refuse the head in the contributor lane; unchecked heads wait (contributor-lane:adoption-intent-pending). - relay: an awaiting-ci note on an unchecked or refused adopted head no longer promises a merge. - dashboard caption/decision text; scanner policy tells the fixer to park instead of pushing such a commit. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar --- changelog.d/fixed-adopted-fixer-reverts-pr.md | 1 + .../stage-labels.md | 15 +- ...age_tracker_adoption_fixer_reverts_test.go | 29 +++ src/pkg/dashboard/stage_tracker_caption.go | 2 + .../dashboard/stage_tracker_decision_pr.go | 2 + .../automerge/automerge_adoption_intent.go | 177 ++++++++++++++ .../automerge_adoption_intent_test.go | 230 ++++++++++++++++++ .../automerge/automerge_contributor_adopt.go | 8 +- .../automerge_contributor_adopt_test.go | 9 +- ...utomerge_contributor_adopted_merge_test.go | 22 ++ .../automerge/automerge_contributor_lane.go | 5 + .../issue_request_awaiting_ci_intent_test.go | 61 +++++ src/pkg/github/issue_request_status_notes.go | 41 ++++ src/pkg/github/issue_request_watcher.go | 1 + .../policies/defaults/scanner-automerge.md | 2 +- src/pkg/stagelabels/store.go | 8 + src/policies/scanner-automerge.md | 2 +- 17 files changed, 606 insertions(+), 9 deletions(-) create mode 100644 changelog.d/fixed-adopted-fixer-reverts-pr.md create mode 100644 src/pkg/dashboard/stage_tracker_adoption_fixer_reverts_test.go create mode 100644 src/pkg/github/automerge/automerge_adoption_intent.go create mode 100644 src/pkg/github/automerge/automerge_adoption_intent_test.go create mode 100644 src/pkg/github/issue_request_awaiting_ci_intent_test.go diff --git a/changelog.d/fixed-adopted-fixer-reverts-pr.md b/changelog.d/fixed-adopted-fixer-reverts-pr.md new file mode 100644 index 0000000000..8b992fdc39 --- /dev/null +++ b/changelog.d/fixed-adopted-fixer-reverts-pr.md @@ -0,0 +1 @@ +- The hive no longer merges an adopted PR after its own fixer undid the PR's change. On projectbluefin/utah#1091 the adopted fixer made CI pass by re-adding the 25 `baselines/triage.toml` entries the PR removed, leaving a docs-only diff, then announced "sweep will merge when green". Each hive push on an in-place adoption is now checked: if the PR's diff against its base keeps less than half of the lines it changed before the push, the push is refused, the PR goes to `stage/085-needs-decision` (`adoption-fixer-reverts-pr`) with a "Fixing CI would undo this PR's change" note, and the contributor lane will not merge that head. Until the check passes, the lane holds the head (`contributor-lane:adoption-intent-pending`), and an agent's "sweep will merge when green" note on it is rewritten to say the check comes first. The scanner policy tells the fixer to park instead of pushing such a commit. diff --git a/src/docs/labels-and-control-signals/stage-labels.md b/src/docs/labels-and-control-signals/stage-labels.md index 7c70b15b32..15738505a8 100644 --- a/src/docs/labels-and-control-signals/stage-labels.md +++ b/src/docs/labels-and-control-signals/stage-labels.md @@ -1038,7 +1038,20 @@ When a contributor-agent PR goes red the hive does not just relabel it (a human- admits it under the hive's own authority (`contributor-lane:adopted-by-hive`, `governor.labels.stage.adoption.auto_merge`, default `true`) without the original author's trust tier, so 074 moves - to 095/097 and merges instead of parking on a maintainer `/lgtm`. A later head keeps that ownership + to 095/097 and merges instead of parking on a maintainer `/lgtm`. + Each hive push is first checked against the PR's own change + (`automerge_adoption_intent.go`): the PR's diff against its base + (three-dot, so a merge of the base is not counted) must still carry at + least half of the lines it changed before the push. A push that undoes + more is refused: the PR goes to `stage/085-needs-decision` with reason + `adoption-fixer-reverts-pr` and one "Fixing CI would undo this PR's + change" note, the contributor lane will not merge that head, and the + next push re-checks (projectbluefin/utah#1091: the fixer re-added the 25 + entries the PR removed). Until the check has passed, the lane refuses + the head as `contributor-lane:adoption-intent-pending` and the relay + rewrites an agent's `hive/awaiting-ci: … sweep will merge when green` + note on it to say the check comes first. A diff of 300 files or more is + not judged. A later head keeps that ownership only when the commit's GitHub-linked author/committer is the App bot (the stage store remembers SHAs that already passed that check; it is not a separate evidence source) diff --git a/src/pkg/dashboard/stage_tracker_adoption_fixer_reverts_test.go b/src/pkg/dashboard/stage_tracker_adoption_fixer_reverts_test.go new file mode 100644 index 0000000000..6c2bf4b997 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_adoption_fixer_reverts_test.go @@ -0,0 +1,29 @@ +package dashboard + +import ( + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// projectbluefin/utah#1091: an adopted PR whose hive push undid its change +// reads as a person's decision with that reason, not as the hive fixing it. +func TestStageTrackerAdoptionFixerRevertsSaysWhy(t *testing.T) { + now := time.Date(2026, 11, 3, 21, 15, 0, 0, time.UTC) + s, store, status, key := orphanTrackerFixture(t, now, stagelabels.NeedsDecision, stagelabels.LaneReasonAdoptionFixerReverts, []string{"stage/085-needs-decision"}) + store.MarkAdoptedInPlace(key, "bc3a6ea", "contributor-offline", now.Add(-time.Hour)) + store.MarkAdoptionEscalated(key, "bc3a6ea", stagelabels.LaneReasonAdoptionFixerReverts) + + it := trackerItem(t, s.buildStageTracker(status, store, now), "pr", 14947) + if !strings.Contains(it.Caption, "fixing CI would undo this PR's change") { + t.Fatalf("caption = %q", it.Caption) + } + if it.DecisionNeeded == nil || !strings.Contains(it.DecisionNeeded.Question, "undoes most of the PR's own change") { + t.Fatalf("decision_needed = %+v", it.DecisionNeeded) + } + if got := humanizeStageReason(stagelabels.LaneReasonAdoptionFixerReverts); !strings.Contains(got, "undo this PR's change") { + t.Fatalf("humanizeStageReason = %q", got) + } +} diff --git a/src/pkg/dashboard/stage_tracker_caption.go b/src/pkg/dashboard/stage_tracker_caption.go index 33b4751b07..aeb6eff50c 100644 --- a/src/pkg/dashboard/stage_tracker_caption.go +++ b/src/pkg/dashboard/stage_tracker_caption.go @@ -354,6 +354,8 @@ func humanizeStageReason(reason string) string { return "the hive's copies of this PR were closed without merging twice within an hour" case stagelabels.LaneReasonAdoptionCopyFailed: return "the hive's copy of this PR failed and this PR was reopened" + case stagelabels.LaneReasonAdoptionFixerReverts: + return "fixing CI would undo this PR's change: the hive's push removed most of what the PR changes" case "held": return "held by a hold label" case "label:needs-rebase": diff --git a/src/pkg/dashboard/stage_tracker_decision_pr.go b/src/pkg/dashboard/stage_tracker_decision_pr.go index 5fc5fbc303..e8cb47c257 100644 --- a/src/pkg/dashboard/stage_tracker_decision_pr.go +++ b/src/pkg/dashboard/stage_tracker_decision_pr.go @@ -113,6 +113,8 @@ func decisionForPR(it StageTrackerItem, verdict *review.Aggregate, sentinelLabel d.Question = "The hive's copies of this PR were closed without merging twice within an hour, so the hive stopped opening copies. Reopen the last copy (#" + strconv.Itoa(it.AdoptedBy) + "), give direction, or close it?" case rebaseFailedTwice: d.Question = "The hive adopted this PR but its fixer could not resolve the conflicts with the base in two attempts. Adopt the commits into a fresh branch, give direction, or close it as superseded?" + case lower == stagelabels.LaneReasonAdoptionFixerReverts: + d.Question = "The hive adopted this PR, but the commit it pushed to fix CI undoes most of the PR's own change, so the hive will not merge it. Wait for what the PR depends on, revert the hive's commit, give direction, or close it?" case lower == stagelabels.LaneReasonAdoptionCopyFailed: d.Question = "The hive's copy of this PR (#" + strconv.Itoa(it.AdoptedBy) + ") failed, so this PR was reopened. Ask the hive to supersede it again, give direction, or close it?" case adoptionStalled: diff --git a/src/pkg/github/automerge/automerge_adoption_intent.go b/src/pkg/github/automerge/automerge_adoption_intent.go new file mode 100644 index 0000000000..29759ef571 --- /dev/null +++ b/src/pkg/github/automerge/automerge_adoption_intent.go @@ -0,0 +1,177 @@ +package automerge + +import ( + "context" + "fmt" + "strings" + + gh "github.com/google/go-github/v72/github" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// Intent check for a hive push on an in-place adopted PR +// (projectbluefin/utah#1091). The adopted fixer is there to get the PR's own +// change merged. On utah#1091 it made CI green by re-adding the 25 +// baselines/triage.toml entries the PR existed to remove, leaving a docs-only +// diff, and the PR was one green run from merging. Each hive push is checked +// before the head is taken as the hive's: the PR's net diff against its base +// must keep at least half of the lines it changed before the push. + +// adoptionIntentMaxFiles is the compare page GitHub returns at most; a diff +// that fills it is not judged (its tail is unknown), and the push stands. +const adoptionIntentMaxFiles = 300 + +// adoptionIntent is one push's verdict: Own is how many changed lines the PR +// carried before the push, Kept how many of them its diff still carries. +type adoptionIntent struct { + Own, Kept int + // Unjudged is set when the diff could not be judged (too large). + Unjudged bool +} + +// Reverts reports whether the push undid most of the PR's own change. +func (a adoptionIntent) Reverts() bool { + return !a.Unjudged && a.Own > 0 && a.Kept*2 < a.Own +} + +// prChangeUnits is the PR's change as a multiset: one unit per added or +// removed line of each file's patch ("path\x00+text"). A file GitHub sends +// without a patch (binary, too large) counts as one unit for its status. +func prChangeUnits(files []*gh.CommitFile) map[string]int { + units := map[string]int{} + for _, f := range files { + name := f.GetFilename() + patch := f.GetPatch() + if patch == "" { + units[name+"\x00file:"+f.GetStatus()]++ + continue + } + for _, line := range strings.Split(patch, "\n") { + if line == "" || strings.HasPrefix(line, "+++") || strings.HasPrefix(line, "---") { + continue + } + if line[0] == '+' || line[0] == '-' { + units[name+"\x00"+line[:1]+strings.TrimSpace(line[1:])]++ + } + } + } + return units +} + +// judgeAdoptionIntent compares the PR's change before the push with its +// change after. +func judgeAdoptionIntent(before, after []*gh.CommitFile) adoptionIntent { + if len(before) >= adoptionIntentMaxFiles || len(after) >= adoptionIntentMaxFiles { + return adoptionIntent{Unjudged: true} + } + own, now := prChangeUnits(before), prChangeUnits(after) + var out adoptionIntent + for unit, n := range own { + out.Own += n + out.Kept += min(n, now[unit]) + } + return out +} + +// adoptedPushIntent reads the PR's diff against its base (three-dot, so a +// merge of the base into the branch is not counted) at the head before the +// push and at the pushed head. +func (c *Engine) adoptedPushIntent(ctx context.Context, obs stageObservation, before string) (adoptionIntent, error) { + if obs.BaseRef == "" || before == "" || obs.HeadSHA == "" { + return adoptionIntent{Unjudged: true}, nil + } + files := func(head string) ([]*gh.CommitFile, error) { + cmp, _, err := c.gh.Repositories.CompareCommits(ctx, obs.Owner, obs.Repo, obs.BaseRef, head, &gh.ListOptions{PerPage: adoptionIntentMaxFiles}) + if err != nil { + return nil, err + } + return cmp.Files, nil + } + was, err := files(before) + if err != nil { + return adoptionIntent{}, err + } + now, err := files(obs.HeadSHA) + if err != nil { + return adoptionIntent{}, err + } + return judgeAdoptionIntent(was, now), nil +} + +// checkAdoptedPushIntent runs when the hive advanced an in-place adopted PR +// from prev.AdoptedHead to obs.HeadSHA. A push that keeps the PR's change is +// taken as the hive's head (MarkAdoptedHead). One that undoes it is +// escalated to 085 with LaneReasonAdoptionFixerReverts: the contributor lane +// refuses to merge that head and the author or a maintainer is told why, +// once; the head is taken only after the note posts, so a failed post is +// re-checked and retried next sweep. An unreadable diff leaves the head +// unmarked, so no merge admits it, and is re-read next sweep. +func (c *Engine) checkAdoptedPushIntent(ctx context.Context, store *stagelabels.Store, key string, obs stageObservation, prev stagelabels.Record) (int, error) { + intent, err := c.adoptedPushIntent(ctx, obs, prev.AdoptedHead) + if err != nil { + c.warn("stage labels: adopted PR advanced by the hive; diff unreadable, intent check deferred", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA, "error", err) + return 0, nil + } + if !intent.Reverts() { + if intent.Unjudged { + c.info("stage labels: adopted PR advanced by the hive; diff too large to judge intent", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA) + } + store.MarkAdoptedHead(key, obs.HeadSHA) + return 0, nil + } + reason := stagelabels.LaneReasonAdoptionFixerReverts + store.MarkAdoptionEscalated(key, obs.HeadSHA, reason) + c.warn("stage labels: hive push undoes the adopted PR's own change; refusing it and escalating to needs-decision", "repo", obs.Display, "pr", obs.Number, "before", prev.AdoptedHead, "head", obs.HeadSHA, "own_lines", intent.Own, "kept_lines", intent.Kept) + n := 0 + if rec, _ := store.Get(key); !rec.AdoptionEscalationNoted(obs.HeadSHA, reason) { + n, err = c.postAdoptionEscalationNote(ctx, store, key, obs, reason, AdoptionFixerRevertsComment(obs, prev.AdoptedHead, intent), "stage labels: fixer-reverts note failed") + if err != nil { + return n, err + } + } + store.MarkAdoptedHead(key, obs.HeadSHA) + return n, nil +} + +// AdoptionFixerRevertsComment is the one note on a head whose hive push +// undid the PR's change. +func AdoptionFixerRevertsComment(obs stageObservation, before string, intent adoptionIntent) string { + return fmt.Sprintf("**Fixing CI would undo this PR's change.** The hive adopted this PR (`%s`) and pushed `%s` to fix it, but that push leaves %d of the %d lines this PR changed at `%s`, so the PR would no longer do what it set out to do. The hive will not merge `%s`.\n\n"+ + "**Ask (author or maintainer):** decide what this PR should do: wait for what it depends on, revert the hive's commit and fix the cause another way, or close it. A new push re-checks.\n\n"+ + "Moving to `%s` so a person sees it.", + stagelabels.AdoptedByHive.Label(), shortSHA(obs.HeadSHA), intent.Kept, intent.Own, shortSHA(before), shortSHA(obs.HeadSHA), stagelabels.NeedsDecision.Label()) +} + +// adoptionIntentRefused reports whether the stage store refuses headSHA as +// the hive's adopted head: its push undid the PR's change, or the hive +// pushed it and the intent check has not passed yet. +func adoptionIntentRefused(rec stagelabels.Record, headSHA string) string { + if headSHA == "" || !rec.AdoptedInPlace() { + return "" + } + if rec.AdoptionEscalated(headSHA) && rec.AdoptEscalatedReason == stagelabels.LaneReasonAdoptionFixerReverts { + return stagelabels.LaneReasonAdoptionFixerReverts + } + if rec.HivePushedHead(headSHA) && rec.AdoptedHead != headSHA { + return contributorLaneReasonAdoptionIntentPending + } + return "" +} + +// contributorLaneReasonAdoptionIntentPending: the hive pushed this head on +// an adopted PR and has not yet checked it keeps the PR's change. +const contributorLaneReasonAdoptionIntentPending = "contributor-lane:adoption-intent-pending" + +// adoptionIntentGate is the contributor lane's refusal for such a head, +// whatever else would admit it. +func (c *Engine) adoptionIntentGate(owner, repo string, number int, headSHA string) string { + if c == nil { + return "" + } + rec, ok := c.stageStoreOrShared().Get(stageKey(owner, repo, number)) + if !ok { + return "" + } + return adoptionIntentRefused(rec, headSHA) +} diff --git a/src/pkg/github/automerge/automerge_adoption_intent_test.go b/src/pkg/github/automerge/automerge_adoption_intent_test.go new file mode 100644 index 0000000000..007f162ad3 --- /dev/null +++ b/src/pkg/github/automerge/automerge_adoption_intent_test.go @@ -0,0 +1,230 @@ +package automerge + +import ( + "strings" + "testing" + "time" + + gh "github.com/google/go-github/v72/github" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// projectbluefin/utah#1091: the PR removes 25 resolved entries from +// baselines/triage.toml and adds 10 lines of docs. The adopted fixer's +// a75a567 put all 25 entries back, leaving a docs-only diff. +func utah1091Files(withTriage bool, extraFix string) []map[string]string { + docs := map[string]string{"filename": "docs/skills/package-contract/references/factory-consumption.md", "status": "modified", + "patch": "@@ -1,0 +1,10 @@\n" + strings.Repeat("+factory consumption note\n", 9) + "+see package-contract.md"} + files := []map[string]string{docs} + if withTriage { + var b strings.Builder + b.WriteString("@@ -1,25 +0,0 @@\n") + for i := 0; i < 25; i++ { + b.WriteString("-[[missing]] package = \"pkg-" + string(rune('a'+i)) + "\"\n") + } + files = append(files, map[string]string{"filename": "baselines/triage.toml", "status": "modified", "patch": strings.TrimSuffix(b.String(), "\n")}) + } + if extraFix != "" { + files = append(files, map[string]string{"filename": "tests/triage_test.py", "status": "modified", "patch": "@@ -3,1 +3,1 @@\n-" + extraFix + "_old\n+" + extraFix}) + } + return files +} + +func commitFiles(in []map[string]string) []*gh.CommitFile { + out := make([]*gh.CommitFile, 0, len(in)) + for _, f := range in { + out = append(out, &gh.CommitFile{Filename: gh.Ptr(f["filename"]), Status: gh.Ptr(f["status"]), Patch: gh.Ptr(f["patch"])}) + } + return out +} + +func TestJudgeAdoptionIntent(t *testing.T) { + before := commitFiles(utah1091Files(true, "")) + for _, tc := range []struct { + name string + after []*gh.CommitFile + reverts bool + kept int + }{ + {name: "utah#1091: the 25 removals put back, docs only", after: commitFiles(utah1091Files(false, "")), reverts: true, kept: 10}, + {name: "a normal fix keeps the PR's change and adds its own", after: commitFiles(utah1091Files(true, "assert_missing")), reverts: false, kept: 35}, + {name: "unchanged diff (a base merge)", after: before, reverts: false, kept: 35}, + {name: "everything reverted", after: nil, reverts: true, kept: 0}, + } { + t.Run(tc.name, func(t *testing.T) { + got := judgeAdoptionIntent(before, tc.after) + if got.Reverts() != tc.reverts || got.Own != 35 || got.Kept != tc.kept { + t.Fatalf("intent = %+v reverts=%v, want own 35 kept %d reverts %v", got, got.Reverts(), tc.kept, tc.reverts) + } + }) + } + // Exactly half kept is not "most reverted". + half := judgeAdoptionIntent(commitFiles([]map[string]string{{"filename": "a", "patch": "+x\n+y"}}), commitFiles([]map[string]string{{"filename": "a", "patch": "+x"}})) + if half.Reverts() { + t.Fatalf("half kept read as reverted: %+v", half) + } + // A file without a patch (binary) is one unit for its status. + bin := judgeAdoptionIntent(commitFiles([]map[string]string{{"filename": "logo.png", "status": "added"}}), nil) + if bin.Own != 1 || !bin.Reverts() { + t.Fatalf("binary unit: %+v", bin) + } + // A diff that fills GitHub's compare page is not judged. + many := make([]*gh.CommitFile, adoptionIntentMaxFiles) + for i := range many { + many[i] = &gh.CommitFile{Filename: gh.Ptr("f" + string(rune(i))), Patch: gh.Ptr("+x")} + } + if got := judgeAdoptionIntent(many, nil); !got.Unjudged || got.Reverts() { + t.Fatalf("oversized diff judged: %+v", got) + } +} + +// adoptUtah1091InPlace adopts PR #7 in place at head aaa (the utah#1091 diff). +func adoptUtah1091InPlace(t *testing.T) (*adoptHarness, func(), []string) { + t.Helper() + p := adoptPolicy() + p.AdoptInPlace = true + h, done := newAdoptHarness(t, ContributorNudgeOutcome{Mode: "comment"}, p) + h.adopt.allowMaintainerEdits(7, true) + h.adopt.comparePatches = map[string][]map[string]string{"aaa": utah1091Files(true, "")} + h.observe(adoptPR(7, "aaa"), "check-failing:unit") + labels := []string{"stage/072-returned-to-contributor", "role/contributor", "author/clanker"} + h.clock.advance(30 * time.Minute) + h.observe(adoptPR(7, "aaa", labels...), "check-failing:unit") + h.observe(adoptPR(7, "aaa", labels...), "check-failing:unit") + rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7)) + if !rec.AdoptedInPlace() || rec.AdoptedHead != "aaa" { + done() + t.Fatalf("not adopted in place: %+v", rec) + } + return h, done, []string{"stage/074-adopted-by-hive", "role/contributor", "author/clanker"} +} + +func fixerRevertsComments(api *stageAPI) []string { + var out []string + for _, c := range api.comments { + if strings.Contains(c, "Fixing CI would undo this PR's change") { + out = append(out, c) + } + } + return out +} + +// The fixer's push re-adds what the PR removed: refused, parked at 085 with +// the reason, one note, and the contributor lane will not merge that head. +func TestAdoptedFixerPushThatRevertsPRIsRefused(t *testing.T) { + h, done, adopted := adoptUtah1091InPlace(t) + defer done() + h.adopt.comparePatches["a75a567"] = utah1091Files(false, "") + h.adopt.setCommitAuthor("a75a567", testHiveAppBotLogin) + h.api.reset() + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "a75a567", adopted...), "ci-pending") + + notes := fixerRevertsComments(h.api) + if len(notes) != 1 || !strings.Contains(notes[0], "leaves 10 of the 35 lines") || !strings.Contains(notes[0], "will not merge `a75a567`") { + t.Fatalf("notes = %v (all comments %v)", notes, h.api.comments) + } + if added := strings.Join(h.addedLabels(), ","); !strings.Contains(added, "stage/085-needs-decision") { + t.Fatalf("added = %v, want the 085 park", h.api.added) + } + rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7)) + if !rec.AdoptionEscalated("a75a567") || rec.AdoptEscalatedReason != stagelabels.LaneReasonAdoptionFixerReverts || rec.AdoptedHead != "a75a567" { + t.Fatalf("record = %+v", rec) + } + if got := h.e.adoptionIntentGate("acme", "widget", 7, "a75a567"); got != stagelabels.LaneReasonAdoptionFixerReverts { + t.Fatalf("merge gate = %q, want the refusal", got) + } + + // Next sweep on the same head: the park holds, the note is not repeated. + h.api.reset() + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "a75a567", "stage/085-needs-decision", "role/contributor", "author/clanker"), "ci-pending") + if len(fixerRevertsComments(h.api)) != 0 || strings.Contains(strings.Join(h.addedLabels(), ","), "stage/074") { + t.Fatalf("second sweep: comments=%v added=%v", h.api.comments, h.api.added) + } +} + +// A fix that keeps the PR's change is the hive's head as before. +func TestAdoptedFixerPushThatKeepsPRIsAllowed(t *testing.T) { + h, done, adopted := adoptUtah1091InPlace(t) + defer done() + h.adopt.comparePatches["bbb"] = utah1091Files(true, "assert_missing") + h.adopt.setCommitAuthor("bbb", testHiveAppBotLogin) + h.api.reset() + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "bbb", adopted...), "check-failing:unit") + if h.api.writes() != 0 { + t.Fatalf("writes after a good fix: added=%v removed=%v comments=%v", h.api.added, h.api.removed, h.api.comments) + } + rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7)) + if rec.AdoptedHead != "bbb" || rec.AdoptionEscalated("bbb") { + t.Fatalf("record = %+v", rec) + } + if got := h.e.adoptionIntentGate("acme", "widget", 7, "bbb"); got != "" { + t.Fatalf("merge gate = %q, want none", got) + } +} + +// An unreadable diff leaves the hive's head unconfirmed: no merge until the +// check passes on a later sweep. +func TestAdoptedFixerPushIntentUnreadableHoldsMerge(t *testing.T) { + h, done, adopted := adoptUtah1091InPlace(t) + defer done() + h.adopt.setCommitAuthor("bbb", testHiveAppBotLogin) + h.adopt.failCompare = true + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "bbb", adopted...), "check-failing:unit") + rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7)) + if rec.AdoptedHead != "aaa" || !rec.HivePushedHead("bbb") { + t.Fatalf("record = %+v, want the head unconfirmed with push evidence kept", rec) + } + if got := h.e.adoptionIntentGate("acme", "widget", 7, "bbb"); got != contributorLaneReasonAdoptionIntentPending { + t.Fatalf("merge gate = %q, want pending", got) + } + h.adopt.failCompare = false + h.adopt.comparePatches["bbb"] = utah1091Files(true, "") + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "bbb", adopted...), "check-failing:unit") + if rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7)); rec.AdoptedHead != "bbb" { + t.Fatalf("retry did not confirm the head: %+v", rec) + } + if got := h.e.adoptionIntentGate("acme", "widget", 7, "bbb"); got != "" { + t.Fatalf("merge gate after retry = %q", got) + } +} + +// The push came through the hive's own push record (a fixer committing under +// a bare git identity): the same check applies, and a note already posted on +// the head is not posted again. +func TestAdoptedRecordedHivePushThatRevertsPRIsRefusedOnce(t *testing.T) { + h, done, adopted := adoptUtah1091InPlace(t) + defer done() + key := stageKey("acme", "widget", 7) + h.adopt.comparePatches["a75a567"] = utah1091Files(false, "") + h.adopt.setCommitAuthor("a75a567", "git:scanner") + h.e.stageStoreOrShared().MarkHivePushedHead(key, "a75a567") + h.api.reset() + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "a75a567", adopted...), "ci-pending") + if len(fixerRevertsComments(h.api)) != 1 { + t.Fatalf("comments = %v", h.api.comments) + } + rec, _ := h.e.stageStoreOrShared().Get(key) + if rec.AdoptEscalatedReason != stagelabels.LaneReasonAdoptionFixerReverts || rec.AdoptedHead != "a75a567" { + t.Fatalf("record = %+v", rec) + } + + // The note posted but the head was not taken (a restart in between): + // the re-check does not post it again. + h.e.stageStoreOrShared().MarkAdoptedHead(key, "aaa") + h.api.reset() + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "a75a567", "stage/085-needs-decision", "role/contributor", "author/clanker"), "ci-pending") + if n := len(fixerRevertsComments(h.api)); n != 0 { + t.Fatalf("note re-posted: %v", h.api.comments) + } + if rec, _ := h.e.stageStoreOrShared().Get(key); rec.AdoptedHead != "a75a567" || rec.AdoptEscalatedReason != stagelabels.LaneReasonAdoptionFixerReverts { + t.Fatalf("record after re-check = %+v", rec) + } +} diff --git a/src/pkg/github/automerge/automerge_contributor_adopt.go b/src/pkg/github/automerge/automerge_contributor_adopt.go index faaf2b3b18..853269e6e7 100644 --- a/src/pkg/github/automerge/automerge_contributor_adopt.go +++ b/src/pkg/github/automerge/automerge_contributor_adopt.go @@ -1977,9 +1977,8 @@ func (c *Engine) settleInPlaceAdoption(ctx context.Context, store *stagelabels.S return 0, nil } if prev.HivePushedHead(obs.HeadSHA) { - store.MarkAdoptedHead(key, obs.HeadSHA) c.info("stage labels: adopted PR advanced by recorded hive push", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA) - return 0, nil + return c.checkAdoptedPushIntent(ctx, store, key, obs, prev) } app := c.transport.AppBotLogin() commit, _, err := c.gh.Repositories.GetCommit(ctx, obs.Owner, obs.Repo, obs.HeadSHA, nil) @@ -1991,9 +1990,8 @@ func (c *Engine) settleInPlaceAdoption(ctx context.Context, store *stagelabels.S } if commitByApp(commit, app) { store.MarkHivePushedHead(key, obs.HeadSHA) - store.MarkAdoptedHead(key, obs.HeadSHA) c.info("stage labels: adopted PR advanced by the hive", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA, "pusher", commitIdentity(commit)) - return 0, nil + return c.checkAdoptedPushIntent(ctx, store, key, obs, prev) } if !policy.AdoptionStrictAttribution { store.MarkAdoptedHead(key, obs.HeadSHA) @@ -2309,7 +2307,7 @@ func (c *Engine) escapeStalledAdoption(ctx context.Context, store *stagelabels.S n, err := c.postAdoptionEscalationNote(ctx, store, key, obs, adoptionWorkflowRefusedReason, AdoptionWorkflowRefusedComment(obs), "stage labels: workflow-path refusal note failed") return esc, n, err } - if rec.AdoptEscalatedReason == stagelabels.LaneReasonAdoptionChildClosedTwice || rec.AdoptEscalatedReason == stagelabels.LaneReasonAdoptionCopyFailed { + if rec.AdoptEscalatedReason == stagelabels.LaneReasonAdoptionChildClosedTwice || rec.AdoptEscalatedReason == stagelabels.LaneReasonAdoptionCopyFailed || rec.AdoptEscalatedReason == stagelabels.LaneReasonAdoptionFixerReverts { return adoptionEscape{Escalated: true, Reason: rec.AdoptEscalatedReason}, 0, nil } stalled := "" diff --git a/src/pkg/github/automerge/automerge_contributor_adopt_test.go b/src/pkg/github/automerge/automerge_contributor_adopt_test.go index 46afc6500f..309d6a87a5 100644 --- a/src/pkg/github/automerge/automerge_contributor_adopt_test.go +++ b/src/pkg/github/automerge/automerge_contributor_adopt_test.go @@ -36,7 +36,11 @@ type adoptAPI struct { // compareFiles are the base-side files served by GET compare/head...base; // failCompare makes it answer 500. compareFiles []string - failCompare bool + // comparePatches, when set for a head, are the files (filename, status, + // patch) GET compare/... serves for it: the PR's diff the + // intent check reads (automerge_adoption_intent.go). + comparePatches map[string][]map[string]string + failCompare bool // prFiles are the files served by GET pulls/n/files (the adopted PR's // diff); failPRFiles makes it answer 500. prFiles []map[string]any @@ -273,6 +277,9 @@ func (a *adoptAPI) handle(w http.ResponseWriter, r *http.Request) bool { for _, f := range a.compareFiles { files = append(files, map[string]string{"filename": f}) } + if _, head, ok := strings.Cut(strings.TrimPrefix(path, "/repos/acme/widget/compare/"), "..."); ok && a.comparePatches[head] != nil { + files = a.comparePatches[head] + } payload := map[string]any{"files": files, "behind_by": a.compareBehind} if a.compareBase != "" { payload["base_commit"] = map[string]any{"sha": a.compareBase} diff --git a/src/pkg/github/automerge/automerge_contributor_adopted_merge_test.go b/src/pkg/github/automerge/automerge_contributor_adopted_merge_test.go index 701f6035a8..dd86236ae6 100644 --- a/src/pkg/github/automerge/automerge_contributor_adopted_merge_test.go +++ b/src/pkg/github/automerge/automerge_contributor_adopted_merge_test.go @@ -113,6 +113,28 @@ func TestTrySweepContributorLanePRAdoptedByHiveAdmission(t *testing.T) { autoMerge: true, wantReason: contributorLaneReasonAuthorAssociation, }, + { + // projectbluefin/utah#1091: the fixer's push undid the PR; even + // an author the lane trusts does not get that head merged. + name: "hive push that undoes the PR is refused for any author", + seed: func(store *stagelabels.Store, key string, now time.Time) { + inPlace(head)(store, key, now) + store.MarkAdoptionEscalated(key, head, stagelabels.LaneReasonAdoptionFixerReverts) + }, + mutate: func(fx *contributorLaneFixture) {}, + autoMerge: true, + wantReason: stagelabels.LaneReasonAdoptionFixerReverts, + }, + { + name: "hive push not yet intent-checked waits", + seed: func(store *stagelabels.Store, key string, now time.Time) { + inPlace(oldHead)(store, key, now) + store.MarkHivePushedHead(key, head) + }, + mutate: func(fx *contributorLaneFixture) {}, + autoMerge: true, + wantReason: contributorLaneReasonAdoptionIntentPending, + }, { name: "no stage record falls back to author gates", mutate: untrusted, diff --git a/src/pkg/github/automerge/automerge_contributor_lane.go b/src/pkg/github/automerge/automerge_contributor_lane.go index dd2ad6f810..84522a9354 100644 --- a/src/pkg/github/automerge/automerge_contributor_lane.go +++ b/src/pkg/github/automerge/automerge_contributor_lane.go @@ -1405,6 +1405,11 @@ func (c *Engine) evaluateContributorLanePR(ctx context.Context, displayRepo, own if reason := c.closingContradictionGate(owner, repo, pr); reason != "" { return contributorLaneEval{pr: pr}, reason, nil } + // A hive push on an adopted PR merges only once it is known to keep the + // PR's own change (automerge_adoption_intent.go). + if reason := c.adoptionIntentGate(owner, repo, number, pr.GetHead().GetSHA()); reason != "" { + return contributorLaneEval{pr: pr}, reason, nil + } author := hgithub.SafeGetLogin(pr.GetUser()) headSHA := pr.GetHead().GetSHA() eval := contributorLaneEval{pr: pr, author: author, headSHA: headSHA} diff --git a/src/pkg/github/issue_request_awaiting_ci_intent_test.go b/src/pkg/github/issue_request_awaiting_ci_intent_test.go new file mode 100644 index 0000000000..52fb6aeab3 --- /dev/null +++ b/src/pkg/github/issue_request_awaiting_ci_intent_test.go @@ -0,0 +1,61 @@ +package github + +import ( + "context" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// projectbluefin/utah#1091: 22 s after the adopted fixer's push the relay +// posted "hive/awaiting-ci: CI pending — sweep will merge when green." for a +// head that undid the PR. On an in-place adopted PR the note promises a +// merge only once the head passed the intent check. +func TestAwaitingCINoteOnAdoptedPRWaitsForIntentCheck(t *testing.T) { + const agentNote = "hive/awaiting-ci: CI pending — sweep will merge when green." + head := "a75a567" + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + if r.Method == http.MethodGet && strings.HasSuffix(r.URL.Path, "/pulls/1091") { + _, _ = w.Write([]byte(`{"number":1091,"head":{"sha":"` + head + `"}}`)) + return + } + w.WriteHeader(http.StatusNotFound) + })) + defer srv.Close() + c := testClient(t, srv.URL) + + store := stagelabels.Shared() + key := stagelabels.Key("o/utah", 1091) + t.Cleanup(func() { store.Forget(key) }) + store.Observe(key, stagelabels.AdoptedByHive, "adopted") + now := time.Date(2026, 11, 3, 21, 0, 0, 0, time.UTC) + store.MarkAdoptedInPlace(key, "7e9dfd7", "contributor-offline", now) + + ctx := context.Background() + if got := c.adoptedAwaitingCINote(ctx, "o/utah", 1091, agentNote); got != awaitingCIIntentPendingNote { + t.Fatalf("unchecked hive head: %q", got) + } + store.MarkAdoptionEscalated(key, head, stagelabels.LaneReasonAdoptionFixerReverts) + if got := c.adoptedAwaitingCINote(ctx, "o/utah", 1091, agentNote); got != awaitingCIIntentRefusedNote { + t.Fatalf("refused head: %q", got) + } + store.ClearAdoptionEscalation(key) + store.MarkAdoptedHead(key, head) + if got := c.adoptedAwaitingCINote(ctx, "o/utah", 1091, agentNote); got != agentNote { + t.Fatalf("checked head: %q", got) + } + if got := c.adoptedAwaitingCINote(ctx, "o/utah", 1091, "Parking on stage/045-needs-decision: why"); !strings.HasPrefix(got, "Parking on") { + t.Fatalf("another note rewritten: %q", got) + } + if got := c.adoptedAwaitingCINote(ctx, "o/utah", 9999, agentNote); got != agentNote { + t.Fatalf("not adopted: %q", got) + } + if relayStatusNoteKey(awaitingCIIntentPendingNote) == "" || relayStatusNoteKey(awaitingCIIntentRefusedNote) == "" { + t.Fatal("rewritten notes must stay awaiting-ci status notes") + } +} diff --git a/src/pkg/github/issue_request_status_notes.go b/src/pkg/github/issue_request_status_notes.go index 3e81d51c98..6faa180d71 100644 --- a/src/pkg/github/issue_request_status_notes.go +++ b/src/pkg/github/issue_request_status_notes.go @@ -1,9 +1,11 @@ package github import ( + "context" "strings" "github.com/hivecommons/hive/pkg/prstatus" + "github.com/hivecommons/hive/pkg/stagelabels" ) // Agent status notes the policies tell an agent to leave as a PR/issue @@ -40,3 +42,42 @@ func firstLine(s string) string { } return s } + +// Awaiting-CI notes on an in-place adopted PR whose head the hive itself +// pushed (projectbluefin/utah#1091): "sweep will merge when green" is only +// true once the stage pass has checked that the push keeps the PR's own +// change (automerge checkAdoptedPushIntent). Until then the note says the +// check is pending; after a refusal it says the sweep will not merge. +const ( + awaitingCIIntentPendingNote = "hive/awaiting-ci: CI pending — the hive first checks that this push keeps the PR's own change; the sweep merges only after that check passes." + awaitingCIIntentRefusedNote = "hive/awaiting-ci: CI pending, but the sweep will not merge this head: the hive's push undoes this PR's own change (see the hive's note on this PR)." +) + +// adoptedAwaitingCINote rewrites an awaiting-ci note on an in-place adopted +// PR whose current head the adoption record has not taken yet (its intent +// check is pending) or has refused. Any other body is returned unchanged; an +// unreadable PR keeps the agent's text. +func (c *Client) adoptedAwaitingCINote(ctx context.Context, repo string, number int, body string) string { + if relayStatusNoteKey(body) != prstatus.KeyAgentNotePrefix+agentNoteAwaitingCI { + return body + } + owner, name := c.splitRepo(repo) + rec, ok := stagelabels.Shared().Get(stagelabels.Key(owner+"/"+name, number)) + if !ok || !rec.AdoptedInPlace() { + return body + } + pr, _, err := c.client.PullRequests.Get(ctx, owner, name, number) + if err != nil { + return body + } + head := pr.GetHead().GetSHA() + switch { + case head == "": + return body + case rec.AdoptionEscalated(head) && rec.AdoptEscalatedReason == stagelabels.LaneReasonAdoptionFixerReverts: + return awaitingCIIntentRefusedNote + case head != rec.AdoptedHead && rec.YieldedHead != head: + return awaitingCIIntentPendingNote + } + return body +} diff --git a/src/pkg/github/issue_request_watcher.go b/src/pkg/github/issue_request_watcher.go index 874ac4349f..59962d3b46 100644 --- a/src/pkg/github/issue_request_watcher.go +++ b/src/pkg/github/issue_request_watcher.go @@ -780,6 +780,7 @@ func (c *Client) handleOneIssueRequest(ctx context.Context, path string, nowFn f } else if issueDecisionDowngrade.Active { commentBody = appendHiveDecisionTaken(commentBody, issueDecisionDowngrade.Question) } + commentBody = c.adoptedAwaitingCINote(ctx, req.Repo, req.Number, commentBody) if key := relayStatusNoteKey(commentBody); key != "" && (c.notificationsQuiet() || c.attentionPilot()) { // A one-line state note (awaiting-ci, parking, already fixed) // is a section of the item's status comment in quiet mode or diff --git a/src/pkg/policies/defaults/scanner-automerge.md b/src/pkg/policies/defaults/scanner-automerge.md index e75aeec76b..3cd1ff8f50 100644 --- a/src/pkg/policies/defaults/scanner-automerge.md +++ b/src/pkg/policies/defaults/scanner-automerge.md @@ -16,7 +16,7 @@ You are the **scanner** agent. Your job is to fix bugs and implement enhancement - **Always triage the baseline first** — before repairing or escalating a failed PR check, follow the mandatory shared-baseline procedure below. A broken default branch or the same check failing across sibling PRs is one repository incident; it is never N independent repair targets. - **Finish existing PRs before creating new ones** — PRs in the PR_LIST are unfinished work from previous cycles. Fix their CI failures, resolve merge conflicts, and get them merge-ready BEFORE dispatching agents for new issues. Creating new PRs while old ones rot wastes agent cycles and creates PR sprawl. -- **Never push content to PRs this hive did not author** — for PRs authored by humans or other bots (same-repo or fork), do not push content or fixup commits; post the proposed change as a PR comment or GitHub suggestion and leave the author to apply it. The exceptions are DCO-safe update-branch/base-sync operations that `review.contributor_prs.base_sync: true` authorizes, in-place adopted contributor PRs carrying `stage/074-adopted-by-hive` (Hive owns getting them merged and may push signed fixer commits while the adoption holds), or a hive-owned repair that removes/re-homes a bad commit the hive itself already pushed; `review.fix_human_prs` never authorizes new follow-up commits on ordinary non-App-authored branches because their sign-off will not survive a squash attributed to the PR author. Never change governance or policy text without the author's or a maintainer's consent. +- **Never push content to PRs this hive did not author** — for PRs authored by humans or other bots (same-repo or fork), do not push content or fixup commits; post the proposed change as a PR comment or GitHub suggestion and leave the author to apply it. The exceptions are DCO-safe update-branch/base-sync operations that `review.contributor_prs.base_sync: true` authorizes, in-place adopted contributor PRs carrying `stage/074-adopted-by-hive` (Hive owns getting them merged and may push signed fixer commits while the adoption holds; a fixer commit must keep the PR's own change — if CI can pass only by undoing what the PR changes, for example because it waits on another unmerged PR, do not push: park it with `needs-human` naming that dependency, since the hive refuses an adopted head whose diff keeps less than half of the PR's change), or a hive-owned repair that removes/re-homes a bad commit the hive itself already pushed; `review.fix_human_prs` never authorizes new follow-up commits on ordinary non-App-authored branches because their sign-off will not survive a squash attributed to the PR author. Never change governance or policy text without the author's or a maintainer's consent. - Only work items from the kick message — never run `gh issue list` or `gh pr list` - Always sign commits with DCO: `git commit -s` - Add a `changelog.d/-.md` fragment (repository-root `changelog.d/`, never `src/changelog.d/`) for user-visible `src/` changes before requesting a PR; CI is the sole verdict for missing or malformed fragments. diff --git a/src/pkg/stagelabels/store.go b/src/pkg/stagelabels/store.go index 4b6ed68b08..c022ae1f2e 100644 --- a/src/pkg/stagelabels/store.go +++ b/src/pkg/stagelabels/store.go @@ -2240,6 +2240,14 @@ const AdoptionReopenWindow = 24 * time.Hour // across two heads, or could not be pushed: a person must decide. const LaneReasonAdoptionCopyFailed = "adoption-copy-failed" +// LaneReasonAdoptionFixerReverts is the 085 reason for an in-place adopted +// PR whose hive push undid most of the PR's own change: the net diff against +// the base kept less than half of the lines the PR changed before the push +// (projectbluefin/utah#1091, where the fixer re-added the 25 triage entries +// the PR removed and announced a merge). Fixing CI that way would undo the +// PR, so the author or a maintainer decides. It holds until the head moves. +const LaneReasonAdoptionFixerReverts = "adoption-fixer-reverts-pr" + // MarkSupersededClosedFirst records that the original was closed as soon // as superseding PR `by` existed (close-first supersession). The copy is // still polled; see CloseFirstPollDue. open is true when GitHub refused diff --git a/src/policies/scanner-automerge.md b/src/policies/scanner-automerge.md index e75aeec76b..3cd1ff8f50 100644 --- a/src/policies/scanner-automerge.md +++ b/src/policies/scanner-automerge.md @@ -16,7 +16,7 @@ You are the **scanner** agent. Your job is to fix bugs and implement enhancement - **Always triage the baseline first** — before repairing or escalating a failed PR check, follow the mandatory shared-baseline procedure below. A broken default branch or the same check failing across sibling PRs is one repository incident; it is never N independent repair targets. - **Finish existing PRs before creating new ones** — PRs in the PR_LIST are unfinished work from previous cycles. Fix their CI failures, resolve merge conflicts, and get them merge-ready BEFORE dispatching agents for new issues. Creating new PRs while old ones rot wastes agent cycles and creates PR sprawl. -- **Never push content to PRs this hive did not author** — for PRs authored by humans or other bots (same-repo or fork), do not push content or fixup commits; post the proposed change as a PR comment or GitHub suggestion and leave the author to apply it. The exceptions are DCO-safe update-branch/base-sync operations that `review.contributor_prs.base_sync: true` authorizes, in-place adopted contributor PRs carrying `stage/074-adopted-by-hive` (Hive owns getting them merged and may push signed fixer commits while the adoption holds), or a hive-owned repair that removes/re-homes a bad commit the hive itself already pushed; `review.fix_human_prs` never authorizes new follow-up commits on ordinary non-App-authored branches because their sign-off will not survive a squash attributed to the PR author. Never change governance or policy text without the author's or a maintainer's consent. +- **Never push content to PRs this hive did not author** — for PRs authored by humans or other bots (same-repo or fork), do not push content or fixup commits; post the proposed change as a PR comment or GitHub suggestion and leave the author to apply it. The exceptions are DCO-safe update-branch/base-sync operations that `review.contributor_prs.base_sync: true` authorizes, in-place adopted contributor PRs carrying `stage/074-adopted-by-hive` (Hive owns getting them merged and may push signed fixer commits while the adoption holds; a fixer commit must keep the PR's own change — if CI can pass only by undoing what the PR changes, for example because it waits on another unmerged PR, do not push: park it with `needs-human` naming that dependency, since the hive refuses an adopted head whose diff keeps less than half of the PR's change), or a hive-owned repair that removes/re-homes a bad commit the hive itself already pushed; `review.fix_human_prs` never authorizes new follow-up commits on ordinary non-App-authored branches because their sign-off will not survive a squash attributed to the PR author. Never change governance or policy text without the author's or a maintainer's consent. - Only work items from the kick message — never run `gh issue list` or `gh pr list` - Always sign commits with DCO: `git commit -s` - Add a `changelog.d/-.md` fragment (repository-root `changelog.d/`, never `src/changelog.d/`) for user-visible `src/` changes before requesting a PR; CI is the sole verdict for missing or malformed fragments. From adc32cbabbff302403fa867834f266552d6b4de2 Mon Sep 17 00:00:00 2001 From: Danathar Date: Thu, 5 Nov 2026 19:21:35 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20fix(adoption):=20judge=20fix?= =?UTF-8?q?er=20pushes=20against=20the=20contributor's=20head;=20keep=20th?= =?UTF-8?q?e=20refusal=20through=20recovery?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review findings on #16816 at 49a7da8: - ci-maintainer/adjudicator: a refused head became the next check's baseline. Record.AdoptedIntentHead (set in MarkAdoptedInPlace, IntentBaseHead falls back to AdoptedHead) is the baseline for every push. - adjudicator-2: stale-red recovery cleared any escalation; it no longer clears adoption-fixer-reverts-pr. - reviewer: the awaiting-ci rewrite now needs a hive push (recorded or App-linked commit); an author's push keeps its note. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar --- changelog.d/fixed-adopted-fixer-reverts-pr.md | 2 +- .../stage-labels.md | 26 +++-- .../automerge/automerge_adoption_intent.go | 25 +++-- .../automerge_adoption_intent_test.go | 103 ++++++++++++++++++ .../automerge/automerge_contributor_adopt.go | 5 +- .../issue_request_awaiting_ci_intent_test.go | 24 +++- src/pkg/github/issue_request_status_notes.go | 25 ++++- src/pkg/stagelabels/intent_base_head_test.go | 25 +++++ src/pkg/stagelabels/store.go | 23 +++- 9 files changed, 225 insertions(+), 33 deletions(-) create mode 100644 src/pkg/stagelabels/intent_base_head_test.go diff --git a/changelog.d/fixed-adopted-fixer-reverts-pr.md b/changelog.d/fixed-adopted-fixer-reverts-pr.md index 8b992fdc39..ab5f50d864 100644 --- a/changelog.d/fixed-adopted-fixer-reverts-pr.md +++ b/changelog.d/fixed-adopted-fixer-reverts-pr.md @@ -1 +1 @@ -- The hive no longer merges an adopted PR after its own fixer undid the PR's change. On projectbluefin/utah#1091 the adopted fixer made CI pass by re-adding the 25 `baselines/triage.toml` entries the PR removed, leaving a docs-only diff, then announced "sweep will merge when green". Each hive push on an in-place adoption is now checked: if the PR's diff against its base keeps less than half of the lines it changed before the push, the push is refused, the PR goes to `stage/085-needs-decision` (`adoption-fixer-reverts-pr`) with a "Fixing CI would undo this PR's change" note, and the contributor lane will not merge that head. Until the check passes, the lane holds the head (`contributor-lane:adoption-intent-pending`), and an agent's "sweep will merge when green" note on it is rewritten to say the check comes first. The scanner policy tells the fixer to park instead of pushing such a commit. +- The hive no longer merges an adopted PR after its own fixer undid the PR's change. On projectbluefin/utah#1091 the adopted fixer made CI pass by re-adding the 25 `baselines/triage.toml` entries the PR removed, leaving a docs-only diff, then announced "sweep will merge when green". Each hive push on an in-place adoption is now checked against the PR's diff at the contributor's head the adoption started from: if fewer than half of those changed lines remain, the push is refused (so is any push on top of it, and stale-red recovery never releases it), the PR goes to `stage/085-needs-decision` (`adoption-fixer-reverts-pr`) with a "Fixing CI would undo this PR's change" note, and the contributor lane will not merge that head. Until the check passes, the lane holds the head (`contributor-lane:adoption-intent-pending`), and an agent's "sweep will merge when green" note on a hive push is rewritten to say the check comes first. The scanner policy tells the fixer to park instead of pushing such a commit. diff --git a/src/docs/labels-and-control-signals/stage-labels.md b/src/docs/labels-and-control-signals/stage-labels.md index 969342861f..1a4a381332 100644 --- a/src/docs/labels-and-control-signals/stage-labels.md +++ b/src/docs/labels-and-control-signals/stage-labels.md @@ -1054,16 +1054,22 @@ When a contributor-agent PR goes red the hive does not just relabel it (a human- Each hive push is first checked against the PR's own change (`automerge_adoption_intent.go`): the PR's diff against its base (three-dot, so a merge of the base is not counted) must still carry at - least half of the lines it changed before the push. A push that undoes - more is refused: the PR goes to `stage/085-needs-decision` with reason - `adoption-fixer-reverts-pr` and one "Fixing CI would undo this PR's - change" note, the contributor lane will not merge that head, and the - next push re-checks (projectbluefin/utah#1091: the fixer re-added the 25 - entries the PR removed). Until the check has passed, the lane refuses - the head as `contributor-lane:adoption-intent-pending` and the relay - rewrites an agent's `hive/awaiting-ci: … sweep will merge when green` - note on it to say the check comes first. A diff of 300 files or more is - not judged. A later head keeps that ownership + least half of the lines the PR changed at the contributor's head the + adoption started from (`adopted_intent_head`; older records fall back to + the adopted head). Every push is judged against that head, so a push on + top of a refused one is refused too, and a chain of pushes cannot erode + the change below half. A push that undoes more is refused: the PR goes + to `stage/085-needs-decision` with reason `adoption-fixer-reverts-pr` + and one "Fixing CI would undo this PR's change" note per head, and the + contributor lane will not merge that head; stale-red recovery may re-run + its CI but never releases the refusal (projectbluefin/utah#1091: the + fixer re-added the 25 entries the PR removed). Until the check has + passed, the lane refuses the head as + `contributor-lane:adoption-intent-pending`, and the relay rewrites an + agent's `hive/awaiting-ci: … sweep will merge when green` note on a hive + push (recorded, or App-linked on GitHub) to say the check comes first; + an author's push keeps the note as written. A diff of 300 files or more + is not judged. A later head keeps that ownership only when the commit's GitHub-linked author/committer is the App bot (the stage store remembers SHAs that already passed that check; it is not a separate evidence source) diff --git a/src/pkg/github/automerge/automerge_adoption_intent.go b/src/pkg/github/automerge/automerge_adoption_intent.go index 29759ef571..774d49363d 100644 --- a/src/pkg/github/automerge/automerge_adoption_intent.go +++ b/src/pkg/github/automerge/automerge_adoption_intent.go @@ -100,15 +100,20 @@ func (c *Engine) adoptedPushIntent(ctx context.Context, obs stageObservation, be } // checkAdoptedPushIntent runs when the hive advanced an in-place adopted PR -// from prev.AdoptedHead to obs.HeadSHA. A push that keeps the PR's change is -// taken as the hive's head (MarkAdoptedHead). One that undoes it is -// escalated to 085 with LaneReasonAdoptionFixerReverts: the contributor lane -// refuses to merge that head and the author or a maintainer is told why, -// once; the head is taken only after the note posts, so a failed post is -// re-checked and retried next sweep. An unreadable diff leaves the head -// unmarked, so no merge admits it, and is re-read next sweep. +// to obs.HeadSHA. The push is judged against the PR's diff at the +// contributor's head the adoption started from (Record.IntentBaseHead), not +// the previous hive head: a refused head never becomes the baseline, and a +// chain of pushes that each keep most of the previous one cannot erode the +// change below half. A push that keeps the PR's change is taken as the +// hive's head (MarkAdoptedHead). One that undoes it is escalated to 085 with +// LaneReasonAdoptionFixerReverts: the contributor lane refuses to merge that +// head and the author or a maintainer is told why, once; the head is taken +// only after the note posts, so a failed post is re-checked and retried next +// sweep. An unreadable diff leaves the head unmarked, so no merge admits it, +// and is re-read next sweep. func (c *Engine) checkAdoptedPushIntent(ctx context.Context, store *stagelabels.Store, key string, obs stageObservation, prev stagelabels.Record) (int, error) { - intent, err := c.adoptedPushIntent(ctx, obs, prev.AdoptedHead) + base := prev.IntentBaseHead() + intent, err := c.adoptedPushIntent(ctx, obs, base) if err != nil { c.warn("stage labels: adopted PR advanced by the hive; diff unreadable, intent check deferred", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA, "error", err) return 0, nil @@ -122,10 +127,10 @@ func (c *Engine) checkAdoptedPushIntent(ctx context.Context, store *stagelabels. } reason := stagelabels.LaneReasonAdoptionFixerReverts store.MarkAdoptionEscalated(key, obs.HeadSHA, reason) - c.warn("stage labels: hive push undoes the adopted PR's own change; refusing it and escalating to needs-decision", "repo", obs.Display, "pr", obs.Number, "before", prev.AdoptedHead, "head", obs.HeadSHA, "own_lines", intent.Own, "kept_lines", intent.Kept) + c.warn("stage labels: hive push undoes the adopted PR's own change; refusing it and escalating to needs-decision", "repo", obs.Display, "pr", obs.Number, "intent_base", base, "head", obs.HeadSHA, "own_lines", intent.Own, "kept_lines", intent.Kept) n := 0 if rec, _ := store.Get(key); !rec.AdoptionEscalationNoted(obs.HeadSHA, reason) { - n, err = c.postAdoptionEscalationNote(ctx, store, key, obs, reason, AdoptionFixerRevertsComment(obs, prev.AdoptedHead, intent), "stage labels: fixer-reverts note failed") + n, err = c.postAdoptionEscalationNote(ctx, store, key, obs, reason, AdoptionFixerRevertsComment(obs, base, intent), "stage labels: fixer-reverts note failed") if err != nil { return n, err } diff --git a/src/pkg/github/automerge/automerge_adoption_intent_test.go b/src/pkg/github/automerge/automerge_adoption_intent_test.go index 007f162ad3..ba82ca1bf2 100644 --- a/src/pkg/github/automerge/automerge_adoption_intent_test.go +++ b/src/pkg/github/automerge/automerge_adoption_intent_test.go @@ -228,3 +228,106 @@ func TestAdoptedRecordedHivePushThatRevertsPRIsRefusedOnce(t *testing.T) { t.Fatalf("record after re-check = %+v", rec) } } + +// utah1091Partial is the PR's diff with only the first n of its 25 triage +// removals left (plus the 10 docs lines). +func utah1091Partial(n int) []map[string]string { + full := utah1091Files(true, "") + triage := full[1] + lines := strings.Split(triage["patch"], "\n") + files := []map[string]string{full[0]} + if n > 0 { + files = append(files, map[string]string{"filename": triage["filename"], "status": "modified", "patch": strings.Join(lines[:n+1], "\n")}) + } + return files +} + +// A further hive push on top of a refused head is judged against the +// contributor's head, not the refused one: it stays refused and the lane +// still will not merge it. +func TestAdoptedFixerPushOnTopOfRefusedHeadStaysRefused(t *testing.T) { + h, done, adopted := adoptUtah1091InPlace(t) + defer done() + key := stageKey("acme", "widget", 7) + h.adopt.comparePatches["a75a567"] = utah1091Files(false, "") + h.adopt.setCommitAuthor("a75a567", testHiveAppBotLogin) + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "a75a567", adopted...), "ci-pending") + + // A lint fix on top keeps the docs-only diff. + h.adopt.comparePatches["ccc"] = utah1091Files(false, "") + h.adopt.setCommitAuthor("ccc", testHiveAppBotLogin) + h.api.reset() + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "ccc", "stage/085-needs-decision", "role/contributor", "author/clanker"), "ci-pending") + if notes := fixerRevertsComments(h.api); len(notes) != 1 || !strings.Contains(notes[0], "leaves 10 of the 35 lines this PR changed at `aaa`") { + t.Fatalf("notes = %v", h.api.comments) + } + if got := h.e.adoptionIntentGate("acme", "widget", 7, "ccc"); got != stagelabels.LaneReasonAdoptionFixerReverts { + t.Fatalf("merge gate on the push over the refused head = %q", got) + } + if rec, _ := h.e.stageStoreOrShared().Get(key); rec.IntentBaseHead() != "aaa" { + t.Fatalf("intent baseline moved: %+v", rec) + } +} + +// Pushes that each keep 60% of the previous head cannot erode the PR's +// change below half: the second one is judged against the contributor's +// head (12/35 kept) and refused. +func TestAdoptedFixerPushChainCannotErodeChange(t *testing.T) { + h, done, adopted := adoptUtah1091InPlace(t) + defer done() + h.adopt.comparePatches["b1"] = utah1091Partial(11) // 21 of 35 kept (60%) + h.adopt.setCommitAuthor("b1", testHiveAppBotLogin) + h.api.reset() + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "b1", adopted...), "check-failing:unit") + if len(fixerRevertsComments(h.api)) != 0 || h.e.adoptionIntentGate("acme", "widget", 7, "b1") != "" { + t.Fatalf("60%% kept must pass: comments=%v", h.api.comments) + } + + h.adopt.comparePatches["b2"] = utah1091Partial(2) // 12 of b1's 21 (57%), 12 of 35 overall + h.adopt.setCommitAuthor("b2", testHiveAppBotLogin) + h.api.reset() + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "b2", adopted...), "check-failing:unit") + if notes := fixerRevertsComments(h.api); len(notes) != 1 || !strings.Contains(notes[0], "leaves 12 of the 35 lines") { + t.Fatalf("eroding chain not refused: %v", h.api.comments) + } + if got := h.e.adoptionIntentGate("acme", "widget", 7, "b2"); got != stagelabels.LaneReasonAdoptionFixerReverts { + t.Fatalf("merge gate = %q", got) + } +} + +// Stale-red recovery re-runs CI on the refused head; it must not release the +// refusal (a rerun cannot restore the PR's change). +func TestAdoptedFixerRevertsSurvivesStaleRedRecovery(t *testing.T) { + h, done, adopted := adoptUtah1091InPlace(t) + defer done() + key := stageKey("acme", "widget", 7) + h.adopt.comparePatches["a75a567"] = utah1091Files(false, "") + h.adopt.setCommitAuthor("a75a567", testHiveAppBotLogin) + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "a75a567", adopted...), recoveryReason) + if rec, _ := h.e.stageStoreOrShared().Get(key); rec.AdoptEscalatedReason != stagelabels.LaneReasonAdoptionFixerReverts { + t.Fatalf("not refused: %+v", rec) + } + + // The head sits red past the dwell; base is green, so recovery re-runs. + h.adopt.compareBase = "base1" + h.adopt.baseChecks = map[string]string{"coverage": "success"} + h.adopt.failedRuns = []int64{41} + h.api.reset() + h.clock.advance(adoptedDwell + time.Minute) + h.observe(adoptPR(7, "a75a567", "stage/085-needs-decision", "role/contributor", "author/clanker"), recoveryReason) + if len(h.adopt.reruns) != 1 { + t.Fatalf("recovery did not run: reruns=%v", h.adopt.reruns) + } + rec, _ := h.e.stageStoreOrShared().Get(key) + if !rec.AdoptionEscalated("a75a567") || rec.AdoptEscalatedReason != stagelabels.LaneReasonAdoptionFixerReverts { + t.Fatalf("recovery released the refusal: %+v", rec) + } + if got := h.e.adoptionIntentGate("acme", "widget", 7, "a75a567"); got != stagelabels.LaneReasonAdoptionFixerReverts { + t.Fatalf("merge gate after recovery = %q", got) + } +} diff --git a/src/pkg/github/automerge/automerge_contributor_adopt.go b/src/pkg/github/automerge/automerge_contributor_adopt.go index 9a51a24faf..050309021b 100644 --- a/src/pkg/github/automerge/automerge_contributor_adopt.go +++ b/src/pkg/github/automerge/automerge_contributor_adopt.go @@ -2316,7 +2316,10 @@ func (c *Engine) escapeStalledAdoption(ctx context.Context, store *stagelabels.S // an attempt holds the escalation while CI runs on the result, and // releases one already in place for the same head. if recovery := c.recoverStaleRedAdoption(ctx, store, key, obs, rec); recovery.Attempted { - if rec.AdoptionEscalated(obs.HeadSHA) { + // A fixer-reverts refusal is a verdict on the head's content, not + // its CI: a rerun or rebase cannot restore the PR's change, so the + // recovery never releases it. + if rec.AdoptionEscalated(obs.HeadSHA) && rec.AdoptEscalatedReason != stagelabels.LaneReasonAdoptionFixerReverts { store.ClearAdoptionEscalation(key) c.info("stage labels: adoption escalation released for recovery; back to adopted-by-hive", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA, "was", rec.AdoptEscalatedReason, "recovery", recovery.Reason) } diff --git a/src/pkg/github/issue_request_awaiting_ci_intent_test.go b/src/pkg/github/issue_request_awaiting_ci_intent_test.go index 52fb6aeab3..5467cddc27 100644 --- a/src/pkg/github/issue_request_awaiting_ci_intent_test.go +++ b/src/pkg/github/issue_request_awaiting_ci_intent_test.go @@ -18,16 +18,21 @@ import ( func TestAwaitingCINoteOnAdoptedPRWaitsForIntentCheck(t *testing.T) { const agentNote = "hive/awaiting-ci: CI pending — sweep will merge when green." head := "a75a567" + pusher := "hive[bot]" srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - if r.Method == http.MethodGet && strings.HasSuffix(r.URL.Path, "/pulls/1091") { + switch { + case r.Method == http.MethodGet && strings.HasSuffix(r.URL.Path, "/pulls/1091"): _, _ = w.Write([]byte(`{"number":1091,"head":{"sha":"` + head + `"}}`)) - return + case r.Method == http.MethodGet && strings.HasSuffix(r.URL.Path, "/commits/"+head): + _, _ = w.Write([]byte(`{"sha":"` + head + `","author":{"login":"` + pusher + `"},"committer":{"login":"` + pusher + `"}}`)) + default: + w.WriteHeader(http.StatusNotFound) } - w.WriteHeader(http.StatusNotFound) })) defer srv.Close() c := testClient(t, srv.URL) + c.SetAppBotLogin("hive[bot]") store := stagelabels.Shared() key := stagelabels.Key("o/utah", 1091) @@ -38,7 +43,18 @@ func TestAwaitingCINoteOnAdoptedPRWaitsForIntentCheck(t *testing.T) { ctx := context.Background() if got := c.adoptedAwaitingCINote(ctx, "o/utah", 1091, agentNote); got != awaitingCIIntentPendingNote { - t.Fatalf("unchecked hive head: %q", got) + t.Fatalf("unchecked hive head (App-linked commit, not yet recorded): %q", got) + } + // The author pushed: that head is never intent-checked, so the note + // must not claim it is. + pusher = "thatguywob" + if got := c.adoptedAwaitingCINote(ctx, "o/utah", 1091, agentNote); got != agentNote { + t.Fatalf("author push: %q", got) + } + // A recorded hive push (bare git identity) is checked. + store.MarkHivePushedHead(key, head) + if got := c.adoptedAwaitingCINote(ctx, "o/utah", 1091, agentNote); got != awaitingCIIntentPendingNote { + t.Fatalf("recorded hive push: %q", got) } store.MarkAdoptionEscalated(key, head, stagelabels.LaneReasonAdoptionFixerReverts) if got := c.adoptedAwaitingCINote(ctx, "o/utah", 1091, agentNote); got != awaitingCIIntentRefusedNote { diff --git a/src/pkg/github/issue_request_status_notes.go b/src/pkg/github/issue_request_status_notes.go index 6faa180d71..a67d245d6a 100644 --- a/src/pkg/github/issue_request_status_notes.go +++ b/src/pkg/github/issue_request_status_notes.go @@ -54,9 +54,12 @@ const ( ) // adoptedAwaitingCINote rewrites an awaiting-ci note on an in-place adopted -// PR whose current head the adoption record has not taken yet (its intent -// check is pending) or has refused. Any other body is returned unchanged; an -// unreadable PR keeps the agent's text. +// PR whose current head is a hive push the adoption record has not taken yet +// (its intent check is pending) or has refused. A head the author pushed is +// never checked, so its note is left alone. The note usually lands before +// the stage pass records the push, so a hive push is the recorded push +// evidence or a commit GitHub links to the hive's App. Any other body is +// returned unchanged; an unreadable PR or commit keeps the agent's text. func (c *Client) adoptedAwaitingCINote(ctx context.Context, repo string, number int, body string) string { if relayStatusNoteKey(body) != prstatus.KeyAgentNotePrefix+agentNoteAwaitingCI { return body @@ -76,8 +79,22 @@ func (c *Client) adoptedAwaitingCINote(ctx context.Context, repo string, number return body case rec.AdoptionEscalated(head) && rec.AdoptEscalatedReason == stagelabels.LaneReasonAdoptionFixerReverts: return awaitingCIIntentRefusedNote - case head != rec.AdoptedHead && rec.YieldedHead != head: + case head != rec.AdoptedHead && rec.YieldedHead != head && c.hivePushedAdoptedHead(ctx, owner, name, head, rec): return awaitingCIIntentPendingNote } return body } + +// hivePushedAdoptedHead reports whether head is the hive's own push: recorded +// as one, or a commit whose GitHub-linked author or committer is a hive +// account (the evidence settleInPlaceAdoption accepts). +func (c *Client) hivePushedAdoptedHead(ctx context.Context, owner, name, head string, rec stagelabels.Record) bool { + if rec.HivePushedHead(head) { + return true + } + commit, _, err := c.client.Repositories.GetCommit(ctx, owner, name, head, nil) + if err != nil { + return false + } + return c.isHiveAccount(commit.GetAuthor()) || c.isHiveAccount(commit.GetCommitter()) +} diff --git a/src/pkg/stagelabels/intent_base_head_test.go b/src/pkg/stagelabels/intent_base_head_test.go new file mode 100644 index 0000000000..fda71e4a2f --- /dev/null +++ b/src/pkg/stagelabels/intent_base_head_test.go @@ -0,0 +1,25 @@ +package stagelabels + +import ( + "testing" + "time" +) + +// The intent baseline is the contributor's head at in-place adoption; hive +// pushes move AdoptedHead but never the baseline. A record written before +// AdoptedIntentHead existed falls back to AdoptedHead. +func TestIntentBaseHead(t *testing.T) { + now := time.Date(2026, 11, 3, 21, 0, 0, 0, time.UTC) + s := NewStore("", func() time.Time { return now }) + key := Key("o/utah", 1091) + s.Observe(key, AdoptedByHive, "adopted") + s.MarkAdoptedInPlace(key, "7e9dfd7", "contributor-offline", now) + s.MarkAdoptedHead(key, "a75a567") + rec, _ := s.Get(key) + if rec.AdoptedHead != "a75a567" || rec.IntentBaseHead() != "7e9dfd7" { + t.Fatalf("record = %+v, baseline %q", rec, rec.IntentBaseHead()) + } + if got := (Record{AdoptedHead: "old"}).IntentBaseHead(); got != "old" { + t.Fatalf("pre-field record baseline = %q, want AdoptedHead", got) + } +} diff --git a/src/pkg/stagelabels/store.go b/src/pkg/stagelabels/store.go index 52a414a67e..fb5e5b5ae8 100644 --- a/src/pkg/stagelabels/store.go +++ b/src/pkg/stagelabels/store.go @@ -86,9 +86,15 @@ type Record struct { // contributor head the hive adopted, the superseding App PR's number // (0 while the attempt is recorded but no PR exists) and when. One // attempt per head. - AdoptedHead string `json:"adopted_head,omitempty"` - AdoptedBy int `json:"adopted_by,omitempty"` - AdoptedAt time.Time `json:"adopted_at,omitempty"` + AdoptedHead string `json:"adopted_head,omitempty"` + // AdoptedIntentHead is the contributor's head an in-place adoption + // started from. Every hive push is judged against the PR's diff at this + // head, never against the previous hive head, so a refused push cannot + // become the baseline for the next one and a chain of small cuts cannot + // erode the change (IntentBaseHead). + AdoptedIntentHead string `json:"adopted_intent_head,omitempty"` + AdoptedBy int `json:"adopted_by,omitempty"` + AdoptedAt time.Time `json:"adopted_at,omitempty"` // AdoptCheckedAt is the last time the superseding PR's state was polled. AdoptCheckedAt time.Time `json:"adopt_checked_at,omitempty"` // SupersededBy / SupersededAt record that the superseding App PR merged @@ -1427,6 +1433,16 @@ func (s *Store) HasHivePushEvidence(repo string) bool { return false } +// IntentBaseHead is the head whose PR diff a hive push on an in-place +// adoption must keep: the contributor's head at adoption, or AdoptedHead for +// a record written before AdoptedIntentHead existed. +func (r Record) IntentBaseHead() string { + if r.AdoptedIntentHead != "" { + return r.AdoptedIntentHead + } + return r.AdoptedHead +} + // AdoptionLive reports whether the hive currently owns this PR (stage 074): // an in-place adoption that was not yielded, or a superseding adoption of // exactly this head. Adoption is an ownership state, not a CI state — it @@ -1590,6 +1606,7 @@ func (s *Store) MarkAdoptedInPlace(key, head, reason string, now time.Time) { return } r.AdoptedHead, r.AdoptedBy, r.AdoptedAt, r.AdoptCheckedAt = head, 0, now, now + r.AdoptedIntentHead = head r.AdoptMode, r.AdoptReason = AdoptModeInPlace, reason r.AdoptBlockedHead, r.AdoptBlockedBy, r.AdoptBlockedAt = "", "", time.Time{} r.AdoptedHeadAt = now