From 776df2fa07b1aed885fd5982fa335505536a9f06 Mon Sep 17 00:00:00 2001 From: Karibhou Date: Tue, 27 Oct 2026 21:29:28 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20contribute:=20drop=20merged?= =?UTF-8?q?=20and=20closed=20PRs=20from=20the=20rework=20card?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fleetReworkFor built pending_rework from stage-store records and the fix queue without checking the PR was still open. A record outlives its PR when the stage sweep never observes the close (it then waits for the 14-day prune), so a card showed merged PRs as "awaiting rework". The fleet snapshot now builds an open-PR index from the status snapshot's canonical open-items set (actionable, held, drafts and sidelined rows) and drops a PR only when its repo's listing is complete and does not carry it. No GitHub call is added. Fixes #14708 Hive-Run: hivecommons/hive#14708 Hive-Plan: issue-14708 fix step 1 (exclude merged/closed PRs in fleetReworkFor) Hive-Spec: contribute-fleet-rework#pending-rework-open-only Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HRH6kiRtEyaHtiLvBsdLrG Signed-off-by: Karibhou --- .../fixed-14708-rework-card-closed-prs.md | 1 + src/docs/contributor-relay.md | 2 +- src/pkg/dashboard/contribute_fleet.go | 3 +- src/pkg/dashboard/contribute_fleet_rework.go | 61 +++++++++- .../contribute_fleet_rework_14708_test.go | 114 ++++++++++++++++++ 5 files changed, 174 insertions(+), 7 deletions(-) create mode 100644 changelog.d/fixed-14708-rework-card-closed-prs.md create mode 100644 src/pkg/dashboard/contribute_fleet_rework_14708_test.go diff --git a/changelog.d/fixed-14708-rework-card-closed-prs.md b/changelog.d/fixed-14708-rework-card-closed-prs.md new file mode 100644 index 0000000000..db84f0b2b6 --- /dev/null +++ b/changelog.d/fixed-14708-rework-card-closed-prs.md @@ -0,0 +1 @@ +- The contributor card's "PRs awaiting rework" count no longer includes PRs that have merged or closed while their stage record still said 072 or 074; a PR is only dropped when its repo's open-PR listing is complete (hivecommons/hive#14708). diff --git a/src/docs/contributor-relay.md b/src/docs/contributor-relay.md index 46488098a0..aebd74160d 100644 --- a/src/docs/contributor-relay.md +++ b/src/docs/contributor-relay.md @@ -1485,7 +1485,7 @@ Each row of the "Connected contributor agents (ClankeR)" list on `/contribute/op | `fix_queue_depth` | Red PRs waiting in the contributor's server-side fix queue (not dispatched). | | `pending_rework`, `pending_rework_prs[]` | The contributor's open PRs in `stage/072-returned-to-contributor` that have **not** been dispatched to them. The row prints a red **N PRs awaiting rework (not yet dispatched)** line, and an idle relay reads **idle · N PRs awaiting rework** instead of `idle: no matching work`. | -`kind: rework` means the item repairs one of the contributor's own PRs: any `fix-pr` task, or a task whose target the stage store has in a repair stage (`070-fixing`, `071-needs-author`, `072-returned-to-contributor`, `074-adopted-by-hive`). Everything else is `new`. `pending_rework` is derived without a GitHub call: the stage-label store (which remembers each PR's author) ∪ the fix queue, minus the fix tasks in flight on any of the contributor's connections. A non-zero `pending_rework` on an idle row is the signal to look at — typically a relay that did not advertise `fix_pr_interrupt_v1`, a preempt-mode relay inside its `contribute.min_focus_window`, or a contributor who is offline. +`kind: rework` means the item repairs one of the contributor's own PRs: any `fix-pr` task, or a task whose target the stage store has in a repair stage (`070-fixing`, `071-needs-author`, `072-returned-to-contributor`, `074-adopted-by-hive`). Everything else is `new`. `pending_rework` is derived without a GitHub call: the stage-label store (which remembers each PR's author) ∪ the fix queue, minus the fix tasks in flight on any of the contributor's connections, minus any PR the status snapshot shows as merged or closed. A stage record can outlive its PR when the stage sweep never saw it close, so a PR is dropped when its repo's open-PR list is complete (not incomplete, stale or carrying unlisted PRs) and does not include it; with no complete listing the record is kept. A non-zero `pending_rework` on an idle row is the signal to look at — typically a relay that did not advertise `fix_pr_interrupt_v1`, a preempt-mode relay inside its `contribute.min_focus_window`, or a contributor who is offline. ## Reconnecting without losing in-flight work diff --git a/src/pkg/dashboard/contribute_fleet.go b/src/pkg/dashboard/contribute_fleet.go index b80cdb5459..b4c105b066 100644 --- a/src/pkg/dashboard/contribute_fleet.go +++ b/src/pkg/dashboard/contribute_fleet.go @@ -227,6 +227,7 @@ type FleetSnapshot struct { // last pong is older than wsHeartbeatTimeout is reported with Stale=true and its // in-flight task is treated as no longer active (matching LiveStates()). func (h *ContributeWSHub) FleetSnapshot() FleetSnapshot { + openPRs := h.openPRIndex() h.mu.RLock() defer h.mu.RUnlock() snap := FleetSnapshot{ @@ -326,7 +327,7 @@ func (h *ContributeWSHub) FleetSnapshot() FleetSnapshot { if task == nil { fc.IdleReason = c.lastIdleReason } - fc.FleetRework = h.fleetReworkFor(c, fc.Stale) + fc.FleetRework = h.fleetReworkFor(c, fc.Stale, openPRs) c.mu.Unlock() fc.CurrentTask = task fc.PromptPreview = promptPreview diff --git a/src/pkg/dashboard/contribute_fleet_rework.go b/src/pkg/dashboard/contribute_fleet_rework.go index cc44a499a2..1d85edfe4f 100644 --- a/src/pkg/dashboard/contribute_fleet_rework.go +++ b/src/pkg/dashboard/contribute_fleet_rework.go @@ -138,9 +138,60 @@ func workKindFor(store *stagelabels.Store, taskKind, repo string, number int) (k return kind, stage } +// openPRIndex is the status snapshot's canonical open-PR set (repoOpenItems: +// actionable, held, drafts and sidelined rows), keyed like the stage store. +// It answers "is this PR closed?" only for a repo whose PR list is complete; +// for any other repo, or with no snapshot yet, a PR counts as open. +type openPRIndex struct { + repos map[string]bool // lower-cased owner/repo with a complete PR list + prs map[string]bool // stagelabels.Key of every listed open PR +} + +// openPRIndex builds the index from the hub server's current status. A repo +// whose counts are incomplete, stale or carry unlisted PRs is left out: a PR +// missing from a partial listing is not evidence that it closed. +func (h *ContributeWSHub) openPRIndex() openPRIndex { + var idx openPRIndex + if h == nil || h.server == nil { + return idx + } + h.server.statusMu.RLock() + status := h.server.status + h.server.statusMu.RUnlock() + if status == nil { + return idx + } + idx.repos, idx.prs = map[string]bool{}, map[string]bool{} + for _, repo := range status.Repos { + if repo.CountsIncomplete || repo.CountsStale || repo.UnlistedPRs > 0 { + continue + } + full := nonEmpty(repo.Full, repo.Name) + idx.repos[strings.ToLower(full)] = true + for _, it := range repoOpenItems(repo) { + if it.Kind == "pr" { + idx.prs[stagelabels.Key(full, it.Number)] = true + } + } + } + return idx +} + +// closed reports whether the snapshot shows repo#number as no longer open: +// the repo's PR list is complete and does not carry it +// (hivecommons/hive#14708). +func (idx openPRIndex) closed(repo string, number int) bool { + if !idx.repos[strings.ToLower(strings.TrimSpace(repo))] { + return false + } + return !idx.prs[stagelabels.Key(repo, number)] +} + // fleetReworkFor builds the rework view for one connection. Call with c.mu -// held; it takes only the fix scheduler's and stage store's own locks. -func (h *ContributeWSHub) fleetReworkFor(c *ContributorConnection, stale bool) FleetRework { +// held; it takes only the fix scheduler's and stage store's own locks. open +// drops PRs that have merged or closed: stage records outlive a PR whose +// close the stage sweep never observed (hivecommons/hive#14708). +func (h *ContributeWSHub) fleetReworkFor(c *ContributorConnection, stale bool, open openPRIndex) FleetRework { var out FleetRework store := h.stageStoreOrShared() cap := h.fixCapacity(c) @@ -212,7 +263,7 @@ func (h *ContributeWSHub) fleetReworkFor(c *ContributorConnection, stale bool) F } pending := map[string]FleetReworkPR{} for _, it := range queued { - if inFlightKeys[it.Key()] { + if inFlightKeys[it.Key()] || open.closed(it.Repo, it.Number) { continue } cause := it.Cause.Check @@ -233,7 +284,7 @@ func (h *ContributeWSHub) fleetReworkFor(c *ContributorConnection, stale bool) F continue } repo, number := splitStageKey(ai.Key) - if repo == "" || number == 0 { + if repo == "" || number == 0 || open.closed(repo, number) { continue } pr := FleetReworkPR{Repo: repo, Number: number, Stage: ai.Record.Stage.Label()} @@ -250,7 +301,7 @@ func (h *ContributeWSHub) fleetReworkFor(c *ContributorConnection, stale bool) F continue } repo, number := splitStageKey(ai.Key) - if repo == "" || number == 0 { + if repo == "" || number == 0 || open.closed(repo, number) { continue } pr := FleetReworkPR{Repo: repo, Number: number, Stage: ai.Record.Stage.Label(), State: FleetReworkStateAdopted} diff --git a/src/pkg/dashboard/contribute_fleet_rework_14708_test.go b/src/pkg/dashboard/contribute_fleet_rework_14708_test.go new file mode 100644 index 0000000000..86ebdcc78a --- /dev/null +++ b/src/pkg/dashboard/contribute_fleet_rework_14708_test.go @@ -0,0 +1,114 @@ +package dashboard + +import ( + "testing" + "time" + + "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// hivecommons/hive#14708: a contributor card said "4 PRs awaiting rework" +// when three of them had merged two days earlier still wearing 072. The +// stage records outlived the PRs, so the card must check the PR is open. + +func setReworkStatus(srv *Server, repos ...FrontendRepo) { + srv.statusMu.Lock() + srv.status = &StatusPayload{Repos: repos} + srv.statusMu.Unlock() +} + +func noteRework(store *stagelabels.Store, repo string, n int, stage stagelabels.Stage, author string) { + store.Observe(stagelabels.Key(repo, n), stage, "check-failing:build") + store.NoteAuthor(stagelabels.Key(repo, n), author) +} + +func pendingNumbers(fc FleetClanker) []int { + var out []int + for _, pr := range fc.PendingReworkPRs { + out = append(out, pr.Number) + } + return out +} + +func TestFleetReworkExcludesMergedAndClosedPRs(t *testing.T) { + hub, srv, store := reworkHub(t) + fixConn(hub, "alice", fixCaps(capFixPRInterrupt), time.Now()) + + noteRework(store, "org/r", 1, stagelabels.ReturnedToContributor, "alice") // open + noteRework(store, "org/r", 2, stagelabels.ReturnedToContributor, "alice") // merged + noteRework(store, "org/r", 3, stagelabels.AdoptedByHive, "alice") // closed + setReworkStatus(srv, FrontendRepo{Name: "r", Full: "org/r", OpenPrs: []any{ + FrontendPR{PullRequest: github.PullRequest{Repo: "org/r", Number: 1, Author: "alice"}}, + }}) + + fc := snapshotFor(t, hub, "alice") + if got := pendingNumbers(fc); fc.PendingRework != 1 || len(got) != 1 || got[0] != 1 { + t.Fatalf("pending_rework=%d prs=%v, want only the open #1", fc.PendingRework, got) + } +} + +func TestFleetReworkKeepsOpenDraftAndAdoptedPRs(t *testing.T) { + hub, srv, store := reworkHub(t) + fixConn(hub, "alice", fixCaps(capFixPRInterrupt), time.Now()) + + noteRework(store, "org/r", 4, stagelabels.ReturnedToContributor, "alice") + noteRework(store, "org/r", 5, stagelabels.AdoptedByHive, "alice") + // A draft is not in OpenPrs; the enumeration carries it as a sidelined + // row, which is still the canonical open set. + setReworkStatus(srv, FrontendRepo{Name: "r", Full: "org/r", + OpenPrs: []any{FrontendPR{PullRequest: github.PullRequest{Repo: "org/r", Number: 5}}}, + NonActionablePrs: []any{github.RepoWorkPR{Repo: "org/r", Number: 4, Draft: true, Bucket: "draft"}}, + }) + + fc := snapshotFor(t, hub, "alice") + if got := pendingNumbers(fc); fc.PendingRework != 2 || len(got) != 2 || got[0] != 4 || got[1] != 5 { + t.Fatalf("pending_rework=%d prs=%v, want open #4 (draft) and #5 (074)", fc.PendingRework, got) + } +} + +func TestFleetReworkIncompleteListingKeepsRecords(t *testing.T) { + cases := map[string]FrontendRepo{ + "incomplete": {Name: "r", Full: "org/r", CountsIncomplete: true}, + "stale": {Name: "r", Full: "org/r", CountsStale: true}, + "unlisted": {Name: "r", Full: "org/r", UnlistedPRs: 1}, + "other repo": {Name: "q", Full: "org/q"}, + } + for name, repo := range cases { + t.Run(name, func(t *testing.T) { + hub, srv, store := reworkHub(t) + fixConn(hub, "alice", fixCaps(capFixPRInterrupt), time.Now()) + noteRework(store, "org/r", 1, stagelabels.ReturnedToContributor, "alice") + setReworkStatus(srv, repo) + + fc := snapshotFor(t, hub, "alice") + if got := pendingNumbers(fc); fc.PendingRework != 1 || len(got) != 1 || got[0] != 1 { + t.Fatalf("pending_rework=%d prs=%v: a PR missing from a listing that cannot vouch for it must stay", fc.PendingRework, got) + } + }) + } +} + +func TestFleetReworkNoStatusKeepsRecords(t *testing.T) { + hub, _, store := reworkHub(t) + fixConn(hub, "alice", fixCaps(capFixPRInterrupt), time.Now()) + noteRework(store, "org/r", 1, stagelabels.ReturnedToContributor, "alice") + + fc := snapshotFor(t, hub, "alice") + if fc.PendingRework != 1 { + t.Fatalf("pending_rework=%d, want 1 before the first status snapshot", fc.PendingRework) + } +} + +func TestOpenPRIndexClosedIsCaseInsensitive(t *testing.T) { + idx := openPRIndex{repos: map[string]bool{"org/r": true}, prs: map[string]bool{stagelabels.Key("org/r", 1): true}} + if idx.closed("Org/R", 1) { + t.Fatal("#1 is listed open") + } + if !idx.closed("Org/R", 2) { + t.Fatal("#2 is absent from a complete listing") + } + if (openPRIndex{}).closed("org/r", 2) { + t.Fatal("an empty index knows nothing") + } +} From 9c8fd6e7d919d5dcd3e60088da7d93fba7e80083 Mon Sep 17 00:00:00 2001 From: Karibhou Date: Tue, 27 Oct 2026 21:53:14 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20dashboard:=20keep=20rework?= =?UTF-8?q?=20records=20for=20paused=20or=20never-enumerated=20repos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit openPRIndex treated a paused repo, or one built before the first eval cycle (no actionable snapshot), as a complete empty PR listing, so every rework PR in it counted as closed and the card emptied. Gate on ownershipRowsComplete, the existing "a missing row means the item left" predicate, and cover both shapes in TestFleetReworkIncompleteListingKeepsRecords. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HRH6kn4BsouThkrpz1TTCU Signed-off-by: Karibhou --- src/docs/contributor-relay.md | 2 +- src/pkg/dashboard/contribute_fleet_rework.go | 8 +++++--- src/pkg/dashboard/contribute_fleet_rework_14708_test.go | 6 +++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/docs/contributor-relay.md b/src/docs/contributor-relay.md index aebd74160d..2a015aeae2 100644 --- a/src/docs/contributor-relay.md +++ b/src/docs/contributor-relay.md @@ -1485,7 +1485,7 @@ Each row of the "Connected contributor agents (ClankeR)" list on `/contribute/op | `fix_queue_depth` | Red PRs waiting in the contributor's server-side fix queue (not dispatched). | | `pending_rework`, `pending_rework_prs[]` | The contributor's open PRs in `stage/072-returned-to-contributor` that have **not** been dispatched to them. The row prints a red **N PRs awaiting rework (not yet dispatched)** line, and an idle relay reads **idle · N PRs awaiting rework** instead of `idle: no matching work`. | -`kind: rework` means the item repairs one of the contributor's own PRs: any `fix-pr` task, or a task whose target the stage store has in a repair stage (`070-fixing`, `071-needs-author`, `072-returned-to-contributor`, `074-adopted-by-hive`). Everything else is `new`. `pending_rework` is derived without a GitHub call: the stage-label store (which remembers each PR's author) ∪ the fix queue, minus the fix tasks in flight on any of the contributor's connections, minus any PR the status snapshot shows as merged or closed. A stage record can outlive its PR when the stage sweep never saw it close, so a PR is dropped when its repo's open-PR list is complete (not incomplete, stale or carrying unlisted PRs) and does not include it; with no complete listing the record is kept. A non-zero `pending_rework` on an idle row is the signal to look at — typically a relay that did not advertise `fix_pr_interrupt_v1`, a preempt-mode relay inside its `contribute.min_focus_window`, or a contributor who is offline. +`kind: rework` means the item repairs one of the contributor's own PRs: any `fix-pr` task, or a task whose target the stage store has in a repair stage (`070-fixing`, `071-needs-author`, `072-returned-to-contributor`, `074-adopted-by-hive`). Everything else is `new`. `pending_rework` is derived without a GitHub call: the stage-label store (which remembers each PR's author) ∪ the fix queue, minus the fix tasks in flight on any of the contributor's connections, minus any PR the status snapshot shows as merged or closed. A stage record can outlive its PR when the stage sweep never saw it close, so a PR is dropped when its repo's open-PR list is complete (enumerated, not paused, not incomplete, stale or carrying unlisted PRs) and does not include it; with no complete listing the record is kept. A non-zero `pending_rework` on an idle row is the signal to look at — typically a relay that did not advertise `fix_pr_interrupt_v1`, a preempt-mode relay inside its `contribute.min_focus_window`, or a contributor who is offline. ## Reconnecting without losing in-flight work diff --git a/src/pkg/dashboard/contribute_fleet_rework.go b/src/pkg/dashboard/contribute_fleet_rework.go index 1d85edfe4f..aed0851250 100644 --- a/src/pkg/dashboard/contribute_fleet_rework.go +++ b/src/pkg/dashboard/contribute_fleet_rework.go @@ -148,8 +148,10 @@ type openPRIndex struct { } // openPRIndex builds the index from the hub server's current status. A repo -// whose counts are incomplete, stale or carry unlisted PRs is left out: a PR -// missing from a partial listing is not evidence that it closed. +// whose rows cannot vouch for a departure (ownershipRowsComplete: counts +// incomplete, paused, or never enumerated), or whose counts are stale or carry +// unlisted PRs, is left out: a PR missing from such a listing is not evidence +// that it closed. func (h *ContributeWSHub) openPRIndex() openPRIndex { var idx openPRIndex if h == nil || h.server == nil { @@ -163,7 +165,7 @@ func (h *ContributeWSHub) openPRIndex() openPRIndex { } idx.repos, idx.prs = map[string]bool{}, map[string]bool{} for _, repo := range status.Repos { - if repo.CountsIncomplete || repo.CountsStale || repo.UnlistedPRs > 0 { + if !ownershipRowsComplete(repo) || repo.CountsStale || repo.UnlistedPRs > 0 { continue } full := nonEmpty(repo.Full, repo.Name) diff --git a/src/pkg/dashboard/contribute_fleet_rework_14708_test.go b/src/pkg/dashboard/contribute_fleet_rework_14708_test.go index 86ebdcc78a..e60107d7f3 100644 --- a/src/pkg/dashboard/contribute_fleet_rework_14708_test.go +++ b/src/pkg/dashboard/contribute_fleet_rework_14708_test.go @@ -72,7 +72,11 @@ func TestFleetReworkIncompleteListingKeepsRecords(t *testing.T) { "incomplete": {Name: "r", Full: "org/r", CountsIncomplete: true}, "stale": {Name: "r", Full: "org/r", CountsStale: true}, "unlisted": {Name: "r", Full: "org/r", UnlistedPRs: 1}, - "other repo": {Name: "q", Full: "org/q"}, + "paused": {Name: "r", Full: "org/r", Paused: true}, + // Pre-scan shape: built before the first eval cycle (no actionable + // snapshot), so no counts or item lists are set at all. + "never enumerated": {Name: "r", Full: "org/r", ownershipDataMissing: true}, + "other repo": {Name: "q", Full: "org/q"}, } for name, repo := range cases { t.Run(name, func(t *testing.T) {