From c1d441d0d39fab63b322ab725d2b330912746b4f Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Thu, 19 Nov 2026 12:34:48 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Keep=20agents=20from=20pushing?= =?UTF-8?q?=20their=20own=20commits=20to=20a=20person's=20PR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The trusted-author rebase kick, the FIX-BEFORE-NEW work list and the merge-request re-engagement kick sent the scanner lane to people's PRs with "commit -s, push" and nothing more. It pushed its own follow-up commits and once re-signed a person's commit (#19110, #19102, #19063). The squash lands those under the PR author with the agent's sign-off, which fails "Sign-off survives the squash". Rows for a person's PR now carry person_authored and a shared rule: no own commits, no re-signing, anything beyond the rebase goes in a PR comment. The review-fix prompt signs off only the agent's own commits instead of git rebase --signoff, and the sign-off attribution note no longer says the commits are signed off as the hive App when an agent wrote them. Fixes #19296 Signed-off-by: Andy Anderson --- ...ixed-agent-no-own-commits-on-person-prs.md | 1 + src/cmd/hive/adopted_pr_fixer_test.go | 5 +++ src/cmd/hive/main_sweeps.go | 13 +++---- src/cmd/hive/merge_eligibility.go | 7 ++++ src/cmd/hive/merge_eligible_buckets_test.go | 23 ++++++++++++ .../hive/redpr_fix_kick_no_ci_wait_test.go | 17 +++++++++ .../stage-labels.md | 17 +++++++++ .../automerge_signoff_attribution.go | 4 +-- .../automerge_signoff_attribution_test.go | 8 ++--- .../github/automerge/automerge_stage_dco.go | 2 +- .../automerge/automerge_stage_labels_test.go | 4 +-- src/pkg/review/dispatch.go | 5 ++- src/pkg/review/dispatch_test.go | 3 +- src/pkg/scheduler/fork_aware_queue_test.go | 27 ++++++++++++++ src/pkg/scheduler/policy_overlays.go | 14 +++++++- src/pkg/stagelabels/agent_signoff.go | 31 ++++++++++++++++ src/pkg/stagelabels/agent_signoff_test.go | 35 +++++++++++++++++++ 17 files changed, 198 insertions(+), 18 deletions(-) create mode 100644 changelog.d/fixed-agent-no-own-commits-on-person-prs.md create mode 100644 src/pkg/stagelabels/agent_signoff.go create mode 100644 src/pkg/stagelabels/agent_signoff_test.go diff --git a/changelog.d/fixed-agent-no-own-commits-on-person-prs.md b/changelog.d/fixed-agent-no-own-commits-on-person-prs.md new file mode 100644 index 0000000000..2afcaab961 --- /dev/null +++ b/changelog.d/fixed-agent-no-own-commits-on-person-prs.md @@ -0,0 +1 @@ +- Hive agents no longer push their own commits to a person's PR. Fix kicks for a red or conflicting PR whose author is a person (the FIX-BEFORE-NEW block, the trusted-author rebase and the merge-request re-engagement kick) now say that a commit the agent authors, or its `Signed-off-by` on the person's commit, fails "Sign-off survives the squash", and that any change beyond the rebase goes in a PR comment for the author instead (#19110, #19102, #19063). The review-fix prompt no longer tells agents to run `git rebase --signoff` over the whole branch; it names the `--exec` that signs off only the agent's own commits. diff --git a/src/cmd/hive/adopted_pr_fixer_test.go b/src/cmd/hive/adopted_pr_fixer_test.go index d2c990cbe5..ce62b32c09 100644 --- a/src/cmd/hive/adopted_pr_fixer_test.go +++ b/src/cmd/hive/adopted_pr_fixer_test.go @@ -190,6 +190,11 @@ func TestWriteMergeEligible_TrustedAuthorConflictGetsRebaseKickWithLoopGuard(t * if !row.Conflict || !row.TrustedAuthor || row.ReachableAction != github.ReachableActionPush || row.Agent != "scanner" { t.Errorf("row = %+v, want a trusted-author push conflict row owned by the fallback fixer", row) } + // hivecommons/hive#19102, #19063: the squash lands this PR under the + // person, so the row must tell the fixer it is a person's PR. + if !row.PersonAuthored { + t.Errorf("row = %+v, want person_authored on a trusted author's PR", row) + } if row.RebaseAttempt != 1 || row.RebaseAttemptsMax != rebasemerge.MaxRebaseAttempts || row.BaseRef != "v5" { t.Errorf("row = %+v, want attempt 1/%d onto v5", row, rebasemerge.MaxRebaseAttempts) } diff --git a/src/cmd/hive/main_sweeps.go b/src/cmd/hive/main_sweeps.go index 8599dba9e7..2a024671eb 100644 --- a/src/cmd/hive/main_sweeps.go +++ b/src/cmd/hive/main_sweeps.go @@ -336,12 +336,9 @@ func resolveRedPRFixer(cfg *config.Config, owner string, available func(string) } // redPRFixOwnSignoffExec is the `git rebase --exec` step the no-dco repair -// advice names: it amends with --signoff only a commit whose author email is -// the agent's own (git var GIT_AUTHOR_IDENT honours the lane's pinned -// GIT_AUTHOR_* env), so a person's commit on the PR keeps exactly the -// trailers its author wrote. A blanket `git rebase --signoff` appended the -// agent's bot sign-off to a human's commit on hivecommons/hive#19102. -const redPRFixOwnSignoffExec = `'case "$(git var GIT_AUTHOR_IDENT)" in *"<$(git log -1 --format=%ae)>"*) git commit --amend --no-edit --signoff;; esac'` +// advice names (stagelabels.OwnSignoffRebaseExec): it signs off only the +// agent's own commits, never a person's (hivecommons/hive#19102). +const redPRFixOwnSignoffExec = stagelabels.OwnSignoffRebaseExec // redPRFixKick renders the targeted FIX-BEFORE-NEW kick a re-engagement // delivers. It names ONE PR — the stuck one — with its evidence, so the kick is @@ -360,6 +357,10 @@ func redPRFixKick(o escalation.Observation, rerouted bool) string { b.WriteString(" THEN fix any failing CI the same way.\n") } fmt.Fprintf(&b, " gh pr checkout %d --repo %s → fix → git commit -s → git push\n", o.Number, o.Repo) + // The merge-request re-engagement path reaches this kick for a person's + // PR too (hivecommons/hive#19110: a coverage fix pushed as the lane + // failed the squash sign-off check), and the hook knows no author. + b.WriteString(" If the PR's author is a person, not the hive App or a bot: " + stagelabels.PersonPRAgentCommitRule + "\n") b.WriteString("Push to the SAME branch. Do NOT open a replacement PR.\n") b.WriteString("After the push, STOP: do not watch, poll, or sleep on CI (no gh run watch/view loops).\n") b.WriteString("The automerge sweep merges the PR once it is green; if the failure is infrastructure\n") diff --git a/src/cmd/hive/merge_eligibility.go b/src/cmd/hive/merge_eligibility.go index a8056cecdf..da1e0e6b2d 100644 --- a/src/cmd/hive/merge_eligibility.go +++ b/src/cmd/hive/merge_eligibility.go @@ -1114,6 +1114,12 @@ func writeMergeEligible(actionable *github.ActionableResult, hold github.HoldRes RebaseAttemptsMax int `json:"rebase_attempts_max,omitempty"` BaseRef string `json:"base_ref,omitempty"` TrustedAuthor bool `json:"trusted_author,omitempty"` + // PersonAuthored marks a PR whose GitHub author is a person: not + // hive-authored, not adopted, not a bot account. The squash lands + // every commit under that person, so the kick tells the fixer not + // to push its own commits there (hivecommons/hive#19110, #19102, + // #19063; the attribution check counts no Co-authored-by). + PersonAuthored bool `json:"person_authored,omitempty"` // DeferredIncident is the open [shared-ci] incident issue this red // PR was already deferred to (github.PullRequest.SharedCIIncident, // hivecommons/hive#10528); only red PRs carry one. It applies to a @@ -1280,6 +1286,7 @@ func writeMergeEligible(actionable *github.ActionableResult, hold github.HoldRes BaseRedChecks: pr.BaseRedChecks, BaseRed: pr.AllFailuresBaseRed(), AppAuthored: scheduler.PRAppAuthored(pr), + PersonAuthored: !adopted && !hiveAuthoredPR(pr) && !pr.AuthorNonHuman, HeadPushedAt: scheduler.PRHeadPushedAt(pr), Issues: scheduler.PRIssueNumbers(pr), } diff --git a/src/cmd/hive/merge_eligible_buckets_test.go b/src/cmd/hive/merge_eligible_buckets_test.go index ad596963ad..5857cd6997 100644 --- a/src/cmd/hive/merge_eligible_buckets_test.go +++ b/src/cmd/hive/merge_eligible_buckets_test.go @@ -56,6 +56,7 @@ type failingEntry struct { RebaseAttemptsMax int `json:"rebase_attempts_max"` BaseRef string `json:"base_ref"` TrustedAuthor bool `json:"trusted_author"` + PersonAuthored bool `json:"person_authored"` } type mergeEligibleInputs struct { @@ -620,3 +621,25 @@ func TestWriteMergeEligible_EscalatedNonFailingPRsListedForReviewerLane(t *testi t.Errorf("escalated row mergeable=%q ci_status=%q, want no/success", got.Mergeable, got.CIStatus) } } + +// hivecommons/hive#19110: a person's red PR reaches ci-failing.json and its +// kick sent the fixer to push a coverage fix of its own, which the squash +// lands under the person with the lane's sign-off. Only a person's PR is +// marked person_authored: not the App's, not a bot account's. +func TestWriteMergeEligible_FailingRowMarksPersonAuthored(t *testing.T) { + prs := []github.PullRequest{ + {Repo: "hive", Number: 19110, Author: "clubanderson", CIStatus: "failure", HeadSHA: "a", FailingChecks: []string{"coverage"}}, + {Repo: "hive", Number: 19111, Author: "app/hivecommons-hive", CIStatus: "failure", HeadSHA: "b", FailingChecks: []string{"coverage"}, AppAuthored: true}, + {Repo: "hive", Number: 19112, Author: "some-bot", CIStatus: "failure", HeadSHA: "c", FailingChecks: []string{"coverage"}, AuthorNonHuman: true}, + } + _, failing := runWriteMergeEligible(t, prs, mergeEligibleInputs{org: "hivecommons"}) + want := map[int]bool{19110: true, 19111: false, 19112: false} + if len(failing) != len(want) { + t.Fatalf("failing=%+v, want %d rows", failing, len(want)) + } + for _, f := range failing { + if f.PersonAuthored != want[f.Number] { + t.Errorf("#%d person_authored = %v, want %v", f.Number, f.PersonAuthored, want[f.Number]) + } + } +} diff --git a/src/cmd/hive/redpr_fix_kick_no_ci_wait_test.go b/src/cmd/hive/redpr_fix_kick_no_ci_wait_test.go index 34920b124f..3ec89bc33d 100644 --- a/src/cmd/hive/redpr_fix_kick_no_ci_wait_test.go +++ b/src/cmd/hive/redpr_fix_kick_no_ci_wait_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/hivecommons/hive/pkg/escalation" + "github.com/hivecommons/hive/pkg/stagelabels" ) // The targeted FIX-BEFORE-NEW re-engagement kick carries no policy template, @@ -62,3 +63,19 @@ func TestRedPRFixKickSignsOffOnlyOwnCommits(t *testing.T) { } } } + +// hivecommons/hive#19110: the merge-request re-engagement kick reached a +// person's red PR and the lane pushed its own coverage fix, which the squash +// would land under the person's name with the lane's sign-off. The kick +// carries the person's-PR rule whatever the labels say. +func TestRedPRFixKickCarriesPersonPRRule(t *testing.T) { + for _, o := range []escalation.Observation{ + {Repo: "hivecommons/hive", Number: 19110}, + {Repo: "hivecommons/hive", Number: 19110, Labels: []string{"no-dco"}}, + } { + got := redPRFixKick(o, false) + if !strings.Contains(got, "author is a person") || !strings.Contains(got, stagelabels.PersonPRAgentCommitRule) { + t.Errorf("kick for %v lacks the person's-PR rule:\n%s", o.Labels, got) + } + } +} diff --git a/src/docs/labels-and-control-signals/stage-labels.md b/src/docs/labels-and-control-signals/stage-labels.md index d38d17c2ea..f22efe54ca 100644 --- a/src/docs/labels-and-control-signals/stage-labels.md +++ b/src/docs/labels-and-control-signals/stage-labels.md @@ -504,6 +504,23 @@ sandbox push broker enforces the same rule: it refuses to push a commit that carries the lane's `Signed-off-by` when another identity authored or committed it (see [Sandbox isolation](../sandbox-isolation.md)). +On a **person's PR** (GitHub author not the hive App and not a bot) an agent +pushes no commit of its own and never re-signs the person's commits, unless the +PR carries `merge-method/merge`. The squash lands every commit under the PR +author, and the attribution check counts no `Co-authored-by`, so an agent's +self-signed follow-up (a test fix or refreshed citations after a rebase, a +coverage fix) fails it just like a re-signed commit +([#19110](https://github.com/hivecommons/hive/pull/19110), +[#19102](https://github.com/hivecommons/hive/pull/19102), +[#19063](https://github.com/hivecommons/hive/pull/19063)). The agent may +rebase such a PR (replaying the person's commits with their own trailers); +any other change goes in a PR comment for the author. Every kick that sends an +agent to such a branch carries this rule (`stagelabels.PersonPRAgentCommitRule`): +the FIX-BEFORE-NEW block marks the row `person_authored`, and the targeted +re-engagement kick states it for any author. The rule is prompt-level for +agents that push outside the sandbox push broker, which only sees sandboxed +kicks. + The labels are written on every managed repo; the **072 routing is per repo**. It applies only where the repo actually enforces DCO — detected when a `dco` / `DCO` context is in the branch's required checks or reported on diff --git a/src/pkg/github/automerge/automerge_signoff_attribution.go b/src/pkg/github/automerge/automerge_signoff_attribution.go index 81bc33ad5c..467979ccd6 100644 --- a/src/pkg/github/automerge/automerge_signoff_attribution.go +++ b/src/pkg/github/automerge/automerge_signoff_attribution.go @@ -47,7 +47,7 @@ func signoffAttributionCore(n ContributorNudge, stage stagelabels.Stage) string b.WriteString(SignoffAttributionMarker) b.WriteString("\n") fmt.Fprintf(&b, "@%s this PR is back in your court (`%s`). ", n.Author, stage.Label()) - b.WriteString("Its commits are signed off as the hive App rather than as you, so a squash merge would misattribute them and the sign-off attribution check stays red. No hive agent can rewrite a contributor's commits — the fix is yours:\n\n") + b.WriteString("Some of its commits are signed off by a hive agent, not by you (an agent wrote them or re-signed them), so a squash merge would land them under your name with the agent's sign-off and the sign-off attribution check stays red. No hive agent rewrites a contributor's commits, so the fix is yours:\n\n") for _, a := range n.ReviewAsks { fmt.Fprintf(&b, "- %s\n", a) } @@ -64,7 +64,7 @@ func signoffAttributionChange(headSHA string, hiveSigned int) string { if hiveSigned == 1 { plural = "" } - return fmt.Sprintf("head `%s`, %d commit%s signed off as the hive App", shortSHA(headSHA), hiveSigned, plural) + return fmt.Sprintf("head `%s`, %d commit%s signed off by a hive agent", shortSHA(headSHA), hiveSigned, plural) } // nudgeSignoffAttribution tells a non-clanker author once per PR that the diff --git a/src/pkg/github/automerge/automerge_signoff_attribution_test.go b/src/pkg/github/automerge/automerge_signoff_attribution_test.go index d667527d1e..7c8cdd9ac6 100644 --- a/src/pkg/github/automerge/automerge_signoff_attribution_test.go +++ b/src/pkg/github/automerge/automerge_signoff_attribution_test.go @@ -76,15 +76,15 @@ func TestSignoffAttributionRewrite(t *testing.T) { {name: "same head and asks leave the note alone", previous: first, head: "eb40422ae63967eb7363a3f866e73121c58f2c1b", hiveSigned: 8}, { name: "new head rewrites and records one line", previous: first, head: "2940830726b72f08dff5a1ef6a37bff871b4a7d5", hiveSigned: 20, - wantChanged: true, wantLines: 1, wantLast: "updated 2026-11-04 12:04 UTC: head `2940830726b7`, 20 commits signed off as the hive App", + wantChanged: true, wantLines: 1, wantLast: "updated 2026-11-04 12:04 UTC: head `2940830726b7`, 20 commits signed off by a hive agent", }, { name: "legacy per-head note is adopted under the stable marker", previous: legacy, head: "2940830726b72f08dff5a1ef6a37bff871b4a7d5", hiveSigned: 1, - wantChanged: true, wantLines: 1, wantLast: "updated 2026-11-04 12:04 UTC: head `2940830726b7`, 1 commit signed off as the hive App", + wantChanged: true, wantLines: 1, wantLast: "updated 2026-11-04 12:04 UTC: head `2940830726b7`, 1 commit signed off by a hive agent", }, { name: "history stays capped at five", previous: fiveDeep, head: "dc8ccef2b084b5860f317dacc5037071d78bc1b6", hiveSigned: 30, - wantChanged: true, wantLines: markerHistoryCap, wantLast: "updated 2026-11-04 12:04 UTC: head `dc8ccef2b084`, 30 commits signed off as the hive App", + wantChanged: true, wantLines: markerHistoryCap, wantLast: "updated 2026-11-04 12:04 UTC: head `dc8ccef2b084`, 30 commits signed off by a hive agent", }, } { t.Run(tc.name, func(t *testing.T) { @@ -164,7 +164,7 @@ func TestApplyStageLabelsSignoffAttributionUpsertsAcrossHeads(t *testing.T) { if !strings.HasPrefix(last, SignoffAttributionMarker+"\n") || !strings.Contains(last, "Current head: `"+head+"`.") { t.Fatalf("head %s: edit not the upserted note:\n%s", head, last) } - if _, hist := splitMarkerHistory(last); len(hist) != i+1 || !strings.Contains(hist[i], "head `"+head+"`, 1 commit signed off as the hive App") { + if _, hist := splitMarkerHistory(last); len(hist) != i+1 || !strings.Contains(hist[i], "head `"+head+"`, 1 commit signed off by a hive agent") { t.Fatalf("head %s: history %q", head, hist) } } diff --git a/src/pkg/github/automerge/automerge_stage_dco.go b/src/pkg/github/automerge/automerge_stage_dco.go index a8af6c9969..54f19e2610 100644 --- a/src/pkg/github/automerge/automerge_stage_dco.go +++ b/src/pkg/github/automerge/automerge_stage_dco.go @@ -325,6 +325,6 @@ func signoffAttributionAsk(d stageDetail) string { if n == 1 { plural, pronoun = " is", "it" } - return fmt.Sprintf("%d commit%s signed off as the hive App instead of you, so a squash merge would misattribute %s — set `git config user.email` to your own address, then run `%s`", + return fmt.Sprintf("%d commit%s signed off by a hive agent, not by you, so a squash merge would misattribute %s: set `git config user.email` to your own address, then run `%s`", n, plural, pronoun, signoffResetCommand(max(d.DCOTotal, n))) } diff --git a/src/pkg/github/automerge/automerge_stage_labels_test.go b/src/pkg/github/automerge/automerge_stage_labels_test.go index 94ffc371f1..6e152c17ef 100644 --- a/src/pkg/github/automerge/automerge_stage_labels_test.go +++ b/src/pkg/github/automerge/automerge_stage_labels_test.go @@ -2276,11 +2276,11 @@ func TestApplyStageLabelsHiveBotSignoffOnHumanHeadNeedsAuthorWithInstructions(t func TestSignoffAttributionAsk(t *testing.T) { one := signoffAttributionAsk(stageDetail{DCOTotal: 1, DCOSquashUnsafeHive: 1}) - if !strings.Contains(one, "1 commit is signed off as the hive App") || !strings.Contains(one, "`git commit --amend --reset-author -s && git push --force-with-lease`") { + if !strings.Contains(one, "1 commit is signed off by a hive agent") || !strings.Contains(one, "`git commit --amend --reset-author -s && git push --force-with-lease`") { t.Fatalf("one: %s", one) } many := signoffAttributionAsk(stageDetail{DCOTotal: 3, DCOSquashUnsafeHive: 2}) - if !strings.Contains(many, "2 commits are signed off as the hive App") || !strings.Contains(many, "git rebase --exec 'git commit --amend --no-edit --reset-author -s' HEAD~3 && git push --force-with-lease") { + if !strings.Contains(many, "2 commits are signed off by a hive agent") || !strings.Contains(many, "git rebase --exec 'git commit --amend --no-edit --reset-author -s' HEAD~3 && git push --force-with-lease") { t.Fatalf("many: %s", many) } if zero := signoffAttributionAsk(stageDetail{}); !strings.Contains(zero, "1 commit is") { diff --git a/src/pkg/review/dispatch.go b/src/pkg/review/dispatch.go index 8a0f6452e3..fa817bcef5 100644 --- a/src/pkg/review/dispatch.go +++ b/src/pkg/review/dispatch.go @@ -1801,7 +1801,10 @@ func BuildFixPrompt(pr PullRequest, agg Aggregate, attempt, maxAttempts int) str } fmt.Fprintf(&b, "Auto-fix attempt %d of %d. Stay narrowly scoped to the review findings below; push a new commit to the PR branch.\n\n", attempt, maxAttempts) fmt.Fprintf(&b, "When committing the fix, include this exact git trailer so rework metrics can count the attempt: Hive-Fix-Attempt: %d/%d\n\n", attempt, maxAttempts) - b.WriteString("REQUIRED: every follow-up commit MUST carry a Signed-off-by trailer — create it with `git commit -s`, and run `git rebase --signoff` before pushing if any new commit lacks one. An unsigned fix commit bounces the PR to no-dco.\n\n") + // Sign only the agent's own commits: a blanket `git rebase --signoff` + // re-signs every commit in the range, a contributor's too + // (hivecommons/hive#19267 and its follow-up audit). + b.WriteString("REQUIRED: every follow-up commit MUST carry a Signed-off-by trailer: create it with `git commit -s`, and if a commit you authored lacks one, sign off ONLY your own commits before pushing: `git rebase --exec " + stagelabels.OwnSignoffRebaseExec + "`. Never add your Signed-off-by to a commit someone else wrote. An unsigned fix commit bounces the PR to no-dco.\n\n") if req := pr.HumanChangeRequest; req != nil && strings.TrimSpace(req.Body) != "" { b.WriteString(humanChangeRequestPromptSection(*req)) } diff --git a/src/pkg/review/dispatch_test.go b/src/pkg/review/dispatch_test.go index 49f832cfc8..14ac763579 100644 --- a/src/pkg/review/dispatch_test.go +++ b/src/pkg/review/dispatch_test.go @@ -9,6 +9,7 @@ import ( "github.com/hivecommons/hive/pkg/config" "github.com/hivecommons/hive/pkg/escalation" "github.com/hivecommons/hive/pkg/outputschema" + "github.com/hivecommons/hive/pkg/stagelabels" ) func reviewer(name string) AgentCapability { @@ -170,7 +171,7 @@ func TestBuildFixPromptAndCapExhaustion(t *testing.T) { if !strings.Contains(prompt, "nil panic") || !strings.Contains(prompt, "attempt 1") || !strings.Contains(prompt, "Hive-Fix-Attempt: 1/") || !strings.Contains(prompt, "acme/hive#7") { t.Fatalf("fix prompt missing expected context:\n%s", prompt) } - if !strings.Contains(prompt, "git commit -s") || !strings.Contains(prompt, "git rebase --signoff") || !strings.Contains(prompt, "Signed-off-by") { + if !strings.Contains(prompt, "git commit -s") || !strings.Contains(prompt, stagelabels.OwnSignoffRebaseExec) || strings.Contains(prompt, "git rebase --signoff") || !strings.Contains(prompt, "Signed-off-by") { t.Fatalf("fix prompt must require sign-off on follow-up commits:\n%s", prompt) } state := DispatchState{} diff --git a/src/pkg/scheduler/fork_aware_queue_test.go b/src/pkg/scheduler/fork_aware_queue_test.go index 9ecc7be187..58ce7eba98 100644 --- a/src/pkg/scheduler/fork_aware_queue_test.go +++ b/src/pkg/scheduler/fork_aware_queue_test.go @@ -15,6 +15,7 @@ import ( "testing" "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/stagelabels" ) const forkQueueFixture = `{"generated_at":"2026-09-17T00:00:00Z","ci_failing":[ @@ -254,3 +255,29 @@ func TestRebaseResolveInstructions(t *testing.T) { } } } + +// hivecommons/hive#19110, #19102, #19063: the FIX-BEFORE-NEW block sent the +// fixer to a person's PR with "commit -s → git push" and nothing else, and its +// own follow-up commits failed `Sign-off survives the squash`. A person's row +// carries the rule; the hive's own PR does not. +func TestFormatRedPRFixData_PersonAuthoredRowCarriesSignoffRule(t *testing.T) { + data := `{"ci_failing":[` + + `{"number":19110,"repo":"hivecommons/hive","title":"human red","author":"clubanderson","failing_checks":["coverage"],"person_authored":true},` + + `{"number":19102,"repo":"hivecommons/hive","title":"human dirty","author":"clubanderson","conflict":true,"mergeable_state":"dirty","trusted_author":true,"person_authored":true,"base_ref":"v5","rebase_attempt":1,"rebase_attempts_max":2},` + + `{"number":19200,"repo":"hivecommons/hive","title":"hive red","author":"app/hivecommons-hive","app_authored":true,"failing_checks":["test"]}` + + `]}` + out := formatRedPRFixData([]byte(data), "scanner") + if got := strings.Count(out, stagelabels.PersonPRAgentCommitRule); got != 2 { + t.Fatalf("person's-PR rule appears %d times, want once per person's row:\n%s", got, out) + } + if !strings.Contains(out, "PERSON'S PR (author clubanderson)") { + t.Errorf("rule does not name the author:\n%s", out) + } + hive := out[strings.Index(out, "#19200"):] + if strings.Contains(hive, "PERSON'S PR") { + t.Errorf("the hive's own PR got the person's-PR rule:\n%s", hive) + } + if !strings.Contains(out, "add no commit or Signed-off-by of your own") { + t.Errorf("trusted-author rebase lacks the no-own-commit clause:\n%s", out) + } +} diff --git a/src/pkg/scheduler/policy_overlays.go b/src/pkg/scheduler/policy_overlays.go index f5e5957b0f..b821968f53 100644 --- a/src/pkg/scheduler/policy_overlays.go +++ b/src/pkg/scheduler/policy_overlays.go @@ -10,6 +10,7 @@ import ( "github.com/hivecommons/hive/pkg/github" "github.com/hivecommons/hive/pkg/review" + "github.com/hivecommons/hive/pkg/stagelabels" ) const ( @@ -303,6 +304,7 @@ func formatRedPRFixDataWithTopics(data []byte, agent string, signals []github.CI Number int `json:"number"` Repo string `json:"repo"` Title string `json:"title"` + Author string `json:"author"` Agent string `json:"agent"` FailingChecks []string `json:"failing_checks"` Excerpt string `json:"excerpt"` @@ -323,6 +325,7 @@ func formatRedPRFixDataWithTopics(data []byte, agent string, signals []github.CI RebaseMax int `json:"rebase_attempts_max"` BaseRef string `json:"base_ref"` TrustedAuthor bool `json:"trusted_author"` + PersonAuthored bool `json:"person_authored"` AppAuthored bool `json:"app_authored"` HeadPushedAt *time.Time `json:"head_pushed_at"` Issues []int `json:"issues"` @@ -478,6 +481,15 @@ func formatRedPRFixDataWithTopics(data []byte, agent string, signals []github.CI b.WriteString(" " + adoptedSentinelNote + "\n") } } + if pr.PersonAuthored && !pr.Adopted { + // hivecommons/hive#19110, #19102, #19063: own follow-up commits + // pushed to a person's PR fail the squash sign-off check. + who := "a person" + if a := strings.TrimSpace(pr.Author); a != "" { + who = a + } + b.WriteString(" PERSON'S PR (author " + who + "): " + stagelabels.PersonPRAgentCommitRule + "\n") + } if pr.Conflict { state := strings.TrimSpace(pr.MergeableState) if state == "" { @@ -860,7 +872,7 @@ func rebaseResolveInstructions(baseRef string, attempt, max int, trustedAuthor b var b strings.Builder fmt.Fprintf(&b, "rebase-resolve (attempt %d/%d): `gh pr checkout`, `git rebase %s`, resolve every conflict keeping both sides' intent, re-run the build and tests, then `git push --force-with-lease` to the PR's OWN branch. Do not open a new PR; do not squash away the author's commits.", attempt, max, base) if trustedAuthor { - b.WriteString(" This is a trusted author's PR the hive carries on their behalf — keep their authorship and sign-off intact.") + b.WriteString(" This is a trusted author's PR the hive carries on their behalf: replay their commits with their authorship and sign-off intact, and add no commit or Signed-off-by of your own.") } if attempt >= max { b.WriteString(" Last attempt: if the head is still conflicting after this push the hive stops and asks a person.") diff --git a/src/pkg/stagelabels/agent_signoff.go b/src/pkg/stagelabels/agent_signoff.go new file mode 100644 index 0000000000..498192c7af --- /dev/null +++ b/src/pkg/stagelabels/agent_signoff.go @@ -0,0 +1,31 @@ +package stagelabels + +// Agent sign-off rules shared by every kick that sends an agent to commit on +// a PR branch (hivecommons/hive#19267 and its follow-up audit). +// +// `Sign-off survives the squash` (.github/workflows/dco-squash-attribution.yml) +// fails a PR whose squash would land a commit under the PR author's name with +// a Signed-off-by that does not name that author. On a person's PR that is +// every commit an agent authors (its own sign-off) and every person's commit +// an agent re-signs. Co-authored-by does not count as a sign-off there, so +// the only compliant agent work on such a branch is a rebase that replays the +// person's commits with their own trailers, unless the PR carries +// MergeCommitLabel (a merge commit lands each commit as it is). + +// OwnSignoffRebaseExec is the `git rebase --exec` step that amends with +// --signoff only a commit whose author email is the agent's own (git var +// GIT_AUTHOR_IDENT honours the lane's pinned GIT_AUTHOR_* env), so a +// person's commit keeps exactly the trailers its author wrote. A blanket +// `git rebase --signoff` appended the agent's sign-off to a human's commit on +// hivecommons/hive#19102. +const OwnSignoffRebaseExec = `'case "$(git var GIT_AUTHOR_IDENT)" in *"<$(git log -1 --format=%ae)>"*) git commit --amend --no-edit --signoff;; esac'` + +// PersonPRAgentCommitRule is the instruction for an agent repairing a PR +// whose GitHub author is a person rather than the hive App or a bot. The +// bad commits on hivecommons/hive#19110, #19102 and #19063 were all agent +// follow-ups pushed to such a branch (citation refreshes and test fixes after +// a rebase, a coverage fix), plus one person's commit re-signed by the lane. +const PersonPRAgentCommitRule = "the squash lands every commit under that person's name, so a commit you author, or your Signed-off-by on a commit they wrote, fails `Sign-off survives the squash` and sends the PR back to them. " + + "Unless the PR carries `" + MergeCommitLabel + "`, do NOT push a commit of your own to it and NEVER add your Signed-off-by to their commits " + + "(never commit, amend or rebase their work with `-s`; a rebase replays their commits with only their own trailers). " + + "Any change beyond resolving a conflict inside their commits (a test fix, refreshed citations, a changelog fragment) goes in one PR comment naming the exact edit for the author; then move on." diff --git a/src/pkg/stagelabels/agent_signoff_test.go b/src/pkg/stagelabels/agent_signoff_test.go new file mode 100644 index 0000000000..88efc6f4b4 --- /dev/null +++ b/src/pkg/stagelabels/agent_signoff_test.go @@ -0,0 +1,35 @@ +package stagelabels + +import ( + "strings" + "testing" +) + +// The rule is what keeps an agent from pushing its own commit to a person's +// PR (hivecommons/hive#19110, #19102, #19063): it must name the check that +// fails, the one label that makes own commits safe, and both forbidden acts. +func TestPersonPRAgentCommitRuleNamesCheckLabelAndForbiddenActs(t *testing.T) { + for _, want := range []string{ + "Sign-off survives the squash", + MergeCommitLabel, + "do NOT push a commit of your own", + "NEVER add your Signed-off-by to their commits", + "PR comment", + } { + if !strings.Contains(PersonPRAgentCommitRule, want) { + t.Errorf("rule lacks %q: %s", want, PersonPRAgentCommitRule) + } + } + if strings.Contains(PersonPRAgentCommitRule, "—") { + t.Errorf("rule carries an em-dash, which the outbound filter rewrites: %s", PersonPRAgentCommitRule) + } +} + +// The exec must amend only a commit whose author email is the lane's own. +func TestOwnSignoffRebaseExecSignsOnlyOwnCommits(t *testing.T) { + for _, want := range []string{"git var GIT_AUTHOR_IDENT", "git log -1 --format=%ae", "git commit --amend --no-edit --signoff"} { + if !strings.Contains(OwnSignoffRebaseExec, want) { + t.Errorf("exec %q lacks %q", OwnSignoffRebaseExec, want) + } + } +}