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
30 changes: 27 additions & 3 deletions bin/hive-open-issue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# forge-resistance as the gh wrapper; this shim adds no privilege.
#
# Usage (drop-in for the common gh shapes):
# hive-open-issue --repo <owner/repo> --title "<t>" [--body "<b>"|--body-file f] [--label a,b] [--parent <n>] [--blocked-by <n[,n]>] [--close-on-merge] [--needs-decision] [--no-consolidate <reason>] [--claim]
# hive-open-issue --repo <owner/repo> --title "<t>" [--body "<b>"|--body-file f] [--label a,b] [--parent <n|owner/repo#n>] [--blocked-by <n[,n]>] [--close-on-merge] [--needs-decision] [--no-consolidate <reason>] [--claim]
# hive-open-issue comment --repo <owner/repo> <number|url> --body "<b>" [--blocked-on-pr <n>] [--not-agent-work <verdict>]
# hive-open-issue claim --repo <owner/repo> <number|url>
# hive-open-issue close --repo <owner/repo> <number|url> [--override-reason "..."]
Expand All @@ -30,6 +30,14 @@
# so the link still reads in plain text. A failed link (parent missing, at
# GitHub's sub-issue cap, …) does not stop the child issue from being created.
#
# --parent <owner/repo#n> (or the parent's issue URL) names a parent in
# ANOTHER repo (hivecommons/hive#18680). File each child in the managed repo
# where its work lives (--repo) and point --parent at the tracker: the
# watcher links it across repos, writes `Part of owner/repo#n` and a
# cross-repo `hive:parent` marker, and counts it in the tracker's progress.
# When --repo is not a repo this hive manages, the child is filed in the
# parent's repo instead (the result's repo_fallback_from says so).
#
# --blocked-by <n[,n]> (repeatable) records each issue <n> in the same repo as
# a GitHub "blocked by" dependency of the new issue (hivecommons/hive#9839).
# Use it when a split has an order: the hive keeps a blocked child out of the
Expand Down Expand Up @@ -405,7 +413,7 @@ REVIEWERS_JSON="$(printf '%s\n' "${REVIEWERS[@]:-}" | python3 -c 'import json,sy
TEAM_REVIEWERS_JSON="$(printf '%s\n' "${TEAM_REVIEWERS[@]:-}" | python3 -c 'import json,sys; print(json.dumps([x.rstrip("\n") for x in sys.stdin if x.rstrip("\n")]))')"
BLOCKED_BY_JSON="$(printf '%s\n' "${BLOCKED_BY[@]:-}" | python3 -c 'import json,sys; print(json.dumps([x.rstrip("\n") for x in sys.stdin if x.rstrip("\n")]))')"
python3 - "$TEMP_FILE" "$REQ_FILE" "$KIND" "$REPO" "$TITLE" "${OVERRIDE_REASON:-$BODY}" "$AGENT" "$LABELS_JSON" "${NUMBER:-0}" "$DRY_RUN" "${PARENT:-0}" "$REMOVE_LABELS_JSON" "$REVIEWERS_JSON" "$TEAM_REVIEWERS_JSON" "$BLOCKED_BY_JSON" "$NEEDS_DECISION" "${BLOCKED_ON_PR:-0}" "$NO_CONSOLIDATE" "$CLAIM_ON_CREATE" "${NOT_AGENT_WORK:-}" <<'PY'
import json, os, sys
import json, os, re, sys
temporary, path, kind, repo, title, body, agent, labels, number, dry_run, parent, remove_labels, reviewers, team_reviewers, blocked_by, needs_decision, blocked_on_pr, no_consolidate, claim_on_create, not_agent_work = sys.argv[1:21]
labels = [part.strip() for value in json.loads(labels)
for part in value.split(",") if part.strip()]
Expand Down Expand Up @@ -450,8 +458,21 @@ else:
req["labels"] = labels
# --parent: link the new issue as a GitHub sub-issue of this number
# (hivecommons/hive#9435). Only meaningful for a create.
# (hivecommons/hive#18680) Also accepts "owner/repo#N" or an issue URL
# for a parent in another repo.
parent = parent.strip()
parent_repo = ""
m = re.match(r'^(?:https?://github\.com/)?([A-Za-z0-9_.-]+)/([A-Za-z0-9_.-]+)(?:#|/issues/)(\d+)/?$', parent)
if m:
parent_repo = m.group(1) + "/" + m.group(2)
parent = m.group(3)
parent = parent.lstrip("#")
if not parent.isdigit():
sys.exit("hive-open-issue: --parent must be N, #N, owner/repo#N or an issue URL")
if int(parent) > 0:
req["parent"] = int(parent)
if parent_repo and parent_repo.lower() != repo.strip().lower():
req["parent_repo"] = parent_repo
# --blocked-by: record GitHub "blocked by" dependencies on the new issue
# (hivecommons/hive#9839). Accepts "12", "#12", "12,13", repeated flags.
blockers = []
Expand Down Expand Up @@ -529,7 +550,10 @@ elif [ "$KIND" = "request_review" ]; then
else
echo "hive-open-issue: requested issue on $REPO as the App bot: $TITLE"
if [ -n "$PARENT" ] && [ "$PARENT" != "0" ]; then
echo "hive-open-issue: will link as a GitHub sub-issue of $REPO#$PARENT"
case "$PARENT" in
*/*) echo "hive-open-issue: will link as a GitHub sub-issue of $PARENT" ;;
*) echo "hive-open-issue: will link as a GitHub sub-issue of $REPO#${PARENT#\#}" ;;
esac
fi
if [ "$NEEDS_DECISION" -eq 1 ]; then
echo "hive-open-issue: will park the issue on a maintainer decision (needs-decision label)"
Expand Down
41 changes: 41 additions & 0 deletions bin/test_hive_open_issue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,47 @@ fi
rm -rf "$REQ_DIR"
mkdir -p "$REQ_DIR"

# A cross-repo parent (hivecommons/hive#18680): owner/repo#N and an issue URL
# both produce parent + parent_repo; a same-repo owner/repo#N omits parent_repo.
run_script "xparentbot" --repo "hiveorg/companion" --title "Cross child" --body "body" \
--parent "hiveorg/widgets#100"
REQ_FILE="$(find_req xparentbot)"
if [ -n "$REQ_FILE" ]; then
GOT="$(python3 -c "import json,sys; d=json.load(open(sys.argv[1])); print(d.get('parent', 0), d.get('parent_repo', ''))" "$REQ_FILE")"
check "--parent owner/repo#N produces parent and parent_repo" "100 hiveorg/widgets" "$GOT"
else
echo " FAIL: request file not created for cross-repo --parent test"
FAIL=$((FAIL + 1))
fi
rm -rf "$REQ_DIR"
mkdir -p "$REQ_DIR"

run_script "urlparentbot" --repo "hiveorg/companion" --title "URL child" --body "body" \
--parent "https://github.com/hiveorg/widgets/issues/101"
REQ_FILE="$(find_req urlparentbot)"
if [ -n "$REQ_FILE" ]; then
GOT="$(python3 -c "import json,sys; d=json.load(open(sys.argv[1])); print(d.get('parent', 0), d.get('parent_repo', ''))" "$REQ_FILE")"
check "--parent issue URL produces parent and parent_repo" "101 hiveorg/widgets" "$GOT"
else
echo " FAIL: request file not created for URL --parent test"
FAIL=$((FAIL + 1))
fi
rm -rf "$REQ_DIR"
mkdir -p "$REQ_DIR"

run_script "sameparentbot" --repo "hiveorg/widgets" --title "Same child" --body "body" \
--parent "hiveorg/widgets#102"
REQ_FILE="$(find_req sameparentbot)"
if [ -n "$REQ_FILE" ]; then
GOT="$(python3 -c "import json,sys; d=json.load(open(sys.argv[1])); print(d.get('parent', 0), 'parent_repo' in d)" "$REQ_FILE")"
check "--parent naming the same repo omits parent_repo" "102 False" "$GOT"
else
echo " FAIL: request file not created for same-repo --parent test"
FAIL=$((FAIL + 1))
fi
rm -rf "$REQ_DIR"
mkdir -p "$REQ_DIR"

# Omitting --parent must not add the field at all (optional, not zero-valued).
run_script "noparentbot" --repo "hiveorg/widgets" --title "No parent" --body "body"

Expand Down
1 change: 1 addition & 0 deletions changelog.d/fixed-18676-cross-repo-pr-issue-stage-link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- A PR in one managed repo that references an issue in another (`Refs owner/repo#N`, `Fixes owner/repo#N`) now covers that issue ([#18676](https://github.com/hivecommons/hive/issues/18676)). The claim was keyed `owner/repo#N` while enumeration keys issues by the configured (often bare) repo name, so the issue stayed Actionable with no PR. The claim is now keyed by the configured spelling, the issue is staged covered-by-PR and follows the PR's stage (for example needs-decision), it gets a `hive:issue-stage-pr-link` comment naming the PR as `owner/repo#N`, and the hive agent's claim on the issue is renewed while that PR is open and released once it merges or closes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Scanner decomposition now files each child issue in the managed repo where its work lives, not always in the tracker's repo ([#18680](https://github.com/hivecommons/hive/issues/18680)). `hive-open-issue --parent owner/repo#N` (or the parent's issue URL) names a parent in another repo: the relay links the child as a cross-repo sub-issue, writes `Part of owner/repo#N` and a `<!-- hive:parent owner/repo#N -->` marker (a bare `#N` only resolves inside the child's own repo), and the split-parent ledger records the parent's repo. A tracker's progress and its auto-close count children in any managed repo. A parent repo the hive does not manage is refused, and a child repo it does not manage falls back to the parent's repo (`repo_fallback_from` in the result), so children are never filed in unmanaged repos.
17 changes: 15 additions & 2 deletions src/docs/hive-open-issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Shapes are selected by an optional leading positional keyword (`comment`,
`issue`):

```sh
hive-open-issue --repo <owner/repo> --title "<t>" [--body "<b>"|--body-file f] [--label a,b] [--parent <n>] [--blocked-by <n[,n]>] [--needs-decision] [--no-consolidate <reason>] [--claim]
hive-open-issue --repo <owner/repo> --title "<t>" [--body "<b>"|--body-file f] [--label a,b] [--parent <n|owner/repo#n>] [--blocked-by <n[,n]>] [--needs-decision] [--no-consolidate <reason>] [--claim]
hive-open-issue comment --repo <owner/repo> <number|url> --body "<b>" [--blocked-on-pr <n>] [--not-agent-work <verdict>]
hive-open-issue claim --repo <owner/repo> <number|url>
hive-open-issue label --repo <owner/repo> <number|url> [--label a,b] [--remove-label c]
Expand All @@ -59,7 +59,7 @@ hive-open-issue request-review --repo <owner/repo> <number|url> [--reviewer a,b]
| `--remove-label` | — | label | repeatable; labels to take off the item |
| `--reviewer` | `--add-reviewer` | request-review | repeatable; comma-separated GitHub logins to ask for a review |
| `--team-reviewer` | — | request-review | repeatable; team slugs (an `org/` prefix is accepted) to ask for a review |
| `--parent` | — | issue | issue number in the same repo to link the new issue to as a GitHub sub-issue. Declaring it also exempts the request from the file-set, component and canonical-subject folds (see [DAG children never take a fold](#dag-children-never-take-a-fold)), so `--no-consolidate` is not needed for a decomposition child |
| `--parent` | — | issue | issue number in the same repo (or `owner/repo#n` for a parent in another managed repo) to link the new issue to as a GitHub sub-issue. Declaring it also exempts the request from the file-set, component and canonical-subject folds (see [DAG children never take a fold](#dag-children-never-take-a-fold)), so `--no-consolidate` is not needed for a decomposition child |
| `--blocked-by` | — | issue | repeatable; issue numbers in the same repo the new issue is blocked by, recorded as GitHub "blocked by" dependencies (`#` prefix tolerated). Like `--parent`, declaring it exempts the request from the shared-path folds (see [DAG children never take a fold](#dag-children-never-take-a-fold)) |
| `--needs-decision` | — | issue | park the new issue on a maintainer decision: the watcher applies the hive's configured needs-decision label itself (see [Parking an issue that needs a decision](#parking-an-issue-that-needs-a-decision)) |
| `--claim` | — | issue | file the new issue **and** claim it for this agent in the same request (see [Filing your own next step](#filing-your-own-next-step)). The request carries `"claim": true`; the result reports `claimed`, or `claim_error` when the claim did not land |
Expand Down Expand Up @@ -140,6 +140,19 @@ is never marked `stage/stalled`
([#12857](https://github.com/hivecommons/hive/issues/12857); see
[labels-and-control-signals.md](labels-and-control-signals/stage-labels.md#decomposed-parents--closed-by-their-children-never-stalled)).

`--parent <owner/repo#n>` (or the parent's issue URL) names a parent in
another managed repo, for a tracker whose child work lives elsewhere
([#18680](https://github.com/hivecommons/hive/issues/18680)). File the child in
the repo where its work lives (`--repo`); the request carries `"parent"` and
`"parent_repo"`. The watcher links the child as a cross-repo sub-issue of
`owner/repo#n`, rewrites bare `#n` mentions of the parent (including the
"Part of" line, which it adds when missing) to `owner/repo#n`, and writes the
marker as `<!-- hive:parent owner/repo#n -->`, because a bare `#n` resolves
only inside the child's own repo. The parent's tracker progress counts such
children too. A parent repo this hive does not manage is refused; a child
repo it does not manage falls back to the parent's repo, and the result's
`repo_fallback_from` names the repo that was asked for.

`--blocked-by <n[,n]>` records that the new issue must wait for issue(s) `n`
in the same repo, as GitHub "blocked by" dependencies
(`POST /repos/{owner}/{repo}/issues/{new}/dependencies/blocked_by`), after the
Expand Down
2 changes: 1 addition & 1 deletion src/docs/scale-envelope.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ones to:
2. **Truncation must preserve the prioritization signal, not cut an arbitrary slice.**
This holds today and is easy to assume backwards:
- Issues are sorted by actionable rank tier, then **oldest first** within each tier before any cap is applied
(`RankActionableIssues`, `src/pkg/github/client.go:5343-5353`, descending `AgeMinutes` within each tier).
(`RankActionableIssues`, `src/pkg/github/client.go:5351-5361`, descending `AgeMinutes` within each tier).
- PRs are sorted by **review class then oldest-first within class**
(`SortPullRequestsForReview`, `src/pkg/github/review_priority.go:334`;
fixes → refactors/docs → tests).
Expand Down
77 changes: 77 additions & 0 deletions src/pkg/dashboard/claims_agent_pr_hold_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package dashboard

import (
"testing"

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

// An agent claim stays live while the hive's open PR in ANOTHER managed repo
// references the issue, and is released once that PR stops covering it
// (hivecommons/hive#18676: hivecommons/quorum-companion#3 `Refs
// hivecommons/hive#18660`, whose claim lapsed while the PR was open).
func TestClaims_AgentClaimHeldByCrossRepoPR(t *testing.T) {
hub, s, l := claimsHub(t)
covering := ghpkg.IssueClaim{Repo: "repo1", Issue: 1, PRRepo: "companion", PRNumber: 3,
PRURL: "https://github.com/myorg/companion/pull/3", PRAuthor: "hive[bot]", PRState: ghpkg.PRStateOpen, Reference: true}
open := true
s.deps.IssueClaimed = func(repo string, number int) (ghpkg.IssueClaim, bool) {
// The duplicate-PR ledger keys the claim by the configured (bare)
// spelling; the sweep must find it from the claim's owner/repo key.
if repo == "repo1" && number == 1 && open {
return covering, true
}
return ghpkg.IssueClaim{}, false
}
res, err := l.Claim(claims.Request{Repo: "myorg/repo1", Issue: 1, Holder: "scanner", HolderID: "scanner", Kind: claims.KindAgent})
if err != nil || !res.Outcome.Changed() {
t.Fatalf("claim: %+v %v", res, err)
}
before := res.Claim.ExpiresAt

if n := hub.sweepPRHeldClaims(); n != 0 {
t.Fatalf("sweep released %d claims while the cross-repo PR is open", n)
}
c, ok := l.Lookup("myorg/repo1", 1)
if !ok || c.Holder != "scanner" || !c.PRStarted || c.PRRepo != "companion" || c.PRNumber != 3 {
t.Fatalf("claim after sweep = %+v ok=%v, want held for companion#3", c, ok)
}
if !c.ExpiresAt.After(before) {
t.Fatalf("claim expiry %v not renewed past %v", c.ExpiresAt, before)
}

// External PRs and merged PRs never hold an agent's claim.
for _, pr := range []ghpkg.IssueClaim{
{Repo: "repo1", Issue: 2, PRRepo: "companion", PRNumber: 4, ExternalAuthor: true},
{Repo: "repo1", Issue: 2, PRRepo: "companion", PRNumber: 4, MergedPR: true},
} {
if _, ok := (&ContributeWSHub{server: &Server{deps: &Dependencies{IssueClaimed: func(string, int) (ghpkg.IssueClaim, bool) { return pr, true }}}}).agentCoveringPR(claims.Claim{Repo: "myorg/repo1", Issue: 2}); ok {
t.Fatalf("%+v must not hold an agent claim", pr)
}
}

open = false
if n := hub.sweepPRHeldClaims(); n != 1 {
t.Fatalf("sweep released %d claims once the PR closed, want 1", n)
}
if _, ok := l.Lookup("myorg/repo1", 1); ok {
t.Fatal("PR-held agent claim survived its PR closing")
}
}

// An agent claim with no covering PR is left to its own TTL: the sweep never
// releases a claim it did not hold.
func TestClaims_AgentClaimWithoutPRLeftAlone(t *testing.T) {
hub, s, l := claimsHub(t)
s.deps.IssueClaimed = func(string, int) (ghpkg.IssueClaim, bool) { return ghpkg.IssueClaim{}, false }
if _, err := l.Claim(claims.Request{Repo: "myorg/repo1", Issue: 5, Holder: "scanner", HolderID: "scanner", Kind: claims.KindAgent}); err != nil {
t.Fatal(err)
}
if n := hub.sweepPRHeldClaims(); n != 0 {
t.Fatalf("released %d", n)
}
if c, ok := l.Lookup("myorg/repo1", 5); !ok || c.PRStarted {
t.Fatalf("claim = %+v ok=%v, want untouched", c, ok)
}
}
52 changes: 51 additions & 1 deletion src/pkg/dashboard/claims_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,20 @@ func (h *ContributeWSHub) recordCompletionPRClaim(task *WSTaskAssign, prURL, use
// covers the issue the hold is renewed; once it merged, closed, or stopped
// covering the issue the claim is released. Without the duplicate-PR ledger
// wired there is nothing to re-check against, so the holds are left to their
// own TTL. Returns how many claims were released.
// own TTL. A hive agent's claim is renewed the same way while an open hive
// PR covers its issue, in any managed repo (sweepAgentPRHeldClaim,
// hivecommons/hive#18676). Returns how many claims were released.
func (h *ContributeWSHub) sweepPRHeldClaims() int {
l := h.claimsLedger()
if l == nil || h.server == nil || h.server.deps == nil || h.server.deps.IssueClaimed == nil {
return 0
}
released := 0
for _, c := range l.List() {
if c.Kind == claims.KindAgent && c.HolderID != "" {
released += h.sweepAgentPRHeldClaim(l, c)
continue
}
if c.Kind != claims.KindContributor || c.PRNumber <= 0 || c.HolderID == "" {
continue
}
Expand All @@ -294,6 +300,50 @@ func (h *ContributeWSHub) sweepPRHeldClaims() int {
return released
}

// sweepAgentPRHeldClaim keeps a hive agent's claim alive while an open PR
// the hive authored covers the issue, in whatever managed repo that PR lives
// (hivecommons/hive#18676): the scanner claimed hivecommons/hive#18660 and
// opened hivecommons/quorum-companion#3 with `Refs hivecommons/hive#18660`;
// nothing renewed the claim once the agent's session ended, so it lapsed
// two hours later while the PR waited on a decision and the issue read as
// abandoned. A claim held this way (Claim.PRNumber set) is released once no
// open hive PR covers the issue any more. A claim the sweep never held is
// left to its own TTL. Returns 1 when it released the claim.
func (h *ContributeWSHub) sweepAgentPRHeldClaim(l *claims.Ledger, c claims.Claim) int {
if pr, ok := h.agentCoveringPR(c); ok {
l.HoldForPR(c.HolderID, c.Key(), coveringPRRepo(pr), pr.PRNumber)
return 0
}
if c.PRNumber <= 0 {
return 0
}
released := 0
for _, r := range l.ReleaseByHolderID(c.HolderID, claims.ReasonCoveringPRDone, c.Key()) {
released++
h.logger.Info("[claims] PR-held agent claim released", "issue", r.Key(), "holder", r.Holder, "pr", r.PRNumber, "pr_repo", r.PRRepo)
}
return released
}

// agentCoveringPR reports the open, hive-authored pull request the
// duplicate-PR claim ledger records against an agent claim's issue —
// closing or a non-closing `Refs`, same repo or another managed repo (the
// ledger keys a cross-repo `Refs owner/repo#N` under the issue's repo).
func (h *ContributeWSHub) agentCoveringPR(c claims.Claim) (ghpkg.IssueClaim, bool) {
name := c.Repo
if i := strings.LastIndex(name, "/"); i >= 0 {
name = name[i+1:]
}
pr, ok := h.issueClaimedByOpenPR(c.Repo, name, c.Issue)
if !ok || pr.PRNumber <= 0 || pr.MergedPR || pr.ExternalAuthor {
return ghpkg.IssueClaim{}, false
}
if state := strings.TrimSpace(pr.PRState); state != "" && state != ghpkg.PRStateOpen {
return ghpkg.IssueClaim{}, false
}
return pr, true
}

// removeLegacyClaimLabelForLease tells the stage engine the contributor
// claim that travelled with a lease is gone (a ClaimReleased fact, ADR-0025)
// so the issue's stage/020-claimed comes off; the engine re-reads the issue
Expand Down
Loading
Loading