Skip to content

review: poll statusCheckRollup + mergeStateStatus instead of gh pr checks --required - #308

Merged
max-sixty merged 1 commit into
mainfrom
fix/ci-monitor-mergeable-state
Apr 18, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/ci-monitor-mergeable-state

Conversation

@tend-agent

Copy link
Copy Markdown
Collaborator

Fixes #305.

Summary

  • Replace the gh pr checks <n> --required polling loop with a gh pr view --json mergeStateStatus,reviewDecision,statusCheckRollup loop so late-registering if: always() omnibus checks (e.g. check-ok-to-merge) can't race the polling and make the bot report a broken PR green.
  • Mirror the change in review Step 6 — the snippet was duplicated, flagged in my first comment on review: CI monitor's gh pr checks --required races alls-green/if: always() omnibus checks #305.
  • Bump the polling budget 10 → 15 minutes now that the loop waits on every check-run on the commit, not just required ones.

Why this shape

From issue #305 + discussion with @max-sixty: gh pr checks --required only reports check-runs that are already registered on the commit. An omnibus with if: always() and a long needs: list doesn't register its check-run until the needs start resolving — so early polls see only the fast required contexts (e.g. pre-commit.ci - pr), the loop exits green, and the real matrix is still running or has already failed.

The new loop pairs two signals that between them don't have that blind spot:

  1. statusCheckRollup — every check-run and status context on the commit, not just required ones. Filter out the current run by URL and count IN_PROGRESS/QUEUED/PENDING/WAITING items. This alone catches the PRQL incident because the test matrix jobs are in the rollup even though they're not directly required by branch protection.
  2. mergeStateStatus + reviewDecision — backstop for the narrow window where matrix jobs are already terminal but the omnibus check-run hasn't yet registered. mergeStateStatus = BLOCKED with reviewDecision not in {REVIEW_REQUIRED, CHANGES_REQUESTED} means a required context is outstanding and we should keep polling; BLOCKED with review-required means approval is the blocker (CI-wise we're done, exit).

UNKNOWN (mergeStateStatus hasn't been computed yet) also keeps us polling — GitHub computes it asynchronously after a push.

Known limitation

BLOCKED + REVIEW_REQUIRED can mean either (a) approval-only block with all checks done or (b) approval-needed and a required context not yet registered. These are indistinguishable from a single snapshot without reading branch protection, which most bot PATs can't do. In practice the registration window for an omnibus is seconds (between last needs: job completing and the job starting), so a 60-second poll cadence nearly always catches the next registered state. Documented in-comment.

Test plan

🤖 Generated with Claude Code

…hecks --required`

`gh pr checks --required` only sees already-registered check-runs, so a
late-starting `if: always()` omnibus (e.g. `check-ok-to-merge` that
waits on a big `needs:` matrix) can race the polling loop: the early
polls see only the fast required contexts green and exit while the real
matrix is still running or has already failed. Incident trace in #305
(downstream: PRQL/prql#5807, PRQL/prql#5809).

Switch the loop to `gh pr view --json mergeStateStatus,reviewDecision,statusCheckRollup`:

- `statusCheckRollup` surfaces every check-run and status context on
  the commit, not just the required ones — filter own-run by URL and
  count IN_PROGRESS / QUEUED / PENDING / WAITING to decide whether to
  keep waiting.
- `mergeStateStatus` accounts for required-but-unreported contexts
  that `gh pr checks` cannot see. If the PR is `BLOCKED` and
  `reviewDecision` is not `REVIEW_REQUIRED`/`CHANGES_REQUESTED`, a
  required context is still outstanding — keep polling.
- Bump budget 10 → 15 minutes since the loop now waits on every
  check-run on the commit (not just required).

Mirror the update in the `review` skill's Step 6 so the duplicate
snippet does not drift.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@max-sixty
max-sixty merged commit 2e6aaae into main Apr 18, 2026
3 checks passed
@max-sixty
max-sixty deleted the fix/ci-monitor-mergeable-state branch April 18, 2026 22:07
max-sixty added a commit that referenced this pull request Apr 18, 2026
…check

The `STATE=BLOCKED && !REVIEW_REQUIRED && !CHANGES_REQUESTED → continue`
branch added in #308 deadlocked: `mergeStateStatus` stays `BLOCKED` for
the entire run because our own review check is IN_PROGRESS, so the loop
kept continuing until the 15-minute timeout.

The API can't distinguish "self-blocking" from "required context not
yet registered" without admin scope on branch protection. Use the
rollup (with own run filtered out) as the sole exit signal, and add a
30s grace re-check to cover the short omnibus-registration window
from #305.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Apr 18, 2026
…check (#311)

Fixes the deadlock introduced in #308. The CI monitor loop kept
continuing until its 15-minute timeout on every bot run.

## Root cause

`mergeStateStatus = BLOCKED` while our own review check is IN_PROGRESS.
The loop's fallback branch `BLOCKED && !REVIEW_REQUIRED &&
!CHANGES_REQUESTED → continue` was intended to catch "a required context
hasn't registered yet", but can't distinguish that from "our own check
is still running" — the API doesn't surface which specific context is
blocking without admin scope on branch protection.

So with `PENDING=0` (own filtered out), `STATE=BLOCKED`,
`DECISION=APPROVED`, the loop just kept going. Branch protection stayed
BLOCKED until the bot exited, which it couldn't do until the loop
exited. Observed on tend's own `tend-review` run 24614997930.

## Fix

- Use `statusCheckRollup` (with own run filtered out) as the sole exit
signal.
- After rollup PENDING reaches 0, sleep 30s and re-check. This covers
the short gap between `needs:` jobs finishing and an `if: always()`
omnibus check-run (e.g. `check-ok-to-merge`) registering — the scenario
#308 was built to catch.
- Drop `mergeStateStatus` and `reviewDecision` from the exit decision.
Commented inline why.

## What this gives up vs #308

The `BLOCKED + !REVIEW_REQUIRED` backstop for required contexts that
never register at all (workflow file typo, etc.). In that case the loop
exits cleanly; the human maintainer sees the BLOCKED state in the UI and
handles it. The grace re-check covers the omnibus registration race,
which was the actual scenario from #305.

## Test plan

- [ ] Downstream verification on next nightly regeneration — the
canonical signal is whether `tend-review` runs complete in under 15
minutes again.

> _This was written by Claude Code on behalf of Maximilian_

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty max-sixty mentioned this pull request May 8, 2026
2 of 3 tasks
max-sixty added a commit that referenced this pull request May 8, 2026
## Summary

- Bumps generator version 0.0.16 → 0.0.17
- 57 commits since 0.0.16; the headline change is #375 (gate
fork-exposed scheduled workflows on `github.repository_owner` so
consumer-repo forks no-op on the cron and stop generating cross-repo
CheckSuite notifications back to `tend-agent`)
- Other notable changes: workflow header stamps tend version (#316),
bot-token rebound to `GITHUB_TOKEN` (#373), review skill
draft/light-mode + polling improvements (#308, #311, #315, #362)

## Test plan

- [x] `uv run pytest` — 188 passed
- [x] `pre-commit run --all-files` — clean
- [ ] After merge: tag 0.0.17, PyPI publishes, regenerate tend's own
workflows with `uvx tend@latest init`

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

review: CI monitor's gh pr checks --required races alls-green/if: always() omnibus checks

2 participants