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-scanner-skip-busy-branches.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The scanner (and every repair queue) no longer pushes onto a PR branch the hive App did not open while someone else is working on it ([#18488](https://github.com/hivecommons/hive/issues/18488)). A red or conflicted non-App PR whose head was pushed within `HIVE_SCANNER_BUSY_BRANCH_MINUTES` (default 60), or whose PR or linked issue another worker holds a live claim on, moves from FIX-BEFORE-NEW and the CI_FAILING push queue to a "BUSY BRANCHES — suggest, do not push" list, and the agent posts the fix as one suggestion comment for the worker to apply as its own signed commit. Idle branches, App-authored lane branches and in-place adoptions are listed exactly as before.
45 changes: 45 additions & 0 deletions src/cmd/hive/busy_branch_claims_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"path/filepath"
"strings"
"testing"

"github.com/hivecommons/hive/pkg/claims"
)

// hivecommons/hive#18488: the busy-branch guard reads real claims from the
// worker-claim ledger — never kick listings — and reports which hive agent
// holds one so the kicked agent's own claim is not mistaken for another
// worker's.

func TestClaimsPRLeaseLookup(t *testing.T) {
var none *claims.Ledger
if claimsPRLeaseLookup(none, "hivecommons") != nil {
t.Fatal("no ledger must install no lookup")
}
l, err := claims.New(filepath.Join(t.TempDir(), "claims.json"), claims.DefaultPolicy(), claims.Hooks{})
if err != nil {
t.Fatal(err)
}
for _, req := range []claims.Request{
{Repo: "hivecommons/hive", Issue: 18488, Holder: "quality", HolderID: "quality", Kind: claims.KindAgent},
{Repo: "hivecommons/hive", Issue: 18441, Holder: "clubanderson", Kind: claims.KindHuman},
} {
if res, err := l.Claim(req); err != nil || res.Outcome != claims.OutcomeClaimed {
t.Fatalf("claim %+v: outcome=%s err=%v", req, res.Outcome, err)
}
}
lookup := claimsPRLeaseLookup(l, "hivecommons")
// A bare governor repo name is qualified with the org, as the in-flight
// lookup does.
if holder, agent, ok := lookup("hive", 18488); !ok || agent != "quality" || !strings.Contains(holder, "quality") {
t.Fatalf("agent claim: holder=%q agent=%q ok=%v", holder, agent, ok)
}
if holder, agent, ok := lookup("hivecommons/hive", 18441); !ok || agent != "" || !strings.Contains(holder, "clubanderson") {
t.Fatalf("human claim: holder=%q agent=%q ok=%v (a person is never reported as a hive agent)", holder, agent, ok)
}
if _, _, ok := lookup("hivecommons/hive", 1); ok {
t.Fatal("an unclaimed number must not read as busy")
}
}
31 changes: 31 additions & 0 deletions src/cmd/hive/claimswire.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,37 @@ func claimsInflightLookup(ledger *claims.Ledger, org string) scheduler.InflightL
}
}

// claimsPRLeaseLookup adapts the worker-claim ledger to the scheduler's
// busy-branch guard (hivecommons/hive#18488): a live claim on a PR or its
// linked issue means a worker is on that branch. Only real claims count —
// a kick listing is not a worker — and the holding agent is reported so the
// guard can ignore the kicked agent's own claim.
func claimsPRLeaseLookup(ledger *claims.Ledger, org string) scheduler.PRLeaseLookup {
if ledger == nil {
return nil
}
return func(repo string, number int) (string, string, bool) {
if number <= 0 {
return "", "", false
}
c, ok := ledger.Lookup(repo, number)
if !ok && org != "" && !strings.Contains(repo, "/") {
c, ok = ledger.Lookup(org+"/"+repo, number)
}
if !ok {
return "", "", false
}
holderAgent := ""
if c.Kind == claims.KindAgent {
holderAgent = c.HolderID
if holderAgent == "" {
holderAgent = c.Holder
}
}
return fmt.Sprintf("%s (%s) until %s", c.Holder, c.Kind, c.ExpiresAt.UTC().Format(time.RFC3339)), holderAgent, true
}
}

