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
1 change: 1 addition & 0 deletions changelog.d/fixed-18869-parent-autoclose-reopen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Never auto-close a decomposed parent that a person reopened after a hive auto-close or that is labelled epic/hold, and add the per-repo `repos.<repo>.parent_autoclose` (`true`/`epics_too`/`false`) switch (#18869).
2 changes: 1 addition & 1 deletion src/cmd/hive/main_sweeps.go
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,7 @@ func installReviewRelaySettings(client *github.Client, cfg *config.Config, logge
for name := range cfg.Agents {
agents = append(agents, name)
}
return github.IssueStagePolicy{Enabled: p.Enabled, Dwell: p.Dwell, AgentNames: agents}
return github.IssueStagePolicy{Enabled: p.Enabled, Dwell: p.Dwell, AgentNames: agents, ParentAutoClose: func(repo string) string { return cfg.ParentAutoCloseFor(repo) }}
})
client.SetReviewCadenceLimits(
func() bool { return cfg.Review.CombinedPerspectives },
Expand Down
33 changes: 29 additions & 4 deletions src/docs/labels-and-control-signals/stage-labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ final, and maps each row ([#12436](https://github.com/hivecommons/hive/issues/12
| covered by an open PR the sweep has staged (≥ 050) | still `040-covered-by-pr`; the reason reads `open PR #N covers it (PR at <stage>)`. `050`+ are PR-only stages and never land on an issue ([#12451](https://github.com/hivecommons/hive/issues/12451)) |
| reporter triage (human-filed, held by the #9665 gate until the triage label lands) | `015-triage-needed` — the gate still withholds it from agents |
| exempt / filtered / advisory / dependency dashboard | no stage |
| **decomposed parent** — an issue with tracked child issues (GitHub sub-issues the relay linked with `parent: N`; see below) | keeps the stage the rows above give it while any child is open, **never `stage/stalled`**; once every child is closed the parent is **closed as completed** by the sweep ([#12857](https://github.com/hivecommons/hive/issues/12857)) |
| **decomposed parent** — an issue with tracked child issues (GitHub sub-issues the relay linked with `parent: N`; see below) | keeps the stage the rows above give it while any child is open, **never `stage/stalled`**; once every child is closed the parent is **closed as completed** by the sweep unless it is an epic/hold, was reopened by a person, or the repo disables it ([#12857](https://github.com/hivecommons/hive/issues/12857)) |

Labels come from the issue list payload the cycle already fetched — no
per-issue GETs — and are written only when the planned set differs from the
Expand Down Expand Up @@ -694,9 +694,34 @@ the open-issue snapshot instead — and then:
"delivered" comment is posted until the close succeeds.
- **No children** → nothing changes.

Reopen the parent if something it asked for is still missing; the sweep does
not close it again until a child is reopened and closed once more (the
sub-issue summary is read fresh each cycle).
Reopen the parent if something it asked for is still missing. A parent a
person reopens after a hive auto-close is **never auto-closed again**
([#18869](https://github.com/hivecommons/hive/issues/18869)): once every
child is confirmed closed the sweep reads the parent's timeline (one read,
only at that point, cached per parent) and keeps it open when a non-bot
`reopened` event follows the `<!-- hive:parent-autoclose -->` comment (or a
bot's close). The timeline is the record, so the rule survives restarts;
an unreadable timeline means no close that cycle. This holds under every
config value below.

**Epics and holds are never auto-closed.** An issue labelled `epic` (any
case) or `hold` stays open for a person to close, with all children closed.
Per repo, `repos.<repo>.parent_autoclose` chooses the policy:

| value | behaviour |
|---|---|
| `true` (default) | close a decomposed parent when all children are closed, except `epic`/`hold`-labelled issues |
| `epics_too` | also close `epic`/`hold`-labelled parents |
| `false` | never auto-close a parent in this repo |

```yaml
repos:
torch-spyre/spyre-inference:
parent_autoclose: false
```

The dashboard does not yet show a "kept open: reopened by <login>" pill; the
kept-open decision is logged (`decomposed parent kept open`).

### `stage/stalled` — "nobody is working this"

Expand Down
1 change: 1 addition & 0 deletions src/docs/operator-reference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ Go callers keep reading `cfg.Agents`, `cfg.Governor.Gateways` and so on through
| `governor.trajectory.enabled` | Defaults to enabled. | The lane no-ops until a reviewer endpoint and model resolve from `governor.trajectory` or `governor.litellm`. |
| `governor.kick_limits.max_issues` / `max_prs` | `100` / `50` | Caps on every issue list and every PR list (actionable, stale drafts, merge-eligible, CI-failing) rendered into a kick prompt; a cut list ends with an explicit "… and N more" line. An absent key or a negative value means the default; an explicit `0` opts out of the cap entirely (`KickListUnlimited` — every item is listed), and anything above `500` is pinned to `500`. Editable without touching this file under **Settings → Repos → Kick prompt list caps**. Truncation drops the *newest, lowest-priority* items: issues are listed oldest first, and PRs in review-priority order (fixes, then refactors/docs, then tests, oldest first within each class), so lowering a cap never hides the most urgent work. Raise `max_prs` only if your agents actually work more than 50 PRs per turn; the tail of a long list costs tokens and delivery time on every kick without changing behaviour (#7368). |
| `project.agents_md_max_bytes` | `32768` (or env `HIVE_AGENTS_MD_MAX_BYTES`); clamped to `2048`..`262144`. `repos.<repo>.agents_md_max_bytes` overrides it per repo. | Caps the repo `AGENTS.md` block prepended to a kick. Whole sections (split at `#`/`##` headings; each resolved skill is its own unit) are kept or dropped, never clipped mid-rule; when any are dropped the kick carries a one-line `⚠️ AGENTS.md exceeded N bytes; … — read AGENTS.md …` warning naming them and the scheduler logs it. See [agents-md.md](../agents-md.md#size-cap-whole-sections-visible-warning). |
| `repos.<repo>.parent_autoclose` | `true` (default), `epics_too` or `false` | Decomposed-parent auto-close policy for the repo: `true` closes a parent when every child is closed except `epic`/`hold`-labelled issues; `epics_too` also closes those; `false` never closes a parent. A parent a person reopened after a hive auto-close is never re-closed under any value. See [stage-labels.md](../labels-and-control-signals/stage-labels.md#decomposed-parents--closed-by-their-children-never-stalled). |
| `project.style` | unset (built-in text applies) | Hive-wide **house style**: a short how-to-change rule list prepended to every kick on every backend, directly under the header. A managed repo's root `HIVE_STYLE.md` (read from `project.checkouts_dir`) overrides it; precedence repo > hive > built-in. Inline text wins over `project.style_file`. See [house-style.md](../house-style.md). |
| `project.style_file` | unset | Path on the hive host holding the hive-wide house style; used when `project.style` is empty. |
| `project.style_max_bytes` | `4096`; values under `512` are raised to `512`. | Caps each house-style candidate. An oversize candidate is skipped whole (not clipped) and the next source applies; the skip is audited as `house_style_skip`. The repo file is also run through ioscan at the issue-body policy and refused whole on a block. |
Expand Down
30 changes: 30 additions & 0 deletions src/pkg/config/repo_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,36 @@ type RepoSettings struct {
// project.agents_md_max_bytes. Zero inherits it. The agentsmd floor and
// hard ceiling still apply (agentsmd.EffectiveMaxBytes).
AgentsMdMaxBytes int `yaml:"agents_md_max_bytes,omitempty" json:"agents_md_max_bytes,omitempty"`
// ParentAutoClose is the decomposed-parent auto-close policy for this
// repo (hivecommons/hive#18869): "true" (the default when empty) closes a
// decomposed parent once every child is closed, except an issue labelled
// epic or hold; "false" never auto-closes a parent; "epics_too" also
// closes epic/hold-labelled parents. A parent a person reopened after a
// hive auto-close is never re-closed under any value. YAML booleans
// true/false are accepted and read as the strings.
ParentAutoClose string `yaml:"parent_autoclose,omitempty" json:"parent_autoclose,omitempty"`
}

// Parent auto-close policy values for RepoSettings.ParentAutoClose.
const (
ParentAutoCloseOn = "true"
ParentAutoCloseOff = "false"
ParentAutoCloseEpicsToo = "epics_too"
)

// ParentAutoCloseFor is the normalised parent auto-close policy for repo:
// one of ParentAutoCloseOn (default), ParentAutoCloseOff or
// ParentAutoCloseEpicsToo. An unrecognised value falls back to the default.
func (c *Config) ParentAutoCloseFor(repo string) string {
rs, ok := c.RepoSettingsFor(repo)
if !ok {
return ParentAutoCloseOn
}
switch v := strings.ToLower(strings.TrimSpace(rs.ParentAutoClose)); v {
case ParentAutoCloseOff, ParentAutoCloseEpicsToo:
return v
}
return ParentAutoCloseOn
}

// RepoSettingsFor returns repo's entry from the `repos:` map, and whether one
Expand Down
16 changes: 16 additions & 0 deletions src/pkg/config/repo_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,19 @@ func TestReposAgentsMdMaxBytesYAML(t *testing.T) {
t.Errorf("yaml per-repo cap = %d, want 49152", got)
}
}

func TestParentAutoCloseFor(t *testing.T) {
var cfg Config
if err := yaml.Unmarshal([]byte("project: {org: acme}\nrepos:\n off: {parent_autoclose: false}\n epics: {parent_autoclose: epics_too}\n on: {parent_autoclose: true}\n junk: {parent_autoclose: maybe}\n other: {}\n"), &cfg); err != nil {
t.Fatal(err)
}
cases := map[string]string{
"off": ParentAutoCloseOff, "acme/epics": ParentAutoCloseEpicsToo, "on": ParentAutoCloseOn,
"junk": ParentAutoCloseOn, "other": ParentAutoCloseOn, "unlisted": ParentAutoCloseOn,
}
for repo, want := range cases {
if got := cfg.ParentAutoCloseFor(repo); got != want {
t.Errorf("%s = %q, want %q", repo, got, want)
}
}
}
1 change: 1 addition & 0 deletions src/pkg/dashboard/settings_parity_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ project.repos[] # TODO #11854
providers.status.enabled # TODO #11854
removed_agents[] # TODO #11854
repos.<key>.agents_md_max_bytes # TODO #18495 (per-repo AGENTS.md cap; Settings control pending)
repos.<key>.parent_autoclose # TODO #18869 (per-repo decomposed-parent auto-close policy; Settings control pending)
review.backlog.labels[] # TODO #11854
review.bot_author_full_review_paths[] # TODO #14625
review.bot_author_model # TODO #14625
Expand Down
109 changes: 109 additions & 0 deletions src/pkg/github/decomposed_parents.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import (
"regexp"
"strconv"
"strings"
"sync"
"time"

gh "github.com/google/go-github/v72/github"
"github.com/hivecommons/hive/pkg/config"
"github.com/hivecommons/hive/pkg/prstatus"
"github.com/hivecommons/hive/pkg/stagelabels"
)
Expand Down Expand Up @@ -351,6 +354,13 @@ func decomposedParentCloseComment(children []ChildRef, closers map[ChildRef]int)
// gate refuses does not leave a "delivered" note every cycle.
func (c *Client) closeDecomposedParent(ctx context.Context, in IssueStageInput, store *stagelabels.Store, key string, logger *slog.Logger) bool {
owner, name := c.splitRepo(in.Repo)
// Label/config exemptions cost no API call, so they run first.
if reason := parentAutoCloseExempt(c.parentAutoClosePolicy(in.Repo), in.Labels); reason != "" {
if logger != nil {
logger.Debug("issue stage labels: decomposed parent not auto-closed", "repo", in.Repo, "issue", in.Number, "reason", reason)
}
return false
}
children, open, ok, err := c.decomposedChildren(ctx, owner, name, in.Number)
if err != nil {
if logger != nil {
Expand All @@ -361,6 +371,14 @@ func (c *Client) closeDecomposedParent(ctx context.Context, in IssueStageInput,
if !ok || open > 0 {
return false
}
// Only now, with every child confirmed closed, spend a timeline read:
// a parent a person reopened after a hive auto-close stays open.
if by, kept := c.parentKeptOpenBy(ctx, owner, name, in.Number, logger); kept || by != "" {
if logger != nil {
logger.Info("issue stage labels: decomposed parent kept open, reopened by a person after a hive auto-close", "repo", in.Repo, "issue", in.Number, "reopened_by", by)
}
return false
}
closers := map[ChildRef]int{}
for _, ref := range children {
childOwner, childName := owner, name
Expand Down Expand Up @@ -394,3 +412,94 @@ func (c *Client) closeDecomposedParent(ctx context.Context, in IssueStageInput,
}
return true
}

// parentAutoClosePolicy is the repo's configured parent auto-close policy.
func (c *Client) parentAutoClosePolicy(repo string) string {
if p := c.issueStagePolicy(); p.ParentAutoClose != nil {
return p.ParentAutoClose(repo)
}
return config.ParentAutoCloseOn
}

// parentAutoCloseExempt returns why a parent must not be auto-closed from
// its policy and labels alone, or "" when it may be (hivecommons/hive#18869).
// "false" exempts every parent; unless the policy is "epics_too", an issue
// labelled epic (any case) or hold is left for a person to close.
func parentAutoCloseExempt(policy string, labels []string) string {
if policy == config.ParentAutoCloseOff {
return "repo parent_autoclose is false"
}
if policy == config.ParentAutoCloseEpicsToo {
return ""
}
for _, l := range labels {
if strings.EqualFold(strings.TrimSpace(l), "epic") {
return "labelled epic"
}
}
if HasHoldLabel(labels) {
return "labelled hold"
}
return ""
}

// Reopen-verdict cache (hivecommons/hive#18869). A reopen by a person never
// un-happens, so a "kept open" verdict is cached for the process lifetime
// (a restart re-derives it from the timeline, which is the durable record);
// a "no reopen" verdict is cached briefly so a parent whose close is refused
// each cycle does not cost a timeline read per sweep.
const parentReopenNegativeTTL = 30 * time.Minute

type parentReopenVerdict struct {
by string
checked time.Time
}

var (
parentReopenMu sync.Mutex
parentReopenCache = map[string]parentReopenVerdict{}
)

// parentKeptOpenBy reports the login of a person who reopened the parent
// after a hive auto-close. A timeline that cannot be read fails closed: the
// returned login is "(unknown)" so the parent is not closed this cycle.
func (c *Client) parentKeptOpenBy(ctx context.Context, owner, name string, number int, logger *slog.Logger) (string, bool) {
key := strings.ToLower(owner+"/"+name) + "#" + strconv.Itoa(number)
parentReopenMu.Lock()
v, ok := parentReopenCache[key]
parentReopenMu.Unlock()
if ok && (v.by != "" || time.Since(v.checked) < parentReopenNegativeTTL) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A cached "no reopen" verdict (by == "") is honoured for 30 min even after this sweep closes the parent. A person who reopens within that window is not seen, and the next cycle re-closes the parent. Fix: drop the cache entry for the key once the close succeeds in closeDecomposedParent, or don't cache a negative verdict when the close proceeds. A test that closes, reopens via the fake timeline and sweeps again would fail without it.

return v.by, v.by != ""
}
events, err := c.IssueTimelineSince(ctx, owner+"/"+name, number, time.Time{})
if err != nil {
if logger != nil {
logger.Warn("issue stage labels: parent timeline unreadable, not closing", "repo", owner+"/"+name, "issue", number, "error", err)
}
return "(unknown)", true
}
by := reopenedByPersonAfterAutoClose(events)
parentReopenMu.Lock()
parentReopenCache[key] = parentReopenVerdict{by: by, checked: time.Now()}
parentReopenMu.Unlock()
return by, by != ""
}

// reopenedByPersonAfterAutoClose scans a timeline (oldest first) for a
// `reopened` event by a non-bot actor that follows a hive auto-close: the
// close comment carrying parentAutoCloseMarker, or a `closed` event by a
// bot (the comment is best-effort and can be missing). Returns the reopener.
func reopenedByPersonAfterAutoClose(events []IssueEvent) string {
autoClosed := false
for _, ev := range events {
switch {
case ev.Event == "commented" && ev.Body != "" && strings.Contains(ev.Body, parentAutoCloseMarker):
autoClosed = true
case ev.Event == "closed" && ev.ActorIsBot:
autoClosed = true
case ev.Event == "reopened" && autoClosed && !ev.ActorIsBot && ev.Actor != "":
return ev.Actor
}
}
return ""
}
Loading
Loading