Pr readiness

From d-o-hub/rust-self-learning-memory · View interactive version

Pr readiness is an AI agent skill from the GitHub repository d-o-hub/rust-self-learning-memory. Comprehensive PR health check: merge state, CI status, conflicts, cancelled checks, AND all PR comments/reviews (human + bots). Requires addressing actionable feedback before recommending merge. Prevents 'CI green, ready to merge' when conflicts, pending comments, or Codecov/Codacy findings remain.

How to use this skill

Skill file

PR Readiness Check Skill

Verify that a Pull Request is truly ready to merge — not just that CI is green.

When to Use

Critical Rule

NEVER recommend merge based solely on CI status. You MUST also check:

  1. mergeable field (conflicts?)
  2. mergeStateStatus field (behind? blocked? dirty?)
  3. All required checks passed (not just non-required ones)
  4. No stale CANCELLED checks that should have run
  5. All PR comments and reviews (human + bots) — actionable feedback addressed or explicitly waived with reason
  6. That the head SHA you measured is still current (re-read headRefOid in the same

breath as the verdict) and that every failing row is the **latest run for its check

name** — both are ephemeral under strict_required_status_checks_policy

Hard Blockers (NEVER BYPASS)

These rules have NO exceptions. Do not use --admin, --force, or any bypass mechanism:

  1. NEVER merge when mergeStateStatus is UNSTABLE — Wait for all checks to complete.
  2. NEVER merge when checks are pending — Wait for ALL checks to reach a terminal state.
  3. NEVER use gh pr merge --admin to bypass the main guard — the guard is ruleset main-protection (branch protection 404s here); fix the code, don't bypass the gate. PR #806 did exactly this at UNSTABLE and shipped pre-existing failures to main, costing two follow-up PRs (LESSON-078).
  4. NEVER merge a PR you haven't personally verified — Run the full check and confirm ALL conditions.
  5. NEVER skip loading this skill — Load this skill before any merge recommendation.
  6. NEVER ignore PR comments — Fetch inline reviews, review bodies, and issue

comments; address actionable feedback before declaring ready. **Bots count as

reviewers** (Codecov / Codacy): fix the finding, or waive it with the evidence posted

on the thread — an acknowledgement is not a waiver. Nothing is skipped, waived-away,

or bypassed to reach green.

  1. NEVER read MERGEABLE as "safe" on a long-lived or bot/agent branch — GitHub

compares the tip to the merge base, so mergeable=MERGEABLE means "no textual

conflict", never "no lost work". Run git diff <merge-base> <tip> --stat and reject

any tip that removes files it never touched (PR #1130's tip silently reverted four

merged PRs while reporting MERGEABLE, LESSON-035).

The same failure hides in dependency manifests: repeated

Merge branch 'main' into … resolutions that keep "ours" quietly roll a

dependency bump back. PR #1176 (a one-line query_range clamp) ended up with

sysinfo = "0.38" in memory-cli/memory-mcp/tests Cargo.toml plus the

objc2 tree deleted from Cargo.lock, while both its merge base and main

were at 0.39 — a 3-way merge takes "theirs" for a line only the branch

changed, so merging it would have downgraded main. On any branch whose

title is not a dependency change, every Cargo.toml/Cargo.lock hunk is a

red flag; diff the tip against current main for those paths and fix the

branch (git checkout origin/main -- Cargo.lock '*/Cargo.toml') before merge.

  1. Merge when the gate is green — once every condition above passes, run

./scripts/merge-pr.sh <PR> --execute immediately; do not stop at a

recommendation or wait for a separate prompt.


Full Procedure

1. Query All PR State

# Single PR (preferred when number known)
gh pr view {n} --json number,title,url,mergeable,mergeStateStatus,statusCheckRollup,headRefName,baseRefName,headRefOid,reviews,comments

# All open PRs
gh pr list --state open --json number,title,mergeable,mergeStateStatus,statusCheckRollup,headRefName,baseRefName

