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-advisory-digest-honors-repo-pause.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Repo pause now silences every hive-originated write to the paused repo, not only agent-requested ones: the advisory digest comment is neither edited nor re-created while the repo is paused (logged once per update interval as `advisory digest skipped: repo paused` with the pause's `by`/`reason`, and never counted as a post), the write-back containment gate refuses every kind β€” own items included β€” with reason `repo-paused`, and the duplicate-PR, closed-issue stage-label and hard-suppress sweeps skip paused repos. A paused `torch-spyre` spoke had kept editing its pinned `## 🐝 Advisory Digest` on every restart while the auto-merge sweeps correctly stood down.
86 changes: 86 additions & 0 deletions src/cmd/hive/advisory_repo_pause_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package main

import (
"context"
"testing"
"time"

"github.com/hivecommons/hive/pkg/advisory"
"github.com/hivecommons/hive/pkg/config"
"github.com/hivecommons/hive/pkg/github"
)

// A repo-paused refusal from the poster (#6203) is a SKIP: nothing is
// recorded as posted, no error is raised, no App banner hook fires, and only
// the pacing hook runs so the "skipped: repo paused" line lands once per
// update interval. The moment the poster stops refusing, the very next
// due cycle posts and records normally.
func TestPublishAdvisoryDigest_RepoPausedIsSkipNotFailure(t *testing.T) {
r := &publishRecorder{githubErr: &github.RepoPausedError{Repo: "acme/widget", By: "clubanderson", Reason: "freeze"}}
got := publishAdvisoryDigest(context.Background(), "# digest", twoFindingDigest(), githubRoute(), r.deps(), restoreTestLogger())
if got != advisoryPublishSkipped {
t.Fatalf("outcome = %v, want skipped", got)
}
if len(r.github) != 1 {
t.Fatalf("poster must be consulted (it owns the pause check): calls = %v", r.github)
}
if len(r.posted) != 0 || len(r.errors) != 0 || r.proven != 0 || r.forbidden != 0 || r.authFail != 0 || len(r.backoffs) != 0 {
t.Fatalf("paused skip leaked into other hooks: %+v", r)
}
if len(r.pausedFor) != 1 || r.pausedFor[0] != "acme/widget" {
t.Fatalf("recordRepoPaused = %v, want [acme/widget]", r.pausedFor)
}

// Pause lifted β†’ posts.
r.githubErr = nil
got = publishAdvisoryDigest(context.Background(), "# digest", twoFindingDigest(), githubRoute(), r.deps(), restoreTestLogger())
if got != advisoryPublishPosted || len(r.posted) != 1 || r.proven != 1 {
t.Fatalf("after unpause: outcome=%v recorder=%+v", got, r)
}
}

// With update_interval_s set, a paused skip paces like a post: one attempt
// (and one log line) per interval, and the first due cycle after the pause
// lifts posts. Fake clock throughout.
func TestAdvisoryPostGate_PausedSkipPacesPerInterval(t *testing.T) {
gate := advisory.NewPostGate()
advCfg := config.AdvisoryConfig{UpdateIntervalS: 300}
interval := advCfg.UpdateInterval()
now := time.Date(2026, 10, 28, 23, 22, 0, 0, time.UTC)
repo := "acme/widget"
logger := restoreTestLogger()

paused := true
attempts := 0
cycle := func() bool {
if !gate.Due(advCfg, repo, now, logger) {
return false
}
attempts++
gate.RecordSuccess(repo, now) // what recordRepoPaused / recordPosted both do
return !paused
}

// Paused: 10 one-minute cycles across two intervals β†’ exactly 2 attempts.
for i := 0; i < 10; i++ {
if posted := cycle(); posted {
t.Fatalf("cycle %d posted while paused", i)
}
now = now.Add(time.Minute)
}
wantAttempts := 1 + int((9*time.Minute)/interval)
if attempts != wantAttempts {
t.Fatalf("paused attempts = %d, want %d (one per %s)", attempts, wantAttempts, interval)
}

// Lift the pause: the next due cycle posts, no later than one interval on.
paused = false
posted := false
for i := 0; i < int(interval/time.Minute)+1 && !posted; i++ {
posted = cycle()
now = now.Add(time.Minute)
}
if !posted {
t.Fatalf("pause lifted but no post within one interval (%s)", interval)
}
}
14 changes: 14 additions & 0 deletions src/cmd/hive/eval_cycle_advisory_seams.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ type advisoryPublishDeps struct {
// recordWriteForbidden pauses further post attempts for repo after a
// non-transient 403, so the same refusal is not re-sent every eval cycle.
recordWriteForbidden func(repo string)
// recordRepoPaused advances the pacing gate after a repo-paused skip, so
// the skip is logged once per update interval rather than every cycle.
// It deliberately does NOT record a post: nothing reached GitHub.
recordRepoPaused func(repo string)
}

// advisoryPublishOutcome names how a cycle's digest publish ended, so the
Expand Down Expand Up @@ -246,6 +250,16 @@ func publishAdvisoryDigest(
return advisoryPublishSkipped
}
err := deps.postGitHub(ctx, route.primaryRepo, route.issueNum, md)
var paused *github.RepoPausedError
if errors.As(err, &paused) {
// Operator pause (#6203): the poster wrote nothing and logged why.
// Not an error (the quiet is deliberate), not a post (nothing
// landed) β€” a skip that still paces the next attempt.
if deps.recordRepoPaused != nil {
deps.recordRepoPaused(route.primaryRepo)
}
return advisoryPublishSkipped
}
if err == nil {
logger.Info("posted advisory digest", "repo", route.primaryRepo, "issue", route.issueNum, "findings", digest.TotalCount, "via", "app")
recordPosted(digest.TotalCount, digest.OverflowCount)
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/hive/eval_cycle_advisory_seams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ type publishRecorder struct {
linear []string
githubErr error
linearErr error
pausedFor []string
}

func (r *publishRecorder) deps() advisoryPublishDeps {
Expand All @@ -177,6 +178,7 @@ func (r *publishRecorder) deps() advisoryPublishDeps {
r.moved = append(r.moved, m)
},
recordWriteForbidden: func(repo string) { r.backoffs = append(r.backoffs, repo) },
recordRepoPaused: func(repo string) { r.pausedFor = append(r.pausedFor, repo) },
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/cmd/hive/hard_suppress_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func runHardSuppressReconcileWith(ctx context.Context, cfg *config.Config, ghCli
return
}
result, err := ghClient.ReconcileHiveHardSuppress(ctx, github.HardSuppressReconcileConfig{
Repos: ghClient.Repositories(),
// ActiveRepositories, not Repositories: a paused repo gets no
// hard-suppress lift written to it (#6203).
Repos: ghClient.ActiveRepositories(),
})
if err != nil {
logger.Warn("hard-suppress reconcile incomplete", "error", err)
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/hive/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

import (
Expand Down Expand Up @@ -8103,6 +8103,9 @@
logger.Warn("GitHub App write failed β€” repository transferred to another owner",
"configured", moved.Configured, "current", moved.Current)
},
recordRepoPaused: func(repo string) {
recordAdvisoryPostSuccess(repo, time.Now())
},
recordWriteForbidden: func(repo string) {
backoff := advCfg.PostRetryBackoff()
recordAdvisoryPostForbidden(repo, time.Now(), backoff)
Expand Down
7 changes: 5 additions & 2 deletions src/docs/github-write-surface.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ A rework push uses `--force-with-lease`; there is deliberately no plain
The hive also writes to GitHub on its own schedule, with no agent request
behind the write. These writes are not subject to the lane allowlist, but
every one that lands on an item hive did not open passes the write-back
containment gate (`pkg/writeback`: per-kind ACMM floor + review opt-in
label + backfill guard + per-repo mode; see
containment gate (`pkg/writeback`: repo pause first, then per-kind ACMM
floor + review opt-in label + backfill guard + per-repo mode; see
[operator-reference.md](operator-reference.md#what-hive-writes-to-github-and-when)).
An operator [repo pause](repo-pause.md) refuses every kind on that repo,
own items included, and also stops the advisory digest comment, which is
written outside the gate.
A ratchet test (`pkg/writeback/ratchet_test.go`) fails on any new direct
GitHub write call outside that package. Every
one of them is audited with typed `repo` and `target` fields and redacted
Expand Down
6 changes: 5 additions & 1 deletion src/docs/operator-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,11 @@ on β€” passes through one gate, `writeback.Allowed(repo, item, kind)` in
`pkg/writeback`, before it reaches the GitHub client. The gate never blocks
hive's own PRs and issues, replies to explicit `/hive …` commands, work the
operator started from the dashboard, or agent kicks on items already
labelled for hive. Below the gate the sweeps still *scan*: sentinel findings
labelled for hive β€” with one exception: a repo under an operator pause
([repo-pause.md](repo-pause.md)) refuses **every** kind, own items included,
with reason `repo-paused`. The pause also silences the advisory digest
(`advisory digest skipped: repo paused`, once per update interval), which is
not a gate kind but a write all the same. Below the gate the sweeps still *scan*: sentinel findings
appear in **Security β†’ Suspicious Activity β†’ Sentinel findings** and
`/api/sentinel`, hold-gate mergeability notices become dashboard-only, and
PR stage tracking continues from internal state with no `stage/*` label on
Expand Down
11 changes: 10 additions & 1 deletion src/docs/repo-pause.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ depends on an agent reading the kick and choosing to comply.
| `hive-review` relay | Approvals, change requests and review comments are rejected before any GitHub call, quarantined as `.denied`, with the pause reason in their result files. |
| Work enumeration | The repo contributes no actionable issues or PRs, so nothing downstream β€” kicks, claims, advisories, the contribute queue β€” can hand an agent work on it. |
| Auto-merge sweeps | Both the queued (`lgtm`) and self-authored sweeps skip the repo. |
| Advisory digest | The pinned `## 🐝 Advisory Digest` comment is neither edited nor re-created while the repo is paused. The governor logs `advisory digest skipped: repo paused` (with `by` and `reason`) once per `governor.advisory.update_interval_s`, records an `advisory_digest_suppressed` audit entry with `reason=repo-paused`, and does **not** count the cycle as a post. The first due cycle after resume posts normally. |
| Write-back containment gate | Every periodic writer that asks `pkg/writeback` β€” sentinel, hold-gate upkeep, stage labels, needs-decision parks, supersession and duplicate-fix notices, reporter-trust holds, claim comments, welcome comments, issue filing β€” is refused with reason `repo-paused` **regardless of kind, ACMM level, per-repo mode or whether the item is the hive's own**. The refusal is recorded in the suppressed-writes drill-down (`GET /api/writeback/suppressed`) like any other. |
| Other sweeps over `project.repos` | The duplicate-PR sweep, the closed-issue stage-label sweep and the hard-suppress reconcile iterate the *active* repo set, so a paused repo is never visited. |
| Kick text | The repo is absent from `AUTHORIZED REPOS` and from `$HIVE_REPOS`, and is named separately as paused so an agent does not read the shorter list as scope loss. |

The proxy and relay gates are both required, and neither is redundant. The proxy
Expand All @@ -126,7 +129,13 @@ unpaused repositories continue normally.
elsewhere can still read the paused repo's issues.
- **The hive's own control plane.** App-token minting, heartbeats and other
hive-originated calls are exempt. Stopping them would take the whole spoke
down to quiet one repo.
down to quiet one repo. (Hive-originated *writes to the repo* β€” the advisory
digest, sweep comments and labels β€” are not control plane and **are**
stopped; see the table above.)
- **Creating a pinned advisory issue where none exists yet.** A repo paused
before its first boot still gets its `🐝 Hive Advisory Report` issue
created once, because that lookup doubles as the App-access probe. The
digest comment on it is not written until the repo is resumed.
- **Your own activity.** Pause governs agents. Humans push, review and merge on
a paused repo exactly as before.
- **GraphQL writes whose target repo is only in the request body.** Repo
Expand Down
5 changes: 4 additions & 1 deletion src/pkg/advisory/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ func (g *PostGate) Due(advCfg config.AdvisoryConfig, repo string, now time.Time,
// RecordSuccess advances the update-interval gate for repo after a successful
// digest write. Skip-if-unchanged cycles count too: pkg/github returns nil for
// them by design so freshness advances (#4818/#4821), and an unchanged digest
// is exactly the case the throttle exists to quiet.
// is exactly the case the throttle exists to quiet. A repo-paused skip
// (#6203) advances it as well, so the "skipped: repo paused" log line lands
// once per interval; the pause is re-read on the next due cycle, so lifting
// it posts within one interval.
func (g *PostGate) RecordSuccess(repo string, now time.Time) {
g.mu.Lock()
defer g.mu.Unlock()
Expand Down
12 changes: 12 additions & 0 deletions src/pkg/config/writeback.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,17 @@ func (c *Config) WritebackGateDeps() writeback.Deps {
LevelFor: c.EffectiveACMMLevelForRepo,
OptInLabels: c.WritebackOptInLabels,
RepoListed: c.WritebackRepoListed,
RepoPause: c.WritebackRepoPause,
}
}

// WritebackRepoPause adapts RepoPauseFor to the gate's pause lookup, so a
// pause taken in the dashboard refuses every gated write on the very next
// decision (#6203).
func (c *Config) WritebackRepoPause(repo string) (writeback.RepoPauseInfo, bool) {
rp, paused := c.RepoPauseFor(repo)
if !paused {
return writeback.RepoPauseInfo{}, false
}
return writeback.RepoPauseInfo{By: rp.By, Reason: rp.Reason}, true
}
18 changes: 18 additions & 0 deletions src/pkg/config/writeback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,21 @@ func TestWritebackDefaultsWhenAbsent(t *testing.T) {
t.Fatalf("defaults: %+v", cfg.Writeback)
}
}

func TestWritebackRepoPause_CarriesProvenance(t *testing.T) {
c := &Config{}
c.Project.Org = "acme"
c.Project.Repos = []string{"widget", "gadget"}
c.Project.PausedRepos = []RepoPause{{Repo: "widget", By: "clubanderson", Reason: "freeze"}}
deps := c.WritebackGateDeps()
if deps.RepoPause == nil {
t.Fatal("WritebackGateDeps must wire RepoPause")
}
info, paused := deps.RepoPause("acme/Widget")
if !paused || info.By != "clubanderson" || info.Reason != "freeze" {
t.Fatalf("paused repo: %+v,%v", info, paused)
}
if _, paused := deps.RepoPause("gadget"); paused {
t.Fatal("unpaused repo reported paused")
}
}
19 changes: 19 additions & 0 deletions src/pkg/github/advisory.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,25 @@ func (c *Client) PostAdvisoryDigest(ctx context.Context, repo string, issueNum i
}
owner, repoName := c.splitRepo(repo)

// Repo pause (#6203) means NO hive write against the repo, and the digest
// is a write: an edit of the pinned comment, or a fresh comment when the
// pinned one is out of reach. It is checked before the unchanged-skip
// below so a paused repo never reaches the forge at all, and nothing
// about the process-memory hash state is touched, so the first cycle
// after the pause is lifted posts exactly as the first after boot does.
if perr, paused := c.repoPausedError(repo); paused {
c.logger.Info("advisory digest skipped: repo paused",
slog.String("repo", repo), slog.Int("issue", issueNum),
slog.String("by", perr.By), slog.String("reason", perr.Reason))
c.recordWriteAudit(AuditActionAdvisoryDigestSuppressed, InvocationMeta{Agent: AttributionAgentGovernor},
WriteTarget{Repo: owner + "/" + repoName, Number: issueNum},
"reason", "repo-paused",
"paused_by", perr.By,
"pause_reason", perr.Reason,
"flow", "advisory-digest")
return perr
}

// Canary-gated like CreateIssue/CreatePR/CreateIssueComment
// (kubestellar/hive#4960): the digest aggregates agent-sourced advisory
// finding text, so it is a secondary exfiltration channel that must honor
Expand Down
106 changes: 106 additions & 0 deletions src/pkg/github/advisory_repo_pause_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package github

import (
"context"
"errors"
"strings"
"testing"

"github.com/hivecommons/hive/pkg/writeback"
)

// The advisory digest must honour an operator repo pause (#6203): on the
// a1-vllm-spyre spoke every agent and both repos were paused, the automerge
// sweeps correctly stood down, yet the governor still edited the pinned
// "## 🐝 Advisory Digest" comment on torch-spyre#406 at startup. The digest
// is a write like any other; a paused repo gets neither an edit nor a new
// comment, and the first cycle after the pause lifts posts normally.
func TestPostAdvisoryDigest_HonoursRepoPause(t *testing.T) {
org, repo := "testorg", "testrepo"
digest := advisoryDigestPrefix + "\nFrozen for governor mode SURGE"

cases := []struct {
name string
pausedVia func(c *Client, paused *bool)
wantBy string
}{
{
name: "bare predicate (SetRepoPausedFunc)",
pausedVia: func(c *Client, paused *bool) {
c.SetRepoPausedFunc(func(string) bool { return *paused })
},
},
{
name: "write-back gate with provenance",
pausedVia: func(c *Client, paused *bool) {
c.SetWritebackGate(writeback.New(writeback.Config{}, writeback.Deps{
RepoPause: func(string) (writeback.RepoPauseInfo, bool) {
return writeback.RepoPauseInfo{By: "clubanderson", Reason: "release freeze"}, *paused
},
}, ""))
},
wantBy: "clubanderson",
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
srv := newDigestCountingServer(t, org, repo)
c := newTestClient(t, srv.Server, org, []string{repo})
paused := true
tc.pausedVia(c, &paused)

// Paused across several cycles: nothing reaches the forge, not
// even the comment scan, and the caller is told why.
for i := 0; i < 3; i++ {
err := c.PostAdvisoryDigest(context.Background(), repo, 10, digest)
var perr *RepoPausedError
if !errors.As(err, &perr) {
t.Fatalf("cycle %d: err = %v, want *RepoPausedError", i, err)
}
if perr.Repo != repo || perr.By != tc.wantBy {
t.Fatalf("cycle %d: perr = %+v, want repo %q by %q", i, perr, repo, tc.wantBy)
}
}
if srv.editCalls != 0 || srv.listCalls != 0 {
t.Fatalf("paused: editCalls=%d listCalls=%d, want 0/0", srv.editCalls, srv.listCalls)
}

// Pause lifted: the next cycle posts exactly like the first after
// boot (the pause left no hash state behind).
paused = false
if err := c.PostAdvisoryDigest(context.Background(), repo, 10, digest); err != nil {
t.Fatalf("after unpause: %v", err)
}
if srv.editCalls != 1 {
t.Fatalf("after unpause: editCalls = %d, want 1", srv.editCalls)
}
})
}
}

func TestPostAdvisoryDigest_UnpausedRepoUnchanged(t *testing.T) {
org, repo := "testorg", "testrepo"
srv := newDigestCountingServer(t, org, repo)
c := newTestClient(t, srv.Server, org, []string{repo})
// Some OTHER repo is paused; this one is not.
c.SetRepoPausedFunc(pauseAll("some-other-repo"))
c.SetWritebackGate(writeback.New(writeback.Config{}, writeback.Deps{
RepoPause: func(r string) (writeback.RepoPauseInfo, bool) { return writeback.RepoPauseInfo{}, r == "some-other-repo" },
}, ""))

if err := c.PostAdvisoryDigest(context.Background(), repo, 10, advisoryDigestPrefix+"\nlive"); err != nil {
t.Fatalf("unpaused post: %v", err)
}
if srv.editCalls != 1 {
t.Fatalf("unpaused: editCalls = %d, want 1", srv.editCalls)
}
}

func TestRepoPausedError_Message(t *testing.T) {
e := &RepoPausedError{Repo: "org/r", By: "ops", Reason: "freeze"}
for _, want := range []string{"org/r", "ops", "freeze", "resume"} {
if !strings.Contains(e.Error(), want) {
t.Errorf("Error() = %q, want it to mention %q", e.Error(), want)
}
}
}
Loading
Loading