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
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion src/docs/agent-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/docs/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<name>.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.<name>.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. |

Expand Down
129 changes: 105 additions & 24 deletions src/pkg/dashboard/contribute_prlink.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package dashboard

import (
Expand All @@ -18,12 +18,21 @@
// 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
Expand Down Expand Up @@ -118,13 +127,15 @@
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
Expand All @@ -141,34 +152,104 @@
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
Expand Down
Loading
Loading