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-workflow-fence-approval-head-binding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The contributor lane now binds an unmarked owner approval (a typed `/hive decision approve`, or a dashboard `/approve` posted without a head marker) to the time GitHub first showed the PR's current head, never to the head commit's committer date. That date is written by the pusher's git, so a later push carrying a backdated commit could inherit an approval given on the head before it and release the workflow-path fence for a diff the approver never saw. An approval older than the observed head now leaves the fence armed, exactly like an APPROVED review on a stale commit; the approver re-approves the new head to release it. This is deliberately fail-closed and slightly narrower than before: the observed time is pinned on the hive's first sweep of the head, and any comment or label that lands between the push and that sweep moves it later, so an approval typed in that gap is also treated as stale and has to be typed again. A head with no pinned time yet binds nothing.
7 changes: 6 additions & 1 deletion src/docs/hive-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,12 @@ A PR merges through this tier only when all of the following hold:
same bar that releases a `requires_human` verdict), or a dashboard
approval (`/hive decision approve`, which posts `/lgtm` + `/approve`
attributed to the maintainer and bound to the head) or a trusted merger's
own `/hive decision approve` comment posted after the head. Approval on an
own `/hive decision approve` comment posted after the hive first observed
the head. An unmarked approval is bound to the PR `updated_at` pinned on
the hive's first sweep of the head, not to the push: an approval typed
between the push and that sweep is judged stale and must be typed again
(fail-closed by design,
[#14754](https://github.com/hivecommons/hive/issues/14754)). Approval on an
earlier head never counts: a new push re-arms the fence and the 085 note
reads "awaiting owner approval … re-approve after a push". When released
the lane logs `workflow-path fence released by owner approval login=…
Expand Down
2 changes: 1 addition & 1 deletion src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ advanced into the merge path.
| `auto_merge.contributor_lane.auto_promotion_scope` | `hive` | Where the clean-merged-PR ratchet (`auto_merge.contributor_tier.auto_promote_after_merged`) counts an author's merges: `hive` counts across every repository the hive manages (one `search/issues` query finds the repos holding the author's merges; the PR's own repo is always walked first), `repo` counts only the PR's repository. Revert and sentinel-alert evidence blocks promotion in either scope. |
| `auto_merge.contributor_tier.auto_promote_after_merged` | `5` | Clean merged PRs (no revert, no sentinel label, not undone by a later merged revert) after which the contributor lane treats an author as `trusted` without an operator grant, unless the registry marks them `revoked`. Negative disables the ratchet. |
| `auto_merge.contributor_lane.approve_held_runs_for_registry_trusted` | `true` | When the registry path admitted the PR author and the lane stops at `required-check-missing:<ctx>`, approve the head's `action_required` workflow runs once (`POST /repos/{owner}/{repo}/actions/runs/{id}/approve`, fork heads included), post one `hive:contributor-held-runs-approved` audit comment and log `contributor-lane approved held runs`. Never acts for claim-marker, auto-promoted or association admissions, sentinel/exclude-labelled PRs, or diffs touching `.github/workflows/**`. Needs the App's **Actions: Read and write** permission. See [hive-merge.md](hive-merge.md#contributor-lane-auto-merge). |
| `auto_merge.contributor_lane.owner_approval_releases_workflow_fence` | `true` | A hive owner / trusted merger's explicit approval on the **current** head β€” a GitHub `APPROVED` review on that commit, or a dashboard `/hive decision approve` bound to it β€” releases the contributor lane's `contributor-lane:workflow-path` fence, so the lane merges a PR editing `.github/workflows/**` / `.github/actions/**` itself once CI, soak and the other gates are clear. Logs `workflow-path fence released by owner approval`, leaves one `hive:workflow-approval` audit comment per head; approval on an older head does not count. Needs the App's **Workflows: Read and write**; without it the merge is refused, the PR is marked `hive:unauthorized` (`merge-workflow-path`) and parks at 090 for a person's click. `false` keeps every workflow-path PR a person's merge ([#14664](https://github.com/hivecommons/hive/issues/14664)). See [hive-merge.md](hive-merge.md#contributor-lane-auto-merge). |
| `auto_merge.contributor_lane.owner_approval_releases_workflow_fence` | `true` | A hive owner / trusted merger's explicit approval on the **current** head β€” a GitHub `APPROVED` review on that commit, or a dashboard `/hive decision approve` bound to it β€” releases the contributor lane's `contributor-lane:workflow-path` fence, so the lane merges a PR editing `.github/workflows/**` / `.github/actions/**` itself once CI, soak and the other gates are clear. Logs `workflow-path fence released by owner approval`, leaves one `hive:workflow-approval` audit comment per head; approval on an older head does not count. An unmarked approval binds to the PR `updated_at` pinned on the hive's first sweep of the head, not to the push, so one typed between the push and that sweep is judged stale and must be typed again ([#14754](https://github.com/hivecommons/hive/issues/14754)). Needs the App's **Workflows: Read and write**; without it the merge is refused, the PR is marked `hive:unauthorized` (`merge-workflow-path`) and parks at 090 for a person's click. `false` keeps every workflow-path PR a person's merge ([#14664](https://github.com/hivecommons/hive/issues/14664)). See [hive-merge.md](hive-merge.md#contributor-lane-auto-merge). |
| `auto_merge.contributor_lane.repos` | empty = all watched repos | Optional repo allow-list for the contributor-lane tier (bare name or `owner/repo`). |
| `auto_merge.contributor_lane.exclude_labels` | `hold`, `do-not-merge`, `needs-human`, `blocked`, `needs-rebase` | Labels that keep a PR out of contributor-lane auto-merge (`do-not-merge/*` always excluded). |

Expand Down
7 changes: 7 additions & 0 deletions src/pkg/github/automerge/automerge_contributor_lane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ type contributorLaneFixture struct {
// endpoint reports for sha7 (RFC 3339) and the PR's updated_at; empty
// leaves the route unserved and the timestamp omitted.
headCommittedAt string
// prUpdatedAt, when set, overrides the PR's updated_at (RFC 3339) so a
// test can give the head a committer date that disagrees with when
// GitHub actually saw it pushed.
prUpdatedAt string
// headStatus, when set, is the combined-status state and check-run
// conclusion reported for sha7; empty means "success".
headStatus string
Expand Down Expand Up @@ -179,6 +183,9 @@ func newContributorLaneAPI(t *testing.T, fx *contributorLaneFixture) *httptest.S
if fx.headCommittedAt != "" {
p["updated_at"] = fx.headCommittedAt
}
if fx.prUpdatedAt != "" {
p["updated_at"] = fx.prUpdatedAt
}
return p
}
switch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ package automerge
// and `/approve` attributed to the maintainer β€” ParsePRApprovalCommandComment)
// or a person's own `/hive decision approve` comment, by a trusted
// merger, bound to the current head: the comment's head marker names
// it, or the comment was posted after the head was pushed.
// it, or the comment was posted after the head was first observed
// (headObservedAt β€” the pinned server-side updated_at, never the
// commit's own committer date, which the pusher chooses).
//
// Approval on an older head never counts, so a new push re-arms the fence.
// A released fence is logged once per head and leaves one audit marker per
Expand Down Expand Up @@ -107,7 +109,7 @@ func (c *Engine) workflowFenceApproval(ctx context.Context, owner, repo string,
if login, ok := c.latestTrustedHumanApproval(ctx, owner, repo, number, headSHA); ok {
return login, true
}
headPushedAt := c.headPushedAt(ctx, owner, repo, number, headSHA, pr)
headPushedAt := c.headObservedAt(owner, repo, number, headSHA, pr)
appLogin := strings.TrimSpace(c.transport.AppBotLogin())
for i := len(comments) - 1; i >= 0; i-- {
login, ok := workflowApprovalCommentActor(comments[i], headSHA, headPushedAt, appLogin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,62 @@ func TestContributorLaneWorkflowFenceOwnerApproval(t *testing.T) {
}
}

// An unmarked approval binds to when GitHub first showed the head, never to
// the head commit's committer date: that date is whatever the pusher's git
// wrote, so a later push carrying a backdated commit must not inherit an
// approval typed on the head before it β€” even while the min_head_age window
// (where headPushedAt lets the committer date win) is still open.
func TestContributorLaneWorkflowFenceApprovalIgnoresCommitterDate(t *testing.T) {
const clockAt = "2026-10-27T13:00:00Z"
for _, tc := range []struct {
name string
comment map[string]any
wantReason string
wantMerges int
}{
{
name: "typed approve older than the observed push, committer date backdated",
comment: map[string]any{"id": 5, "user": map[string]string{"login": "clubanderson"}, "body": "/hive decision approve", "created_at": "2026-10-27T12:00:00Z"},
wantReason: contributorLaneReasonWorkflowPath,
},
{
name: "unmarked dashboard approve older than the observed push, committer date backdated",
comment: dashboardApproveComment(5, "clubanderson", "", "2026-10-27T12:00:00Z"),
wantReason: contributorLaneReasonWorkflowPath,
},
{
name: "typed approve after the observed push still releases",
comment: map[string]any{"id": 5, "user": map[string]string{"login": "clubanderson"}, "body": "/hive decision approve", "created_at": "2026-10-27T12:50:00Z"},
wantMerges: 1,
},
} {
t.Run(tc.name, func(t *testing.T) {
fx := validContributorFixture()
fx.files = workflowPathFiles()
// Commit claims 10:00; GitHub first showed this head at 12:40.
fx.headCommittedAt = "2026-10-27T10:00:00Z"
fx.prUpdatedAt = "2026-10-27T12:40:00Z"
fx.prComments = []map[string]any{tc.comment}
api := newContributorLaneAPI(t, &fx)
defer api.Close()
policy := defaultContributorLanePolicy()
policy.OwnerApprovalReleasesWorkflowFence = true
clock := &contributorLaneClock{at: mustParseTime(t, clockAt)}
// A min_head_age wider than the head's observed age keeps
// headPushedAt's committer-date branch live for the whole test.
engine := newContributorLaneEngine(api.URL, policy, clock, Options{ContributorSoak: soakedTracker(clock), MinHeadAge: time.Hour})
engine.SetMergerAuthorizer(func(login string) bool { return strings.EqualFold(login, "clubanderson") })
_, reason, err := engine.trySweepContributorLanePR(context.Background(), "widget", "acme", "widget", 7, policy)
if err != nil {
t.Fatal(err)
}
if reason != tc.wantReason || fx.merges != tc.wantMerges {
t.Fatalf("reason=%q merges=%d, want %q/%d (comments=%v)", reason, fx.merges, tc.wantReason, tc.wantMerges, fx.allComments)
}
})
}
}

// The audit marker is left once per head: a second tick on a head already
// marked merges without a second comment.
func TestContributorLaneWorkflowFenceMarkerOncePerHead(t *testing.T) {
Expand Down
35 changes: 35 additions & 0 deletions src/pkg/github/automerge/automerge_head_age.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package automerge

import (
Expand Down Expand Up @@ -97,6 +97,41 @@
}
}

// headObservedAt is the time an approval must post-date to count for pr at
// sha: the PR updated_at pinned when the sweep first saw this head. It is
// server-side and never earlier than the push that produced the head.
//
// It deliberately differs from headPushedAt, which lets the head commit's
// committer date win while the min_head_age window is open. That date is
// whatever the pusher's git wrote (GIT_COMMITTER_DATE), so a later push can
// carry a date older than an approval typed on an earlier head and inherit
// it. Shortening a soak with a backdated commit is tolerable; re-attributing
// a person's approval to a head they never saw is not. Zero when the head
// has no pinned time yet, which binds nothing.
//
// The pin is taken on the sweep's first observation, not at the push, and any
// comment or label landing in between moves it later. An approval typed in
// that gap is therefore judged stale and must be re-typed: fail-closed by
// design, the accepted price of not trusting a pusher-written clock.
func (c *Engine) headObservedAt(owner, repo string, number int, sha string, pr *gh.PullRequest) time.Time {
if strings.TrimSpace(sha) == "" {
return time.Time{}
}
var updated time.Time
if updatedAt := pr.GetUpdatedAt(); !updatedAt.IsZero() {
updated = updatedAt.Time
}
tracker := sharedHeadFirstSeen
if c != nil && c.headFirstSeen != nil {
tracker = c.headFirstSeen
}
now := time.Now
if c != nil && c.now != nil {
now = c.now
}
return tracker.observe(contributorSoakKey(owner, repo, number, sha), updated, now())
}

// headPushedAt is the HeadPushedAt fed to the min_head_age gate for pr at
// sha. It is never the PR's live updated_at (#12557): the hive's own label
// flips and stage-regressed comments bump updated_at, and measuring from it
Expand Down
Loading