Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
63b6b6c
πŸ› hold guard: accept a trusted merger's recorded approval of the curr…
clubanderson Oct 30, 2026
6e61bef
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
0daf9f0
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
422a9c2
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
c3e9f9b
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
c14cdb0
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
5fc0756
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
3c723c6
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
dc665f0
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
b0b5657
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
58a9ea9
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
a0d30c4
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
7be6bbf
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
b196ac0
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
f2d03ca
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
173ed28
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
26663de
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
5c867d2
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
92c1841
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
c3631f8
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
f35b154
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
85b3ed7
Merge branch 'v5' into fix/hold-guard-operator-approval
hivecommons-hive[bot] Oct 30, 2026
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-hold-guard-operator-approval.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The hold guard no longer re-applies `hold` over a dashboard Approve: when a trusted merger approved the PR's current head through the hive's own decision record and the hive removed the sentinel/hold gate label on their behalf, the guard accepts that head instead of reading the hive's lift as unreviewed drift ([#15644](https://github.com/hivecommons/hive/issues/15644)).
99 changes: 99 additions & 0 deletions src/cmd/hive/hold_guard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/holdguard"
"github.com/hivecommons/hive/pkg/review"
)

func swapHoldGuardStore(t *testing.T, s *holdguard.Store) {
Expand Down Expand Up @@ -1015,3 +1016,101 @@ func TestWriteMergeEligibleExcludesHoldDriftPRs(t *testing.T) {
t.Fatalf("ci_failing = %+v, want only drifted red PR 8 flagged held", failing.CIFailing)
}
}

// swapHoldGuardHumanChangeRequests points the guard's operator-approval
// lookup at a memory-only decision ledger for the test's lifetime.
func swapHoldGuardHumanChangeRequests(t *testing.T) *review.HumanChangeRequests {
t.Helper()
store := review.NewHumanChangeRequests("")
old := holdGuardHumanChangeRequests
holdGuardHumanChangeRequests = func() review.HumanChangeRequestStore { return store }
t.Cleanup(func() { holdGuardHumanChangeRequests = old })
return store
}

func recordHoldGuardDecision(t *testing.T, store *review.HumanChangeRequests, head, actor, kind string) {
t.Helper()
if err := store.Record(review.HumanChangeRequest{
Repo: "acme/widgets", Number: 7, HeadSHA: head, Source: review.HumanChangeRequestSourceDecision,
SourceID: 1, Actor: actor, Body: kind, Kind: kind,
}); err != nil {
t.Fatal(err)
}
}

// hive#15482: the contributor pushed while the PR sat behind the sentinel
// gate; the operator then pressed Approve on the dashboard for that exact
// head and the hive removed the gate label on their behalf. The timeline
// shows a hive lift, which can never cover the head β€” but the head-keyed
// approval record by a trusted merger is the fresh review, so the guard must
// accept the head instead of re-applying `hold` over the approval.
func TestEnforceHoldGuardOperatorApprovalOnCurrentHeadAcceptsHiveLift(t *testing.T) {
store := newTestHoldGuardStore(t)
decisions := swapHoldGuardHumanChangeRequests(t)
recordHoldGuardDecision(t, decisions, "p1", "clubanderson", review.HumanChangeRequestKindApprove)
fake := &holdGuardServer{commits: map[int][]map[string]any{
7: {ghCommit("c1", "odttlnt", "deploy: monitoring"), ghCommit("p1", "odttlnt", "deploy: patch secret")},
}}
fake.timeline = map[int][]map[string]any{
7: gateLiftTimeline("sentinel-alert", "kubestellar-hive[bot]", "Bot", "2026-10-22T18:19:00Z"),
}
client := newHoldGuardClient(t, fake)
client.SetAppBotLogin("kubestellar-hive[bot]")
cfg := escalationTestConfig()
cfg.Dashboard.AuthorizedUsers = []string{"clubanderson:owner"}
store.Snapshot("acme/widgets", 7, "c1", []holdguard.Commit{{SHA: "c1", Author: "odttlnt"}})
store.Touch("acme/widgets", 7, "p1")

got := enforceHoldGuard(context.Background(), cfg, client, client,
actionableWith(github.PullRequest{Repo: "widgets", Number: 7, Author: "odttlnt", HeadSHA: "p1"}), discardLogger())
if got["widgets/7"] {
t.Fatalf("head approved by a trusted merger must not be re-review-gated, got %v", got)
}
if len(fake.comments) != 0 || len(fake.labels) != 0 {
t.Fatalf("comments=%v labels=%v, want no drift comment and no re-hold", fake.comments, fake.labels)
}
if _, ok := store.Recorded("acme/widgets", 7); ok {
t.Fatal("snapshot must clear once the approved head is accepted")
}
}

