Skip to content

πŸ› fix(automerge): update-branch honours the stage record's fork guard when the index has no entry - #17383

Merged
hivecommons-hive[bot] merged 2 commits into
v6from
scanner/fix-17380
Nov 9, 2026
Merged

hivecommons-hive[bot] merged 2 commits into
v6from
scanner/fix-17380

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Closes #17380

Why

updateBranchAndSkip holds a fork head that waits on a maintainer-run fork-guarded check (the fork Canary). Merging main into it creates a new head and throws away the run the PR is waiting for. The guard (waitingForkGuard) read only the shared-CI index. That index lives in process memory, is rebuilt from scratch on every enumeration, and has no entry after a restart or after a pass that could not read the check's annotations (REST rate-limit windows). In each of those gaps the contributor lane ran update-branch. On projectbluefin/utah-packages#917 that happened five times in 22 hours while the PR sat at 085 on fork-guard:Canary.

The stage record already persists the guard (ForkGuardChecks and the fork-guard: reason). The stage path falls back to it in recordStage and foldForkGuard. The branch-update guard was the only fork-guard reader that did not.

What changes

  • When the index has nothing for the head, waitingForkGuard reads the record's guard (rec.ForkGuardChecks, or recordedForkGuard for a fork-guard: reason). It then checks the latest run of those checks on this exact head.
    • If any guarded check is red (failure or action_required), the update is held and the reason stays required-check-failing:<check>, so the stage keeps the PR at 085.
    • If every guarded check is green, the update goes ahead, so a PR whose Canary passed is not kept behind. This was the concern the old doc comment gave for ignoring the record.
    • If the head's checks cannot be read, the update is held for this tick (fail closed): skipping costs one tick, while updating costs the maintainer's run.
  • Same-repo PRs, and fork PRs whose record names no guard, behave as before.
  • The doc comment on waitingForkGuard now says when the record is consulted and why that is safe. A changelog fragment is added.

Tests

TestUpdateBranchHonoursRecordedForkGuard is a new sibling of TestUpdateBranchSkipsForkGuardedHead. It uses an index that is empty for every head and a stage record parked on fork-guard:Canary. It checks that:

  • with Canary completed/failure on the head, no update is sent and the reason is required-check-failing:Canary;
  • when the check-runs read returns 403 or 500, no update is sent;
  • with the latest Canary run completed/success, exactly one update is sent;
  • a record carrying only ForkGuardChecks (no fork-guard: reason) also holds the update;
  • a same-repo head is still updated.

The three existing cases in TestUpdateBranchSkipsForkGuardedHead are unchanged: no stage record exists there, so the new fallback is never reached. I did not run any tests locally; CI is the verdict.

β€” hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 requested_by=@Danathar

… when the index has no entry

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
Co-authored-by: Danathar <6772335+Danathar@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Nov 9, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign danathar for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 9, 2026
@hivecommons-hive

hivecommons-hive Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Hive status β€” updated in place; edits do not notify. Full history is in the Activity Monitor.

hive/awaiting-ci: CI pending β€” sweep will merge when green.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

β€” hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

Review findings from reviewer (folded here because this head already carries its hive review):

Read waitingForkGuard, forkGuardRedOnHead, recordedForkGuard and the caller at automerge_sweep_trusted.go:919-925 against v6. The record fallback is wired the way the body describes: index first, then rec.ForkGuardChecks / fork-guard: reason, latest run per guard name by check-run ID, hold on failure/action_required, hold on an unreadable head. The test covers red, green-after-red, 403, 500, ForkGuardChecks without a fork-guard: reason, and a same-repo head. That reads correct to me.

One gap in the new code that sits inside the exact scenario this fixes (medium):

automerge_fork_guard_carry.go, forkGuardRedOnHead, the loop if cr == nil || cr.GetStatus() != "completed" { continue }. When a maintainer has just started the Canary on this head, the latest run for that name is queued/in_progress (its ID is higher than the failed run, so latest[name] is the new one). It is skipped, red comes back empty, and updateBranchAndSkip proceeds to merge main β€” discarding the maintainer's run while it is executing. That is the window the guard exists for, and it is the one case where the fallback still lets the update through: the record names the guard, the index is empty (restart / rate-limited pass), and the check is live rather than red. Suggest treating a non-completed latest run of a guarded check as held too (the comment's own rule β€” "skipping costs a tick, an update costs the maintainer's run" β€” argues for it). The test's "green" case could gain a sibling with {"id":3,"name":"Canary","status":"in_progress"} expecting the hold.

Not a regression against today's behaviour (the index path has the same hole after a restart), so I'd not block on it, but it is cheap to close here. I have not changed anything.

Review findings from reviewer-2 (folded here because this head already carries its hive review):

Intent alignment: approve (advisory). Read at head c526d8b against #17380. Each acceptance criterion maps to the diff: index-first then record fallback (rec.ForkGuardChecks β†’ recordedForkGuard) in automerge_fork_guard_carry.go:94-108; red-on-exact-head filter :143-151; fail-closed on read error :104-107; reason stays required-check-failing:<check> via the unchanged caller automerge_sweep_trusted.go:919-924; doc comment, changelog fragment and TestUpdateBranchHonoursRecordedForkGuard are present. No unrelated scope.

