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-dco-hive-ownership-consistency.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- DCO checks now treat commits linked to `project.ai_author` as the hive's in both the unsigned split and the squash-unsafe count, and a split cached before hive identities counted is read again once, so an in-flight hive-authored PR is re-signed instead of waiting for a person ([#16701](https://github.com/hivecommons/hive/issues/16701), [#16703](https://github.com/hivecommons/hive/issues/16703)). The docs now state that this login linkage comes from the commit email and is trusted only because the in-place path needs base-repo push access ([#16702](https://github.com/hivecommons/hive/issues/16702)).
20 changes: 14 additions & 6 deletions src/docs/labels-and-control-signals/stage-labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -1166,12 +1166,20 @@ When a contributor-agent PR goes red the hive does not just relabel it (a human-
If an adopted head is DCO-red, an empty signed commit is never enough.
"Hive-authored" is decided the same way as head attribution above: an
unsigned commit is the hive's own only when GitHub links its author or
committer to the App bot; git author/committer names and emails — even a
lane-looking `<lane>@<HIVE_GIT_BOT_EMAIL_DOMAIN>` address — are
contributor-controlled and never count. The stage pass caches that split
with the commit check (`dco_unsigned_hive`), so the decision does not
depend on which labels the PR currently carries. When every unsigned
commit is App-linked and the head lives in the **base repo**, an in-place
committer to the App bot, or its author to one of the hive's identities
(`project.ai_author`); git author/committer names — even a lane-looking
`<lane>@<HIVE_GIT_BOT_EMAIL_DOMAIN>` address — never count on their own.
GitHub derives that login linkage from the commit email and agents push
unsigned commits, so it is not proof of origin: anyone who can push to a
base-repo branch can author a commit as `project.ai_author` and have it
re-signed. Only collaborators with push access reach the in-place path,
so the hive trusts them not to do that
([#16702](https://github.com/hivecommons/hive/issues/16702)). The stage
pass caches that split with the commit check (`dco_unsigned_hive`), so
the decision does not depend on which labels the PR currently carries; a
split cached before hive identities counted is read again once
(`dco_split_hive_identity`). When every unsigned commit is the hive's
and the head lives in the **base repo**, an in-place
adoption stays in place and the stage engine itself re-signs the branch
once per head (`reason=dco-rehomed`): it replays the PR's commits through
the git-data API, keeping each author, message, tree and parents (merge
Expand Down
29 changes: 22 additions & 7 deletions src/pkg/github/automerge/automerge_stage_dco.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ func dcoCommitStatsForSquashAuthor(commits []*gh.RepositoryCommit, appLogin, prA
}

// dcoCommitStatsForHive is dcoCommitStatsForSquashAuthor with the hive's own
// identities (isHive, StageLabelPolicy.HiveAuthor) counted as the hive's when
// splitting unsigned commits; a nil isHive counts only the App bot.
// identities (isHive, StageLabelPolicy.HiveAuthor) counted as the hive's, both
// when splitting unsigned commits and when counting squash-unsafe signed ones
// (hivecommons/hive#16703); a nil isHive counts only the App bot.
func dcoCommitStatsForHive(commits []*gh.RepositoryCommit, appLogin, prAuthor string, selfSquash bool, isHive func(login string) bool) dcoStats {
var stats dcoStats
for _, rc := range commits {
Expand All @@ -83,7 +84,7 @@ func dcoCommitStatsForHive(commits []*gh.RepositoryCommit, appLogin, prAuthor st
} else {
stats.unsignedOther++
}
} else if !selfSquash && dcoCommitByHive(rc, appLogin) && !messageHasPRAuthorSignoff(msg, prAuthor) {
} else if !selfSquash && dcoCommitOwnedByHive(rc, appLogin, isHive) && !messageHasPRAuthorSignoff(msg, prAuthor) {
stats.squashUnsafeHive++
}
}
Expand All @@ -102,9 +103,20 @@ func dcoCommitByHive(commit *gh.RepositoryCommit, appLogin string) bool {
// dcoCommitOwnedByHive is dcoCommitByHive that also counts a commit GitHub
// links (by author login) to one of the hive's own identities (isHive:
// project.ai_author, the login the hive's agents push as). Only GitHub's
// linkage counts here too: git author names and emails never do, so a
// collaborator's unsigned commit stays "other" and is never signed by the
// App (hivecommons/hive#16685).
// linkage counts here too, never the git author name, so a collaborator's
// unsigned commit under their own email stays "other" and is never signed by
// the App (hivecommons/hive#16685).
//
// Trust assumption (hivecommons/hive#16702): GitHub derives the login from
// the git author email and the hive's agents push plain, unsigned git
// commits (app_signed_commits re-authors only the PR's opening head), so
// neither Commit.Verification nor the committer can tell an agent's commit
// from one a pusher authored with project.ai_author's email. Requiring
// either would stop the hive re-signing its own fix commits. The in-place
// path that acts on this split needs a base-repo head the App can push
// (adoptionDCORepairMode), so only collaborators with push access can
// present such a commit, and they are trusted not to. commitByApp has the
// same property for the App bot login.
func dcoCommitOwnedByHive(commit *gh.RepositoryCommit, appLogin string, isHive func(login string) bool) bool {
if dcoCommitByHive(commit, appLogin) {
return true
Expand All @@ -128,7 +140,10 @@ func (c *Engine) stageDCO(ctx context.Context, store *stagelabels.Store, key str
}
appLogin := c.transport.AppBotLogin()
selfSquash := botSquashAuthor(obs.Author) || hiveAuthoredPR(obs, policy, appLogin)
if rec, ok := store.Get(key); ok {
// A split cached before hive identities counted (hivecommons/hive#16701) filed
// project.ai_author commits as "other"; read the commits once more so
// a hive-authored head is re-signed rather than left waiting.
if rec, ok := store.Get(key); ok && (policy.HiveAuthor == nil || rec.DCOSplitHiveIdentity) {
if t, u, cached := rec.DCOFor(obs.HeadSHA); cached {
// Records cached before the ownership split existed carry
// none; an in-place adoption decides repair-vs-rehome on it,
Expand Down
59 changes: 59 additions & 0 deletions src/pkg/github/automerge/automerge_stage_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log/slog"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"reflect"
"slices"
Expand Down Expand Up @@ -2437,6 +2438,64 @@ func TestDCOCommitStatsForHiveCountsHiveIdentities(t *testing.T) {
}
}

// hivecommons/hive#16703: the squash-unsafe count uses the same ownership
// rule as the unsigned split, so a signed commit GitHub links to a hive
// identity is the hive's to misattribute on a PR a squash would credit to
// someone else.
func TestDCOCommitStatsForHiveSquashUnsafeCountsHiveIdentities(t *testing.T) {
commits := []*gh.RepositoryCommit{
{Author: &gh.User{Login: gh.Ptr("thatguywob")}, Commit: &gh.Commit{Message: gh.Ptr("hive fix\n\nSigned-off-by: Hive <hive@users.noreply.github.com>")}, Parents: []*gh.Commit{{}}},
{Author: &gh.User{Login: gh.Ptr("collaborator")}, Commit: &gh.Commit{Message: gh.Ptr("drive-by\n\nSigned-off-by: C <c@x>")}, Parents: []*gh.Commit{{}}},
}
isHive := func(login string) bool { return strings.EqualFold(login, "thatguywob") }
if stats := dcoCommitStatsForHive(commits, testHiveAppBotLogin, "person", false, isHive); stats.unsigned != 0 || stats.squashUnsafeHive != 1 {
t.Fatalf("with hive identities: %+v, want squashUnsafeHive=1", stats)
}
if stats := dcoCommitStatsForHive(commits, testHiveAppBotLogin, "person", true, isHive); stats.squashUnsafeHive != 0 {
t.Fatalf("self squash: %+v, want squashUnsafeHive=0", stats)
}
if stats := dcoCommitStatsForHive(commits, testHiveAppBotLogin, "person", false, nil); stats.squashUnsafeHive != 0 {
t.Fatalf("nil predicate: %+v, want App-only squashUnsafeHive=0", stats)
}
}

// hivecommons/hive#16701: a split cached before hive identities counted filed
// a project.ai_author commit as "other"; stageDCO reads that head's commits
// once more so the hive's own commit can be re-signed, then trusts the
// refreshed cache.
func TestStageDCORereadsSplitCachedBeforeHiveIdentities(t *testing.T) {
api := &stageAPI{labels: map[string]string{}, commitDetails: map[int][]stageCommitFixture{
42: {{message: "hive fix", authorLogin: "thatguywob"}},
}}
srv := newStageAPI(t, api)
defer srv.Close()
e, _, _ := newStageEngine(t, srv.URL, &contributorLaneClock{at: time.Now()})
key := stageKey("acme", "widget", 42)
path := filepath.Join(t.TempDir(), "legacy.json")
data, err := json.Marshal(map[string]stagelabels.Record{key: {DCOHead: "aaa", DCOTotal: 1, DCOUnsigned: 1, DCOUnsignedOther: 1, DCOSquashUnsafeKnown: true}})
if err != nil {
t.Fatal(err)
}
if err := os.WriteFile(path, data, 0o644); err != nil {
t.Fatal(err)
}
store := stagelabels.NewStore(path, nil)
if err := store.Load(); err != nil {
t.Fatal(err)
}
policy := StageLabelPolicy{HiveAuthor: func(login string) bool { return strings.EqualFold(login, "thatguywob") }}
obs := stageObservation{Owner: "acme", Repo: "widget", Number: 42, HeadSHA: "aaa", Author: "thatguywob"}
got, err := e.stageDCO(context.Background(), store, key, obs, policy)
if err != nil || got.unsigned != 1 || got.unsignedHive != 1 || got.unsignedOther != 0 || api.commitReads != 1 {
t.Fatalf("legacy split: %+v, %v, reads=%d; want hive=1 other=0 after one read", got, err, api.commitReads)
}
store.NoteDCO(key, obs.HeadSHA, got.total, got.unsigned, got.unsignedHive, got.squashUnsafeHive)
got, err = e.stageDCO(context.Background(), store, key, obs, policy)
if err != nil || got.unsignedHive != 1 || got.unsignedOther != 0 || api.commitReads != 1 {
t.Fatalf("refreshed split: %+v, %v, reads=%d; want the cache served", got, err, api.commitReads)
}
}

// hivecommons/hive#12557: a gate flapping between merge-queue and a pending
// stage on one unchanged head used to post a stage-regressed comment every
// sweep, because each recover re-armed the dedupe. One comment per head.
Expand Down
12 changes: 12 additions & 0 deletions src/pkg/stagelabels/stagelabels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,18 @@ func TestStoreNoteDCOSplitAndAdoptReason(t *testing.T) {
}
}

// hivecommons/hive#16701: NoteDCO marks the split as computed with hive
// identities, including on a legacy record whose counts are unchanged.
func TestStoreNoteDCOMarksHiveIdentitySplit(t *testing.T) {
s := NewStore("", nil)
key := Key("acme/widget", 8)
s.items[key] = Record{DCOHead: "a", DCOTotal: 2, DCOUnsigned: 1, DCOUnsignedOther: 1, DCOSquashUnsafeKnown: true}
s.NoteDCO(key, "a", 2, 1, 0, 0)
if r, _ := s.Get(key); !r.DCOSplitHiveIdentity || r.DCOUnsignedOther != 1 {
t.Fatalf("legacy record not marked: %+v", r)
}
}

func TestStoreAdoptInPlaceAndYield(t *testing.T) {
now := time.Date(2026, 10, 16, 12, 0, 0, 0, time.UTC)
s := NewStore("", func() time.Time { return now })
Expand Down
11 changes: 8 additions & 3 deletions src/pkg/stagelabels/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ type Record struct {
DCOUnsignedOther int `json:"dco_unsigned_other,omitempty"`
DCOSquashUnsafeHive int `json:"dco_squash_unsafe_hive,omitempty"`
DCOSquashUnsafeKnown bool `json:"dco_squash_unsafe_known,omitempty"`
// DCOSplitHiveIdentity marks a split computed with the hive's own
// identities (project.ai_author) counted as the hive's; records cached
// before that (hivecommons/hive#16701) lack it and are read again once.
DCOSplitHiveIdentity bool `json:"dco_split_hive_identity,omitempty"`
// EntryCommented records that the stage's entry comment (085 "needs a
// decision", 090 "ready for a human merge") was posted for the current
// stage visit; reset on every stage change so each transition explains
Expand Down Expand Up @@ -2469,8 +2473,8 @@ func (s *Store) NoteHold(key string, hold *HoldProvenance) {
func (s *Store) ClearHold(key string) { s.NoteHold(key, nil) }

// NoteDCO caches the commit check for head on an existing record:
// unsignedHive is the App-linked share of the unsigned commits, the rest
// is recorded as other.
// unsignedHive is the hive's share of the unsigned commits (App bot or a
// hive identity), the rest is recorded as other.
func (s *Store) NoteDCO(key, head string, total, unsigned, unsignedHive, squashUnsafeHive int) {
if head == "" {
return
Expand All @@ -2481,11 +2485,12 @@ func (s *Store) NoteDCO(key, head string, total, unsigned, unsignedHive, squashU
s.mu.Lock()
defer s.mu.Unlock()
r, ok := s.items[key]
if !ok || (r.DCOHead == head && r.DCOTotal == total && r.DCOUnsigned == unsigned && r.DCOUnsignedHive == unsignedHive && r.DCOUnsignedOther == other && r.DCOSquashUnsafeHive == squashUnsafeHive && r.DCOSquashUnsafeKnown) {
if !ok || (r.DCOHead == head && r.DCOTotal == total && r.DCOUnsigned == unsigned && r.DCOUnsignedHive == unsignedHive && r.DCOUnsignedOther == other && r.DCOSquashUnsafeHive == squashUnsafeHive && r.DCOSquashUnsafeKnown && r.DCOSplitHiveIdentity) {
return
}
r.DCOHead, r.DCOTotal, r.DCOUnsigned, r.DCOUnsignedHive, r.DCOUnsignedOther, r.DCOSquashUnsafeHive = head, total, unsigned, unsignedHive, other, squashUnsafeHive
r.DCOSquashUnsafeKnown = true
r.DCOSplitHiveIdentity = true
s.items[key] = r
s.dirty = true
}
Expand Down
Loading