diff --git a/changelog.d/fixed-adopted-review-fix-undo-guard.md b/changelog.d/fixed-adopted-review-fix-undo-guard.md new file mode 100644 index 0000000000..e14091e787 --- /dev/null +++ b/changelog.d/fixed-adopted-review-fix-undo-guard.md @@ -0,0 +1 @@ +- An adopted PR whose hive fix does what its review asked is no longer stuck at `stage/085-needs-decision` as "Fixing CI would undo this PR's change". On projectbluefin/utah-packages#943 the review asked that the PR's two wontfix entries stay pending; the hive adopted the PR for those asks and pushed a commit that did exactly that, and the undo guard parked it because the push kept only 2 of the PR's 20 changed lines. The park held until the head moved, so a later approve could not release it. When the hive adopts a PR for the review swarm's requested changes (CI not red), a push the guard refuses is now taken once the reviewer approves that exact head, whether the approve comes before or after the push is checked; the park is released with no second note. A fix for red CI that undoes the PR (projectbluefin/utah#1091) stays refused even if the reviewer approves it, and any verdict other than approve keeps the park. diff --git a/src/docs/labels-and-control-signals/stage-labels.md b/src/docs/labels-and-control-signals/stage-labels.md index 53ff279eb5..16c3806dcf 100644 --- a/src/docs/labels-and-control-signals/stage-labels.md +++ b/src/docs/labels-and-control-signals/stage-labels.md @@ -1081,7 +1081,16 @@ When a contributor-agent PR goes red the hive does not just relabel it (a human- 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 + fixer re-added the 25 entries the PR removed). One exception: when the + hive adopted the PR for the review swarm's requested changes with CI + not red (`adopted_for_review`), the review may have asked for part of + the change to go, so a refused push is taken once the reviewer's + verdict on that exact head is approve. The approve is read on every + sweep, so a park posted before the verdict arrived is released then, + with no second note (projectbluefin/utah-packages#943: the review asked + for both wontfix entries to stay pending, and the hive's push did + that). Any other verdict keeps the park, and an adoption for red CI + never takes this path, approve or not. 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 diff --git a/src/pkg/github/automerge/automerge_adoption_intent.go b/src/pkg/github/automerge/automerge_adoption_intent.go index 774d49363d..08a88a206a 100644 --- a/src/pkg/github/automerge/automerge_adoption_intent.go +++ b/src/pkg/github/automerge/automerge_adoption_intent.go @@ -118,6 +118,11 @@ func (c *Engine) checkAdoptedPushIntent(ctx context.Context, store *stagelabels. 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() && c.reviewApprovedFixerRevert(prev, obs.Owner, obs.Repo, obs.Number, obs.HeadSHA) { + c.info("stage labels: hive push drops most of the adopted PR's change, as its review asked; the reviewer approved this head", "repo", obs.Display, "pr", obs.Number, "intent_base", base, "head", obs.HeadSHA, "own_lines", intent.Own, "kept_lines", intent.Kept) + store.MarkAdoptedHead(key, obs.HeadSHA) + 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) @@ -139,6 +144,50 @@ func (c *Engine) checkAdoptedPushIntent(ctx context.Context, store *stagelabels. return n, nil } +// adoptedForReview reports whether an in-place adoption of obs is taken +// over for the review swarm's requested changes with CI not red +// (Record.AdoptedForReview). A fix for review asks may rightly drop part of +// the PR's change: on projectbluefin/utah-packages#943 the review asked that +// the PR's two wontfix entries go back to pending, the hive's push did +// exactly that, and the intent check parked it as a CI fix undoing the PR. +func adoptedForReview(obs stageObservation) bool { + if adoptionWaitFor(obs).red { + return false + } + return obs.Reason == contributorLaneReasonChangesRequested || obs.Reason == stagelabels.LaneReasonChangesRequested || verdictBlocks(obs.Detail) +} + +// reviewApprovedFixerRevert reports whether a hive push that drops most of +// an adopted PR's change is still the hive's to merge: the adoption was for +// the review swarm's requested changes (never for red CI, the utah#1091 +// shape) and the reviewer's verdict on this exact head is approve. The +// reviewer then judged the narrowed diff and agreed with it; a CI-only fix +// that undoes the PR stays refused, and no verdict yet means refused. +func (c *Engine) reviewApprovedFixerRevert(rec stagelabels.Record, owner, repo string, number int, head string) bool { + if c == nil || head == "" || !rec.AdoptedInPlace() || !rec.AdoptedForReview { + return false + } + return c.contributorLaneVerdictFor(owner+"/"+repo, number, head).Approved +} + +// releaseApprovedFixerRevert clears a fixer-reverts refusal on obs.HeadSHA +// once reviewApprovedFixerRevert holds: the park is a verdict on the head's +// content, and the reviewer's approve of that content, which arrives after +// the push was judged, answers it. Without this the 085 park held until the +// head moved, so a fix the review asked for and then approved still waited +// on a person. Reports whether it released. +func (c *Engine) releaseApprovedFixerRevert(store *stagelabels.Store, key string, obs stageObservation, rec stagelabels.Record) bool { + if !rec.AdoptionEscalated(obs.HeadSHA) || rec.AdoptEscalatedReason != stagelabels.LaneReasonAdoptionFixerReverts { + return false + } + if !c.reviewApprovedFixerRevert(rec, obs.Owner, obs.Repo, obs.Number, obs.HeadSHA) { + return false + } + store.ClearAdoptionEscalation(key) + c.info("stage labels: fixer-reverts refusal released; the reviewer approved the head the review asked for", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA) + return true +} + // 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 { @@ -178,5 +227,11 @@ func (c *Engine) adoptionIntentGate(owner, repo string, number int, headSHA stri if !ok { return "" } - return adoptionIntentRefused(rec, headSHA) + reason := adoptionIntentRefused(rec, headSHA) + if reason == stagelabels.LaneReasonAdoptionFixerReverts && c.reviewApprovedFixerRevert(rec, owner, repo, number, headSHA) { + // The lane may run before the stage pass releases the park; the + // approve it is about to read admits the head either way. + return "" + } + return reason } diff --git a/src/pkg/github/automerge/automerge_adoption_intent_review_test.go b/src/pkg/github/automerge/automerge_adoption_intent_review_test.go new file mode 100644 index 0000000000..95896d20fe --- /dev/null +++ b/src/pkg/github/automerge/automerge_adoption_intent_review_test.go @@ -0,0 +1,192 @@ +package automerge + +import ( + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// projectbluefin/utah-packages#943: the PR marks two packages wontfix (2 +// lines in config/factory-build-backlog.toml) and adds 18 lines of guidance. +// The review asked for both entries to stay pending. The hive adopted the PR +// for those asks and pushed eed6933, which drops both entries and rewrites +// the guidance, keeping 2 of the PR's 20 changed lines. +func utahPackages943Files(fixed bool) []map[string]string { + if fixed { + return []map[string]string{{"filename": "docs/skills/factory-build-backlog.md", "status": "modified", + "patch": "@@ -355,0 +355,6 @@\n+### Packages removed from Fedora\n+\n" + strings.Repeat("+defer to the kernel-module gate\n", 3) + "+import the negativo17 recipe"}} + } + return []map[string]string{ + {"filename": "config/factory-build-backlog.toml", "status": "modified", + "patch": "@@ -912,0 +913,2 @@\n+intel-vaapi-driver = \"wontfix: dropped from Fedora\"\n+kmod-v4l2loopback = \"wontfix: upstream gone\""}, + {"filename": "docs/skills/factory-build-backlog.md", "status": "modified", + "patch": "@@ -355,0 +355,18 @@\n+### Packages removed from Fedora\n+\n" + strings.Repeat("+removed packages with unreachable upstream go to wontfix\n", 16)}, + } +} + +// adopt943ForReview adopts PR #7 in place at head aaa for the review swarm's +// requested changes, CI green: the utah-packages#943 adoption. +func adopt943ForReview(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": utahPackages943Files(false)} + h.observe(adoptPR(7, "aaa"), contributorLaneReasonChangesRequested) + labels := []string{"stage/072-returned-to-contributor", "role/contributor", "author/clanker"} + h.clock.advance(30 * time.Minute) + h.observe(adoptPR(7, "aaa", labels...), contributorLaneReasonChangesRequested) + h.observe(adoptPR(7, "aaa", labels...), contributorLaneReasonChangesRequested) + rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7)) + if !rec.AdoptedInPlace() || rec.AdoptedHead != "aaa" { + done() + t.Fatalf("not adopted in place: %+v", rec) + } + if nudges := nudgeComments(h.api); len(nudges) != 1 || !strings.Contains(nudges[0], "the review swarm requested changes") { + done() + t.Fatalf("PR was not returned for the review asks: %v", h.api.comments) + } + return h, done, []string{"stage/074-adopted-by-hive", "role/contributor", "author/clanker"} +} + +// reviewerVerdicts stands in for the review swarm: approve for the heads in +// approved, changes requested for every other head. +func reviewerVerdicts(h *adoptHarness, approved ...string) { + h.e.contributorLaneVerdict = func(_ string, _ int, head string) ContributorLaneVerdict { + for _, a := range approved { + if head == a { + return ContributorLaneVerdict{Configured: true, Approved: true, Verdict: "approve"} + } + } + return ContributorLaneVerdict{Configured: true, Verdict: "changes_requested"} + } +} + +// The utah-packages#943 order: the push is judged at once and parked (no +// verdict on it yet), then the reviewer approves that head. The approve +// answers the park: it is released, the lane admits the head, and no second +// note is posted. +func TestAdoptedReviewFixThatDropsChangeIsReleasedByApprove(t *testing.T) { + h, done, adopted := adopt943ForReview(t) + defer done() + reviewerVerdicts(h) + h.adopt.comparePatches["eed6933"] = utahPackages943Files(true) + h.adopt.setCommitAuthor("eed6933", testHiveAppBotLogin) + h.api.reset() + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "eed6933", adopted...), "ci-pending") + if notes := fixerRevertsComments(h.api); len(notes) != 1 || !strings.Contains(notes[0], "leaves 2 of the 20 lines") { + t.Fatalf("before the verdict: notes = %v (all comments %v)", notes, h.api.comments) + } + if got := h.e.adoptionIntentGate("acme", "widget", 7, "eed6933"); got != stagelabels.LaneReasonAdoptionFixerReverts { + t.Fatalf("merge gate before the verdict = %q, want the refusal", got) + } + + // The reviewer approves eed6933. + reviewerVerdicts(h, "eed6933") + if got := h.e.adoptionIntentGate("acme", "widget", 7, "eed6933"); got != "" { + t.Fatalf("merge gate after the approve = %q, want none", got) + } + h.api.reset() + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "eed6933", "stage/085-needs-decision", "role/contributor", "author/clanker"), "ci-pending") + rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7)) + if rec.AdoptionEscalated("eed6933") || rec.Stage == stagelabels.NeedsDecision || rec.AdoptedHead != "eed6933" { + t.Fatalf("park not released after the approve: %+v", rec) + } + if len(fixerRevertsComments(h.api)) != 0 || strings.Contains(strings.Join(h.addedLabels(), ","), "stage/085") { + t.Fatalf("after the approve: comments=%v added=%v", h.api.comments, h.api.added) + } +} + +// The approve is already on the head when the push is first judged: no +// park and no note. +func TestAdoptedReviewFixApprovedBeforeCheckIsNotParked(t *testing.T) { + h, done, adopted := adopt943ForReview(t) + defer done() + reviewerVerdicts(h, "eed6933") + h.adopt.comparePatches["eed6933"] = utahPackages943Files(true) + h.adopt.setCommitAuthor("eed6933", testHiveAppBotLogin) + h.api.reset() + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "eed6933", adopted...), "ci-pending") + if len(fixerRevertsComments(h.api)) != 0 || strings.Contains(strings.Join(h.addedLabels(), ","), "stage/085") { + t.Fatalf("approved review fix parked: comments=%v added=%v", h.api.comments, h.api.added) + } + rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7)) + if rec.AdoptionEscalated("eed6933") || rec.AdoptedHead != "eed6933" { + t.Fatalf("record = %+v", rec) + } + if got := h.e.adoptionIntentGate("acme", "widget", 7, "eed6933"); got != "" { + t.Fatalf("merge gate = %q, want none", got) + } +} + +// What the reviewer actually said on eed6933: the old asks are resolved but +// it still requests changes. That is no approve, so the park holds. +func TestAdoptedReviewFixWithoutApproveStaysParked(t *testing.T) { + h, done, adopted := adopt943ForReview(t) + defer done() + reviewerVerdicts(h) + h.adopt.comparePatches["eed6933"] = utahPackages943Files(true) + h.adopt.setCommitAuthor("eed6933", testHiveAppBotLogin) + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "eed6933", adopted...), "ci-pending") + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "eed6933", "stage/085-needs-decision", "role/contributor", "author/clanker"), "ci-pending") + rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7)) + if !rec.AdoptionEscalated("eed6933") || rec.AdoptEscalatedReason != stagelabels.LaneReasonAdoptionFixerReverts { + t.Fatalf("record = %+v, want the park held", rec) + } + if got := h.e.adoptionIntentGate("acme", "widget", 7, "eed6933"); got != stagelabels.LaneReasonAdoptionFixerReverts { + t.Fatalf("merge gate = %q, want the refusal", got) + } +} + +// The hole hivecommons/hive#16816 closed stays closed: an adoption for red +// CI (utah#1091) whose fixer undid the PR is refused even when the reviewer +// approves the narrowed head, before or after the push is judged. +func TestAdoptedCIFixThatRevertsPRStaysRefusedWhenApproved(t *testing.T) { + h, done, adopted := adoptUtah1091InPlace(t) + defer done() + reviewerVerdicts(h, "a75a567") + 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") + if notes := fixerRevertsComments(h.api); len(notes) != 1 { + t.Fatalf("notes = %v (all comments %v)", notes, h.api.comments) + } + h.clock.advance(time.Minute) + h.observe(adoptPR(7, "a75a567", "stage/085-needs-decision", "role/contributor", "author/clanker"), "ci-pending") + rec, _ := h.e.stageStoreOrShared().Get(stageKey("acme", "widget", 7)) + if !rec.AdoptionEscalated("a75a567") || rec.AdoptEscalatedReason != stagelabels.LaneReasonAdoptionFixerReverts { + t.Fatalf("record = %+v, want the refusal held", rec) + } + if got := h.e.adoptionIntentGate("acme", "widget", 7, "a75a567"); got != stagelabels.LaneReasonAdoptionFixerReverts { + t.Fatalf("merge gate = %q, want the refusal", got) + } +} + +// adoptedForReview reads the adoption's cause: review asks with CI not red. +func TestAdoptedForReview(t *testing.T) { + asked := stageDetail{VerdictKnown: true, Verdict: ContributorLaneVerdict{Configured: true, Verdict: "changes_requested"}} + for name, tc := range map[string]struct { + obs stageObservation + want bool + }{ + "review asks, CI green": {stageObservation{Reason: contributorLaneReasonChangesRequested}, true}, + "blocking verdict, CI pending": {stageObservation{Reason: "ci-pending", Detail: asked}, true}, + "red CI": {stageObservation{Reason: "check-failing:unit"}, false}, + "red CI and review asks": {stageObservation{Reason: "check-failing:unit", Detail: asked}, false}, + "conflict": {stageObservation{Reason: "conflicting"}, false}, + } { + if got := adoptedForReview(tc.obs); got != tc.want { + t.Errorf("%s: adoptedForReview = %v, want %v", name, got, tc.want) + } + } +} diff --git a/src/pkg/github/automerge/automerge_contributor_adopt.go b/src/pkg/github/automerge/automerge_contributor_adopt.go index 25d19ac2be..0a36047616 100644 --- a/src/pkg/github/automerge/automerge_contributor_adopt.go +++ b/src/pkg/github/automerge/automerge_contributor_adopt.go @@ -924,6 +924,9 @@ func (c *Engine) adoptContributorPR(ctx context.Context, store *stagelabels.Stor if policy.AdoptInPlace && canPushInPlace && !dcoRehome { store.MarkAdoptedInPlace(key, obs.HeadSHA, reason, now) + if adoptedForReview(obs) { + store.MarkAdoptedForReview(key, obs.HeadSHA) + } c.recordContributorAbandon(ctx, obs, reason, 0, now) body := AdoptionInPlaceComment(obs, policy.HiveID, reason, grace, rec.NudgeOnline) + adoptionFenceNote(fence) if _, _, err := c.gh.Issues.CreateComment(ctx, obs.Owner, obs.Repo, obs.Number, &gh.IssueComment{Body: gh.Ptr(body)}); err != nil { diff --git a/src/pkg/github/automerge/automerge_stage_labels.go b/src/pkg/github/automerge/automerge_stage_labels.go index 4a27d21ae7..51f9c06582 100644 --- a/src/pkg/github/automerge/automerge_stage_labels.go +++ b/src/pkg/github/automerge/automerge_stage_labels.go @@ -1264,6 +1264,9 @@ func (c *Engine) ApplyStageLabels(ctx context.Context) (StageLabelResult, error) firstErr = err } prevRec, _ = store.Get(key) + if c.releaseApprovedFixerRevert(store, key, obs, prevRec) { + prevRec, _ = store.Get(key) + } } if hadPrev && prevRec.AdoptionLive(obs.HeadSHA) && verdict.Stage.YieldsToAdoptionFor(pass.Route) { // The hive owns this PR: whether the lane sees it red, diff --git a/src/pkg/policies/defaults/scanner-automerge.md b/src/pkg/policies/defaults/scanner-automerge.md index 3cd1ff8f50..91fd16e8dc 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; 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. +- **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; when the review asked for part of the change to be dropped, doing that is the fix, and the hive takes that head once the reviewer approves it), 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 fef6b5bcb4..784a93a2bc 100644 --- a/src/pkg/stagelabels/store.go +++ b/src/pkg/stagelabels/store.go @@ -93,9 +93,16 @@ type Record struct { // 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"` + AdoptedIntentHead string `json:"adopted_intent_head,omitempty"` + // AdoptedForReview says an in-place adoption took the PR over for the + // review swarm's requested changes, with CI not red. Such a fix may + // rightly drop part of the PR's change (the review asked for it), so a + // hive push the intent check refuses is released once the reviewer + // approves that exact head (hivecommons/hive#16816 follow-up, + // projectbluefin/utah-packages#943). An adoption for red CI never sets it. + AdoptedForReview bool `json:"adopted_for_review,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 @@ -1693,7 +1700,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.AdoptedIntentHead, r.AdoptedForReview = head, false r.AdoptMode, r.AdoptReason = AdoptModeInPlace, reason r.AdoptBlockedHead, r.AdoptBlockedBy, r.AdoptBlockedAt = "", "", time.Time{} r.AdoptedHeadAt = now @@ -1701,6 +1708,20 @@ func (s *Store) MarkAdoptedInPlace(key, head, reason string, now time.Time) { s.dirty = true } +// MarkAdoptedForReview records that the live in-place adoption of head was +// taken for the review swarm's requested changes (Record.AdoptedForReview). +func (s *Store) MarkAdoptedForReview(key, head string) { + s.mu.Lock() + defer s.mu.Unlock() + r, ok := s.items[key] + if !ok || head == "" || !r.AdoptedInPlace() || r.AdoptedIntentHead != head { + return + } + r.AdoptedForReview = true + s.items[key] = r + s.dirty = true +} + // StampAdoptedHeadAt starts the adopted-head clock at now on a live in-place // adoption of head that has none (hivecommons/hive#13040: a record written // before AdoptedHeadAt existed, whose AdoptedAt may predate the head by diff --git a/src/policies/scanner-automerge.md b/src/policies/scanner-automerge.md index 3cd1ff8f50..91fd16e8dc 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; 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. +- **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; when the review asked for part of the change to be dropped, doing that is the fix, and the hive takes that head once the reviewer approves it), 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.