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
17 changes: 17 additions & 0 deletions bin/contributor-relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -6985,6 +6985,17 @@ function alreadyDoneVerdictFields(reason) {
};
}

// alreadyDoneCitesRef says whether an already-done reason names something the
// hub can verify: the structured evidence (a merged PR or a commit SHA), a
// bare `#N`, or a pull-request URL. "Already resolved" alone cites nothing,
// and the hub then refuses the label ("cited no PR or commit the hive could
// verify"), so the relay must not have applied it (utah-packages#1175).
function alreadyDoneCitesRef(reason) {
const evidence = alreadyDoneVerdictFields(reason).evidence;
if (evidence && (evidence.pr > 0 || evidence.commit)) return true;
return /(?:^|[^\w&])#\d+\b|\/pull\/\d+\b/.test(String(reason || ''));
}

function isAlreadyDoneNoWork(noWork) {
if (!noWork || noWork.verdict !== HIVE_VERDICT_NO_WORK) return false;
return alreadyDoneVerdictFields(noWork.reason).verdict_reason_kind === ALREADY_DONE_REASON_KIND;
Expand Down Expand Up @@ -8663,6 +8674,12 @@ function readOpenSubIssues(task, env) {

function markIssueAlreadyDone(task, reason) {
if (!task || task.kind !== 'issue' || !task.repo || !(task.number > 0) || task.external_id) return;
// The label means verified done. With no PR or commit cited there is
// nothing to verify: the hub comments and books its own hold instead.
if (!alreadyDoneCitesRef(reason)) {
console.log(`Task ${task.task_id}: already-done verdict on ${task.repo}#${task.number} cites no PR or commit — not applying the '${ALREADY_DONE_WORKFLOW_LABEL}' label; the hub verifies a citation before labelling and holds the issue without one`);
return;
}
const hub = task._hub || hubs[activeHubIndex];
if (!hubGrantsIssuesWrite(hub)) {
console.log(`Task ${task.task_id}: already-done verdict on ${task.repo}#${task.number}, but the task credential does not carry issues:write — leaving the '${ALREADY_DONE_WORKFLOW_LABEL}' label to the hub or a human; the hub's already-done hold suppresses re-offer (#8477)`);
Expand Down
32 changes: 32 additions & 0 deletions bin/contributor-relay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16797,6 +16797,38 @@ test('already-done label is applied as before when the issue has no sub-issues o
}
});

// projectbluefin/utah-packages#1175: "already resolved" with no PR or commit
// is a claim the hub refuses to label, so the relay must not label it either.
test('already-done label is not applied when the reason cites no PR or commit', () => {
const relay = loadRelay({});
const log = console.log; const logged = []; console.log = (...a) => logged.push(a.join(' '));
try {
relay.handleMessage(JSON.stringify({ type: 'auth_ok', contributor_id: 'c1', trust_tier: 'contributor', permissions: ['issues:write'] }));
const before = relay.__commands.length;
relay.markIssueAlreadyDone({ task_id: 't', kind: 'issue', repo: 'foo/bar', number: 7 }, 'external mirror outage already resolved (HTTP 200)');
const after = relay.__commands.slice(before);
assert.strictEqual(after.filter(c => /gh /.test(c)).length, 0,
`no read and no label without a citation: ${JSON.stringify(after)}`);
assert.strictEqual(logged.filter(l => /cites no PR or commit/.test(l) && /not applying the 'hive\/already-done' label/.test(l)).length, 1,
`expected one line saying why, got ${JSON.stringify(logged)}`);
} finally { console.log = log; teardown(relay); }
});

test('already-done label is still applied when the reason cites a commit or a merged PR', () => {
for (const reason of ['already fixed by commit e6d3de3', 'merged PR #532 already resolves this', 'already fixed in https://github.com/foo/bar/pull/532']) {
const relay = loadRelay({});
const log = console.log; console.log = () => {};
try {
relay.handleMessage(JSON.stringify({ type: 'auth_ok', contributor_id: 'c1', trust_tier: 'contributor', permissions: ['issues:write'] }));
const before = relay.__commands.length;
relay.markIssueAlreadyDone({ task_id: 't', kind: 'issue', repo: 'foo/bar', number: 7 }, reason);
const after = relay.__commands.slice(before);
assert.strictEqual(after.filter(c => /gh issue edit/.test(c) && c.includes('--add-label') && c.includes('hive/already-done')).length, 1,
`${reason} must still label: ${JSON.stringify(after)}`);
} finally { console.log = log; teardown(relay); }
}
});

test('already-done label is not applied when the sub-issue read fails', () => {
const relay = loadRelay({ subIssuesSummary: new Error('Command failed: gh api') });
const log = console.log; const logged = []; console.log = (...a) => logged.push(a.join(' '));
Expand Down
1 change: 1 addition & 0 deletions changelog.d/fixed-relay-already-done-unverified.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **An unverified "already done" verdict no longer leaves `hive/already-done` on the issue.** The contributor relay applied the label on reason text alone ("already resolved"), and seconds later the hub commented that the issue "is not labelled `hive/already-done`" because nothing could be verified, leaving the label on, so the issue dropped out of the offer queue with no maintainer check (projectbluefin/utah-packages#1175). The relay now labels only when the reason cites a PR, a PR URL or a commit, and when the citation does not verify the hub removes a label the hive added since the task was dispatched; a label a person added stays.
2 changes: 1 addition & 1 deletion src/docs/contributor-relay.md
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ After a contributor completes an issue, the hub keeps that issue out of the queu
|---|---|---|
| **Cooldown** | `contribute_cooldown_enabled` | Toggles the post-completion cooldown. Absent (older config) or `true` means enabled; an explicit `false` disables it, so no completed issue is ever excluded for cooldown. Failure quarantine is separate and stays on either way. |
| **Cooldown Hours** | `contribute_cooldown_hours` | Length of the with-PR completion cooldown in hours. `0` or unset means the default of `168` (one week); any positive value is clamped to `1`-`8760`. The short no-PR cooldown is fixed and not tuned here; it ends early when the issue's author answers a question the contributor asked during that task (see [The issue author's answer ends the no-PR cooldown](#the-issue-authors-answer-ends-the-no-pr-cooldown)). |
| **Already-done label** | `contribute_already_done_label` | Label applied when a `no_work_needed` verdict is marked `verdict_reason_kind: "already_done"` (or legacy text such as `merged PR #123 already resolves this`) and the cited PR verifies as merged. A verdict with no cited PR/commit, or one that fails verification, never gets this label, and neither does an issue that has open sub-issues: the relay reads the issue's `sub_issues_summary` with the task credential before it labels and skips the label when a sub-issue is open or the read fails, and the hub checks again before it labels or closes. Default `hive/already-done`, which is also in the default contribute skip labels so it stays out of the offer queue until a maintainer removes it. |
| **Already-done label** | `contribute_already_done_label` | Label applied when a `no_work_needed` verdict is marked `verdict_reason_kind: "already_done"` (or legacy text such as `merged PR #123 already resolves this`) and the cited PR verifies as merged. A verdict with no cited PR/commit, or one that fails verification, never gets this label: the relay does not apply it when the reason cites no PR, PR URL or commit, and when verification fails the hub removes one the hive added since the task was dispatched (a label a person added stays). Neither does an issue that has open sub-issues: the relay reads the issue's `sub_issues_summary` with the task credential before it labels and skips the label when a sub-issue is open or the read fails, and the hub checks again before it labels or closes. Default `hive/already-done`, which is also in the default contribute skip labels so it stays out of the offer queue until a maintainer removes it. |
| **Close already done** | `contribute_close_already_done` | Deprecated compatibility key; verified already-done PR evidence now runs the normal issue close path without this toggle. Human-filed bug-family issues close by default; add `hive: needs-confirmation` or enable `issues.reporter_confirmation` only when reporter verification is required. |
| **Already-done hold** | `contribute_already_done_hold_days` | Days to suppress re-offer when an already-done verdict cites no PR/commit or evidence the hub cannot verify (the hold is the only suppression then; newer issue activity lifts it sooner). Default `30`; valid non-zero values are clamped to `1`-`365`. |

Expand Down
13 changes: 10 additions & 3 deletions src/pkg/dashboard/contribute_ledgers.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,14 +781,21 @@ func (h *ContributeWSHub) markTaskCompletedVerdict(repo string, number int, prUR
// evidence; it is a contributor skip label, so on an unverified claim it kept
// unfinished work out of the queue until a maintainer noticed
// (projectbluefin/chairlift#591, fixed later by chairlift#626).
func (h *ContributeWSHub) markAlreadyDoneUnverified(repo string, number int, reporter, reason string, evidence *VerdictEvidence) {
//
// A contributor relay may already have put the label on with the task
// credential (projectbluefin/utah-packages#1175: labelled at 11:49:55, the
// "not labelled" comment at 11:50:11, the label left on). The hub takes off a
// label the hive added since dispatchedAt; one a person added stays.
func (h *ContributeWSHub) markAlreadyDoneUnverified(repo string, number int, reporter, reason string, evidence *VerdictEvidence, dispatchedAt time.Time) {
if h == nil || repo == "" || number <= 0 {
return
}
reason = truncateReasonBytes(reason)
hold := h.configuredAlreadyDoneUnverifiedHold()
// The comment goes out before the hold is booked so the hive's own
// comment does not count as newer issue activity that lifts the hold.
// The label removal and the comment go out before the hold is booked so
// the hive's own activity does not count as newer issue activity that
// lifts the hold.
h.removeUnverifiedAlreadyDoneLabel(repo, number, dispatchedAt)
if err := h.noteAlreadyDoneUnverified(context.Background(), repo, number, reporter, hold); err != nil && h.logger != nil && err != ghpkg.ErrNoGitHubClient {
h.logger.Warn("[contribute-ws] unverified already-done verdict comment failed",
"repo", repo, "number", number, "error", err.Error())
Expand Down
3 changes: 2 additions & 1 deletion src/pkg/dashboard/contribute_ledgers_reason_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"testing"
"time"
"unicode/utf8"
)

Expand Down Expand Up @@ -45,7 +46,7 @@ func TestVerdictLedgerReasonTruncation(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
hub := ledgerHub(t.TempDir())
if path == "already_done_unverified" {
hub.markAlreadyDoneUnverified("o/r", 13110, "reporter", tc.in, nil)
hub.markAlreadyDoneUnverified("o/r", 13110, "reporter", tc.in, nil, time.Time{})
} else {
hub.markTaskCompletedVerdict("o/r", 13110, "", path, "reporter", tc.in)
}
Expand Down
43 changes: 38 additions & 5 deletions src/pkg/dashboard/contribute_verdict_settle.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ func (h *ContributeWSHub) settleIssueFromVerdictWithEvidence(repo string, number
}
if len(refs) == 0 {
if alreadyDone {
h.markAlreadyDoneUnverified(repo, number, reporter, reason, evidence)
h.markAlreadyDoneUnverified(repo, number, reporter, reason, evidence, dispatchedAt)
return verdictDispositionAlreadyDoneUnverified
}
return ""
}
if h.server == nil || h.server.deps == nil || h.server.deps.RecordIssueClaim == nil {
if alreadyDone {
h.markAlreadyDoneUnverified(repo, number, reporter, reason, evidence)
h.markAlreadyDoneUnverified(repo, number, reporter, reason, evidence, dispatchedAt)
return verdictDispositionAlreadyDoneUnverified
}
return ""
Expand All @@ -90,7 +90,7 @@ func (h *ContributeWSHub) settleIssueFromVerdictWithEvidence(repo string, number
if verify == nil {
if h.server.deps.GHClient == nil {
if alreadyDone {
h.markAlreadyDoneUnverified(repo, number, reporter, reason, evidence)
h.markAlreadyDoneUnverified(repo, number, reporter, reason, evidence, dispatchedAt)
return verdictDispositionAlreadyDoneUnverified
}
return ""
Expand All @@ -110,7 +110,7 @@ func (h *ContributeWSHub) settleIssueFromVerdictWithEvidence(repo string, number
"repo", repo, "number", number, "ref", ref.String(), "reason", res.Reason, "error", err.Error())
if ctx.Err() != nil {
if alreadyDone {
h.markAlreadyDoneUnverified(repo, number, reporter, reason, evidence)
h.markAlreadyDoneUnverified(repo, number, reporter, reason, evidence, dispatchedAt)
return verdictDispositionAlreadyDoneUnverified
}
return ""
Expand Down Expand Up @@ -181,7 +181,7 @@ func (h *ContributeWSHub) settleIssueFromVerdictWithEvidence(repo string, number
return ""
}
if alreadyDone {
h.markAlreadyDoneUnverified(repo, number, reporter, reason, evidence)
h.markAlreadyDoneUnverified(repo, number, reporter, reason, evidence, dispatchedAt)
return verdictDispositionAlreadyDoneUnverified
}
return ""
Expand Down Expand Up @@ -239,6 +239,39 @@ func (h *ContributeWSHub) markIssuePRClaim(ctx context.Context, repo string, num
return h.server.deps.GHClient.AddLabels(ctx, repo, number, []string{label})
}

// removeUnverifiedAlreadyDoneLabel takes the already-done label off an issue
// whose verdict did not verify, when the hive itself added it after the task
// was dispatched (a relay labelling on the task credential). Best-effort: a
// failure is logged and the comment and hold still go out.
func (h *ContributeWSHub) removeUnverifiedAlreadyDoneLabel(repo string, number int, dispatchedAt time.Time) {
if h == nil || h.server == nil || h.server.deps == nil || h.server.deps.GHClient == nil {
return
}
label := config.HubConfig{}.ContributeAlreadyDoneLabelOrDefault()
if h.server.deps.Config != nil {
label = h.server.deps.Config.Hub.ContributeAlreadyDoneLabelOrDefault()
}
ctx := h.server.deps.Ctx
if ctx == nil {
ctx = context.Background()
}
ctx, cancel := context.WithTimeout(ctx, verdictSettleTimeout)
defer cancel()
removed, err := h.server.deps.GHClient.RemoveHiveLabelAddedSince(ctx, repo, number, label, dispatchedAt)
if h.logger == nil {
return
}
if err != nil {
h.logger.Warn("[contribute-ws] removing the relay's unverified already-done label failed",
"repo", repo, "number", number, "label", label, "error", err.Error())
return
}
if removed {
h.logger.Info("[contribute-ws] removed the already-done label the relay applied to an unverified verdict",
"repo", repo, "number", number, "label", label)
}
}

// noteAlreadyDoneUnverified posts the claim-worded comment for an already-done
// verdict with no verifiable evidence. It applies no label: the already-done
// label means verified, and hive/likely-done means an API-verified merged PR
Expand Down
74 changes: 72 additions & 2 deletions src/pkg/dashboard/contribute_verdict_settle_ghclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type settleGHFixture struct {
commentsListErr bool
issueLabels []string
labelsRemoved []string
issueEvents []map[string]any
}

func (f *settleGHFixture) server(t *testing.T) *httptest.Server {
Expand Down Expand Up @@ -93,6 +94,12 @@ func (f *settleGHFixture) server(t *testing.T) *httptest.Server {
"user": map[string]any{"login": "hive-bot", "type": "Bot"},
"labels": labels,
})
case r.Method == http.MethodGet && r.URL.Path == "/repos/o/r/issues/7/events":
events := f.issueEvents
if events == nil {
events = []map[string]any{}
}
_ = json.NewEncoder(w).Encode(events)
case r.Method == http.MethodPatch && r.URL.Path == "/repos/o/r/issues/7":
var payload struct {
State string `json:"state"`
Expand Down Expand Up @@ -397,7 +404,7 @@ func TestVerdictSettleGH_UnverifiedAlreadyDone_ExistingCommentIsNotReposted(t *t
fx := &settleGHFixture{}
hub, _ := settleGHHub(t, fx)

hub.markAlreadyDoneUnverified("o/r", 7, "ct", "already fixed upstream", nil)
hub.markAlreadyDoneUnverified("o/r", 7, "ct", "already fixed upstream", nil, time.Time{})
fx.mu.Lock()
if len(fx.comments) != 1 {
fx.mu.Unlock()
Expand All @@ -407,7 +414,7 @@ func TestVerdictSettleGH_UnverifiedAlreadyDone_ExistingCommentIsNotReposted(t *t
fx.comments = nil
fx.mu.Unlock()

hub.markAlreadyDoneUnverified("o/r", 7, "ct", "already fixed upstream", nil)
hub.markAlreadyDoneUnverified("o/r", 7, "ct", "already fixed upstream", nil, time.Time{})
fx.mu.Lock()
defer fx.mu.Unlock()
if len(fx.comments) != 0 {
Expand Down Expand Up @@ -547,3 +554,66 @@ func TestVerdictSettleGH_MarkAlreadyDone_RemovesVerifiedOpen(t *testing.T) {
t.Fatalf("labels removed = %v, want hive/verified-open", fx.labelsRemoved)
}
}

// projectbluefin/utah-packages#1175: the relay labelled the issue
// hive/already-done on "already resolved" alone, then the hub commented "not
// labelled" and left the label on. The unverified path now takes off a label
// the hive added since dispatch, and keeps one a person added or one the hive
// added before this task.
func TestVerdictSettleGH_UnverifiedAlreadyDoneRemovesTheRelayLabel(t *testing.T) {
dispatched := time.Now().Add(-3 * time.Minute)
labeled := func(actor string, at time.Time) map[string]any {
return map[string]any{
"id": 1, "event": "labeled", "created_at": at.UTC().Format(time.RFC3339),
"actor": map[string]any{"login": actor},
"label": map[string]any{"name": "hive/already-done"},
}
}
for _, tc := range []struct {
name string
events []map[string]any
wantRemoved bool
}{
{name: "hive App label after dispatch is removed", events: []map[string]any{labeled("hive-app[bot]", dispatched.Add(time.Minute))}, wantRemoved: true},
{name: "a person's label stays", events: []map[string]any{labeled("maintainer", dispatched.Add(time.Minute))}},
{name: "hive label from before this task stays", events: []map[string]any{labeled("hive-app[bot]", dispatched.Add(-time.Hour))}},
{name: "a person relabelled after the hive", events: []map[string]any{labeled("hive-app[bot]", dispatched.Add(time.Minute)), labeled("maintainer", dispatched.Add(2*time.Minute))}},
} {
t.Run(tc.name, func(t *testing.T) {
fx := &settleGHFixture{issueLabels: []string{"kind/bug", "hive/already-done"}, issueEvents: tc.events}
hub, s := settleGHHub(t, fx)
s.deps.GHClient.SetAppBotLogin("hive-app[bot]")

got := hub.settleIssueFromVerdictWithEvidence("o/r", 7, "external mirror outage already resolved (HTTP 200)", "already_done", nil, dispatched, "kylerankin")
if got != verdictDispositionAlreadyDoneUnverified {
t.Fatalf("disposition = %q, want unverified", got)
}
fx.mu.Lock()
defer fx.mu.Unlock()
removed := len(fx.labelsRemoved) == 1 && fx.labelsRemoved[0] == "hive/already-done"
if removed != tc.wantRemoved {
t.Fatalf("labelsRemoved = %v, want removed=%v", fx.labelsRemoved, tc.wantRemoved)
}
if len(fx.comments) != 1 || !strings.Contains(fx.comments[0], "not labelled `hive/already-done`") {
t.Fatalf("comments = %v, want the unverified comment", fx.comments)
}
if len(fx.labelsAdded) != 0 {
t.Fatalf("unverified claim must not label: %v", fx.labelsAdded)
}
})
}
}

// Without a dispatch time the hub cannot tell this task's label from an older
// one, so it reads nothing and removes nothing.
func TestVerdictSettleGH_UnverifiedAlreadyDoneWithoutDispatchTimeKeepsLabel(t *testing.T) {
fx := &settleGHFixture{issueLabels: []string{"hive/already-done"}}
hub, s := settleGHHub(t, fx)
s.deps.GHClient.SetAppBotLogin("hive-app[bot]")
hub.markAlreadyDoneUnverified("o/r", 7, "ct", "already fixed upstream", nil, time.Time{})
fx.mu.Lock()
defer fx.mu.Unlock()
if len(fx.labelsRemoved) != 0 {
t.Fatalf("labelsRemoved = %v, want none", fx.labelsRemoved)
}
}
Loading
Loading