// composeInflight ORs several in-flight lookups; nil entries are skipped.
func composeInflight(lookups ...scheduler.InflightLookup) scheduler.InflightLookup {
var live []scheduler.InflightLookup
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/hive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3512,6 +3512,9 @@ func (b *boot) bootSupervision() {
contributorClaimOverrideLookup(contributorClaimGuard.Load, claimsInflightLookup(b.issueClaims, b.cfg.Project.Org)),
verifyOnceLookup(b.ctx, b.cfg.Project.Org, b.issueClaims, func() *github.Client { return b.ghClient }, b.logger),
claimEscalationLookup(b.ctx, b.cfg, b.issueClaims, func() *github.Client { return b.ghClient }, b.logger)))
// #18488: a live claim on a non-App PR (or its linked issue) keeps the
// repair queues from sending an agent to push onto that branch.
b.sched.SetPRLeaseLookup(claimsPRLeaseLookup(b.issueClaims, b.cfg.Project.Org))
// Dashboard maintainer notes on a listed item ride its kick as private
// context (pkg/scheduler/kick_maintainer_notes.go).
b.sched.SetMaintainerNotesLookup(maintainernotes.Default().List)
Expand Down
11 changes: 11 additions & 0 deletions src/cmd/hive/merge_eligibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/hivecommons/hive/pkg/intent"
"github.com/hivecommons/hive/pkg/rebasemerge"
"github.com/hivecommons/hive/pkg/review"
"github.com/hivecommons/hive/pkg/scheduler"
"github.com/hivecommons/hive/pkg/stageengine/prstage"
"github.com/hivecommons/hive/pkg/stagelabels"
)
Expand Down Expand Up @@ -1121,6 +1122,13 @@ func writeMergeEligible(actionable *github.ActionableResult, hold github.HoldRes
// needs GitHub's own verdict to pick REPAIR vs DE-ESCALATE.
Mergeable string `json:"mergeable,omitempty"`
CIStatus string `json:"ci_status,omitempty"`
// AppAuthored, HeadPushedAt and Issues are the busy-branch evidence
// (hivecommons/hive#18488): a repair queue must not send an agent to
// push onto a branch that is not the hive App's own while another
// worker is on it. See pkg/scheduler/busy_branch.go.
AppAuthored bool `json:"app_authored,omitempty"`
HeadPushedAt *time.Time `json:"head_pushed_at,omitempty"`
Issues []int `json:"issues,omitempty"`
}

prAgents := auditPRAgents(org, time.Now().Add(-auditPRAttributionWindow), "")
Expand Down Expand Up @@ -1258,6 +1266,9 @@ func writeMergeEligible(actionable *github.ActionableResult, hold github.HoldRes
Held: held,
BaseRedChecks: pr.BaseRedChecks,
BaseRed: pr.AllFailuresBaseRed(),
AppAuthored: scheduler.PRAppAuthored(pr),
HeadPushedAt: scheduler.PRHeadPushedAt(pr),
Issues: scheduler.PRIssueNumbers(pr),
}
if adopted {
row.ReachableAction = github.ReachableActionPush
Expand Down
1 change: 1 addition & 0 deletions src/docs/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ behavior. [Maintenance limitations](#keeping-this-reference-current) still apply
| `HIVE_REPO` | No | none | Bootstrap shortcut in `owner/repo` form; fills `project.org`, `project.repos`, and `project.primary_repo` if missing. |
| `HIVE_RELEASE_SENTINEL_ENABLED` | No | `release_sentinel.enabled` (default `false`) | Process-level override for the opt-in release sentinel ([#9585](https://github.com/hivecommons/hive/issues/9585)). `true`/`1`/`on`/`yes` turns it on and `false`/`0`/`off`/`no` turns it off regardless of config; any other value leaves the config in charge. See [release-sentinel.md](release-sentinel.md). |
| `HIVE_RELEASE_SENTINEL_RETAG_ENABLED` | No | `release_sentinel.retag_enabled` (default `false`) | Process-level override for the release sentinel's separate retag opt-in ([#9585](https://github.com/hivecommons/hive/issues/9585)): when on, the hive moves the `v<version>` tag to a merged, marked fix PR's merge commit with one leased, atomic tag push. Same values as `HIVE_RELEASE_SENTINEL_ENABLED`. It never turns retagging on while the sentinel itself is off. See [release-sentinel.md](release-sentinel.md#retag-after-merge). |
| `HIVE_SCANNER_BUSY_BRANCH_MINUTES` | No | `60` | Busy-branch window for the repair queues ([#18488](https://github.com/hivecommons/hive/issues/18488)). A red or conflicted PR the hive App did not open is listed as "suggest, do not push" instead of as a push target while its head is younger than this many minutes or a claim by another worker covers the PR or a linked issue; the agent posts the fix as one suggestion comment for the worker to apply as its own signed commit. Whole minutes; unset, unparsable or non-positive values keep `60`. |
| `HIVE_ATTRIBUTED_CLOSED_PR_LOOKBACK` | No | `14d` | Bounds the per-repo closed-PR attribution scan that feeds dashboard outcome/rework metrics during PR enumeration. The scan lists closed PRs sorted by `updated_at` descending, stops when results are older than this window, and also stops after five pages so large repositories are never walked from history on every governor tick. Values accept Go durations such as `336h`, or day counts such as `14`/`14d`; invalid or non-positive values fall back to `14d`. |
| `HIVE_LEVEL` | No | config/pack value | ACMM level bootstrap/override used by hosted flows and the entrypoint pack selection. |
| `HIVE_ID` | No | config or generated id | Stable hive/spoke identifier override; passed through to launched agents. |
Expand Down
Loading
Loading