Also use the helper script:

./scripts/check-pr-readiness.sh [PR_NUMBER]
./scripts/check-pr-readiness.sh --fix [PR_NUMBER]   # also update BEHIND branches

A short report is a broken report. Run the sweep without a PR number and compare its

PR count to gh pr list --state open | wc -l before acting on it — the all-PRs loop

historically aborted after 2 of 9 PRs (a bare ((ISSUES_FOUND++)) under set -e, whose

rc=1 was indistinguishable from the script's normal "issues found" exit; LESSON-059).

Missing PRs in the output is not "nothing to report".

Re-read the head SHA last — it is ephemeral. Under

strict_required_status_checks_policy, every merge onto main pushes every other branch

to BEHIND and re-queues all of its runs, so a headRefOid pinned in a doc, comment, or

plan is stale after one merge (#1179 3056b560→c36a874d,

#1177 479eb16d→826f5c7f — both within minutes):

gh pr view {n} --json headRefOid,mergeStateStatus -q '[.headRefOid, .mergeStateStatus] | @tsv'

statusCheckRollup also keeps superseded runs. check-pr-readiness.sh reduces them

to the latest run per check name (#1177); reproduce the same reduction by hand — preferring

an unfinished run over any finished one of the same name, so a stale row never reports

running work as passed:

gh api "repos/{owner}/{repo}/commits/<headRefOid>/check-runs?per_page=100" \
  -q '[.check_runs | group_by(.name)[] | max_by(.id) | {name, status, conclusion}]'

Order by .id (monotonic per check run), not .completed_at: a queued or in-progress run

reports completed_at = null, which sorts first — so when one name has both an older completed

run and a re-queued pending run, sort_by(.completed_at) | last returns the older conclusion

and reports green/red for a run that has already been superseded. Measured at dc731afb: 22 check

names, 17 of them carrying a run with completed_at = null.

Only a FAILURE or CANCELLED that is still the latest run for its name is a blocker.

2. Interpret mergeStateStatus

| State | Meaning | Mergeable? | Fix |

|-------|---------|------------|-----|

| CLEAN | All clear (merge state only) | ✅ if CI + comments OK | Still verify CI + comments |

| BEHIND | Branch behind main, no conflicts | ⚠️ Not yet | Update branch (gh pr update-branch {n}) — expected under strict up-to-date, not a failure |

| BLOCKED | Required checks still pending | ❌ NO | Wait for CI |

| UNSTABLE | Non-required checks failing | ⚠️ Maybe | Investigate |

| DIRTY | Merge conflicts exist | ❌ NO | Resolve conflicts |

| HAS_HOOKS | Pre-receive hooks blocking | ❌ NO | Investigate hooks |

| UNKNOWN | GitHub hasn't computed yet | ⏳ Wait | Re-query in 30s |

BEHIND is the steady state here, not an alarm — but fixing it costs a full re-queue of

every run. Batch all pending doc/skill edits into one push; never push per file, and

never merge while another PR in the queue is still BEHIND (merges are serial).

BLOCKED while every listed row is green is normal, not suspicious: either the

CI / Required aggregate has not been created yet (see below), or an

unresolved review thread / extra-approval rule is holding the PR

(required_review_thread_resolution=true,

require_extra_approval_for_unattributed_changes=true).

Before calling any rollup green, confirm a workflow run exists — green App

rows (Codacy, SonarCloud, CodeQL) are not CI, and they post before the first

pull_request run is created. gh run list --branch <head-branch> returning

nothing one minute after a push is a race, not a verdict: re-query, and read the

per-commit truth with

gh api "repos/{owner}/{repo}/actions/runs?head_sha=<sha>" --jq '.workflow_runs[] | .name'.

That filter wants the full 40-character sha: an 8-character prefix silently

returns zero rows, which looks exactly like a CI that never ran.

Do not explain an empty list with the trigger config without testing the

explanation — seven gating workflows filter pull_request to main/develop,

which looks like it must suppress a PR based on another PR's branch, and that

inference produced a confidently wrong rule (LESSON-080). Also compare

gh pr view --json headRefOid against git ls-remote origin <head-branch>: if

they differ, someone rebased or merged under you and the rollup you are reading

is not for the commit you have locally (LESSON-035).

Which checks are required is a ruleset, not branch protection (ruleset

main-protection, id 9591004; /branches/main/protection 404s). The endpoint

returns an array of rule objects, and the contexts live at

.parameters.required_status_checks:

gh api repos/{owner}/{repo}/rules/branches/main > /tmp/rules.json
jq '.[] | select(.type=="required_status_checks") | .parameters' /tmp/rules.json

Today that set is exactly CI / Required + Codacy Static Code Analysis, with

strict_required_status_checks_policy=true (every merge invalidates other PRs'

runs → merges are serial), required_review_thread_resolution=true,

required_approving_review_count=0, and

dismiss_stale_reviews_on_push=true — any push drops an existing approval, so

batch a cosmetic fix with the substantive change instead of adding it after the

review. A green row outside this list does not

unblock a merge; changing the list is a ruleset change, never a workflow edit

(LESSON-050).

The same ruleset also decides the merge method. main-protection carries

required_linear_history, so a merge commit cannot land — and GitHub refuses it

late: the synchronous GraphQL call may fail first for an unrelated reason

(part of a stack), and the rule only reports itself on the asynchronous merge's

uuid, after a 202 pending that looks like acceptance. merge-pr.sh therefore

refuses --method merge outright, before any API call, and its usage text lists

only squash|rebase. Read .rules for required_linear_history before choosing,

and treat squash as the default (LESSON-081). `do-harness verify --set

verification enforces all of it via the merge-method` sensor

(scripts/check-merge-method.sh), which also asserts merge-pr.sh never sends

bypass_rules and keeps its async stacked-PR path pinned to the verified head.

A PR inside a stack loses the two convenience endpoints. GET /repos/{owner}/{repo}/stacks

lists membership and order — note pulls/{n}.stack.number is the stack's number, not a

PR (gh pr view on it 404s). For stacked PRs, update-branch returns

403 Updating a stacked PR's branch via this endpoint is not supported (so

check-pr-readiness.sh --fix prints the 403 and leaves the branch BEHIND) and

gh pr edit --base is refused. Update the branch with git instead: back up the local tip,

confirm the remote supersedes it with git range-diff (= per commit), reset, merge

main, push (LESSON-082).

CI / Required will not show up in gh pr checks until late. It is the

aggregate job required in ci.yml (needs: fast-gate, commitlint, test,

csm-tests, mcp-build, multi-platform, quality-gates; if: always()), which

fail-closes on any non-success dependency including skipped. So

mergeStateStatus=BLOCKED with 26 green per-job rows usually just means the

aggregate has not been created yet — wait for the slowest dependency (typically

multi-platform/macOS) instead of hunting a phantom failure. If the aggregate

ever reports while the visible rows are green, read

scripts/ci-required-evaluate.sh (the single result-mapping authority) before

anything else (LESSON-050, ADR-079).

3. Interpret CI Check Conclusions

| Conclusion | Meaning | Action |

|------------|---------|--------|

| SUCCESS | Check passed | ✅ None |

| SKIPPED | Expected skip (Release on PRs, Coverage badge on non-main). A row that skips by job guard is structural, e.g. Maintain canonical drift issue (if: github.event_name != 'pull_request') — never a bypassed gate | ✅ None |

| CANCELLED | Workflow was cancelled — may be stale or dependent. gh pr checks prints cancelled rows as fail, so confirm with gh api repos/{owner}/{repo}/actions/jobs/<job_id> --jq '.status, .conclusion' | ⚠️ Investigate; re-run if stale. Never cancel a run of a PR you intend to merge |

| FAILURE | Check failed | ❌ Must fix — once it is the latest run for that check name on the current head SHA (step 1); a superseded row is not a failure |

| pending / IN_PROGRESS | Still running | ⏳ Wait — do NOT recommend merge |

| NEUTRAL | Informational only | ✅ None |

4. Fetch ALL PR Comments (MANDATORY)

Do not stop at CI. Always pull every feedback channel:

OWNER_REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)
N={pr_number}

# A) Inline review comments (file/line threads)
gh api "repos/${OWNER_REPO}/pulls/${N}/comments" --paginate > /tmp/pr${N}_inline.json

# B) Submitted reviews (APPROVED / CHANGES_REQUESTED / COMMENTED + body)
gh api "repos/${OWNER_REPO}/pulls/${N}/reviews" --paginate > /tmp/pr${N}_reviews.json

# C) Issue-style conversation comments (Codecov, Codacy, humans, bots)
gh api "repos/${OWNER_REPO}/issues/${N}/comments" --paginate > /tmp/pr${N}_issue.json

# Optional: conversation via gh
gh pr view ${N} --comments

Parse and classify every item:

| Source | Typical author | Treat as |

|--------|----------------|----------|

| Human review (inline or body) | real users | Must address unless clearly outdated |

| CHANGES_REQUESTED review | reviewers | Hard blocker until fixed or re-reviewed |

| Codecov bot | codecov[bot] | Actionable if patch coverage low / missing lines listed |

| Codacy bot | codacy* | Actionable if new issues > 0 |

| CodeRabbit / Cursor / other bots | varies | Actionable if concrete code suggestions |

| GitHub Actions summary bots | github-actions[bot] | Usually informational (benchmarks) unless FAIL |

| Dependabot / security | bots | Actionable if security findings on the PR |

5. Address Feedback (not just acknowledge)

For each actionable comment:

  1. Understand — reproduce or map to code, against the current head. Read the file

before acting on or closing a finding: a review thread describes the SHA it was written

for, and a summary that says something was fixed is not evidence that the tree says so

(LESSON-010).

  1. Fix or waive — implement the change, or document why not (with evidence)
  2. Verify — tests / clippy / targeted nextest as appropriate
  3. Close the loop — push commits; reply on the PR thread summarizing what was done
  4. Re-check readiness — CI + merge state + no new unresolved threads
Common bot feedback patterns

| Bot / finding | Typical fix |

|---------------|-------------|

| Codecov: low patch % / N missing lines | Add unit tests for listed files; extract pure helpers for I/O-heavy paths |

| Codacy: new issues | Fix lint/complexity/duplication at cited lines |

| Reviewer: correctness bug | Fix code + regression test |

| Reviewer: docs drift | Align CHANGELOG/README with behavior |

| Stale comment on old line | Reply that it was fixed in commit SHA or is no longer applicable |

Waiving feedback (rare)

Only waive when:

Never waive CHANGES_REQUESTED without either implementing the change or getting explicit re-approval.

6. Fix Procedures (CI / merge state)

Branch Behind Main (`BEHIND`)
# Preferred: typed CLI (R-H4)
gh pr update-branch {n}
# Fallback if needed:
# gh api repos/{owner}/{repo}/pulls/{n}/update-branch -X PUT -f update_method=merge
Merge Conflicts (`DIRTY` / `CONFLICTING`)
gh pr checkout {n}
git merge origin/main
# resolve <<<<<<< markers, then PROVE the resolution is lossless — `git diff`
# cannot answer "did I drop a line from either side?" and nothing fails to
# compile on a docs merge (LESSON-070).
#   Read stages 2/3 BEFORE staging: `git add` collapses 1/2/3 into stage 0 and
#   `git show :2:<f>` then dies with "path is in the index, but not at stage 2".
#   LC_ALL=C is mandatory — plain `sort` collates by locale and `comm` reports a
#   bogus missing-lines list.
export LC_ALL=C
f=CHANGELOG.md                              # repeat per conflicted file
git show :2:"$f" | LC_ALL=C sort -u > /tmp/ours
git show :3:"$f" | LC_ALL=C sort -u > /tmp/theirs
comm -23 /tmp/ours        <(LC_ALL=C sort -u "$f")   # lost from ours   -> empty
comm -23 /tmp/theirs      <(LC_ALL=C sort -u "$f")   # lost from theirs -> empty
comm -13 <(cat /tmp/ours /tmp/theirs | LC_ALL=C sort -u) <(LC_ALL=C sort -u "$f")  # invented
git grep -n '^<<<<<<<\|^=======\|^>>>>>>' -- "$f"     # leftover markers
# Never run `git checkout --conflict=merge -- <f>` to re-label markers: it
# overwrites the working file and destroys your resolution.
git add <files> && git commit --no-edit && git push
# Then check the content diff versus the base separately, so a docs merge cannot
# smuggle a Cargo.toml/Cargo.lock revert (LESSON-064, LESSON-074):
git diff origin/main HEAD --stat
Cancelled CI
gh run rerun {run_id}
# or: git commit --allow-empty -m "chore: re-trigger CI" && git push
Failed CI
gh run view {run_id} --log-failed
# Fix via .agents/skills/ci-fix/SKILL.md

7. Verification After Fix

gh pr view {n} --json mergeable,mergeStateStatus,statusCheckRollup
# Re-fetch comments to ensure no new open threads
gh api "repos/${OWNER_REPO}/pulls/${n}/comments" --paginate
gh api "repos/${OWNER_REPO}/issues/${n}/comments" --paginate

A PR is ready to merge ONLY when ALL of:

git diff <merge-base> <tip> --stat shows no removals the branch never made, and no

Cargo.toml/Cargo.lock hunk that rolls back a bump main already has

or a PR comment

the latest per check name (raw statusCheckRollup keeps superseded rows)

not from gh pr checks wording)

