Repository navigation
π Control base-refresh churn without blocking ready successors - #15836
Conversation
Signed-off-by: Andy Anderson <andy@clubanderson.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
Signed-off-by: Andy Anderson <andy@clubanderson.com>
|
stage 080-awaiting-merge-admission β 050-review-pending: required-check-pending:Sign-off survives the squash |
Signed-off-by: Andy Anderson <andy@clubanderson.com>
|
CI iteration on 4403944 identified two compatibility gaps in |
|
stage 080-awaiting-merge-admission β 050-review-pending: required-check-pending:Sign-off survives the squash |
There was a problem hiding this comment.
Security review (head 40875f6) β no blocking findings. Two low advisories:
-
Contributor-lane owner can hold the shared refresh slot by pushing (
src/pkg/github/automerge/automerge_base_preparation.go:217-226,:98-113).preparationKeepsOwnerkeeps ownership onhead-changed-since-eval/contributorLaneReasonNoVerdict, and the owner's liveness check passesexpectedHead=""(:111), so a fork PR that once passed review+CI can push fresh commits and remain owner, parking every behind App/trusted PR on that base. Bounded bypreparationWindow()(ReviewPending dwell, 1h default βsrc/pkg/stagelabels/stagelabels.go:269) and the issue explicitly admits all lanes, so this is accepted design; flagging the trust coupling for the record. If you want to tighten it cheaply, treat an owner head change as a release:if expectedHead != "" && pr.GetHead().GetSHA() != expectedHead { return "head-changed-before-preparation", nil }and pass
st.Owner.Headinstead of""at:111(owner then re-queues via the normal FIFO once the new head re-qualifies). -
State files group-writable (
src/pkg/github/automerge/base_preparation_store.go:81-82):0o775/0o664under/data/base-preparation/, while the sibling stage store uses0o755/0o644(src/pkg/stagelabels/store.go:598,602). Group write on the shared durable volume lets any same-group process alter/corrupt ownership (corruption fails closed per:107, tampering does not). Suggest matching the stage store:const directoryMode = 0o755 const fileMode = 0o644
Checked and fine: snapshot paths are sha256(key) (no traversal from repo/base refs); corrupt JSON fails closed; behind heads can never merge (currentBaseGate stops on every admission/refresh outcome, automerge_current_base.go:104-122); mergeReviewGate is added before the gate, not moved; engine update-branch uses go-github directly (automerge_sweep.go:2689) so the new Client.updateBranch refusal (pullrequest.go:601) doesn't self-block.
β hive: agent=adjudicator-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Hive filed review findings that do not block this PR as backlog items:
Cap: 10 backlog item(s) per PR per day. |
There was a problem hiding this comment.
Style review (head 40875f6) β no blockers; three maintainability notes, worst first.
-
base-refresh:reasons bypass thestageengine/prstageshared-reason idiom. The repo's convention for a reason the sweep writes and the stage engine + dashboard read is aprstageprefix/state constant and parser (src/pkg/stageengine/prstage/merge_train.go:9-26, consumed viastageengineprstage.*insrc/pkg/dashboard/stage_tracker_caption.go:55,379,388andprstage.ParseMergeTraininderive_pr_classify.go). This PR instead hardcodes the wire format in four packages: unexportedbasePreparationPrefixinsrc/pkg/github/automerge/automerge_base_preparation.go:21, string literals insrc/pkg/stageengine/derive_pr_classify.go:375,src/pkg/dashboard/stage_tracker_caption.go:317,323, andsrc/pkg/github/pullrequest.go:602(base-refresh:awaiting-admission). Thesnapshot-changed/state-unavailablesuffixes are also rebuilt inline atautomerge_base_preparation.go:180,255,automerge_current_base.go:117,automerge_sweep.go:2598. Suggest aprstageblock the other three packages import:// src/pkg/stageengine/prstage/base_refresh.go const ( BaseRefreshReasonPrefix = "base-refresh:" BaseRefreshStatePreparing = "preparing" BaseRefreshStateQueuedBehind = "queued-behind#" BaseRefreshStateSnapshotChanged = "snapshot-changed" BaseRefreshStateStateUnavailable = "state-unavailable" BaseRefreshStateAwaitingAdmission = "awaiting-admission" )
-
forgetRejectedPreparationUpdatedrops the caller'sctxand the REST-caller tag.src/pkg/github/automerge/automerge_base_preparation.go:214-217doesc.gh.PullRequests.Get(context.Background(), β¦)although its only caller,executeUpdateBranchEffect(automerge_sweep.go:2664,2702), hasctxin hand, and every otherPullRequests.Getin this file wraps withhgithub.WithRESTCaller(ctx, "hive:base_preparationβ¦")(:118,:173). A cancelled sweep keeps issuing this GET, and it is the one base-preparation call invisible to per-caller REST accounting.func (c *Engine) forgetRejectedPreparationUpdate(ctx context.Context, owner, repo string, number int, head string) { // A synchronous refusal cannot have applied the write. Forget only our // reservation; the mutation journal still owns ambiguous reconciliation. pr, _, err := c.gh.PullRequests.Get(hgithub.WithRESTCaller(ctx, "hive:base_preparation_forget"), owner, repo, number)and
c.forgetRejectedPreparationUpdate(ctx, owner, repo, number, headSHA)atautomerge_sweep.go:2702. -
Lane provenance is a variadic with a silent default.
currentBaseGate(..., admissionLane ...string)atsrc/pkg/github/automerge/automerge_current_base.go:92,113-116falls back tostageLaneSelfwhen omitted. All three production callers pass a lane explicitly (automerge_sweep.go:2002,2484,automerge_contributor_lane.go:1461); only the test helper atautomerge_base_preparation_test.go:140omits it. Since lane provenance decides whether a release is honoured (observeBasePreparation,automerge_base_preparation.go:251-270;TestBasePreparationProvenanceForEveryAdmittingLane), a future caller that forgets the argument gets wrong provenance with no compile error. Make it a requiredlane stringparameter and passstageLaneSelffrom the test helper.
β hive: agent=adjudicator-5 backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Docs currency β reviewed at head 40875f6.
1. review.contributor_prs.base_sync docs no longer match what the setting does (medium). src/cmd/hive/prfollowupwire.go:168 now returns false from BaseSyncEnabled whenever cfg.AutoMerge.RequireCurrentBaseFor(repo) is true, so on current-base-gated repos the setting is silently a no-op and PR follow-up defers to the preparation owner. The two operator-facing descriptions of the setting still say unconditionally that it "lets PR follow-up call GitHub's update-branch API":
src/docs/operator-reference.md:249(review.contributor_prs.base_syncrow)src/docs/review-swarm.md:560
hive-merge.md mentions the deferral only in passing ("client-side follow-up/relay/supersession updates defer to preparation"); an operator reading the setting's own reference row will not find it. Suggested addition to the end of both passages:
-...the repository's "Sign-off survives the squash" check examines the PR's own commits, not GitHub's update-branch merge commit. |
+...the repository's "Sign-off survives the squash" check examines the PR's own commits, not GitHub's update-branch merge commit. On a repository where the current-base gate is on (`auto_merge.require_current_base` / `require_current_base_default`), this setting is ignored: follow-up defers to the automerge base-preparation owner described in [hive-merge.md](hive-merge.md#final-base-preparation-one-refresh-owner-no-ready-work-blockade). |2. auto_merge.require_current_base row describes the pre-PR refresh behavior (low). src/docs/operator-reference.md:438 still says a behind green head "is updated with GitHub update-branch ... and merges once CI is green"; after this PR it is admitted to a single per-repo/base preparation owner and may instead sit at base-refresh:queued-behind#N (src/pkg/github/automerge/automerge_current_base.go hunk at preparationGate, derive_pr_classify.go:375). One sentence pointing at the new hive-merge.md section would keep the setting reference accurate.
3. Machine-reason spelling drift (low). The PR body and the new base-refresh: prefix handling (derive_pr_classify.go:375, stage_tracker_caption.go:317) use base-refresh:state-unavailable, but src/pkg/github/automerge/automerge_adoption_recovery.go:226 emits "base-refresh-state-unavailable" (hyphen), which neither the classifier prefix check nor the humanizer recognizes. Also base-refresh:snapshot-changed / base-refresh:state-unavailable, listed in the PR body as machine reasons, are absent from the new hive-merge.md section (src/docs/hive-merge.md:379-380 names only preparing and queued-behind#N).
return adoptionRecoverySkipped(nonEmpty(reason, basePreparationPrefix+"state-unavailable"))
β hive: agent=ci-maintainer backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Correctness review (head 40875f6)
Review gate now evaluated twice per tick on current-base-policy repos β src/pkg/github/automerge/automerge_sweep.go:1999 (self lane) and :2481 (trusted lane) add an early mergeReviewGate call before currentBaseGate, while the original call at :2050 / :2509 still runs on the re-verified head immediately before merge. The head is guaranteed identical between the two calls (head-changed-since-eval guard at :2044-2046), so on every tick where a green head reaches the merge call, mergeReviewGate (automerge_review_gate.go:235-299) runs its side effects twice: RecordEvaluation emits two self-merge review gate evaluated audit lines (cmd/hive/review_gate.go:108-114), RecordShadow re-signs/merges the shadow evidence twice, and in enforce mode with !priorChecked latestTrustedHumanApproval fetches reviews twice (automerge_review_gate.go:258-260). Since current-base is the hive-wide default (#15335), this doubles review-gate audit/metric counts for essentially all lanes. The early call is justified (keeps an unreviewed head out of preparation), so skip the later one when the early one already cleared this head:
--- a/src/pkg/github/automerge/automerge_sweep.go
+++ b/src/pkg/github/automerge/automerge_sweep.go
@@ trySweepSelfAuthoredPR
+ reviewGated := false
if c.requireCurrentBaseFor(owner+"/"+repo) && !queueSkipsBase() {
if reviewReason := c.mergeReviewGate(ctx, displayRepo, owner, repo, lane, number, pr, evaluatedHeadSHA, priorApprover, priorChecked); reviewReason != "" {
return AutoMergeSweepEvent{}, reviewReason, nil
}
+ reviewGated = true
if ev, reason, stop, err := c.currentBaseGate(...); stop {
return ev, reason, err
}
}
@@
- if reviewReason := c.mergeReviewGate(ctx, displayRepo, owner, repo, lane, number, current, evaluatedHeadSHA, priorApprover, priorChecked); reviewReason != "" {
- return AutoMergeSweepEvent{}, reviewReason, nil
+ if !reviewGated {
+ if reviewReason := c.mergeReviewGate(ctx, displayRepo, owner, repo, lane, number, current, evaluatedHeadSHA, priorApprover, priorChecked); reviewReason != "" {
+ return AutoMergeSweepEvent{}, reviewReason, nil
+ }
}Same shape for trySweepTrustedAuthorPR (:2481 / :2509). A test asserting a single RecordEvaluation per tick on a policy repo would pin it.
β hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Intent alignment (read at head 40875f6, against #15833)
The engine-side design matches the issue: all three lanes route the behind refresh through admitBasePreparation (automerge_current_base.go:111-117), the early behind shortcuts are disabled on policy repos (automerge_sweep.go:1920, :2426; automerge_contributor_lane.go:1385), already-current heads return before admission (automerge_current_base.go:104-108), the preparing owner is excluded from train seats (automerge_merge_train.go:426) and sibling refreshes are stopped (:784). One gap between the body and the diff:
1. [medium] Operator "merge now / rebase-then-merge" from the dashboard now routes hive-authored behind PRs to a fixer-agent rebase instead of update-branch
Client.updateBranch refuses unconditionally on policy repos (src/pkg/github/pullrequest.go:601-603). The PR body and base_refresh_policy.go:3-5 scope this to "follow-up, merge relay, supersession", but the same method backs two operator-solicited dashboard paths: rebase_merge_followthrough.go:113 (armRebaseThenMerge) and api_repo_item_decision.go:782 (queueRebaseOnApprove). Both catch the error, log "leaving the rebase to the fixer", and keep the episode armed; cmd/hive/merge_eligibility.go:1157-1160 then routes every armed PR to a fixer agent for a manual rebase. Net effect on policy repos: a human's merge-now on a merely-behind hive PR consumes a fixer agent and pushes a fresh head outside the preparation owner β the kind of unserialized refresh #15833 is trying to remove β and the PR's own text does not state this behavior change. Suggested fix: let solicited callers bypass the scheduler:
--- a/src/pkg/github/pullrequest.go
+++ b/src/pkg/github/pullrequest.go
@@ func (c *Client) UpdateBranch(ctx context.Context, repo string, number int) error {
- return c.updateBranch(ctx, repo, number, "", "")
+ return c.updateBranch(ctx, repo, number, "", "", false)
}
+
+// UpdateBranchSolicited is UpdateBranch for an operator-initiated action
+// (dashboard merge-now / approve). It is not an automatic refresh, so it
+// does not defer to the automerge preparation front.
+func (c *Client) UpdateBranchSolicited(ctx context.Context, repo string, number int) error {
+ return c.updateBranch(ctx, repo, number, "", "", true)
+}
@@ func (c *Client) UpdateBranchExpectedHead(...) error {
- return c.updateBranch(ctx, repo, number, expectedHeadSHA, observedBaseSHA)
+ return c.updateBranch(ctx, repo, number, expectedHeadSHA, observedBaseSHA, false)
}
@@
-func (c *Client) updateBranch(ctx context.Context, repo string, number int, expectedHeadSHA string, observedBaseSHA string) error {
+func (c *Client) updateBranch(ctx context.Context, repo string, number int, expectedHeadSHA string, observedBaseSHA string, solicited bool) error {
@@
- if c.baseRefreshScheduled(owner + "/" + repo) {
+ if !solicited && c.baseRefreshScheduled(owner + "/" + repo) {
return fmt.Errorf("base-refresh:awaiting-admission: ...")
}and switch rebase_merge_followthrough.go:113 and api_repo_item_decision.go:782 to gh.UpdateBranchSolicited(...) (plus a test in base_refresh_policy_test.go). Alternatively, document the dashboard redirection in the PR body/hive-merge.md if it is intended β but a fixer push per operator merge-now looks contrary to the issue's goal.
2. [low, advisory] mergeReviewGate now runs twice per tick on policy repos β automerge_sweep.go:1999 then :2050 (trusted: :2481 then :2509). It calls StartReviewEvidence and RecordEvaluation (automerge_review_gate.go ~L280-290), so each sweep tick records two evaluations for the same head/lane. Harmless for gating; worth a priorReviewOK short-circuit or accepting the duplicate metric.
β hive: agent=adjudicator-3 backend=copilot model=claude-fable-5.1 copilot=1.0.88
Pairwise integration check with #15831 (fixes #15825)Checked #15836 head
The fixes are complementary, not a hard compile dependency. Existing regressions cover fully gated ready-successor bypass, CI/review negative controls and preparation stage classification; #15831 separately covers ready-only seating/ejection. Combined-tree test execution has not occurred: repository rules require CI, and current-head CI remains pending. Neither PR was merged or deployed; #15831 was not modified. |
Signed-off-by: Andy Anderson <andy@clubanderson.com>
|
Pushed DCO-signed fixture-only correction |
|
stage 080-awaiting-merge-admission β 050-review-pending: required-check-pending:Sign-off survives the squash |
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
Port the #15836 base-preparation hunks that landed in the moved trySweepSelfAuthoredPR/trySweepTrustedAuthorPR/updateBranchAndSkip/ executeUpdateBranchEffect bodies into automerge_sweep_trusted.go. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
Fixes #15833
Owner-approved outcome
One final base-refresh owner per destination repository/base across App, trusted-author and contributor lanes. Waiting heads develop/review normally, without repeatedly merging the base into every head. A successor already current-base, CI-green and reviewed bypasses an unready preparation owner under every existing merge gate. Behind successors cannot bypass testing.
Design
/data/base-preparation/; write-ahead head/base identity and expected-head mutation guard deduplicate concurrent lanes/sweeps/restarts. FIFO admission tickets keep provenance; only a caller freshly qualifying its head becomes owner, not a stale ticket.behind, required-check fallback, train sibling refreshes, adoption recovery and explicit trusted-human merge-forward through shared ownership. Client follow-up/relay/supersession refreshes defer to the scheduler on current-base-policy repos. Non-policy behavior remains unchanged.Related, not duplicate: #15825 / #15831 own ready-only train seating/ejection; #15823 owns reviewer scheduling. Train touch points here only exclude preparing owners and stop blanket sibling base merges. No managed PR/issue edits beyond this issue and PR.
Observability and rollout
automerge base preparation selected,automerge base preparation refresh claimed,automerge base preparation waiting,automerge base preparation releasedinclude repo/base/PR plus head/base SHA or cause. Machine reasonsbase-refresh:queued-behind#N,base-refresh:preparing,base-refresh:snapshot-changed,base-refresh:state-unavailable; stage/caption stays CI / Review, not ready. Existingautomerge update-branchandupdated_branchesremain refresh signals. Deploy the changed hive binary after review/CI; no rollout or live edits performed here.Human/direct/external writers may still move the base. Preparation coalesces moves while its CI/review is pending, then requalifies and refreshes again if needed; this cannot prevent external writes or authorize stale-tested merges.
Review and validation
Read-only code-review agent completed before commit; addressed lane-provenance revocation, stale-ticket promotion and explicit merge-forward repair findings, with regressions. Local validation is gofmt only plus patch inspection, per AGENTS.md; no local Go tests/build/vet/lint/docs guards run. CI is the sole verdict; results will be updated here.
Regression coverage: multiple pending PRs/repeated sweeps, sticky preparing head, lane provenance, FIFO/head-change requalification, closed/gone/hold/draft/conflict/retarget/red/rejected/withdrawn/expired release, distinct repo/base and canonical casing, concurrent independent store instances/pod restart dedup, pinned-head/base changes, persistence fail-closed, opted-out behavior, repair serialization, non-ready stage/caption, and fully gated current-base successor merging while preparation CI is queued with negative CI/review controls. No new sleeps.
Do not merge or deploy this PR automatically as part of this handoff. No /approve or /lgtm requested by this implementation agent.