Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-signoff-rehome-hive-authored.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Hive no longer supersedes its own PRs for a missing sign-off: the automerge DCO stage treats commits on a PR by hive's `ai_author` or App login as self-squash (so an App-signed commit no longer counts as squash-unsafe), `signoff-rehome` keeps hive-authored and operator-approved heads in place instead of re-authoring them as a new PR, the App's signed re-author commit always carries a `Signed-off-by` trailer, and the push relay refuses a hive-identity commit that lacks one.
1 change: 1 addition & 0 deletions src/cmd/hive/merge_eligibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func stageLabelPolicyFunc(cfg *config.Config) func() automerge.StageLabelPolicy
AuthorKindLabels: cfg.Governor.Labels.Author.Names(),
RelayKnown: contributorRelayKnown,
OwnerAuthor: dashboardOwnerLogin(cfg),
HiveAuthor: hiveIdentity(cfg).Matches,
SharedCIIncident: stageSharedCIIncident,
BaseBranchRed: stageBaseBranchRed,
ForkGuard: stageForkGuard,
Expand Down
114 changes: 114 additions & 0 deletions src/pkg/github/automerge/automerge_adoption_escape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

gh "github.com/google/go-github/v72/github"
"github.com/hivecommons/hive/pkg/stagelabels"
)

Expand Down Expand Up @@ -639,3 +640,116 @@ func TestFormatSat(t *testing.T) {
}
}
}

// hivecommons/hive#16619: the hive's own clanker (project.ai_author) opened
// the PR from its fork; the hive's fixer pushed a commit signed as the App.
// The squash attributes that commit to the hive's own author, so there is
// nothing to re-home: the PR keeps its number, approval and CI, and the
// adoption stays in place. No superseder, no stall note.
func TestAdoptedInPlaceHiveAuthoredSquashUnsafeCommitStaysInPlace(t *testing.T) {
p := adoptPolicy()
p.AdoptInPlace = true
p.DCORequired = func(string) (bool, bool) { return true, true }
p.HiveAuthor = func(login string) bool { return strings.EqualFold(login, "thatguywob") }
h, done := newAdoptHarness(t, ContributorNudgeOutcome{Mode: "comment"}, p)
defer done()
h.api.commitDetails = map[int][]stageCommitFixture{7: {
{message: "fix: preserve verdicts\n\nSigned-off-by: thatguywob <thatguywob@users.noreply.github.com>", authorLogin: "thatguywob", authorName: "thatguywob", authorEmail: "thatguywob@users.noreply.github.com"},
{message: "fix: escape tooltip lines\n\nSigned-off-by: hive[bot] <12345+hive[bot]@users.noreply.github.com>", authorLogin: testHiveAppBotLogin, authorName: "scanner", authorEmail: "12345+hive[bot]@users.noreply.github.com"},
}}
own := func(head string, labels ...string) *gh.PullRequest {
pr := adoptPR(7, head, labels...)
pr.User = &gh.User{Login: gh.Ptr("thatguywob")}
pr.Head.Repo = &gh.Repository{FullName: gh.Ptr("thatguywob/widget")}
return pr
}
h.adopt.allowMaintainerEdits(7, true)
h.observe(own("5980996"), contributorLaneReasonNoVerdict)
key := stageKey("acme", "widget", 7)
h.e.stageStoreOrShared().MarkAdoptedInPlace(key, "5980996", AdoptReasonGrace, h.clock.at)
h.adopt.setCommitAuthor("5980996", testHiveAppBotLogin)
h.api.reset()

for _, advance := range []time.Duration{time.Minute, adoptedDwell + time.Hour} {
h.clock.advance(advance)
h.observe(own("5980996", adoptedLabels...), contributorLaneReasonNoVerdict)
// Past the dwell the idle head may escalate to a person (085);
// that is a note on the same PR, never a copy of it.
if len(h.adopt.pulls) != 0 || len(adoptionComments(h.api)) != 0 || h.adopt.refs["refs/heads/hive/adopt-7"] != "" {
t.Fatalf("hive-authored PR superseded for sign-off: pulls=%v refs=%v comments=%v", h.adopt.pulls, h.adopt.refs, h.api.comments)
}
rec, _ := h.e.stageStoreOrShared().Get(key)
if !rec.AdoptedInPlace() || rec.AdoptedBy != 0 || rec.AdoptReason == AdoptReasonSignoffRehome || rec.DCOSquashUnsafeHive != 0 {
t.Fatalf("record after %v: %+v", advance, rec)
}
for _, c := range stalledComments(h.api) {
if strings.Contains(c, stagelabels.LaneReasonHiveSignoffAttribution) {
t.Fatalf("hive-authored PR parked on sign-off attribution: %s", c)
}
}
}
}