fixed + pushed, or waived with the evidence posted on the thread

./scripts/merge-pr.sh {n} --execute


Common Mistakes

❌ Wrong: Check only CI status

"All checks pass → ready to merge"

✅ Correct: CI + merge state + comments

"CI green, mergeStateStatus=CLEAN, all review/bot feedback addressed → ready to merge"

❌ Wrong: Ignore Codecov / Codacy conversation comments

"No human reviews → nothing to address"

✅ Correct: Bots count

"Codecov reports 54 missing lines on config_template.rs → add tests, push, reply on PR"

❌ Wrong: "Acknowledged" without code change

"Thanks for the review" (no fix, no test, no waiver evidence)

✅ Correct: Fix or evidence-based waiver

Implement + test + push; reply with what changed and commit SHA

❌ Wrong: Recommend merge while checks are pending

✅ Correct: Wait for ALL checks terminal

❌ Wrong: Verdict from a remembered SHA and raw rollup rows

"headRefOid from an earlier query + `statusCheckRollup` counted as-is → '2 fail, NOT READY'"

✅ Correct: Fresh SHA, latest run per check name

Re-read `headRefOid,mergeStateStatus`, reduce check-runs to the latest run per name;
a `FAILURE` superseded by a later `SUCCESS` for the same name is not a blocker

