Repository navigation
🐛 fix(automerge): a refused update-branch, merge or merge-forward is sent once per PR head, not again on every sweep - #17178
Conversation
The queued, trusted-author and contributor lanes run every minute on a fresh engine (SweepTrustedAuthorAutoMerges, SweepContributorLaneAutoMerges, cmd/hive runAutoMergeSweepIfDue). The marks meant to make a refused write happen once per head lived on that engine, so they were empty on every tick: - a refused update-branch (fork head, base changed workflow files) was re-PUT every sweep (projectbluefin fsdk-containers#508, ~every 75 s); - a merge refused with 405 was re-PUT every minute, not every 30; - the trusted-author merge-forward was re-POSTed every sweep; - "logged once per head" holds were logged on every sweep. The marks now live in a sweepMemory kept on the long-lived GitHub client (Client.SharedState) and shared by every engine built over it. A read-only integration-eligibility probe gets a private memory so it never marks a head as tried. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar <Danathar@users.noreply.github.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 |
…run ledger The integration eligibility probe builds its own engine with the live options. With HeldRunApprovals unset, that engine picked up the process-wide ledger. approveHeldRunsForRegistryTrusted claims a head before it calls the approve API, and the probe's read-only transport refuses that call. So a probe could mark a head as tried, and the real contributor-lane sweep would never approve it. integrationReadOnlyOptions now gives the probe a private ledger. Found by the agent auditing hivecommons#17178. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar <Danathar@users.noreply.github.com>
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
There was a problem hiding this comment.
Read the diff against the v6 tree and the callers. The mechanism is sound and I found no defect; one low-priority consolidation note.
What I verified
cmd/hive/main_sweeps.go:937-954passes the*github.Clientitself as theTransporttoSweepQueuedAutoMerges/SweepTrustedAuthorAutoMerges/SweepContributorLaneAutoMerges, so thetransport.(interface{ SharedState(...) })assertion insharedSweepMemory(automerge_sweep_memory.go:56) succeeds in production and the one-shot engines really do share onesweepMemory. It is the same assertion patternNewalready uses forMutationBoundary().- Locking is preserved: every former
c.mergeRefusalsMusection now takesm.mergeRefusalsMuon the shared struct, andchecksExpectedKnownis still only called under that lock fromknownMergeRefusal(automerge_merge_refusal.go:188-200). - Pruning cannot drop a live mark:
hasOnce/markOncerefresh the timestamp on every read, so a head that is still being swept is never idle; only marks untouched for 24h go, and only once the set reaches 1024 (automerge_sweep_memory.go:112-121). integrationReadOnlyOptionssetsisolatedSweepMemory, soNewskips the shared memory andmemory()lazily builds a private one — the probe cannot mark a head as tried.- The body's "merges cleanly with #17169 in either order" claim holds:
git merge-tree pr17169 pr17178produces a tree with no conflicts.
Note (low, not blocking)
After this and #17169 both land, github.Client will carry two sharing mechanisms for the same job: #17169 adds dedicated heldRunApprovals/installationPerms fields with a HeldRunApprovals() accessor (client.go:182-183 on that branch), while this PR adds the generic SharedState(name, build) slot (shared_state.go:19). Either is fine; having both is one more thing the next reader has to learn. Since both are yours, consider moving #17169's ledger onto SharedState in whichever PR lands second, or say in a comment why the held-run ledger deserves a typed field.
Open question, not a finding: a refused update-branch / merge-forward is now remembered for the process lifetime at that head (until a new head or restart), with no re-check if the workflows permission is later granted. That matches how the long-lived self loop already behaved and the "once per PR head" intent, so I'm only flagging that #17169 chose a permission-aware retry rule for approvals and this PR does not for pushes.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. Review findings from Read against the tree at
This is not a duplicate of #17169: that one owns the held-run approval ledger, this one owns update-branch/merge-forward/merge-refusal/hold-logged marks. They do touch the same hunk of |
…ad, not again on every sweep (#17169) * fix(automerge): approve a contributor's held runs once per head, not once per sweep The contributor lane's once-per-head mark for held-run approvals lived on the automerge engine, which SweepContributorLaneAutoMerges rebuilds every tick. A head whose approvals GitHub refused with 403 (App without actions: write) was therefore re-POSTed on every sweep: on projectbluefin dakota-iso#307 and fsdk-containers#508 cost ~270 charged POST actions/runs/{id}/approve calls an hour, all 403. Move the pass and the refusal into a process-wide ledger on the GitHub client (HeldRunApprovals). A refused head keeps reporting unauthorized:approve-workflow-runs without another call until the head changes or the installation gains actions: write (read via InstallationPermission, cached 5 min). Only send runs GitHub's approve endpoint accepts: fork pull_request runs and Actions-bot runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar <Danathar@users.noreply.github.com> * fix(automerge): drop an unused constant; docs name the contributor lane's grant retry golangci-lint flagged contributorHeldRunsApprovalKeyPrefix as unused after the ledger moved to the long-lived client. The hive reviewer pointed out that github-app-setup.md still said a refused head needs Approve and run after the grant. The contributor lane now retries a refused head once the installation reads actions: write, so the doc says so. hive-merge.md also notes that a ledger entry untouched for 24 hours is dropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar <Danathar@users.noreply.github.com> * fix(automerge): the read-only eligibility probe keeps a private held-run ledger The integration eligibility probe builds its own engine with the live options. With HeldRunApprovals unset, that engine picked up the process-wide ledger. approveHeldRunsForRegistryTrusted claims a head before it calls the approve API, and the probe's read-only transport refuses that call. So a probe could mark a head as tried, and the real contributor-lane sweep would never approve it. integrationReadOnlyOptions now gives the probe a private ledger. Found by the agent auditing #17178. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar <Danathar@users.noreply.github.com> * docs(scale-envelope): re-point the RankActionableIssues citation after client.go grew The new held-run ledger fields on Client shifted RankActionableIssues by five lines, so the docs citation check reported drift. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1 Signed-off-by: Danathar <Danathar@users.noreply.github.com> --------- Signed-off-by: Danathar <Danathar@users.noreply.github.com> Co-authored-by: Danathar <Danathar@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: hivecommons-hive[bot] <280983584+hivecommons-hive[bot]@users.noreply.github.com>
Summary
The queued, trusted-author and contributor merge lanes run every minute on a brand-new automerge engine. Several "do this once per PR head" marks lived on that engine, so they were empty again on every tick. On projectbluefin this re-sent a refused
update-branchforfsdk-containers#508about every 75 seconds. It also logged "once per head" holds on every sweep, about 15 PRs every 80 seconds. This PR moves those marks onto the long-lived GitHub client, the same idea as #17169, so every lane's engine shares them for the life of the process. It is the follow-up to #17169's finding and merges cleanly with it in either order. Refs #17169What went wrong
SweepTrustedAuthorAutoMerges,SweepContributorLaneAutoMergesandSweepQueuedAutoMergeseach callNew(transport, opts). cmd/hive'srunAutoMergeSweepIfDuecalls them every minute. Only the self-authored loop keeps one engine alive, and that loop also runs the trusted and contributor lanes. So any per-head memo on the engine works for the long-lived loop but resets for the one-minute sweep.Live evidence from the projectbluefin hive since the dd6b372 deploy (read with
log_read, 2026-11-07 22:14Z to 2026-11-08 02:14Z):automerge update-branch refused: the base changed workflow files and the head is in a fork the app cannot push them toforfsdk-containers#508: 11 times between 01:45Z and 02:11Z, each one preceded byhead is behind the current base; updating before merge. Head and base were unchanged, so each line is one more refusedPUT /pulls/508/update-branch(about 45 an hour). The memo that should stop it (branchUpdateWorkflowRefused, added for fix(ci): isolate invalid GNOME extension heads projectbluefin/utah#1001) was on the engine.merge train: PR left out of every train: 400 lines in 53 minutes, about 15 PRs every ~80 s (for example utah-packages#924, utah#1141, testsuite#1116). This is log volume only, with no API cost, but it buries real lines.POST /merges, a push to a person's branch) is tried every sweep instead of once per head.What changes
Client.SharedState(name, build)in pkg/github: a process-wide slot other packages own and type.sweepMemoryin automerge, fetched from that slot byNew(). It holds:mergeRefusals);terminalHoldsLogged).mergeRefusalskeeps its own 30-minute recheck and prune.IntegrationEligibilityprobe gets a private memory. A probe cannot write, so it must never mark a head as tried for the real sweep. A transport that keeps no shared state, such as the test fakes, keeps per-engine memory as before.contributor_held_runs.goand theheldRunApprovalsfield are left as they are, so the two PRs merge in either order. A trial merge of both branches builds and passes the automerge package.Every cross-sweep field on the engine
heldRunApprovals: update-branch workflow refusalPUT update-branch(write)heldRunApprovals: merge-forward attempt and workflow refusalPOST /mergesmerge commit and conflict note (writes)mergeRefusalsPUT /pulls/N/mergeafter a 405, and the native-queue method refusalmerge-refusedlines; latent (#15419 pattern)terminalHoldsLoggedOnTerminalHoldhand-off (self lane only)heldRunApprovals:@dependabot rebasenudgetrySweepSelfAuthoredPR, which runs on the long-lived loop. The comment is also deduped by the effects journalheldRunApprovals: bot takeoverheldRunApprovals: contributor held runsPOST actions/runs/{id}/approveunauthorized,unauthorizedLabelReadyhive:unauthorizedlabel and notelane unauthorizedlines, all the #17169 case. Writes are durable: the label is read from the PR, and the note is upserted by its marker and the heads it coversworkflowApprovalCommands,Scans,Untrusted,WorkflowChecks/ok-to-testcomment and comment scanshumanReturnCheckedGETlabel events once per head (stage labels)maintainerPermGETcollaborator permission (10 min TTL)contributorMergedReposCachesearch/issues(1 h TTL)closingNonPRTargets,closingCommitRefs,approvalReach,baseRefreshnativeQueueProbes,inactiveQueueLastmergeTrain*(files, attempts, merged, logged, verdicts, seats)RebaseResolver, so one-shot engines never request rebases. Files are re-readselfSkipWarned,currentBaseFallbackWarned,requiredChecksFallbackWarnedevaluatedHeadsclaimantsThese are already process-wide through
Optionsor package defaults:mergeQueueBases,contributorSoak,headFirstSeen,headSightings,sweepClock, the stage store and tracker, and base preparation.Files
src/pkg/github/shared_state.go(new),src/pkg/github/client.go: theSharedStateslot.src/pkg/github/automerge/automerge_sweep_memory.go(new):sweepMemoryand its once and logged sets.automerge_sweep.go: engine fields,New()wiring, the private-memory option.automerge_merge_forward.go,automerge_v6_lane.go,automerge_held_runs.go,automerge_merge_refusal.go: use the shared memory.automerge_integration_eligibility.go: the probe keeps a private memory.automerge_sweep_memory_test.go(new);automerge_contributor_lane_test.gofixture gains an update-branch status.changelog.d/fixed-automerge-once-per-head-memory.md.Tests
Each test builds one engine per sweep on one shared client, the way production does. The contributor-lane tests call the package-level
SweepContributorLaneAutoMergesagain and again.TestContributorLaneRefusedUpdateBranchNotRetriedAcrossSweepsTestContributorLaneRefusedMergeNotRetriedAcrossSweepsTestMergeForwardTriedOncePerHeadAcrossSweepsTestCurrentBaseGateRefusedUpdateNotRetriedAcrossSweepsTestMergeTrainSkipLoggedOnceAcrossSweepsTestSweepMemorySharedPerClientFull packages run:
./pkg/github/automerge/,./pkg/github/,./pkg/writeback/and./cmd/hive/all pass.go vetis clean,check-docs-citations.pypasses, and the changelog-fragment and DCO checks pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01BQYnPGFJx81c8JXR3o1sg1