// The same head on an external contributor's fork keeps the existing
// behaviour: the App-signed commit is squash-unsafe under mallory's name,
// so the adoption re-homes onto hive/adopt-7 at once
// (TestAdoptedInPlaceSquashUnsafeHiveCommitSupersedes covers the full
// path; this pins the decision with the hive-author hook present).
func TestAdoptedInPlaceExternalForkSquashUnsafeStillSupersedes(t *testing.T) {
policy := adoptPolicy()
policy.AdoptInPlace = true
policy.HiveAuthor = func(login string) bool { return strings.EqualFold(login, "thatguywob") }
now := time.Date(2026, 10, 16, 12, 0, 0, 0, time.UTC)
inPlace := stagelabels.Record{AdoptedHead: "aaa", AdoptMode: stagelabels.AdoptModeInPlace, AdoptedAt: now, AdoptedHeadAt: now}
external := stageObservation{HeadSHA: "aaa", Author: "mallory", HeadRepo: "mallory/widget", Reason: stagelabels.LaneReasonHiveSignoffAttribution, Detail: stageDetail{DCOSquashUnsafeHive: 1}}
if got := inPlaceRehomeReason(external, inPlace, policy, now.Add(time.Minute), false); got != AdoptReasonSignoffRehome {
t.Fatalf("external fork: inPlaceRehomeReason=%q, want %q", got, AdoptReasonSignoffRehome)
}
if got := adoptionStalledReason(external, inPlace, policy, now.Add(time.Minute)); got != "adoption-stalled:hive-signoff-attribution" {
t.Fatalf("external fork stall reason=%q", got)
}
own := external
own.Author, own.HeadRepo = "thatguywob", "thatguywob/widget"
if got := inPlaceRehomeReason(own, inPlace, policy, now.Add(time.Minute), false); got != "" {
t.Fatalf("hive-authored: inPlaceRehomeReason=%q, want none", got)
}
if got := adoptionStalledReason(own, inPlace, policy, now.Add(time.Minute)); got != "" {
t.Fatalf("hive-authored stall reason=%q, want none", got)
}
}

// An operator's approval on the adopted head is never thrown away for a
// copy: neither the sign-off, the rebase nor the stalled-finding re-home
// fires while the approval stands on that head. A new head starts over.
func TestAdoptedInPlaceApprovedHeadIsNotSuperseded(t *testing.T) {
policy := adoptPolicy()
policy.AdoptInPlace = true
now := time.Date(2026, 10, 16, 12, 0, 0, 0, time.UTC)
inPlace := stagelabels.Record{AdoptedHead: "aaa", AdoptMode: stagelabels.AdoptModeInPlace, AdoptedAt: now, AdoptedHeadAt: now}
late := now.Add(adoptedDwell + time.Hour)
approved := stageDetail{HumanApprover: "clubanderson", HumanApprovalHead: "aaa"}
cases := []struct {
name string
obs stageObservation
}{
{"squash-unsafe sign-off", stageObservation{HeadSHA: "aaa", Author: "mallory", Reason: stagelabels.LaneReasonHiveSignoffAttribution, Detail: stageDetail{DCOSquashUnsafeHive: 1}}},
{"needs-rebase past dwell", stageObservation{HeadSHA: "aaa", Author: "mallory", Labels: []string{"needs-rebase"}, Reason: "conflicting"}},
{"finding past dwell", stageObservation{HeadSHA: "aaa", Author: "mallory", LaneReason: contributorLaneReasonChangesRequested, Detail: stageDetail{VerdictKnown: true, Verdict: ContributorLaneVerdict{Configured: true, Verdict: "changes_requested"}}}},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := inPlaceRehomeReason(tc.obs, inPlace, policy, late, true); got == "" {
t.Fatalf("precondition: unapproved head must re-home")
}
obs := tc.obs
obs.Detail.HumanApprover, obs.Detail.HumanApprovalHead = approved.HumanApprover, approved.HumanApprovalHead
if got := inPlaceRehomeReason(obs, inPlace, policy, late, true); got != "" {
t.Fatalf("approved head re-homed: %q", got)
}
obs.Detail.HumanApprovalHead = "older"
if got := inPlaceRehomeReason(obs, inPlace, policy, late, true); got == "" {
t.Fatalf("an approval on an older head must not pin the new one")
}
})
}
}
69 changes: 57 additions & 12 deletions src/pkg/github/automerge/automerge_contributor_adopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ func adoptionCloses(body string) []string {
return out
}

