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/added-18898-contributor-owner-grace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **The contributor lane waits 15 minutes before claiming an issue an owner, maintainer or the hive itself just filed.** `governor.claims.contributor_grace_s` (default `900`; negative turns it off) withholds an issue whose author is an owner/maintainer (author association `OWNER`, `MEMBER`, `COLLABORATOR`) or this hive's own App from `selectTask` and the Ready queue (Withheld reason `owner_grace`) and refuses a contributor's fresh ledger claim with `owner grace: filed by <login> 3m ago; ...`, so the owner or the owner's dispatcher can claim first; #18866 and #18880 each grew a duplicate contributor PR because the lane claimed within seconds of filing. A person adding `help wanted` after filing waives the grace. Live leases, hive agents and outside reporters are unaffected. ([#18898](https://github.com/hivecommons/hive/issues/18898), part of [#18890](https://github.com/hivecommons/hive/issues/18890)).
37 changes: 37 additions & 0 deletions src/cmd/hive/claims_admission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"sync/atomic"
"testing"
"time"

"github.com/hivecommons/hive/pkg/claims"
"github.com/hivecommons/hive/pkg/config"
Expand Down Expand Up @@ -294,3 +295,39 @@ func TestRecordAgentStartFiledClaimLedgersSelfFiledIssue(t *testing.T) {
t.Fatalf("another agent's dispatch of the self-filed issue = %+v, %v; want held by scanner", res, err)
}
}

// hivecommons/hive#18898: a contributor's fresh claim on an issue an owner
// filed moments ago is refused with the owner-grace reason; the same issue
// after the window, or a hive agent's own claim on it, is admitted.
func TestContributorClaimRefusedInsideOwnerGrace(t *testing.T) {
var ageMin atomic.Int64
ageMin.Store(2)
api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/repos/o/r/issues/7" {
http.NotFound(w, r)
return
}
created := time.Now().Add(-time.Duration(ageMin.Load()) * time.Minute).UTC().Format(time.RFC3339)
fmt.Fprintf(w, `{"number":7,"state":"open","created_at":%q,"author_association":"OWNER","user":{"login":"andy"},"labels":[]}`, created)
}))
defer api.Close()
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
client := github.NewClientForTest(api.URL, "o", []string{"r"}, logger)
client.SetContributorGrace(15 * time.Minute)
ledger := testClaimsLedger(t)
installClaimAdmissionCheck(context.Background(), ledger, func() *github.Client { return client })

