From 6cdf1f0a7dbce029432427abf4c59ff5e6efaf1a Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Wed, 28 Oct 2026 23:49:59 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20advisory:=20digest=20and=20all?= =?UTF-8?q?=20periodic=20writers=20honour=20repo=20pause?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A paused spoke (every agent paused, both repos in project.paused_repos) still edited its pinned '## 🐝 Advisory Digest' comment at startup while the auto-merge sweeps correctly logged repo-auto-merge-disabled. Repo pause (#6203) is documented as stopping all agent writes; the digest path never consulted it. - pkg/writeback: Deps.RepoPause lookup; the gate refuses every kind on a paused repo with reason repo-paused, checked before mode/own-item, and records the suppression. Gate.RepoPaused exposes the lookup for writers that are not a gate kind. - pkg/config: WritebackGateDeps wires RepoPauseFor (by/reason) into it. - pkg/github: PostAdvisoryDigest returns *RepoPausedError before any forge call, logging 'advisory digest skipped: repo paused' with by and reason and auditing advisory_digest_suppressed reason=repo-paused; no hash state is touched so the first cycle after resume posts. SweepDuplicatePRs and SweepClosedIssueStageLabels iterate activeRepos. - cmd/hive: publishAdvisoryDigest treats RepoPausedError as a skip (not a post, not an error, no App-banner hooks) and paces the next attempt by the update interval; hard-suppress reconcile uses ActiveRepositories. - docs: repo-pause.md, operator-reference.md, github-write-surface.md. Signed-off-by: Andrew Anderson --- ...fixed-advisory-digest-honors-repo-pause.md | 1 + src/cmd/hive/advisory_repo_pause_test.go | 86 ++++++++++++++ src/cmd/hive/eval_cycle_advisory_seams.go | 14 +++ .../hive/eval_cycle_advisory_seams_test.go | 2 + src/cmd/hive/hard_suppress_reconcile.go | 4 +- src/cmd/hive/main.go | 3 + src/docs/github-write-surface.md | 7 +- src/docs/operator-reference.md | 6 +- src/docs/repo-pause.md | 11 +- src/pkg/advisory/policy.go | 5 +- src/pkg/config/writeback.go | 12 ++ src/pkg/config/writeback_test.go | 18 +++ src/pkg/github/advisory.go | 19 ++++ src/pkg/github/advisory_repo_pause_test.go | 106 ++++++++++++++++++ src/pkg/github/closed_issue_stage_sweep.go | 3 +- src/pkg/github/duplicate_sweep.go | 3 +- src/pkg/github/writeback_gate.go | 30 +++++ src/pkg/writeback/gate.go | 54 +++++++++ src/pkg/writeback/writeback_test.go | 62 ++++++++++ 19 files changed, 438 insertions(+), 8 deletions(-) create mode 100644 changelog.d/fixed-advisory-digest-honors-repo-pause.md create mode 100644 src/cmd/hive/advisory_repo_pause_test.go create mode 100644 src/pkg/github/advisory_repo_pause_test.go diff --git a/changelog.d/fixed-advisory-digest-honors-repo-pause.md b/changelog.d/fixed-advisory-digest-honors-repo-pause.md new file mode 100644 index 0000000000..81c32ba990 --- /dev/null +++ b/changelog.d/fixed-advisory-digest-honors-repo-pause.md @@ -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. diff --git a/src/cmd/hive/advisory_repo_pause_test.go b/src/cmd/hive/advisory_repo_pause_test.go new file mode 100644 index 0000000000..093063a7b2 --- /dev/null +++ b/src/cmd/hive/advisory_repo_pause_test.go @@ -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) + } +} diff --git a/src/cmd/hive/eval_cycle_advisory_seams.go b/src/cmd/hive/eval_cycle_advisory_seams.go index 249552e8f2..cd0d0decd9 100644 --- a/src/cmd/hive/eval_cycle_advisory_seams.go +++ b/src/cmd/hive/eval_cycle_advisory_seams.go @@ -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 @@ -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) diff --git a/src/cmd/hive/eval_cycle_advisory_seams_test.go b/src/cmd/hive/eval_cycle_advisory_seams_test.go index 702bcf69d7..1571cae8b7 100644 --- a/src/cmd/hive/eval_cycle_advisory_seams_test.go +++ b/src/cmd/hive/eval_cycle_advisory_seams_test.go @@ -156,6 +156,7 @@ type publishRecorder struct { linear []string githubErr error linearErr error + pausedFor []string } func (r *publishRecorder) deps() advisoryPublishDeps { @@ -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) }, } } diff --git a/src/cmd/hive/hard_suppress_reconcile.go b/src/cmd/hive/hard_suppress_reconcile.go index 7eea19b948..cad93c2428 100644 --- a/src/cmd/hive/hard_suppress_reconcile.go +++ b/src/cmd/hive/hard_suppress_reconcile.go @@ -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) diff --git a/src/cmd/hive/main.go b/src/cmd/hive/main.go index 051a4a7a9f..5af466ce29 100644 --- a/src/cmd/hive/main.go +++ b/src/cmd/hive/main.go @@ -8103,6 +8103,9 @@ func runEvalCycle( 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) diff --git a/src/docs/github-write-surface.md b/src/docs/github-write-surface.md index 330184ef03..9ac9986337 100644 --- a/src/docs/github-write-surface.md +++ b/src/docs/github-write-surface.md @@ -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 diff --git a/src/docs/operator-reference.md b/src/docs/operator-reference.md index 84a0f8ab6f..56c904e1e3 100644 --- a/src/docs/operator-reference.md +++ b/src/docs/operator-reference.md @@ -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 diff --git a/src/docs/repo-pause.md b/src/docs/repo-pause.md index 9a2bb78b94..fa63790500 100644 --- a/src/docs/repo-pause.md +++ b/src/docs/repo-pause.md @@ -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 @@ -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 diff --git a/src/pkg/advisory/policy.go b/src/pkg/advisory/policy.go index 7592e3360c..c266eaf7a8 100644 --- a/src/pkg/advisory/policy.go +++ b/src/pkg/advisory/policy.go @@ -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() diff --git a/src/pkg/config/writeback.go b/src/pkg/config/writeback.go index 3565181e6d..235c14a7ff 100644 --- a/src/pkg/config/writeback.go +++ b/src/pkg/config/writeback.go @@ -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 +} diff --git a/src/pkg/config/writeback_test.go b/src/pkg/config/writeback_test.go index 6622819d79..f0c1b4a5da 100644 --- a/src/pkg/config/writeback_test.go +++ b/src/pkg/config/writeback_test.go @@ -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") + } +} diff --git a/src/pkg/github/advisory.go b/src/pkg/github/advisory.go index 7d86de6bfd..82e096a9d4 100644 --- a/src/pkg/github/advisory.go +++ b/src/pkg/github/advisory.go @@ -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 diff --git a/src/pkg/github/advisory_repo_pause_test.go b/src/pkg/github/advisory_repo_pause_test.go new file mode 100644 index 0000000000..6fa77ab7a3 --- /dev/null +++ b/src/pkg/github/advisory_repo_pause_test.go @@ -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) + } + } +} diff --git a/src/pkg/github/closed_issue_stage_sweep.go b/src/pkg/github/closed_issue_stage_sweep.go index 72ddac8a48..32cebd7240 100644 --- a/src/pkg/github/closed_issue_stage_sweep.go +++ b/src/pkg/github/closed_issue_stage_sweep.go @@ -74,7 +74,8 @@ func (c *Client) SweepClosedIssueStageLabels(ctx context.Context, opts ClosedIss since = time.Now().Add(-DefaultClosedIssueStageSweepWindow) } result := &ClosedIssueStageSweepResult{} - for _, repo := range c.getRepos() { + // activeRepos, not getRepos: a paused repo keeps its labels untouched (#6203). + for _, repo := range c.activeRepos() { if len(result.Cleaned) >= maxActions { break } diff --git a/src/pkg/github/duplicate_sweep.go b/src/pkg/github/duplicate_sweep.go index 426e4de6b6..1e407824ee 100644 --- a/src/pkg/github/duplicate_sweep.go +++ b/src/pkg/github/duplicate_sweep.go @@ -132,7 +132,8 @@ func (c *Client) SweepDuplicatePRs(ctx context.Context, opts DuplicateSweepOptio var firstErr error var all []dupsweep.PR - for _, repo := range c.getRepos() { + // activeRepos, not getRepos: a paused repo gets no duplicate-fix comment (#6203). + for _, repo := range c.activeRepos() { prs, skipped, err := c.fingerprintOpenPRs(ctx, repo, maxPRs) result.Skipped += skipped if err != nil { diff --git a/src/pkg/github/writeback_gate.go b/src/pkg/github/writeback_gate.go index 9815c2378f..855e824283 100644 --- a/src/pkg/github/writeback_gate.go +++ b/src/pkg/github/writeback_gate.go @@ -84,6 +84,36 @@ func (c *Client) writebackSweepSummary(repo string) { c.WritebackGate().SweepSummary(repo) } +// RepoPausedError is returned by a periodic writer that fell silent because +// its target repo is operator-paused (#6203). Callers treat it as a healthy +// skip, not a failure: the quiet is deliberate. +type RepoPausedError struct { + Repo string + By string + Reason string +} + +func (e *RepoPausedError) Error() string { + return "writeback: " + writeback.RepoPausedDetail(e.Repo, writeback.RepoPauseInfo{By: e.By, Reason: e.Reason}) +} + +// repoPausedError combines the two pause sources a client may carry: the +// gate's provenance-bearing lookup (config.RepoPauseFor) and the bare +// SetRepoPausedFunc predicate. Either one pausing the repo pauses it; the +// provenance is filled in when the gate knows it. +func (c *Client) repoPausedError(repo string) (*RepoPausedError, bool) { + if c == nil { + return nil, false + } + if info, paused := c.WritebackGate().RepoPaused(repo); paused { + return &RepoPausedError{Repo: repo, By: info.By, Reason: info.Reason}, true + } + if c.RepoIsPaused(repo) { + return &RepoPausedError{Repo: repo}, true + } + return nil, false +} + // WritebackSuppressedSince returns gate suppressions newer than since for // the dashboard drill-down (nil gate → nil). func (c *Client) WritebackSuppressedSince(since time.Time) []writeback.Suppressed { diff --git a/src/pkg/writeback/gate.go b/src/pkg/writeback/gate.go index 41d64402a3..a3d5b00b7a 100644 --- a/src/pkg/writeback/gate.go +++ b/src/pkg/writeback/gate.go @@ -60,8 +60,20 @@ const ( ReasonBackfill = "backfill-off" ReasonLevelUnknown = "level-unknown" ReasonRepoNotListed = "repo-not-in-project" + // ReasonRepoPaused refuses EVERY kind on an operator-paused repo + // (#6203), own items included: a pause means the hive is deliberately + // quiet on the repo, and the advisory digest edit that kept landing on + // a paused torch-spyre showed that "unsolicited only" was not enough. + ReasonRepoPaused = "repo-paused" ) +// RepoPauseInfo is the provenance of an operator pause, as config records +// it. Both fields may be empty for a pause written by hand into the config. +type RepoPauseInfo struct { + By string + Reason string +} + // ErrSuppressed is returned by writers that surface a refusal as an error. var ErrSuppressed = errors.New("writeback: unsolicited write suppressed") @@ -137,6 +149,10 @@ type Deps struct { // RepoListed reports whether repo is in project.repos. nil means every // repo is listed. RepoListed func(repo string) bool + // RepoPause reports whether repo is under an operator pause and who + // paused it. nil means no repo is ever paused. Checked before anything + // else: a paused repo refuses every kind, own items included. + RepoPause func(repo string) (RepoPauseInfo, bool) // Config, when set, is read on every decision instead of the Config // passed to New, so a dashboard edit of the writeback block is live // without re-wiring (cmd/hive passes a closure over the shared config). @@ -335,6 +351,9 @@ func (g *Gate) AllowedPreview(repo string, item Item, kind Kind, preview string) } func (g *Gate) decideLocked(repo string, item Item, kind Kind) Decision { + if info, paused := g.repoPauseLocked(repo); paused { + return Decision{Reason: ReasonRepoPaused, Detail: RepoPausedDetail(repo, info)} + } cfg := g.cfgLocked() mode := cfg.RepoModeFor(repo) if mode == RepoModeOff { @@ -403,6 +422,41 @@ func (g *Gate) decideLocked(repo string, item Item, kind Kind) Decision { return Decision{Reason: ReasonNeedsLabel, Detail: fmt.Sprintf("#%d carries none of %s; %s needs the label at L%d (%s is at L%d)", item.Number, strings.Join(labels, ","), kind, p.MinLevel, repo, level)} } +// repoPauseLocked asks the configured pause predicate, if any. +func (g *Gate) repoPauseLocked(repo string) (RepoPauseInfo, bool) { + if g.deps.RepoPause == nil { + return RepoPauseInfo{}, false + } + return g.deps.RepoPause(repo) +} + +// RepoPaused reports whether repo is operator-paused, with the pause's +// provenance, for writers that are not a gate Kind (the advisory digest) +// but must still fall silent on a paused repo. A nil gate never pauses. +func (g *Gate) RepoPaused(repo string) (RepoPauseInfo, bool) { + if g == nil { + return RepoPauseInfo{}, false + } + g.mu.Lock() + defer g.mu.Unlock() + return g.repoPauseLocked(repo) +} + +// RepoPausedDetail is the drill-down/log text for a repo-paused refusal. +func RepoPausedDetail(repo string, info RepoPauseInfo) string { + d := repo + " is paused by the operator" + if info.By != "" { + d += " (by " + info.By + if info.Reason != "" { + d += ": " + info.Reason + } + d += ")" + } else if info.Reason != "" { + d += " (" + info.Reason + ")" + } + return d + "; resume the repo to allow hive writes again" +} + // levelCheckLocked applies the kind's min level to an issue-file decision. func (g *Gate) levelCheckLocked(repo string, _ Item, kind Kind, ok Decision) Decision { p := g.cfgLocked().Policy(kind) diff --git a/src/pkg/writeback/writeback_test.go b/src/pkg/writeback/writeback_test.go index f4d9f334af..328f78ffa5 100644 --- a/src/pkg/writeback/writeback_test.go +++ b/src/pkg/writeback/writeback_test.go @@ -315,3 +315,65 @@ func TestRecentAndSnapshot(t *testing.T) { t.Fatal("firstLine truncation") } } + +// A repo pause (#6203) refuses EVERY kind, own items and mode=full +// included, and is checked before any other rule; lifting it restores the +// ordinary decision. +func TestRepoPausedRefusesEveryKind(t *testing.T) { + paused := map[string]RepoPauseInfo{"org/repo": {By: "clubanderson", Reason: "release freeze"}} + g := New(Config{PerRepo: map[string]RepoOverride{"org/full": {Mode: RepoModeFull}}}, Deps{ + LevelFor: func(string) int { return 6 }, + RepoPause: func(repo string) (RepoPauseInfo, bool) { + info, ok := paused[repo] + return info, ok + }, + Now: func() time.Time { return t0 }, + }, "") + cases := []struct { + name string + repo string + item Item + kind Kind + }{ + {"own item", "org/repo", ownPR, KindHoldGateNotice}, + {"foreign L6 sentinel", "org/repo", humanPR, KindSentinel}, + {"issue file", "org/repo", Item{}, KindIssueFile}, + {"stage label opted", "org/repo", optedPR, KindStageLabel}, + {"case-insensitive repo", "org/repo", ownPR, KindClaimComment}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + d := g.AllowedPreview(tc.repo, tc.item, tc.kind, "preview") + if d.Allowed || d.Reason != ReasonRepoPaused { + t.Fatalf("got %+v, want refused with %s", d, ReasonRepoPaused) + } + for _, want := range []string{"clubanderson", "release freeze", "paused"} { + if !strings.Contains(d.Detail, want) { + t.Errorf("detail %q lacks %q", d.Detail, want) + } + } + }) + } + if n := len(g.Recent()); n != len(cases) { + t.Fatalf("suppressions recorded = %d, want %d", n, len(cases)) + } + // Unpaused repos are untouched: own items and mode=full still pass. + if d := g.Allowed("org/other", ownPR, KindSentinel); !d.Allowed || d.Reason != ReasonOwnItem { + t.Fatalf("unpaused own item: %+v", d) + } + if d := g.Allowed("org/full", humanPR, KindSentinel); !d.Allowed || d.Reason != ReasonRepoFull { + t.Fatalf("unpaused full repo: %+v", d) + } + // Lifted → back to the normal decision. + delete(paused, "org/repo") + if d := g.Allowed("org/repo", ownPR, KindHoldGateNotice); !d.Allowed || d.Reason != ReasonOwnItem { + t.Fatalf("after unpause: %+v", d) + } + if info, ok := g.RepoPaused("org/repo"); ok || info.By != "" { + t.Fatalf("RepoPaused after unpause = %+v,%v", info, ok) + } + var nilGate *Gate + if _, ok := nilGate.RepoPaused("org/repo"); ok { + t.Fatal("nil gate must never report paused") + } +}