One advisory gap between the PR body and the code:

  • A guarded check whose latest run on the head is not completed falls through to an update. forkGuardRedOnHead skips any run with GetStatus() != "completed" (automerge_fork_guard_carry.go:145-147), so when a maintainer has just started the Canary on this exact head (queued/in_progress), red is empty and updateBranchAndSkip sends the update that discards that very run. The PR body says the update proceeds only "if every guarded check is green"; [v6] The hive merges main into a fork PR parked on a maintainer-run Canary when its fork-guard index entry is missingΒ #17380's criteria only name red and green, so this is not a contract miss, but it is the same failure mode in a window the issue did not enumerate. Suggested follow-up: treat a non-completed latest run of a recorded guard as held (append to red), as the unreadable case already is.
Evidence bundle `#1738365c8387` sha256:9cda6054317f8fdcce8fa97f3636cb102933797d921a3f3c3750d43c0665a2a9 β€” download from the dashboard or `hivectl review evidence #17383`.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v6

Conflicts are checked with every PR merged onto the current tip of v6, so a PR that only needs a rebase is not reported as conflicting with its siblings.

No conflicting open PRs or same-file overlaps were found.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks correct to me. Read the new waitingForkGuard/forkGuardRedOnHead against the v6 tree at c526d8b and the callers, not just the diff.

What I checked:

  • automerge_sweep_trusted.go:919-924 β€” the only caller; the held-update reason stays required-check-failing:<check>, so the stage path is unchanged and a held PR still parks at 085 rather than 072.
  • automerge_fork_guard_carry.go:40-55 β€” recordedForkGuard parses the fork-guard: reason; the fallback here uses rec.ForkGuardChecks first and the reason only when that is empty, matching how recordStage/foldForkGuard already read the record.
  • pkg/github/fork_guard.go:43-64 β€” the index (ForkGuardChecksFor) only ever names failing checks, so the record fallback counting failure/action_required on the latest run per check (by max run ID) is the same "red" the index would have produced. A green latest run clears it, which answers the old doc comment's objection to consulting the record.
  • Fail-closed on an unreadable check list (warn + return the full guard) is the right side to err on; it costs one tick, an update costs the maintainer's run.
  • Same-repo PRs never reach this (isForkPR gate at :917); the test covers red/forbidden/5xx/green, ForkGuardChecks without a reason, and the same-repo case.

One open question, not a defect β€” it is parity with the existing index path: when the maintainer's exact-head run is in_progress (latest run not completed), forkGuardRedOnHead skips it (automerge_fork_guard_carry.go, the GetStatus() != "completed" continue), so an update-branch could still land mid-run and discard it. If that window matters for #917, holding on a non-completed guard run would close it in a follow-up.

β€” hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added author/hive This repository's own hive (the App or one of its agent lanes) authored this PR dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 9, 2026
…ch update

forkGuardRedOnHead only reported completed failure/action_required runs. A newer queued or in_progress run for the guard name won latest[] and was skipped, so the update merged main over the maintainer's live run. A non-completed latest guarded run is now held.

Hive-Fix-Attempt: 1/6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Nov 9, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Read automerge_fork_guard_carry.go, the single caller at automerge_sweep_trusted.go:919, recordedForkGuard, stageStoreOrShared, and stagelabels/store.go:NoteForkGuard on v6. The change looks correct to me.

Verified

  • The fallback is reached only on the fork branch of updateBranchAndSkip (automerge_sweep_trusted.go:917-918), so same-repo heads are untouched; the index-first order means the three existing TestUpdateBranchSkipsForkGuardedHead cases take the old path unchanged.
  • recordedForkGuard (automerge_fork_guard_carry.go:36) is only used when rec.ForkGuardChecks is empty, so a record with either field holds; the !ok guard after it prevents a nil record from reaching the REST call.
  • Fail-closed on an unreadable head (return guard after the warn) matches the stated tick-vs-maintainer-run trade; the test covers both 403 and 500.
  • "Latest run" by max check-run ID is the same heuristic the index uses elsewhere, and in_progress/queued counting as held is right β€” that is the maintainer's run.

One observation, not a defect

stagelabels.Store.NoteForkGuard (store.go:2586) only ever sets ForkGuardChecks; nothing clears it. So once a fork PR has had a guard recorded, every later update-branch attempt for it β€” including after the Canary is green, when the index correctly has no entry β€” pays one paginated ListCheckRunsForRef on the head before updating. Bounded (one call per behind-fork-PR per tick) and strictly less than the maintainer-run it protects, but worth knowing given the hourly REST caps being discussed in #17378/#17385. If it ever matters, clearing the field when the stage leaves 085 would remove it.

CI was still in progress at the head I read (65c8387); tide pending as usual.

β€” hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive
hivecommons-hive Bot merged commit 6f7f5d8 into v6 Nov 9, 2026
82 of 85 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-17380 branch November 9, 2026 12:54
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

We'd love to hear how your experience was: share feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/hive This repository's own hive (the App or one of its agent lanes) authored this PR copilot dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) size/L Denotes a PR that changes 100-499 lines, ignoring generated files. stage/050-review-pending Review swarm requested; awaiting a verdict for the current head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v6] The hive merges main into a fork PR parked on a maintainer-run Canary when its fork-guard index entry is missing

0 participants