From ab64a959a716964e72a285e822c454550cee3c31 Mon Sep 17 00:00:00 2001 From: sec-check <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 20:28:23 -0400 Subject: [PATCH 1/3] fix(automerge): bind unmarked owner approvals to the head's observed push time workflowFenceApproval judged a typed /hive decision approve (or an unmarked dashboard /approve) as bound to the current head when it was created after headPushedAt. Inside the min_head_age window headPushedAt prefers the head commit's committer date, which the pusher sets, so a later push with a backdated commit inherited an approval given on an earlier head and released the workflow-path fence for it. Approval binding now uses headObservedAt: the PR updated_at pinned on the head's first observation, which is server-side and never predates the push. headPushedAt is unchanged for the soak gate it was built for. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: sec-check <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- ...ed-workflow-fence-approval-head-binding.md | 1 + .../automerge_contributor_lane_test.go | 7 +++ ...automerge_contributor_workflow_approval.go | 6 +- ...erge_contributor_workflow_approval_test.go | 56 +++++++++++++++++++ .../github/automerge/automerge_head_age.go | 30 ++++++++++ 5 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 changelog.d/fixed-workflow-fence-approval-head-binding.md diff --git a/changelog.d/fixed-workflow-fence-approval-head-binding.md b/changelog.d/fixed-workflow-fence-approval-head-binding.md new file mode 100644 index 0000000000..fd64851766 --- /dev/null +++ b/changelog.d/fixed-workflow-fence-approval-head-binding.md @@ -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. diff --git a/src/pkg/github/automerge/automerge_contributor_lane_test.go b/src/pkg/github/automerge/automerge_contributor_lane_test.go index 0cb1993408..32e9733ccb 100644 --- a/src/pkg/github/automerge/automerge_contributor_lane_test.go +++ b/src/pkg/github/automerge/automerge_contributor_lane_test.go @@ -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 @@ -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 { diff --git a/src/pkg/github/automerge/automerge_contributor_workflow_approval.go b/src/pkg/github/automerge/automerge_contributor_workflow_approval.go index 1c24540a00..1a0dd1728a 100644 --- a/src/pkg/github/automerge/automerge_contributor_workflow_approval.go +++ b/src/pkg/github/automerge/automerge_contributor_workflow_approval.go @@ -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 @@ -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) diff --git a/src/pkg/github/automerge/automerge_contributor_workflow_approval_test.go b/src/pkg/github/automerge/automerge_contributor_workflow_approval_test.go index cc98cbb94e..130a473bd6 100644 --- a/src/pkg/github/automerge/automerge_contributor_workflow_approval_test.go +++ b/src/pkg/github/automerge/automerge_contributor_workflow_approval_test.go @@ -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) { diff --git a/src/pkg/github/automerge/automerge_head_age.go b/src/pkg/github/automerge/automerge_head_age.go index a25f680128..00641fcfed 100644 --- a/src/pkg/github/automerge/automerge_head_age.go +++ b/src/pkg/github/automerge/automerge_head_age.go @@ -97,6 +97,36 @@ func (t *HeadFirstSeenTracker) touchLocked(key string, now time.Time) { } } +// 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. +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 From 700a640dfd264fcc1b346e0ec4f4a2598643b9dc Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 23:23:32 -0400 Subject: [PATCH 2/3] docs(automerge): state the re-approve narrowing of the observed-head binding The changelog fragment and headObservedAt doc comment now say that the binding time is pinned on the sweep's first observation of the head, so an owner approval typed between the push and that sweep is judged stale and must be re-typed. Fail-closed by design; code is unchanged. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/fixed-workflow-fence-approval-head-binding.md | 2 +- src/pkg/github/automerge/automerge_head_age.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/changelog.d/fixed-workflow-fence-approval-head-binding.md b/changelog.d/fixed-workflow-fence-approval-head-binding.md index fd64851766..3e0b5b5679 100644 --- a/changelog.d/fixed-workflow-fence-approval-head-binding.md +++ b/changelog.d/fixed-workflow-fence-approval-head-binding.md @@ -1 +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. +- 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. diff --git a/src/pkg/github/automerge/automerge_head_age.go b/src/pkg/github/automerge/automerge_head_age.go index 00641fcfed..93cbe56660 100644 --- a/src/pkg/github/automerge/automerge_head_age.go +++ b/src/pkg/github/automerge/automerge_head_age.go @@ -108,6 +108,11 @@ func (t *HeadFirstSeenTracker) touchLocked(key string, now time.Time) { // 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{} From 244c091fac7f7701a03391e768c31485790a2923 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 23:50:41 -0400 Subject: [PATCH 3/3] docs(automerge): say unmarked approvals bind to the first-observed head, not the push hive-merge.md and operator-reference.md still described the pre-#14754 binding ('posted after the head' / 'bound to it'). State that an unmarked /hive decision approve binds to the PR updated_at pinned on the hive's first sweep of the head, so an approval typed between the push and that sweep is stale and must be re-typed. Hive-Fix-Attempt: 2/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- src/docs/hive-merge.md | 7 ++++++- src/docs/operator-reference.md | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/docs/hive-merge.md b/src/docs/hive-merge.md index 8d9c75a078..5da7eb7ce8 100644 --- a/src/docs/hive-merge.md +++ b/src/docs/hive-merge.md @@ -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=… diff --git a/src/docs/operator-reference.md b/src/docs/operator-reference.md index f5da073492..97ac477351 100644 --- a/src/docs/operator-reference.md +++ b/src/docs/operator-reference.md @@ -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:`, 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). |