Repository navigation
Description
What
The "Auto-merge if approved" step in principal-review.yml treats any gh pr merge failure the same way — conflict, branch protection, or a merely-stale branch all fall straight through to status:needs-human-merge with a generic "see the log" comment. In a busy pipeline, `dev` routinely advances between principal review's approval and the actual merge call (other PRs from the same pipeline landing concurrently), which makes gh pr merge fail with "the head branch is not up to date with the base branch" — a transient, self-resolvable race, not a real problem with the PR.
Live repro
Hit this manually while merging PR #239 (a risk:high PR, so it went through human-merge rather than this auto-merge path, but the underlying race is identical): the branch went BEHIND twice within about 15 minutes purely from ordinary pipeline throughput (issues #238/#240/#242/#243 all landing on dev in that window), each requiring a manual git merge origin/dev && git push before gh pr merge would succeed. An auto-merge-approved (risk:low) PR hitting the same race today would silently fall through to status:needs-human-merge for no real reason — routing a clean, already-approved PR to a human purely because it lost a timing race.
Acceptance criteria
- Before attempting
gh pr merge, check the PR'smergeStateStatus.BEHIND→ request GitHub's server-side "Update branch" (PUT /pulls/{n}/update-branch) and retry, bounded (not an infinite loop).DIRTY(real conflict) → don't retry, route tostatus:needs-human-mergeimmediately as today.UNKNOWN(mergeability still computing) → brief bounded wait, then re-check.
- The whole merge attempt is retried a bounded number of times so a burst of concurrent merges doesn't defeat auto-merge, but a genuinely stuck/failing merge still terminates and routes to a human rather than spinning indefinitely.
- Existing kill-switch checks (
AGENTS_PAUSED,AUTO_MERGE_DISABLED,status:blocked) and the CI-wait loop above this step are unaffected. - YAML parses cleanly; the step's bash is traced by hand and passes
bash -n/shellcheck (no standalone test harness exists for inline workflow bash, same precedent as PR fix(ci): route dev-agent triage failures to needs-info when a PR was found #239/fix(ci): detect a dev-agent crash mid-triage, not just mid-revise #212).
Manual gh pr merge by a human on a status:needs-human-merge PR (like the risk:high case that surfaced this) is out of scope — there's no automated step to retry there, a human just re-runs it.
Activity
github-actions commentedon Aug 17, 2026
Triage
Confirmed the repro path against
principal-review.yml's "Auto-merge if approved" step:gh pr merge(line ~373) is a single unconditional call — any failure (real conflict, transientBEHINDrace, branch protection) falls through to the same genericstatus:needs-human-mergehandling. Notsecurity/release-blocker— this is a pipeline-throughput correctness bug, not a vulnerability or a shipped-release issue.Scope is clear, so I implemented the fix rather than stopping at ready-for-dev: wrapped the merge call in a bounded (5-attempt) retry loop that checks
mergeStateStatusfirst —BEHIND→PUT /pulls/{n}/update-branchviagh api, then re-checkUNKNOWN→ brief wait, then re-checkDIRTY→ break immediately, no retry (same as today)gh pr mergeas beforeVerified
bash -nandshellcheckclean on the extracted step (GH Actions${{ }}expressions substituted with placeholders first, same approach as the precedent PRs #239/#212 — no standalone test harness exists for inline workflow bash) and that the YAML still parses.Blocked on push permissions — routing to a human
I can't get this onto a branch on the remote: both the default
GITHUB_TOKENand thelibravault-pipeline-botApp token are rejected by GitHub when pushing a change to.github/workflows/**, independent of anything about the diff itself:This is GitHub's own hard-coded protection on GitHub App-authored pushes to
.github/workflows/**— it requires the App to hold an explicitworkflowspermission grant at the installation level, separate fromcontents/pull-requests. Perdocs/agent-team-pipeline.md,libravault-pipeline-botis installed with "read/write on code, issues, and pull requests" only — noworkflowspermission — so this isn't something either credential available to this pipeline can do, regardless ofagent-policy.yml'srisk:highforce-classification (that only governs merge routing after a PR exists; it doesn't help me get a PR opened in the first place here). The three prior PRs that touched workflow files (#239, #240, #242) were all authored by the human accountlibravault-xyz, not this pipeline — consistent with this being a real, standing gap rather than something specific to this change.I have the fix fully written and verified locally; a human just needs to actually push it. Here's the diff, ready to apply directly (
git applyfrom repo root, or by hand):Beyond just this one issue: if workflow files are meant to stay in-pipeline-scope going forward (several past ones clearly have been, just always by a human pushing on the pipeline's behalf),
libravault-pipeline-bot's GitHub App installation would need theworkflowspermission added — that's an App-settings change only an org admin can make, out of scope for me to request via API.Routing to
status:needs-infosince I can't get a PR open.fix(ci): guard mergeStateStatus lookup against transient gh failures
fix(ci): self-heal stale branch during principal-review auto-merge (#247