func adoptionNeedsDCORehome(obs stageObservation, canPushInPlace bool) bool {
return adoptionDCORepairMode(obs, canPushInPlace) == stagelabels.AdoptModeSupersede
func adoptionNeedsDCORehome(obs stageObservation, canPushInPlace, hiveAuthored bool) bool {
return adoptionDCORepairMode(obs, canPushInPlace, hiveAuthored) == stagelabels.AdoptModeSupersede
}

// adoptionDCORepairMode decides how a DCO-red head gets its sign-off:
Expand All @@ -298,16 +298,34 @@ func adoptionNeedsDCORehome(obs stageObservation, canPushInPlace bool) bool {
// base repository — a fork branch is pushable by an agent's git but not by
// the App's REST token, so a fork head re-homes (AdoptModeSupersede) even
// when every unsigned commit is the hive's (hivecommons/hive#14666).
func adoptionDCORepairMode(obs stageObservation, canPushInPlace bool) string {
//
// A hive-authored PR (hiveAuthored: the App bot or project.ai_author opened
// it) is never re-homed: every commit on it is the hive's to sign, so a
// pushable base-repo head is amended in place and any other head keeps its
// PR number, approvals and CI history and waits for a person (""),
// rather than restarting as a copy (hivecommons/hive#16619).
func adoptionDCORepairMode(obs stageObservation, canPushInPlace, hiveAuthored bool) string {
if obs.Detail.DCO != stagelabels.DCONo || obs.Detail.DCOUnsigned <= 0 {
return ""
}
if canPushInPlace && headInBaseRepo(obs) && obs.Detail.DCOUnsignedHive == obs.Detail.DCOUnsigned && obs.Detail.DCOUnsignedOther == 0 {
if canPushInPlace && headInBaseRepo(obs) && (hiveAuthored || (obs.Detail.DCOUnsignedHive == obs.Detail.DCOUnsigned && obs.Detail.DCOUnsignedOther == 0)) {
return stagelabels.AdoptModeInPlace
}
if hiveAuthored {
return ""
}
return stagelabels.AdoptModeSupersede
}

// adoptionHeadApproved reports whether a trusted human's APPROVED review
// stands on the observed head. Such a head is never re-homed onto a copy:
// the copy would restart CI and drop the approval (hivecommons/hive#16619).
// The one exception is a fork branch the hive cannot push to
// (AdoptReasonPushRehome), which the caller decides.
func adoptionHeadApproved(obs stageObservation) bool {
return obs.HeadSHA != "" && strings.TrimSpace(obs.Detail.HumanApprover) != "" && strings.TrimSpace(obs.Detail.HumanApprovalHead) == obs.HeadSHA
}

// headInBaseRepo reports whether the PR head lives in the base repository
// (not a fork), where the App's git-data API can rewrite it.
func headInBaseRepo(obs stageObservation) bool {
Expand All @@ -317,8 +335,8 @@ func headInBaseRepo(obs stageObservation) bool {
// adoptedHeadNeedsDCORepair decides, for an in-place-adopted PR, whether the
// unsigned commits are the hive's own on a base-repo branch it rewrites in
// place with its sign-off.
func adoptedHeadNeedsDCORepair(obs stageObservation, rec stagelabels.Record, canPushInPlace bool) bool {
return adoptedHeadDCORed(obs, rec) && adoptionDCORepairMode(obs, canPushInPlace) == stagelabels.AdoptModeInPlace
func adoptedHeadNeedsDCORepair(obs stageObservation, rec stagelabels.Record, canPushInPlace, hiveAuthored bool) bool {
return adoptedHeadDCORed(obs, rec) && adoptionDCORepairMode(obs, canPushInPlace, hiveAuthored) == stagelabels.AdoptModeInPlace
}

// adoptedHeadDCORed reports whether an in-place-adopted PR's head carries
Expand All @@ -330,8 +348,8 @@ func adoptedHeadDCORed(obs stageObservation, rec stagelabels.Record) bool {
// adoptedHeadNeedsDCORehome decides, for an in-place-adopted PR, whether the
// unsigned commits can be rewritten on the contributor branch (all App-linked
// and the branch still pushable) or the work must be re-homed.
func adoptedHeadNeedsDCORehome(obs stageObservation, rec stagelabels.Record, canPushInPlace bool) bool {
return adoptedHeadDCORed(obs, rec) && adoptionDCORepairMode(obs, canPushInPlace) == stagelabels.AdoptModeSupersede
func adoptedHeadNeedsDCORehome(obs stageObservation, rec stagelabels.Record, canPushInPlace, hiveAuthored bool) bool {
return adoptedHeadDCORed(obs, rec) && adoptionDCORepairMode(obs, canPushInPlace, hiveAuthored) == stagelabels.AdoptModeSupersede
}

func adoptionRehomeCommitMessage(obs stageObservation) string {
Expand Down Expand Up @@ -696,7 +714,7 @@ func (c *Engine) adoptContributorPR(ctx context.Context, store *stagelabels.Stor
if policy.AdoptInPlace && !requested && !forced {
canPushInPlace = c.canPushToPRBranch(ctx, obs)
}
dcoRehome := adoptionNeedsDCORehome(obs, canPushInPlace)
dcoRehome := adoptionNeedsDCORehome(obs, canPushInPlace, hiveAuthoredPR(obs, policy, appLogin))
// Record the attempt first: whatever happens below, this head is tried once.
store.MarkAdopted(key, obs.HeadSHA, 0, now)
store.NoteAdoptDiffFence(key, fence)
Expand Down Expand Up @@ -1344,10 +1362,17 @@ func (c *Engine) settleAdoption(ctx context.Context, store *stagelabels.Store, k
}
if adoptedHeadDCORed(obs, rec) {
canPushInPlace := c.canPushToPRBranch(ctx, obs)
if adoptedHeadNeedsDCORepair(obs, rec, canPushInPlace) {
hiveAuthored := hiveAuthoredPR(obs, policy, c.transport.AppBotLogin())
if adoptedHeadNeedsDCORepair(obs, rec, canPushInPlace, hiveAuthored) {
return c.repairAdoptedDCOInPlace(ctx, store, key, obs, rec)
}
if adoptedHeadNeedsDCORehome(obs, rec, canPushInPlace) {
if hiveAuthored && !adoptionHeadApproved(obs) && obs.Detail.DCOUnsigned > 0 {
// The hive's own PR on a head it cannot rewrite over REST:
// it keeps its number, approvals and CI; the unsigned head
// is the hive's agent's to re-sign on the same branch.
c.info("stage labels: hive-authored adopted PR has unsigned commits on a head the sweep cannot rewrite; keeping it in place", "repo", obs.Display, "pr", obs.Number, "author", obs.Author, "head", obs.HeadSHA, "head_repo", obs.HeadRepo, "can_push", canPushInPlace)
}
if adoptedHeadNeedsDCORehome(obs, rec, canPushInPlace, hiveAuthored) {
fence, err := c.adoptionDiffRefusal(ctx, obs)
if fence != "" && (err != nil || adoptionFenceDefers(fence)) {
// Not a verdict: the head moved, or its file list is
Expand Down Expand Up @@ -1954,7 +1979,18 @@ func inPlaceRehomeReason(obs stageObservation, rec stagelabels.Record, policy St
if !rec.AdoptedInPlace() || obs.HeadSHA == "" || obs.HeadSHA != rec.AdoptedHead || adoptedHeadDCORed(obs, rec) || adoptionBlocked(obs.Labels) != "" || verdictNeedsHuman(obs.Detail) {
return ""
}
if adoptionHeadApproved(obs) {
// A copy restarts CI and drops the approval; the head stays where
// the approval is. Only a fork the hive cannot push to re-homes
// (AdoptReasonPushRehome, decided by the caller).
return ""
}
if adoptedHeadSignoffUnfixable(obs, rec) {
if hiveAuthoredPR(obs, policy, "") {
// The squash attributes the hive's commits to the hive's own
// author: nothing to re-home (hivecommons/hive#16619).
return ""
}
return AdoptReasonSignoffRehome
}
if humanConflictReasons[obs.Reason] || humanConflictReasons[obs.LaneReason] || hasLabelFold(obs.Labels, "needs-rebase") {
Expand Down Expand Up @@ -1992,7 +2028,7 @@ func adoptionStalledReasonWith(obs stageObservation, rec stagelabels.Record, pol
if rec.AdoptionAttemptedNothingOpened(obs.HeadSHA) {
return stagelabels.LaneReasonAdoptionStalledPrefix + "supersede-failed:" + nonEmpty(rec.AdoptReason, obs.Reason)
}
if adoptedHeadSignoffUnfixable(obs, rec) {
if adoptedHeadSignoffUnfixable(obs, rec) && !hiveAuthoredPR(obs, policy, "") {
return stagelabels.LaneReasonAdoptionStalledPrefix + stagelabels.LaneReasonHiveSignoffAttribution
}
if adoptionOptionalCheckOnly(obs) || !adoptionStale(obs, rec, policy, now) {
Expand Down Expand Up @@ -2020,6 +2056,15 @@ func (c *Engine) escapeStalledAdoption(ctx context.Context, store *stagelabels.S
rec, _ = store.Get(key)
}
rehomeReason := inPlaceRehomeReason(obs, rec, policy, now, c.inPlaceRebaseExhausted(obs, rec))
if rehomeReason == AdoptReasonSignoffRehome && hiveAuthoredPR(obs, policy, c.transport.AppBotLogin()) {
rehomeReason = ""
}
if rehomeReason != "" && c.operatorAdmission(ctx, obs.Owner, obs.Repo, obs.Number, obs.HeadSHA) != "" {
// An operator admitted this head: a copy would drop that and
// restart CI. Only a fork the hive cannot push to re-homes.
c.info("stage labels: in-place adoption keeps its approved head; not superseding", "repo", obs.Display, "pr", obs.Number, "head", obs.HeadSHA, "would_rehome", rehomeReason)
rehomeReason = ""
}
if rehomeReason == "" && rec.AdoptedInPlace() && obs.HeadSHA == rec.AdoptedHead && !adoptedHeadDCORed(obs, rec) && adoptionBlocked(obs.Labels) == "" && !verdictNeedsHuman(obs.Detail) && c.pushAccessLost(ctx, obs) {
rehomeReason = AdoptReasonPushRehome
}
Expand Down
38 changes: 27 additions & 11 deletions src/pkg/github/automerge/automerge_contributor_adopt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,45 +586,61 @@ func TestAdoptionDCORehomeDecisionAndRendering(t *testing.T) {
Body: "Implements widgets.\n\nHive-Run: acme/widget#44\n",
Detail: stageDetail{DCO: stagelabels.DCONo, DCOTotal: 3, DCOUnsigned: 2},
}
if !adoptionNeedsDCORehome(obs, false) {
if !adoptionNeedsDCORehome(obs, false, false) {
t.Fatal("unsigned commits without branch push permission must re-home")
}
if !adoptionNeedsDCORehome(obs, true) {
if !adoptionNeedsDCORehome(obs, true, false) {
t.Fatal("unknown unsigned commit ownership must re-home")
}
obs.Detail.DCOUnsignedHive = 2
if !adoptionNeedsDCORehome(obs, true) {
if !adoptionNeedsDCORehome(obs, true, false) {
t.Fatal("a fork head must re-home even when only hive-authored commits are unsigned: the engine cannot rewrite a fork branch")
}
obs.Owner, obs.Repo, obs.HeadRepo = "acme", "widget", "acme/widget"
if adoptionNeedsDCORehome(obs, true) {
if adoptionNeedsDCORehome(obs, true, false) {
t.Fatal("branch push permission with only hive-authored unsigned commits on a base-repo head allows in-place repair")
}
if !adoptionNeedsDCORehome(obs, false) {
if !adoptionNeedsDCORehome(obs, false, false) {
t.Fatal("hive-authored unsigned commits without branch push permission must still re-home")
}
inPlace := stagelabels.Record{AdoptedHead: "aaa", AdoptMode: stagelabels.AdoptModeInPlace}
if adoptedHeadNeedsDCORehome(obs, inPlace, true) {
if adoptedHeadNeedsDCORehome(obs, inPlace, true, false) {
t.Fatal("already adopted in place with App-owned unsigned commits and push access stays in place")
}
if !adoptedHeadNeedsDCORepair(obs, inPlace, true) {
if !adoptedHeadNeedsDCORepair(obs, inPlace, true, false) {
t.Fatal("that head is the in-place repair's job")
}
obs.HeadRepo = ""
if !adoptedHeadNeedsDCORehome(obs, inPlace, true) {
if !adoptedHeadNeedsDCORehome(obs, inPlace, true, false) {
t.Fatal("already adopted in place on a fork must re-home")
}
if !adoptedHeadNeedsDCORehome(obs, inPlace, false) {
if !adoptedHeadNeedsDCORehome(obs, inPlace, false, false) {
t.Fatal("already adopted in place without push access must re-home")
}
if adoptedHeadNeedsDCORehome(obs, stagelabels.Record{AdoptedHead: "aaa", AdoptedBy: 90, AdoptMode: stagelabels.AdoptModeSupersede}, false) {
if adoptedHeadNeedsDCORehome(obs, stagelabels.Record{AdoptedHead: "aaa", AdoptedBy: 90, AdoptMode: stagelabels.AdoptModeSupersede}, false, false) {
t.Fatal("a superseded adoption is never re-homed again")
}
obs.Detail.DCOUnsignedHive = 0
obs.Detail.DCOUnsigned = 0
if adoptionNeedsDCORehome(obs, false) {
if adoptionNeedsDCORehome(obs, false, false) {
t.Fatal("signed head does not need DCO re-home")
}
// A hive-authored PR (hivecommons/hive#16619) is never re-homed for
// sign-off: a pushable base-repo head is amended in place whoever the
// unsigned commits are linked to; a fork head keeps its PR and waits.
own := obs
own.Author, own.Detail.DCOUnsigned, own.Detail.DCOUnsignedOther = "thatguywob", 2, 2
own.Owner, own.Repo, own.HeadRepo = "acme", "widget", "acme/widget"
if got := adoptionDCORepairMode(own, true, true); got != stagelabels.AdoptModeInPlace {
t.Fatalf("hive-authored base-repo head: mode=%q, want in-place amend", got)
}
own.HeadRepo = "thatguywob/widget"
if got := adoptionDCORepairMode(own, false, true); got != "" {
t.Fatalf("hive-authored fork head: mode=%q, want no re-home", got)
}
if adoptionNeedsDCORehome(own, false, true) || adoptedHeadNeedsDCORehome(own, inPlace, false, true) {
t.Fatal("a hive-authored PR must never be superseded for sign-off")
}
obs.Detail.DCOUnsigned = 2
body := AdoptionPRBody(obs, stagelabels.Record{Reason: "check-failing:dco"}, true, "")
for _, want := range []string{
Expand Down
Loading
Loading