❌ Wrong: `MERGEABLE` means no work was lost

✅ Correct: `git diff <merge-base> <tip> --stat` on long-lived / bot branches

❌ Wrong: Use `gh pr merge --admin`

✅ Correct: Fix the underlying issue


Output Format

When reporting PR readiness, always include:

## PR #{number}: {title}
- **URL**: {url}
- **Merge State**: {mergeStateStatus} ({mergeable})
- **Head SHA**: {headRefOid} — re-read immediately before this verdict
- **CI Status** (latest run per check name on that SHA): {pass} pass, {fail} fail, {pending} pending, {cancelled} cancelled
- **Codacy**: {status}
- **Comments**:
  - Inline review threads: {n} ({open} open / {resolved} resolved)
  - Reviews: {APPROVED / CHANGES_REQUESTED / COMMENTED counts}
  - Issue comments: {n} (list bots + humans with actionable summary)
  - Actionable remaining: {list or "none"}
- **Feedback addressed this session**: {what was fixed / waived}
- **Verdict**: READY TO MERGE | NEEDS FIX: {reason} | WAITING ON CI
- **Action**: {specific next step, or "None — merge when ready"}

Related

Pipeline Traps (2026-10-11/12/15/16, LESSON-039…052)

other PRs' runs. Land the structural PR first when branches split the same

