diff --git a/changelog.d/fixed-16707.md b/changelog.d/fixed-16707.md new file mode 100644 index 0000000000..97449a01cd --- /dev/null +++ b/changelog.d/fixed-16707.md @@ -0,0 +1 @@ +- A DCO split cached while no `project.ai_author` was configured is no longer treated as computed with the hive identity, so configuring it later re-reads the commits for in-flight heads ([#16707](https://github.com/hivecommons/hive/issues/16707)). diff --git a/src/pkg/github/automerge/automerge_stage_labels.go b/src/pkg/github/automerge/automerge_stage_labels.go index e4adeb5fa5..bfd2b11315 100644 --- a/src/pkg/github/automerge/automerge_stage_labels.go +++ b/src/pkg/github/automerge/automerge_stage_labels.go @@ -1190,7 +1190,7 @@ func (c *Engine) ApplyStageLabels(ctx context.Context) (StageLabelResult, error) soakFirstGreen, _ := c.contributorSoak.FirstGreen(obs.Owner, obs.Repo, obs.Number, obs.HeadSHA) noteSoak(store, key, obs.Reason, obs.HeadSHA, pass.Route, c.currentContributorLanePolicy().Soak, soakFirstGreen, now) if dcoRead { - store.NoteDCO(key, obs.HeadSHA, obs.Detail.DCOTotal, obs.Detail.DCOUnsigned, obs.Detail.DCOUnsignedHive, obs.Detail.DCOSquashUnsafeHive) + store.NoteDCO(key, obs.HeadSHA, obs.Detail.DCOTotal, obs.Detail.DCOUnsigned, obs.Detail.DCOUnsignedHive, obs.Detail.DCOSquashUnsafeHive, policy.HiveAuthor != nil) } if verdict.Stage != stagelabels.ReturnedToContributor && verdict.Stage != stagelabels.NeedsAuthor { c.resolveNudge(ctx, prevRec, hadPrev, obs) diff --git a/src/pkg/github/automerge/automerge_stage_labels_test.go b/src/pkg/github/automerge/automerge_stage_labels_test.go index e8059712d8..dc1fcdf8fb 100644 --- a/src/pkg/github/automerge/automerge_stage_labels_test.go +++ b/src/pkg/github/automerge/automerge_stage_labels_test.go @@ -2489,7 +2489,7 @@ func TestStageDCORereadsSplitCachedBeforeHiveIdentities(t *testing.T) { 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) + store.NoteDCO(key, obs.HeadSHA, got.total, got.unsigned, got.unsignedHive, got.squashUnsafeHive, true) 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) diff --git a/src/pkg/github/automerge/shared_ci_attribution_test.go b/src/pkg/github/automerge/shared_ci_attribution_test.go index 1e20a6a6d3..0716ff0aee 100644 --- a/src/pkg/github/automerge/shared_ci_attribution_test.go +++ b/src/pkg/github/automerge/shared_ci_attribution_test.go @@ -42,7 +42,7 @@ func TestStageDCONormalizesCachedBotAttributionWithoutChangingSignoffs(t *testin e, _, store := newStageEngine(t, srv.URL, &contributorLaneClock{at: time.Now()}) key := stageKey("acme", "widget", 42) store.Observe(key, stagelabels.Fixing, stagelabels.LaneReasonHiveSignoffAttribution) - store.NoteDCO(key, "aaa", 3, 0, 0, 1) + store.NoteDCO(key, "aaa", 3, 0, 0, 1, true) got, err := e.stageDCO(context.Background(), store, key, stageObservation{ Owner: "acme", Repo: "widget", Number: 42, HeadSHA: "aaa", Author: "dependabot[bot]", }, StageLabelPolicy{}) diff --git a/src/pkg/stagelabels/stagelabels_test.go b/src/pkg/stagelabels/stagelabels_test.go index 56dbe14573..73ffb6cac3 100644 --- a/src/pkg/stagelabels/stagelabels_test.go +++ b/src/pkg/stagelabels/stagelabels_test.go @@ -998,18 +998,18 @@ func TestStoreNoteDCOSplitAndAdoptReason(t *testing.T) { now := time.Date(2026, 10, 16, 12, 0, 0, 0, time.UTC) s := NewStore("", func() time.Time { return now }) key := Key("acme/widget", 7) - s.NoteDCO(key, "a", 3, 2, 1, 0) + s.NoteDCO(key, "a", 3, 2, 1, 0, true) s.NoteAdoptReason(key, "dco-rehome") if _, ok := s.Get(key); ok { t.Fatal("NoteDCO/NoteAdoptReason created a record") } s.Observe(key, ReturnedToContributor, "check-failing:dco") - s.NoteDCO(key, "a", 3, 2, 1, 0) + s.NoteDCO(key, "a", 3, 2, 1, 0, true) r, _ := s.Get(key) if t0, u, ok := r.DCOFor("a"); !ok || t0 != 3 || u != 2 || r.DCOUnsignedHive != 1 || r.DCOUnsignedOther != 1 || !r.DCOSplitKnown("a") || r.DCOSplitKnown("b") { t.Fatalf("cached split: %+v", r) } - s.NoteDCO(key, "a", 3, 2, 2, 0) + s.NoteDCO(key, "a", 3, 2, 2, 0, true) if r, _ = s.Get(key); r.DCOUnsignedHive != 2 || r.DCOUnsignedOther != 0 || !r.DCOSplitKnown("a") { t.Fatalf("hive share not updated: %+v", r) } @@ -1033,12 +1033,28 @@ 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) + s.NoteDCO(key, "a", 2, 1, 0, 0, true) if r, _ := s.Get(key); !r.DCOSplitHiveIdentity || r.DCOUnsignedOther != 1 { t.Fatalf("legacy record not marked: %+v", r) } } +// hivecommons/hive#16707: an App-only split (no hive identity configured) +// must not be marked, so configuring one later triggers the re-read. +func TestStoreNoteDCOAppOnlySplitNotMarked(t *testing.T) { + s := NewStore("", nil) + key := Key("acme/widget", 9) + s.items[key] = Record{DCOHead: "a", DCOTotal: 2, DCOUnsigned: 1, DCOUnsignedOther: 1, DCOSquashUnsafeKnown: true} + s.NoteDCO(key, "a", 2, 1, 1, 0, false) + if r, _ := s.Get(key); r.DCOSplitHiveIdentity || r.DCOUnsignedHive != 1 { + t.Fatalf("app-only split marked or not stored: %+v", r) + } + s.NoteDCO(key, "a", 2, 1, 1, 0, true) + if r, _ := s.Get(key); !r.DCOSplitHiveIdentity { + t.Fatalf("hive-identity split 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 }) diff --git a/src/pkg/stagelabels/store.go b/src/pkg/stagelabels/store.go index 0b2bdbedce..afd0af8b70 100644 --- a/src/pkg/stagelabels/store.go +++ b/src/pkg/stagelabels/store.go @@ -2474,8 +2474,10 @@ func (s *Store) ClearHold(key string) { s.NoteHold(key, nil) } // NoteDCO caches the commit check for head on an existing record: // 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) { +// hive identity), the rest is recorded as other. hiveIdentity says the split +// was computed with a hive identity configured; an App-only split leaves the +// marker unset so configuring one later triggers the one-time re-read. +func (s *Store) NoteDCO(key, head string, total, unsigned, unsignedHive, squashUnsafeHive int, hiveIdentity bool) { if head == "" { return } @@ -2485,12 +2487,14 @@ 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 && r.DCOSplitHiveIdentity) { + if !ok || (r.DCOHead == head && r.DCOTotal == total && r.DCOUnsigned == unsigned && r.DCOUnsignedHive == unsignedHive && r.DCOUnsignedOther == other && r.DCOSquashUnsafeHive == squashUnsafeHive && r.DCOSquashUnsafeKnown && (r.DCOSplitHiveIdentity || !hiveIdentity)) { 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 + if hiveIdentity { + r.DCOSplitHiveIdentity = true + } s.items[key] = r s.dirty = true }