diff --git a/changelog.d/fixed-issue-reference-detection-commits-comments.md b/changelog.d/fixed-issue-reference-detection-commits-comments.md new file mode 100644 index 0000000000..95aec36907 --- /dev/null +++ b/changelog.d/fixed-issue-reference-detection-commits-comments.md @@ -0,0 +1 @@ +- **A PR that names an issue in its title, body or a comment now counts as linked to it** ([#14859](https://github.com/hivecommons/hive/issues/14859)). The contribute view's issue→PR resolver checked only the PR title and body, so it dropped any search hit that mentioned the issue elsewhere. The same title/body-only view let a scanner note claim that a PR "does not reference" an issue when two of its commits said `Fixes #N`. The resolver now also reads the issue's timeline `cross-referenced` events (up to five pages of 100, under the existing 4s lookup timeout), which cover title, body and comment references (a commit-message-only reference is a `referenced` event and is not matched). The scanner and dedupe policies now tell agents to check that timeline and the PR's commits and comments before saying a PR does not reference an issue, and to say "no closing keyword in the PR body" when only the body lacks one. The added policy section grows the largest shipped policy past the 2x headroom the prompt-size cap requires, so `promptsrc.DefaultMaxPromptBytes` rises from 64 KiB to 96 KiB; `HIVE_PROMPT_SOURCE_MAX_BYTES` still overrides it. diff --git a/src/docs/agent-configuration.md b/src/docs/agent-configuration.md index e4085ce136..268888bca1 100644 --- a/src/docs/agent-configuration.md +++ b/src/docs/agent-configuration.md @@ -938,7 +938,7 @@ An empty allowlist denies every repo even with `allow_github_prompt: true` — t A fetched file is capped at 512 KiB (`maxDefinitionBytes`, `defsrc.go:43`); an oversized file is truncated (and likely then fails to parse) rather than consuming unbounded memory. -The per-agent `prompt_source` (a kick template fetched from GitHub by `pkg/promptsrc`) has a tighter, token-oriented cap and a stricter failure mode ([#12130](https://github.com/hivecommons/hive/issues/12130)): 64 KiB by default (`promptsrc.DefaultMaxPromptBytes`, >2× the largest shipped template; `HIVE_PROMPT_SOURCE_MAX_BYTES` overrides), and a body over it is **rejected whole, never truncated**. The kick falls back to the last successfully fetched copy, then to the normal `kick_template` chain, with a logged warning naming the repo, path, size and cap; the dashboard's save/bake flow fails with the same message instead of writing a cut-off policy. See [operator-reference.md](operator-reference.md#notable-fields). +The per-agent `prompt_source` (a kick template fetched from GitHub by `pkg/promptsrc`) has a tighter, token-oriented cap and a stricter failure mode ([#12130](https://github.com/hivecommons/hive/issues/12130)): 96 KiB by default (`promptsrc.DefaultMaxPromptBytes`, >2× the largest shipped template; `HIVE_PROMPT_SOURCE_MAX_BYTES` overrides), and a body over it is **rejected whole, never truncated**. The kick falls back to the last successfully fetched copy, then to the normal `kick_template` chain, with a logged warning naming the repo, path, size and cap; the dashboard's save/bake flow fails with the same message instead of writing a cut-off policy. See [operator-reference.md](operator-reference.md#notable-fields). ### Validating a source before saving it diff --git a/src/docs/env-vars.md b/src/docs/env-vars.md index 5052203368..add0f06384 100644 --- a/src/docs/env-vars.md +++ b/src/docs/env-vars.md @@ -174,7 +174,7 @@ new value at the same time. | `HIVE_PR_FOLLOWUP_DIR` | No | `/data/turn/pr-followups` | Directory the per-PR follow-up pointers (`pkg/turn` envelopes) are persisted under. On the persistent volume so pointers and queued follow-ups survive restarts. | | `OTEL_EXPORTER_OTLP_ENDPOINT` | No | none | OTLP/HTTP exporter endpoint for traces and metrics (`github.*`, `forgestate.*`, `webhook.*`). Both stay disabled while unset; see `operator-reference.md` § OpenTelemetry. | | `HIVE_WIKI_GIT_URL` | No | none | Optional wiki vault URL cloned into `/data/vaults/hive-wiki` on first boot. | -| `HIVE_PROMPT_SOURCE_MAX_BYTES` | No | `65536` (`promptsrc.DefaultMaxPromptBytes`, 64 KiB) | Size cap on a GitHub `prompt_source` kick template ([#12130](https://github.com/hivecommons/hive/issues/12130)). A body over the cap is **rejected whole, never truncated**: the kick falls back to the last successfully fetched copy, then the inline template chain, and logs `prompt from GitHub exceeds size cap; REJECTED whole` with repo, path, size and cap. Accepts a byte count or `KiB`/`MiB` suffix (`128KiB`); unparseable values keep the default. The largest shipped template is ~28 KiB, so the default leaves >2× headroom — raise it only for a real template that outgrows that. | +| `HIVE_PROMPT_SOURCE_MAX_BYTES` | No | `98304` (`promptsrc.DefaultMaxPromptBytes`, 96 KiB) | Size cap on a GitHub `prompt_source` kick template ([#12130](https://github.com/hivecommons/hive/issues/12130)). A body over the cap is **rejected whole, never truncated**: the kick falls back to the last successfully fetched copy, then the inline template chain, and logs `prompt from GitHub exceeds size cap; REJECTED whole` with repo, path, size and cap. Accepts a byte count or `KiB`/`MiB` suffix (`128KiB`); unparseable values keep the default. The largest shipped template is ~33 KiB, so the default leaves >2× headroom — raise it only for a real template that outgrows that. | ## Inference, CLI backends, and agents diff --git a/src/docs/operator-reference.md b/src/docs/operator-reference.md index 02046c1f2a..5cf3107b55 100644 --- a/src/docs/operator-reference.md +++ b/src/docs/operator-reference.md @@ -270,7 +270,7 @@ Go callers keep reading `cfg.Agents`, `cfg.Governor.Gateways` and so on through | `knowledge.publish` | Unset (`connector` empty): publishing off. | One-way mirror of curator-promoted facts into one connector target: `connector` (a `knowledge.connectors` name whose type can publish), `layers` (`project`/`org`/`community`; personal is never published), `root`, optional `include_types`, `dry_run`, `propose_via`. Facts are read from each layer's `knowledge.layers[].path`. Started at boot (a bad connector logs `knowledge publish mirror disabled` and leaves publishing off); state in `/data/knowledge/connector-state/_publish`. Status in the `publish` object of `GET /api/knowledge/connectors`; owner-only `POST /api/knowledge/publish/sync`. See [knowledge-connectors.md](knowledge-connectors.md#publish-mirror). | | `knowledge.bead_synthesizer.publish` | Off (`enabled: false`). | Publishes synthesized facts into a repository through one PR on `hive/bead-synth-knowledge`: `enabled`, `repo` (empty = `project.primary_repo`), `path` (default `docs/knowledge/`; `.hive/knowledge/` is the alternative; relative, no `..`), `base_branch` (empty = repo default branch), `mode` (`pr` default or `commit`), `cadence` (`per_run` default or `daily`). ACMM L<=4 hives publish via PR only; `commit` is warned about and still opens a PR. See [knowledge-curator.md](knowledge-curator.md#repository-publish-knowledgebead_synthesizerpublish). | | `variables.security.*` | Deny by default. | `allow_exec`, `allow_http`, and GitHub prompt-source allowlists are honored only from the trusted seed, not dashboard overlays. | -| `agents..prompt_source` (size cap) | 64 KiB (`promptsrc.DefaultMaxPromptBytes`); `HIVE_PROMPT_SOURCE_MAX_BYTES` overrides it. | A fetched kick template over the cap is **rejected whole, not truncated** ([#12130](https://github.com/hivecommons/hive/issues/12130)): the kick uses the last successfully fetched copy if there is one, otherwise the ordinary `kick_template` → pack → convention → embedded-default chain, and the scheduler logs `prompt from GitHub exceeds size cap; REJECTED whole (not truncated), falling back` with `repo`, `path`, `size_bytes` and `cap_bytes`. Saving an agent whose source is over the cap fails in the dashboard with the same sizes rather than baking a cut-off policy. A half-policy is a policy with its closing rules missing; no remote policy is the safer failure. Every shipped template fits with >2× headroom (`TestShippedTemplatesFitUnderCap`). | +| `agents..prompt_source` (size cap) | 96 KiB (`promptsrc.DefaultMaxPromptBytes`); `HIVE_PROMPT_SOURCE_MAX_BYTES` overrides it. | A fetched kick template over the cap is **rejected whole, not truncated** ([#12130](https://github.com/hivecommons/hive/issues/12130)): the kick uses the last successfully fetched copy if there is one, otherwise the ordinary `kick_template` → pack → convention → embedded-default chain, and the scheduler logs `prompt from GitHub exceeds size cap; REJECTED whole (not truncated), falling back` with `repo`, `path`, `size_bytes` and `cap_bytes`. Saving an agent whose source is over the cap fails in the dashboard with the same sizes rather than baking a cut-off policy. A half-policy is a policy with its closing rules missing; no remote policy is the safer failure. Every shipped template fits with >2× headroom (`TestShippedTemplatesFitUnderCap`). | | `data.claude_sessions_dir` | `/data/home/.claude/projects` | Where the dashboard reads Claude Code session JSONL for per-agent token/cost accounting. Point it at the agents' real session directory if you relocate `HOME`. | | `data.copilot_sessions_dir` | `/data/home/.copilot/session-state` | Same, for the Copilot CLI backend's session state. | diff --git a/src/pkg/dashboard/contribute_prlink.go b/src/pkg/dashboard/contribute_prlink.go index 70b6334500..a963f3715e 100644 --- a/src/pkg/dashboard/contribute_prlink.go +++ b/src/pkg/dashboard/contribute_prlink.go @@ -18,12 +18,21 @@ const ( // request. Mirrors the "cheap cached projection" cadence of the metrics rollup. prLinkCacheTTL = 90 * time.Second - // prLinkLookupTimeout bounds a single GitHub Search call so one slow response - // can never wedge the resolver (and, transitively, the triage endpoint). On - // timeout the issue degrades to "no linked PR" for this cycle and is retried - // after the TTL, exactly like an error. + // prLinkLookupTimeout bounds one whole lookup — the GitHub Search call plus + // the issue-timeline read that follows it (at most prLinkTimelineMaxPages + // requests) — so one slow response can never wedge the resolver (and, + // transitively, the triage endpoint). On timeout the issue degrades to "no + // linked PR" for this cycle and is retried after the TTL, exactly like an + // error. prLinkLookupTimeout = 4 * time.Second + // prLinkTimelineMaxPages caps how many 100-event timeline pages one lookup + // reads. Like prLinkSearchPerPage, the point is to stay cheap: a real issue + // has a few dozen events, and an issue busy enough to exceed 500 almost + // always has its referencing PR among the earlier ones. Past the cap the + // lookup keeps what it has read instead of walking the rest. + prLinkTimelineMaxPages = 5 + // prLinkStateOpen / prLinkStateMerged are the two surfaced link states. A PR // that is closed-but-not-merged is treated as "no active link" (nil) — it did // not land the fix and is not awaiting review — so only these two states ever @@ -118,13 +127,15 @@ func (r *prLinkResolver) resolve(ctx context.Context, repo string, number int) * return status } -// searchLinkedPR asks GitHub which PR (if any) references this issue. It runs ONE +// searchLinkedPR asks GitHub which PR (if any) references this issue. It runs one // Search.Issues query scoped to the issue's repo, matching PRs that mention the // issue number — GitHub indexes the Fixes/Closes/Resolves cross-reference as well // as any plain "#N" body/title mention, so the closing PR is included. A merged // PR wins over a merely-open one (the fix landed), so results are scanned for a -// merged hit first, then an open one. A nil client or empty result is "no linked -// PR" (nil, nil) — never an error the caller must handle. +// merged hit first, then an open one. When the search yields no merged PR it also +// reads the issue's timeline, whose cross-referenced events catch a PR that names +// the issue in its body or a comment. A nil client or empty result is +// "no linked PR" (nil, nil) — never an error the caller must handle. func searchLinkedPR(ctx context.Context, gc *gh.Client, repo string, number int) (*prLinkStatus, error) { if gc == nil || repo == "" || number <= 0 { return nil, nil @@ -141,34 +152,104 @@ func searchLinkedPR(ctx context.Context, gc *gh.Client, repo string, number int) if err != nil { return nil, err } - if result == nil { - return nil, nil - } var open *prLinkStatus - for _, iss := range result.Issues { - if iss == nil || iss.PullRequestLinks == nil { - continue // search can return issues too; keep only PRs + if result != nil { + for _, iss := range result.Issues { + if iss == nil || iss.PullRequestLinks == nil { + continue // search can return issues too; keep only PRs + } + if !prReferencesIssue(iss, number) { + continue + } + st, merged := prLinkCandidate(iss) + if merged { + return st, nil + } + if st != nil && open == nil { + open = st + } } - if !prReferencesIssue(iss, number) { - continue - } - st := &prLinkStatus{Number: iss.GetNumber(), URL: iss.GetHTMLURL()} - // A closed PR that carries a merged_at (via PullRequestLinks) landed the - // fix — surface it as merged immediately (it also implies the issue is - // Closed in the triage ladder). Prefer it over any open candidate. - if iss.PullRequestLinks.MergedAt != nil { - st.State = prLinkStateMerged + } + + // The title/body check above cannot see a PR that names the issue only in + // a PR comment (hivecommons/hive#14859). GitHub records such a mention + // as a cross-referenced event on the issue's timeline, so one timeline + // read covers body and comment references. Commit-message references + // arrive as referenced events and are not matched here. A + // timeline error keeps whatever the search already found. + for _, iss := range crossReferencingPRs(ctx, gc, repo, number) { + st, merged := prLinkCandidate(iss) + if merged { return st, nil } - if iss.GetState() == "open" && open == nil { - st.State = prLinkStateOpen + if st != nil && open == nil { open = st } } return open, nil } +// prLinkCandidate grades one referencing PR: merged (the fix landed), open +// (awaiting review), or nil for a PR closed without merging. +func prLinkCandidate(iss *gh.Issue) (*prLinkStatus, bool) { + st := &prLinkStatus{Number: iss.GetNumber(), URL: iss.GetHTMLURL()} + // A closed PR that carries a merged_at (via PullRequestLinks) landed the + // fix — surface it as merged immediately (it also implies the issue is + // Closed in the triage ladder). Prefer it over any open candidate. + if iss.PullRequestLinks != nil && iss.PullRequestLinks.MergedAt != nil { + st.State = prLinkStateMerged + return st, true + } + if iss.GetState() == "open" { + st.State = prLinkStateOpen + return st, false + } + return nil, false +} + +// crossReferencingPRs returns the same-repo pull requests named by the +// issue's timeline cross-referenced events — a reference from a PR's title, +// body, or comments (commit-message references are referenced events and are +// not matched). It reads at most prLinkTimelineMaxPages +// pages; errors and the page cap yield what was read so far. +func crossReferencingPRs(ctx context.Context, gc *gh.Client, repo string, number int) []*gh.Issue { + owner, name, ok := strings.Cut(repo, "/") + if !ok || owner == "" || name == "" { + return nil + } + var out []*gh.Issue + seen := map[int]bool{} + opts := &gh.ListOptions{PerPage: 100} + for page := 0; page < prLinkTimelineMaxPages; page++ { + events, resp, err := gc.Issues.ListIssueTimeline(ctx, owner, name, number, opts) + if err != nil { + return out + } + for _, ev := range events { + if ev == nil || !strings.EqualFold(ev.GetEvent(), "cross-referenced") { + continue + } + src := ev.GetSource() + if src == nil || src.Issue == nil || !src.Issue.IsPullRequest() { + continue + } + if full := src.Issue.GetRepository().GetFullName(); full != "" && !strings.EqualFold(full, repo) { + continue + } + if n := src.Issue.GetNumber(); n > 0 && !seen[n] { + seen[n] = true + out = append(out, src.Issue) + } + } + if resp == nil || resp.NextPage == 0 { + return out + } + opts.Page = resp.NextPage + } + return out +} + // prLinkSearchPerPage caps how many candidate PRs one lookup inspects. A handful // is plenty: a real issue has at most a few referencing PRs, and we only need to // know whether an open or merged one exists. Small page keeps the Search call diff --git a/src/pkg/dashboard/contribute_prlink_test.go b/src/pkg/dashboard/contribute_prlink_test.go index ba7df89791..ee43519366 100644 --- a/src/pkg/dashboard/contribute_prlink_test.go +++ b/src/pkg/dashboard/contribute_prlink_test.go @@ -3,6 +3,9 @@ package dashboard import ( "context" "fmt" + "net/http" + "net/http/httptest" + "net/url" "strings" "sync" "testing" @@ -374,3 +377,134 @@ func TestHumanizeAge(t *testing.T) { // ── helpers ───────────────────────────────────────────────────────────────── func strPtr(s string) *string { return &s } + +// ── searchLinkedPR: commit / comment / timeline references (#14859) ──────── + +// TestSearchLinkedPR_CountsCommitCommentAndTimelineReferences pins +// hivecommons/hive#14859: a PR that names the issue only in a commit message +// or a PR comment must still count as linked. GitHub records those mentions +// as cross-referenced events on the issue's timeline; before the fix only the +// PR title/body was consulted, so such a PR read as "no linked PR". +func TestSearchLinkedPR_CountsCommitCommentAndTimelineReferences(t *testing.T) { + const issue = 13135 + // A search hit whose title/body does not name the issue: GitHub search + // matched it on a comment or commit mention. + searchHit := `{"number":14656,"state":"open","title":"keep the header chips from overlapping the title","body":"Hive Agent","html_url":"https://github.com/o/r/pull/14656","pull_request":{"url":"x"}}` + crossRef := func(src string) string { + return `{"event":"cross-referenced","created_at":"2026-10-27T00:00:00Z","source":{"type":"issue","issue":` + src + `}}` + } + openPR := `{"number":14656,"state":"open","html_url":"https://github.com/o/r/pull/14656","repository":{"full_name":"o/r"},"pull_request":{"url":"x"}}` + mergedPR := `{"number":14656,"state":"closed","html_url":"https://github.com/o/r/pull/14656","repository":{"full_name":"o/r"},"pull_request":{"url":"x","merged_at":"2026-10-28T00:00:00Z"}}` + otherRepoPR := `{"number":77,"state":"open","html_url":"https://github.com/x/y/pull/77","repository":{"full_name":"x/y"},"pull_request":{"url":"x"}}` + plainIssue := `{"number":14859,"state":"open","html_url":"https://github.com/o/r/issues/14859","repository":{"full_name":"o/r"}}` + + cases := []struct { + name string + search string + timeline string + wantNumber int + wantState string + }{ + { + name: "comment reference only (cross-referenced event, search miss)", + search: `[]`, + timeline: `[` + crossRef(openPR) + `]`, + wantNumber: 14656, + wantState: prLinkStateOpen, + }, + { + name: "PR comment reference only (search hit rejected by title/body)", + search: `[` + searchHit + `]`, + timeline: `[` + crossRef(openPR) + `]`, + wantNumber: 14656, + wantState: prLinkStateOpen, + }, + { + name: "timeline cross-reference from a merged PR", + search: `[]`, + timeline: `[{"event":"labeled","created_at":"2026-10-26T00:00:00Z"},` + crossRef(mergedPR) + `]`, + wantNumber: 14656, + wantState: prLinkStateMerged, + }, + { + name: "no reference anywhere", + search: `[` + searchHit + `]`, + timeline: `[{"event":"labeled","created_at":"2026-10-26T00:00:00Z"},` + crossRef(otherRepoPR) + `,` + crossRef(plainIssue) + `]`, + }, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + mux := http.NewServeMux() + mux.HandleFunc("/search/issues", func(w http.ResponseWriter, _ *http.Request) { + fmt.Fprintf(w, `{"total_count":1,"items":%s}`, tc.search) + }) + mux.HandleFunc(fmt.Sprintf("/repos/o/r/issues/%d/timeline", issue), func(w http.ResponseWriter, _ *http.Request) { + fmt.Fprint(w, tc.timeline) + }) + srv := httptest.NewServer(mux) + defer srv.Close() + gc := gh.NewClient(nil) + base, err := url.Parse(srv.URL + "/") + if err != nil { + t.Fatal(err) + } + gc.BaseURL = base + + got, err := searchLinkedPR(context.Background(), gc, "o/r", issue) + if err != nil { + t.Fatalf("searchLinkedPR: %v", err) + } + if tc.wantNumber == 0 { + if got != nil { + t.Fatalf("got linked PR %+v, want none", got) + } + return + } + if got == nil { + t.Fatalf("got no linked PR, want #%d (%s)", tc.wantNumber, tc.wantState) + } + if got.Number != tc.wantNumber || got.State != tc.wantState { + t.Fatalf("got #%d (%s), want #%d (%s)", got.Number, got.State, tc.wantNumber, tc.wantState) + } + }) + } +} + +// TestCrossReferencingPRs_PageCap pins the prLinkTimelineMaxPages bound: a +// timeline that keeps advertising a next page is read at most that many +// times, and the lookup keeps what it has read instead of walking to +// exhaustion — the design note on prLinkSearchPerPage applies to the timeline +// read too. +func TestCrossReferencingPRs_PageCap(t *testing.T) { + const issue = 13135 + var calls int + mux := http.NewServeMux() + mux.HandleFunc(fmt.Sprintf("/repos/o/r/issues/%d/timeline", issue), func(w http.ResponseWriter, r *http.Request) { + calls++ + page := r.URL.Query().Get("page") + if page == "" { + page = "1" + } + w.Header().Set("Link", fmt.Sprintf(`<%s?page=%d>; rel="next"`, "http://x"+r.URL.Path, calls+1)) + fmt.Fprintf(w, `[{"event":"cross-referenced","created_at":"2026-10-27T00:00:00Z","source":{"type":"issue","issue":{"number":%s00,"state":"open","html_url":"https://github.com/o/r/pull/%s00","repository":{"full_name":"o/r"},"pull_request":{"url":"x"}}}}]`, page, page) + }) + srv := httptest.NewServer(mux) + defer srv.Close() + gc := gh.NewClient(nil) + base, err := url.Parse(srv.URL + "/") + if err != nil { + t.Fatal(err) + } + gc.BaseURL = base + + got := crossReferencingPRs(context.Background(), gc, "o/r", issue) + if calls != prLinkTimelineMaxPages { + t.Fatalf("timeline requests = %d, want exactly %d (page cap)", calls, prLinkTimelineMaxPages) + } + if len(got) != prLinkTimelineMaxPages { + t.Fatalf("got %d PRs from %d pages, want one per page", len(got), prLinkTimelineMaxPages) + } + if got[0].GetNumber() != 100 || got[len(got)-1].GetNumber() != prLinkTimelineMaxPages*100 { + t.Fatalf("got PRs %d..%d, want 100..%d in page order", got[0].GetNumber(), got[len(got)-1].GetNumber(), prLinkTimelineMaxPages*100) + } +} diff --git a/src/pkg/policies/defaults/dedupe-issues.md b/src/pkg/policies/defaults/dedupe-issues.md index 0705ac4111..372bafed69 100644 --- a/src/pkg/policies/defaults/dedupe-issues.md +++ b/src/pkg/policies/defaults/dedupe-issues.md @@ -297,6 +297,18 @@ label, or comment on items labelled `hold`, `on-hold`, `hold/review`, `hive-pause/` (any label containing `hold` counts), or `do-not-merge`; you were not going to anyway, because the checklist is the only thing you write. +## Before Saying a PR Does Not Reference an Issue (MANDATORY) + +A PR can reference an issue in its title, its body, any commit message, or any PR comment. GitHub records title, body and comment references on the issue's timeline as `cross-referenced` events, but a reference that exists only in a commit message is a `referenced` event instead, which is why step 2 is still needed. Reading only the PR body misses the rest, and that is how a scanner note once said a PR "does not reference" an issue when two of its commits said `Fixes #N`. + +Before you write that PR #P does not reference, link to, or mention issue #N: + +1. Read the issue timeline: `gh api repos/OWNER/REPO/issues/N/timeline --paginate --jq '.[] | select(.event=="cross-referenced") | .source.issue.number'`. If P is listed, the PR references the issue. +2. Read the PR's commit messages and comments: `gh pr view P --repo OWNER/REPO --json commits,comments`. +3. Only if both checks come up empty, say the PR does not reference the issue. + +If the only gap is that the PR body has no `Fixes`/`Closes`/`Resolves #N` line, say "no closing keyword in the PR body", not "does not reference". Merging such a PR will not close the issue, but GitHub still links the two. + ## Workflow 1. For each authorized repository, build the inventory (snapshot, then search). diff --git a/src/pkg/policies/defaults/scanner-automerge.md b/src/pkg/policies/defaults/scanner-automerge.md index 2b3e35b0b7..98b65f09d4 100644 --- a/src/pkg/policies/defaults/scanner-automerge.md +++ b/src/pkg/policies/defaults/scanner-automerge.md @@ -301,6 +301,18 @@ Items marked **ESCALATED** in your kick (or PRs carrying the `needs-human` label For **CI-FAILING** items, your kick includes `ERROR:` lines extracted from the failing check-run annotations — that is the actual failure. Start your diagnosis from those lines; do not guess from the check name alone. +## Before Saying a PR Does Not Reference an Issue (MANDATORY) + +A PR can reference an issue in its title, its body, any commit message, or any PR comment. GitHub records title, body and comment references on the issue's timeline as `cross-referenced` events, but a reference that exists only in a commit message is a `referenced` event instead, which is why step 2 is still needed. Reading only the PR body misses the rest, and that is how a scanner note once said a PR "does not reference" an issue when two of its commits said `Fixes #N`. + +Before you write that PR #P does not reference, link to, or mention issue #N: + +1. Read the issue timeline: `gh api repos/OWNER/REPO/issues/N/timeline --paginate --jq '.[] | select(.event=="cross-referenced") | .source.issue.number'`. If P is listed, the PR references the issue. +2. Read the PR's commit messages and comments: `gh pr view P --repo OWNER/REPO --json commits,comments`. +3. Only if both checks come up empty, say the PR does not reference the issue. + +If the only gap is that the PR body has no `Fixes`/`Closes`/`Resolves #N` line, say "no closing keyword in the PR body", not "does not reference". Merging such a PR will not close the issue, but GitHub still links the two. + ## Publishable Content Boundary Attribution belongs ONLY in the issue or PR body and the DCO commit trailer. NEVER write `Filed by`, ACMM levels, agent names, or hive run metadata inside any committed file. diff --git a/src/pkg/policies/defaults/scanner-full.md b/src/pkg/policies/defaults/scanner-full.md index f6776a31d3..84e56fc680 100644 --- a/src/pkg/policies/defaults/scanner-full.md +++ b/src/pkg/policies/defaults/scanner-full.md @@ -197,6 +197,18 @@ nothing, and it hides as "Working" on the dashboard while nothing happens. ${KNOWLEDGE} +## Before Saying a PR Does Not Reference an Issue (MANDATORY) + +A PR can reference an issue in its title, its body, any commit message, or any PR comment. GitHub records title, body and comment references on the issue's timeline as `cross-referenced` events, but a reference that exists only in a commit message is a `referenced` event instead, which is why step 2 is still needed. Reading only the PR body misses the rest, and that is how a scanner note once said a PR "does not reference" an issue when two of its commits said `Fixes #N`. + +Before you write that PR #P does not reference, link to, or mention issue #N: + +1. Read the issue timeline: `gh api repos/OWNER/REPO/issues/N/timeline --paginate --jq '.[] | select(.event=="cross-referenced") | .source.issue.number'`. If P is listed, the PR references the issue. +2. Read the PR's commit messages and comments: `gh pr view P --repo OWNER/REPO --json commits,comments`. +3. Only if both checks come up empty, say the PR does not reference the issue. + +If the only gap is that the PR body has no `Fixes`/`Closes`/`Resolves #N` line, say "no closing keyword in the PR body", not "does not reference". Merging such a PR will not close the issue, but GitHub still links the two. + ## Publishable Content Boundary Attribution belongs ONLY in the issue or PR body and the DCO commit trailer. NEVER write `Filed by`, ACMM levels, agent names, or hive run metadata inside any committed file. diff --git a/src/pkg/policies/defaults/scanner-holdgated.md b/src/pkg/policies/defaults/scanner-holdgated.md index 922e9a8ef9..522acfdb84 100644 --- a/src/pkg/policies/defaults/scanner-holdgated.md +++ b/src/pkg/policies/defaults/scanner-holdgated.md @@ -205,6 +205,18 @@ happens. ${KNOWLEDGE} +## Before Saying a PR Does Not Reference an Issue (MANDATORY) + +A PR can reference an issue in its title, its body, any commit message, or any PR comment. GitHub records title, body and comment references on the issue's timeline as `cross-referenced` events, but a reference that exists only in a commit message is a `referenced` event instead, which is why step 2 is still needed. Reading only the PR body misses the rest, and that is how a scanner note once said a PR "does not reference" an issue when two of its commits said `Fixes #N`. + +Before you write that PR #P does not reference, link to, or mention issue #N: + +1. Read the issue timeline: `gh api repos/OWNER/REPO/issues/N/timeline --paginate --jq '.[] | select(.event=="cross-referenced") | .source.issue.number'`. If P is listed, the PR references the issue. +2. Read the PR's commit messages and comments: `gh pr view P --repo OWNER/REPO --json commits,comments`. +3. Only if both checks come up empty, say the PR does not reference the issue. + +If the only gap is that the PR body has no `Fixes`/`Closes`/`Resolves #N` line, say "no closing keyword in the PR body", not "does not reference". Merging such a PR will not close the issue, but GitHub still links the two. + ## Publishable Content Boundary Attribution belongs ONLY in the issue or PR body and the DCO commit trailer. NEVER write `Filed by`, ACMM levels, agent names, or hive run metadata inside any committed file. diff --git a/src/pkg/policies/defaults/scanner-issues.md b/src/pkg/policies/defaults/scanner-issues.md index df9b133288..04eedd5f23 100644 --- a/src/pkg/policies/defaults/scanner-issues.md +++ b/src/pkg/policies/defaults/scanner-issues.md @@ -177,6 +177,18 @@ dashboard while nothing happens. green" (or "...; merges after human review" if the PR is held), then continue. +## Before Saying a PR Does Not Reference an Issue (MANDATORY) + +A PR can reference an issue in its title, its body, any commit message, or any PR comment. GitHub records title, body and comment references on the issue's timeline as `cross-referenced` events, but a reference that exists only in a commit message is a `referenced` event instead, which is why step 2 is still needed. Reading only the PR body misses the rest, and that is how a scanner note once said a PR "does not reference" an issue when two of its commits said `Fixes #N`. + +Before you write that PR #P does not reference, link to, or mention issue #N: + +1. Read the issue timeline: `gh api repos/OWNER/REPO/issues/N/timeline --paginate --jq '.[] | select(.event=="cross-referenced") | .source.issue.number'`. If P is listed, the PR references the issue. +2. Read the PR's commit messages and comments: `gh pr view P --repo OWNER/REPO --json commits,comments`. +3. Only if both checks come up empty, say the PR does not reference the issue. + +If the only gap is that the PR body has no `Fixes`/`Closes`/`Resolves #N` line, say "no closing keyword in the PR body", not "does not reference". Merging such a PR will not close the issue, but GitHub still links the two. + ## Workflow 1. Read the work list above diff --git a/src/pkg/policies/defaults/scanner.md b/src/pkg/policies/defaults/scanner.md index b5d8f41176..851bec1ffe 100644 --- a/src/pkg/policies/defaults/scanner.md +++ b/src/pkg/policies/defaults/scanner.md @@ -114,6 +114,18 @@ dashboard while nothing happens. **Three of a class means the gate is missing.** Before filing, look at the findings you have already filed in this repository (your beads via `bd list --actor scanner`, and the `[scanner]` issues in your work list). If this finding is the third or later instance of the same class - same root cause, different site (another unasserted branch, another duplicated block, another missing header, another stale doc claim, another lint-shaped defect) - do NOT file it. File ONE issue instead, titled `[scanner] Gate proposal: `, that lists the prior instances, names the missing gate (the tool and where it runs in CI), and asks the maintainers to accept or decline it. Use `--needs-decision` with `Risk: governance`. Resume filing individual findings in that class only if the proposal is declined; if it is accepted, the gate check above applies once the gate lands. +## Before Saying a PR Does Not Reference an Issue (MANDATORY) + +A PR can reference an issue in its title, its body, any commit message, or any PR comment. GitHub records title, body and comment references on the issue's timeline as `cross-referenced` events, but a reference that exists only in a commit message is a `referenced` event instead, which is why step 2 is still needed. Reading only the PR body misses the rest, and that is how a scanner note once said a PR "does not reference" an issue when two of its commits said `Fixes #N`. + +Before you write that PR #P does not reference, link to, or mention issue #N: + +1. Read the issue timeline: `gh api repos/OWNER/REPO/issues/N/timeline --paginate --jq '.[] | select(.event=="cross-referenced") | .source.issue.number'`. If P is listed, the PR references the issue. +2. Read the PR's commit messages and comments: `gh pr view P --repo OWNER/REPO --json commits,comments`. +3. Only if both checks come up empty, say the PR does not reference the issue. + +If the only gap is that the PR body has no `Fixes`/`Closes`/`Resolves #N` line, say "no closing keyword in the PR body", not "does not reference". Merging such a PR will not close the issue, but GitHub still links the two. + ## Workflow 1. Read the work list above diff --git a/src/pkg/promptsrc/promptsrc.go b/src/pkg/promptsrc/promptsrc.go index df5799acf6..96b05e91e9 100644 --- a/src/pkg/promptsrc/promptsrc.go +++ b/src/pkg/promptsrc/promptsrc.go @@ -35,7 +35,7 @@ import ( // DefaultMaxPromptBytes caps how large a fetched prompt body may be // (hivecommons/hive#12130). A kick prompt is a markdown template; the largest -// shipped policy (src/policies/scanner-automerge.md) is ~28 KiB, so 64 KiB +// shipped policy (src/policies/scanner-automerge.md) is ~33 KiB, so 96 KiB // leaves better than 2x headroom for a real template while refusing a // mis-pointed prompt_source before it costs a ~100K-token kick. This is a token // budget, not just a memory bound — the old 512 KiB cap was the latter. @@ -46,7 +46,7 @@ import ( // then to the caller's inline template, and logs the rejection with the // source and the observed size. TestShippedTemplatesFitUnderCap pins the // headroom against every shipped template. -const DefaultMaxPromptBytes = 64 * 1024 // 64 KiB +const DefaultMaxPromptBytes = 96 * 1024 // 96 KiB // MaxPromptBytesEnv names the environment variable that overrides // DefaultMaxPromptBytes. It accepts a positive byte count (e.g. "131072") or a diff --git a/src/policies/dedupe-issues.md b/src/policies/dedupe-issues.md index 0705ac4111..372bafed69 100644 --- a/src/policies/dedupe-issues.md +++ b/src/policies/dedupe-issues.md @@ -297,6 +297,18 @@ label, or comment on items labelled `hold`, `on-hold`, `hold/review`, `hive-pause/` (any label containing `hold` counts), or `do-not-merge`; you were not going to anyway, because the checklist is the only thing you write. +## Before Saying a PR Does Not Reference an Issue (MANDATORY) + +A PR can reference an issue in its title, its body, any commit message, or any PR comment. GitHub records title, body and comment references on the issue's timeline as `cross-referenced` events, but a reference that exists only in a commit message is a `referenced` event instead, which is why step 2 is still needed. Reading only the PR body misses the rest, and that is how a scanner note once said a PR "does not reference" an issue when two of its commits said `Fixes #N`. + +Before you write that PR #P does not reference, link to, or mention issue #N: + +1. Read the issue timeline: `gh api repos/OWNER/REPO/issues/N/timeline --paginate --jq '.[] | select(.event=="cross-referenced") | .source.issue.number'`. If P is listed, the PR references the issue. +2. Read the PR's commit messages and comments: `gh pr view P --repo OWNER/REPO --json commits,comments`. +3. Only if both checks come up empty, say the PR does not reference the issue. + +If the only gap is that the PR body has no `Fixes`/`Closes`/`Resolves #N` line, say "no closing keyword in the PR body", not "does not reference". Merging such a PR will not close the issue, but GitHub still links the two. + ## Workflow 1. For each authorized repository, build the inventory (snapshot, then search). diff --git a/src/policies/scanner-automerge.md b/src/policies/scanner-automerge.md index 2b3e35b0b7..98b65f09d4 100644 --- a/src/policies/scanner-automerge.md +++ b/src/policies/scanner-automerge.md @@ -301,6 +301,18 @@ Items marked **ESCALATED** in your kick (or PRs carrying the `needs-human` label For **CI-FAILING** items, your kick includes `ERROR:` lines extracted from the failing check-run annotations — that is the actual failure. Start your diagnosis from those lines; do not guess from the check name alone. +## Before Saying a PR Does Not Reference an Issue (MANDATORY) + +A PR can reference an issue in its title, its body, any commit message, or any PR comment. GitHub records title, body and comment references on the issue's timeline as `cross-referenced` events, but a reference that exists only in a commit message is a `referenced` event instead, which is why step 2 is still needed. Reading only the PR body misses the rest, and that is how a scanner note once said a PR "does not reference" an issue when two of its commits said `Fixes #N`. + +Before you write that PR #P does not reference, link to, or mention issue #N: + +1. Read the issue timeline: `gh api repos/OWNER/REPO/issues/N/timeline --paginate --jq '.[] | select(.event=="cross-referenced") | .source.issue.number'`. If P is listed, the PR references the issue. +2. Read the PR's commit messages and comments: `gh pr view P --repo OWNER/REPO --json commits,comments`. +3. Only if both checks come up empty, say the PR does not reference the issue. + +If the only gap is that the PR body has no `Fixes`/`Closes`/`Resolves #N` line, say "no closing keyword in the PR body", not "does not reference". Merging such a PR will not close the issue, but GitHub still links the two. + ## Publishable Content Boundary Attribution belongs ONLY in the issue or PR body and the DCO commit trailer. NEVER write `Filed by`, ACMM levels, agent names, or hive run metadata inside any committed file. diff --git a/src/policies/scanner-full.md b/src/policies/scanner-full.md index f6776a31d3..84e56fc680 100644 --- a/src/policies/scanner-full.md +++ b/src/policies/scanner-full.md @@ -197,6 +197,18 @@ nothing, and it hides as "Working" on the dashboard while nothing happens. ${KNOWLEDGE} +## Before Saying a PR Does Not Reference an Issue (MANDATORY) + +A PR can reference an issue in its title, its body, any commit message, or any PR comment. GitHub records title, body and comment references on the issue's timeline as `cross-referenced` events, but a reference that exists only in a commit message is a `referenced` event instead, which is why step 2 is still needed. Reading only the PR body misses the rest, and that is how a scanner note once said a PR "does not reference" an issue when two of its commits said `Fixes #N`. + +Before you write that PR #P does not reference, link to, or mention issue #N: + +1. Read the issue timeline: `gh api repos/OWNER/REPO/issues/N/timeline --paginate --jq '.[] | select(.event=="cross-referenced") | .source.issue.number'`. If P is listed, the PR references the issue. +2. Read the PR's commit messages and comments: `gh pr view P --repo OWNER/REPO --json commits,comments`. +3. Only if both checks come up empty, say the PR does not reference the issue. + +If the only gap is that the PR body has no `Fixes`/`Closes`/`Resolves #N` line, say "no closing keyword in the PR body", not "does not reference". Merging such a PR will not close the issue, but GitHub still links the two. + ## Publishable Content Boundary Attribution belongs ONLY in the issue or PR body and the DCO commit trailer. NEVER write `Filed by`, ACMM levels, agent names, or hive run metadata inside any committed file. diff --git a/src/policies/scanner-holdgated.md b/src/policies/scanner-holdgated.md index 922e9a8ef9..522acfdb84 100644 --- a/src/policies/scanner-holdgated.md +++ b/src/policies/scanner-holdgated.md @@ -205,6 +205,18 @@ happens. ${KNOWLEDGE} +## Before Saying a PR Does Not Reference an Issue (MANDATORY) + +A PR can reference an issue in its title, its body, any commit message, or any PR comment. GitHub records title, body and comment references on the issue's timeline as `cross-referenced` events, but a reference that exists only in a commit message is a `referenced` event instead, which is why step 2 is still needed. Reading only the PR body misses the rest, and that is how a scanner note once said a PR "does not reference" an issue when two of its commits said `Fixes #N`. + +Before you write that PR #P does not reference, link to, or mention issue #N: + +1. Read the issue timeline: `gh api repos/OWNER/REPO/issues/N/timeline --paginate --jq '.[] | select(.event=="cross-referenced") | .source.issue.number'`. If P is listed, the PR references the issue. +2. Read the PR's commit messages and comments: `gh pr view P --repo OWNER/REPO --json commits,comments`. +3. Only if both checks come up empty, say the PR does not reference the issue. + +If the only gap is that the PR body has no `Fixes`/`Closes`/`Resolves #N` line, say "no closing keyword in the PR body", not "does not reference". Merging such a PR will not close the issue, but GitHub still links the two. + ## Publishable Content Boundary Attribution belongs ONLY in the issue or PR body and the DCO commit trailer. NEVER write `Filed by`, ACMM levels, agent names, or hive run metadata inside any committed file. diff --git a/src/policies/scanner-issues.md b/src/policies/scanner-issues.md index df9b133288..04eedd5f23 100644 --- a/src/policies/scanner-issues.md +++ b/src/policies/scanner-issues.md @@ -177,6 +177,18 @@ dashboard while nothing happens. green" (or "...; merges after human review" if the PR is held), then continue. +## Before Saying a PR Does Not Reference an Issue (MANDATORY) + +A PR can reference an issue in its title, its body, any commit message, or any PR comment. GitHub records title, body and comment references on the issue's timeline as `cross-referenced` events, but a reference that exists only in a commit message is a `referenced` event instead, which is why step 2 is still needed. Reading only the PR body misses the rest, and that is how a scanner note once said a PR "does not reference" an issue when two of its commits said `Fixes #N`. + +Before you write that PR #P does not reference, link to, or mention issue #N: + +1. Read the issue timeline: `gh api repos/OWNER/REPO/issues/N/timeline --paginate --jq '.[] | select(.event=="cross-referenced") | .source.issue.number'`. If P is listed, the PR references the issue. +2. Read the PR's commit messages and comments: `gh pr view P --repo OWNER/REPO --json commits,comments`. +3. Only if both checks come up empty, say the PR does not reference the issue. + +If the only gap is that the PR body has no `Fixes`/`Closes`/`Resolves #N` line, say "no closing keyword in the PR body", not "does not reference". Merging such a PR will not close the issue, but GitHub still links the two. + ## Workflow 1. Read the work list above diff --git a/src/policies/scanner.md b/src/policies/scanner.md index b5d8f41176..851bec1ffe 100644 --- a/src/policies/scanner.md +++ b/src/policies/scanner.md @@ -114,6 +114,18 @@ dashboard while nothing happens. **Three of a class means the gate is missing.** Before filing, look at the findings you have already filed in this repository (your beads via `bd list --actor scanner`, and the `[scanner]` issues in your work list). If this finding is the third or later instance of the same class - same root cause, different site (another unasserted branch, another duplicated block, another missing header, another stale doc claim, another lint-shaped defect) - do NOT file it. File ONE issue instead, titled `[scanner] Gate proposal: `, that lists the prior instances, names the missing gate (the tool and where it runs in CI), and asks the maintainers to accept or decline it. Use `--needs-decision` with `Risk: governance`. Resume filing individual findings in that class only if the proposal is declined; if it is accepted, the gate check above applies once the gate lands. +## Before Saying a PR Does Not Reference an Issue (MANDATORY) + +A PR can reference an issue in its title, its body, any commit message, or any PR comment. GitHub records title, body and comment references on the issue's timeline as `cross-referenced` events, but a reference that exists only in a commit message is a `referenced` event instead, which is why step 2 is still needed. Reading only the PR body misses the rest, and that is how a scanner note once said a PR "does not reference" an issue when two of its commits said `Fixes #N`. + +Before you write that PR #P does not reference, link to, or mention issue #N: + +1. Read the issue timeline: `gh api repos/OWNER/REPO/issues/N/timeline --paginate --jq '.[] | select(.event=="cross-referenced") | .source.issue.number'`. If P is listed, the PR references the issue. +2. Read the PR's commit messages and comments: `gh pr view P --repo OWNER/REPO --json commits,comments`. +3. Only if both checks come up empty, say the PR does not reference the issue. + +If the only gap is that the PR body has no `Fixes`/`Closes`/`Resolves #N` line, say "no closing keyword in the PR body", not "does not reference". Merging such a PR will not close the issue, but GitHub still links the two. + ## Workflow 1. Read the work list above