files (backend.rs in #1149/#1151 vs #1152 — LESSON-042: two PRs chose

backend_trait.rs and a third backend/mod.rs + capabilities.rs, so any

pair conflicted on layout and the later branches took four manual rebuilds,

each costing a local verification cycle plus a CI cycle) and rebuild the rest

on the winner's layout; never merge a stacked PR before its base.

so a headRefOid pinned in a doc, plan, or PR comment is stale one merge later

(#1179 3056b560→c36a874d, #1177 479eb16d→826f5c7f). Re-read

gh pr view <n> --json headRefOid,mergeStateStatus immediately before any readiness claim

or merge; treat BEHIND as expected and fix it by updating the branch — which restarts the

whole suite, so batch doc/skill edits into one push, never one push per file.

(git merge origin/main in a worktree), re-run fmt + workspace clippy + the

PR's own tests, then push. A rebuilt branch that skips fmt reds the fast gate,

Storage Matrix and Coverage at once (quality_gate_formatting, LESSON-039).

render as fail in gh pr checks and keep mergeStateStatus from reaching CLEAN

(LESSON-041). Read the real conclusion with `gh api

repos/{owner}/{repo}/actions/jobs/<job_id> --jq '.status, .conclusion'` before calling a

row failed, and re-run with a fresh push instead of cancelling.

re-run still fails (original payload has no label) — push a commit or

gh pr update-branch so the new synchronize event carries it (LESSON-044).

Prefer the cheaper human toggle when the PR is otherwise green: `gh pr edit <n>

--remove-label release-preparation && gh pr edit <n> --add-label

release-preparation. The bot's own GITHUB_TOKEN` label write cannot re-trigger

the workflow, and gh run rerun only replays the stale payload (LESSON-049).

(cargo deny + cargo audit) with separate DB clones, and a stale deny clone

yields a false "advisories ok". Run both before declaring a readiness verdict on

a dependency PR (LESSON-046/047).

run for the head SHA, so the readiness script can report N fail on a PR whose

latest run of that check passed and whose mergeStateStatus is CLEAN.

Reduce commits/<sha>/check-runs to the latest run per check name before

declaring a failure:

```bash

gh api "repos/{owner}/{repo}/commits/<headRefOid>/check-runs?per_page=100" \

-q '[.check_runs | group_by(.name)[] | max_by(.id) | {name, conclusion}]'

```

Only the newest row counts: on #1179 two stale Check for unreleased changes FAILURE rows sat

next to a later SUCCESS for the same name (run 116964525934), so readiness reported 2 fail

against a gate that had already passed. Then re-trigger on a fresh SHA (--allow-empty commit + push).

Do not delete runs or merge around the gate (LESSON-052); the only merge path stays

./scripts/merge-pr.sh <PR> --execute — never --admin, never --force, never a bypass.

dependent PRs, the auto-merge queue re-checks protection after each merge, so you can monitor

gh pr view --json state,autoMergeRequest instead of polling each check — but `gh pr merge

--auto is not a substitute for merge-pr.sh`, and "cancelled checks are noise" is wrong: a

cancelled row holds mergeStateStatus at non-CLEAN (LESSON-016, LESSON-041, LESSON-050).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.