req := claims.Request{Repo: "o/r", Issue: 7, Holder: "karibhou", HolderID: "c-1", Kind: claims.KindContributor}
res, err := ledger.Claim(req)
if err != nil || res.Outcome != claims.OutcomeRefused || !strings.HasPrefix(res.Reason, github.ClaimBlockReasonOwnerGracePrefix) {
t.Fatalf("claim inside the grace = %+v, %v; want refused with the owner grace reason", res, err)
}
if _, held := ledger.Lookup("o/r", 7); held {
t.Fatal("a refused contributor claim must not be recorded")
}
ageMin.Store(30)
res, err = ledger.Claim(req)
if err != nil || res.Outcome != claims.OutcomeClaimed {
t.Fatalf("claim after the grace = %+v, %v; want claimed", res, err)
}
}
6 changes: 6 additions & 0 deletions src/cmd/hive/claimswire.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ func installClaimAdmissionCheck(ctx context.Context, ledger *claims.Ledger, clie
if req.Kind == claims.KindAgent {
return gh.IssueStartBlockReason(ctx, req.Repo, req.Issue, req.Holder)
}
// A contributor's fresh claim also waits out the owner grace on
// an issue an owner, maintainer or this hive filed moments ago
// (hivecommons/hive#18898).
if req.Kind == claims.KindContributor {
return gh.IssueContributorDispatchBlockReason(ctx, req.Repo, req.Issue)
}
return gh.IssueDispatchBlockReason(ctx, req.Repo, req.Issue)
}
return gh.IssueClaimBlockReason(ctx, req.Repo, req.Issue)
Expand Down
1 change: 1 addition & 0 deletions src/cmd/hive/github_client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (b *boot) applyGitHubClientConfigHooks(client *github.Client) {
// Umbrella issues no automated claim may take and no claim stages
// (governor.claims.never_claim_labels, default `epic`).
client.SetNeverClaimLabels(b.cfg.Governor.Claims.EffectiveNeverClaimLabels())
client.SetContributorGrace(b.cfg.Governor.Claims.EffectiveContributorGrace())
// Pre-dispatch open-PR guard (hivecommons/hive#14799,
// scanner.skip_issues_with_open_pr, default on).
client.SetSkipIssuesWithOpenPR(b.cfg.Scanner.IsSkipIssuesWithOpenPR())
Expand Down
1 change: 1 addition & 0 deletions src/cmd/hive/github_client_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var clientResyncSetters = map[string]bool{
"SetRepos": true,
"SetHoldLabels": true,
"SetNeverClaimLabels": true,
"SetContributorGrace": true,
"SetSkipIssuesWithOpenPR": true,
"SetSentinelAlertLabel": true,
"SetExemptLabels": true,
Expand Down
13 changes: 13 additions & 0 deletions src/cmd/hive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,17 @@ func (b *boot) wireBootClosures() {
IssueClaimed: func(repo string, number int) (github.IssueClaim, bool) {
return getClaimLedger(b.logger).Lookup(repo, number)
},
// hivecommons/hive#18898: an issue an owner, maintainer or this hive
// filed inside the contributor grace window is not offered yet.
ContributorHold: func(repo string, number int, createdAt time.Time) string {
client := b.currentGitHubClient()
if client == nil {
return ""
}
ctx, cancel := context.WithTimeout(context.Background(), openPRLinkGuardTimeout)
defer cancel()
return client.ContributorGraceGuard(ctx, repo, number, createdAt)
},
// hivecommons/hive#14799: the ledger above is one eval cycle old;
// ask the forge directly whether an open PR already links the
// issue before the contribute lane dispatches it again.
Expand Down Expand Up @@ -2531,6 +2542,7 @@ func (b *boot) bootStateWith(deps bootStateDeps) {
b.observeWritebackRepos()
b.ghClient.SetHoldLabels(b.githubHoldLabels())
b.ghClient.SetNeverClaimLabels(b.cfg.Governor.Claims.EffectiveNeverClaimLabels())
b.ghClient.SetContributorGrace(b.cfg.Governor.Claims.EffectiveContributorGrace())
b.ghClient.SetSkipIssuesWithOpenPR(b.cfg.Scanner.IsSkipIssuesWithOpenPR())
b.ghClient.SetSentinelAlertLabel(b.cfg.Sentinel.LabelOrDefault())
if len(b.cfg.Governor.Labels.Exempt) > 0 {
Expand Down Expand Up @@ -5865,6 +5877,7 @@ func (b *boot) bootHeartbeatWith(deps bootHeartbeatDeps) {
}
b.ghClient.SetHoldLabels(b.githubHoldLabels())
b.ghClient.SetNeverClaimLabels(b.cfg.Governor.Claims.EffectiveNeverClaimLabels())
b.ghClient.SetContributorGrace(b.cfg.Governor.Claims.EffectiveContributorGrace())
b.ghClient.SetSkipIssuesWithOpenPR(b.cfg.Scanner.IsSkipIssuesWithOpenPR())
b.ghClient.SetSentinelAlertLabel(b.cfg.Sentinel.LabelOrDefault())
b.ghClient.SetIssueFilter(b.cfg.Project.IssueFilter)
Expand Down
2 changes: 2 additions & 0 deletions src/docs/contributor-relay.md
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ Withheld rows carry a stable reason code and, where the refusing gate had one, t
| `in_flight` | A contributor is working the issue right now. | — |
| `contributor_filter` | A title, author, or label filter above rejected the candidate. | Which filter matched |
| `assigned_to_other` | The issue is assigned to someone else and **Skip Assigned to Others** is on. | Assignee logins |
| `owner_grace` | An owner, maintainer or this hive filed the issue inside `governor.claims.contributor_grace_s` and no person has added `help wanted` ([#18898](https://github.com/hivecommons/hive/issues/18898)). | The forge's sentence: who filed it and how long ago |

Two properties are worth relying on:

Expand Down Expand Up @@ -1531,6 +1532,7 @@ A resume that is genuinely refused — an operator yanked the task, or the relay
- **A disconnect release releases the claim.** Once the [#7838](https://github.com/hivecommons/hive/issues/7838) grace window has passed without the task being re-adopted or finished, the hub releases the ledger claim (reason `released on disconnect`), clears the lease's mirror of it, and — like every release that ends a claim before its `until=`, including `lease revoked` and a lease that aged out unresumed (`lease expired`) — posts the release marker and removes the claim labels, so the issue is claimable by hive agents on their next eval cycle. The lease itself stays resumable; a relay that does come back re-asserts the claim on resume, and if a hive agent took the issue meanwhile the ledger keeps the higher claim and the relay is preempted the usual way. A forge marker this hive wrote is in any case believed only while its own ledger still holds the claim, so a budget-suppressed release comment cannot leave a phantom hold.
- **Repeated drops put the issue in contributor cool-off.** The hub counts disconnect releases per issue; at `governor.claims.contributor_flap_threshold` drops (default 3) inside `contributor_flap_window_s` (default 2h) the issue is withheld from *every* contributor — `selectTask` skips it and a `task_progress` resume of its lease is refused with `task_revoke` — for `contributor_flap_cooloff_s` (default 6h). Hive agents are not withheld; the work detail says `contributor cool-off: 3 drops in 2h0m0s; hive agents may claim it`, and one INFO line names the issue and the cool-off deadline when it trips. In-memory: a hub restart forgets the drops (the claim release is the durable half). A negative threshold turns the cool-off off.
- **Contributor claims cannot starve hive agents.** An issue continuously withheld from hive agents by contributor claims for `contributor_starvation_s` (default 4h; negative turns it off) with no PR evidence on the claim stops being withheld: the claim becomes advisory, the issue stays actionable with the reason `Contributor claim by <login> is advisory: contributor claims have withheld this issue from hive agents for 4h0m with no PR`, and a hive agent may claim it (the ledger's takeover hook then stops the relay). Agent, human and external claims are never overridden.
- **An issue the owner filed moments ago is the owner's to claim first.** An issue whose author is an owner or maintainer (author association `OWNER`, `MEMBER` or `COLLABORATOR`) or this hive's own App/bot is withheld from the contributor lane for `governor.claims.contributor_grace_s` (default 900 = 15m; negative turns it off) after it is filed ([#18898](https://github.com/hivecommons/hive/issues/18898), child of [#18890](https://github.com/hivecommons/hive/issues/18890): #18866 and #18880 each grew a contributor PR because the lane claimed the issue seconds after filing, before the owner or the owner's dispatcher could). Inside the window `selectTask` and the Ready queue skip the issue (Withheld reason `owner_grace`), and a contributor's fresh ledger claim is refused with `owner grace: filed by <login> 3m ago; contributor claims wait 15m unless a person adds `help wanted``. A person adding the `help wanted` label after filing (a timeline `labeled` event whose actor is not a bot) waives the grace at once, because that is the owner opening the issue to outside help. Only a *fresh* claim waits: a lease already live is not touched, hive agents are never held off, and an issue filed by an outside reporter is not delayed.

**Not every task has a lease, and one of them is the relay's own.** After every fifth completion the relay runs a *PR review cycle*: it stops taking new issues and asks its agent to look over the open PRs it has filed, so review comments get answered. That task is built locally — a `pr-review-…` id, `number: 0`, no `task_assign`, no lease — and for a long time the reconnect path above did not know the difference. It re-asserted the review to a hub that had never heard of it, the hub refused under exactly the server-issued-lease rule described above, and the relay treated the resulting revoke as terminal: stop the agent, relaunch the CLI, ask for fresh work ([#5715](https://github.com/hivecommons/hive/issues/5715)). The tell was in the log line itself — `Reconnected while working on kubestellar/hive#0 — resuming`, naming an issue number that does not exist. On a hive where 1006 closes are routine (29 in under four hours in the report) a review that takes a couple of minutes almost never survived to finish, so PR review coverage silently did not happen.

Expand Down
Loading
Loading