// The approval must name the head on the branch now: one recorded on the
// pre-push head, or by someone outside the merger tier, is not a review of
// the current tree and the drift path stands.
func TestEnforceHoldGuardOperatorApprovalMustCoverCurrentHeadByTrustedMerger(t *testing.T) {
cases := []struct {
name, head, actor string
users []string
}{
{name: "approval on the old head", head: "c1", actor: "clubanderson", users: []string{"clubanderson:owner"}},
{name: "approver below merger tier", head: "p1", actor: "visitor", users: []string{"visitor:read-write"}},
{name: "approver not authorized", head: "p1", actor: "stranger", users: []string{"clubanderson:owner"}},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
store := newTestHoldGuardStore(t)
decisions := swapHoldGuardHumanChangeRequests(t)
recordHoldGuardDecision(t, decisions, tc.head, tc.actor, review.HumanChangeRequestKindApprove)
fake := &holdGuardServer{commits: map[int][]map[string]any{
7: {ghCommit("c1", "odttlnt", "deploy: monitoring"), ghCommit("p1", "odttlnt", "deploy: patch secret")},
}}
fake.timeline = map[int][]map[string]any{
7: gateLiftTimeline("sentinel-alert", "kubestellar-hive[bot]", "Bot", "2026-10-22T18:19:00Z"),
}
client := newHoldGuardClient(t, fake)
client.SetAppBotLogin("kubestellar-hive[bot]")
cfg := escalationTestConfig()
cfg.Dashboard.AuthorizedUsers = tc.users
store.Snapshot("acme/widgets", 7, "c1", []holdguard.Commit{{SHA: "c1", Author: "odttlnt"}})

got := enforceHoldGuard(context.Background(), cfg, client, client,
actionableWith(github.PullRequest{Repo: "widgets", Number: 7, Author: "odttlnt", HeadSHA: "p1"}), discardLogger())
if !got["widgets/7"] {
t.Fatalf("must still be re-review-gated, got %v", got)
}
if len(fake.labels) != 1 || fake.labels[0] != holdguard.ReHoldLabel {
t.Fatalf("labels=%v, want re-hold", fake.labels)
}
})
}
}
47 changes: 47 additions & 0 deletions src/cmd/hive/main_helpers.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

import (
Expand All @@ -15,6 +15,7 @@
"github.com/hivecommons/hive/pkg/github/automerge"
"github.com/hivecommons/hive/pkg/holdguard"
"github.com/hivecommons/hive/pkg/intent"
"github.com/hivecommons/hive/pkg/review"
"github.com/hivecommons/hive/pkg/stageengine/prstage"
"github.com/hivecommons/hive/pkg/writeback"
)
Expand All @@ -38,6 +39,40 @@
return holdGuardStore
}

// holdGuardHumanChangeRequests resolves the decision ledger the hold guard
// reads operator approvals from; tests swap in a memory-only store.
var holdGuardHumanChangeRequests = func() review.HumanChangeRequestStore {
return review.DefaultHumanChangeRequests()
}

// holdGuardOperatorApproval reports the trusted merger whose recorded
// approval (dashboard Approve or `/hive decision approve`,
// pr_decision_operator.go) stands against exactly headSHA on repo#number.
// The record is head-scoped β€” a newer head supersedes it β€” so it is proof
// the person reviewed the tree on the branch now, which the gate-lift
// timeline cannot show when the hive removed the label for them. Fails
// closed: no record, a change request, an unknown or untrusted actor, or an
// empty head never cover the head.
func holdGuardOperatorApproval(cfg *config.Config, repo string, number int, headSHA string) (string, bool) {
headSHA = strings.TrimSpace(headSHA)
if cfg == nil || headSHA == "" {
return "", false
}
store := holdGuardHumanChangeRequests()
if store == nil {
return "", false
}
req, ok := store.For(repo, number, headSHA)
if !ok || !req.IsApproval() || !strings.EqualFold(strings.TrimSpace(req.HeadSHA), headSHA) {
return "", false
}
login := strings.TrimSpace(req.Actor)
if !trustedMergerFunc(cfg)(login) {
return "", false
}
return login, true
}

// enforceHoldGuard closes #5589: a hold-gated PR that accumulates commits β€”
// from ANY author, but especially from other agents via contaminated worktree
// bases β€” must not sail into the merge lanes when the hold lifts, because the
Expand Down Expand Up @@ -161,6 +196,18 @@
continue
}
}
// A dashboard Approve (or `/hive decision approve`) is recorded
// against the exact head the person saw; the hive then removes the
// gate label on their behalf, so the timeline below shows a hive
// lift that can never cover the head. The head-keyed approval by a
// trusted merger is the review the guard asks for: accept it.
if login, ok := holdGuardOperatorApproval(cfg, repo, pr.Number, pr.HeadSHA); ok {
store.Clear(repo, pr.Number)
logger.Info("hold guard: current head approved by a trusted merger through the hive's decision record; head accepted",
"repo", repo, "pr", pr.Number,
"recorded_head", rec.HeadSHA, "current_head", pr.HeadSHA, "approver", login)
continue
}
if ghClient != nil {
// A trusted human who removed the gate label AFTER the current
// head arrived reviewed the head that is on the branch now; an
Expand Down
Loading