Close delivered items in scheduled runs by reading required checks from the branch summary
Scheduled closeout fails in nearly every fleet caller as soon as it has a delivered item to close: pm-rust and pm-jira since at least 10-25, pm-lint since 10-28, and 15 more repos today. Tracker item: pm-github-6g0m.
Cause
- Unreadable endpoint:
GITHUB_TOKENcan never read the administration-only classic protection endpoint (/branches/{b}/protection/required_status_checks). - No declarations: no caller declares the
required-checksinput. - Result: every closable row becomes
required_checks_unverified, and the workflow refuses with "Closeout refused; check token read access…". Callers with nothing to close stay green, which hid the pattern.
Fix
- Branch-summary fallback: when the protection endpoint answers 403/404, closeout reads the same required contexts and app bindings from the branch summary (
protection.required_status_checks). Repository read access returns that endpoint. - Fail-closed cases:
- An unprotected branch, or
enforcement_level: "off", adds no classic requirements; rulesets still apply. - A protected branch whose summary omits its required checks stays unavailable.
- An unverifiable
protectedflag ishead_evidence_unavailable.
- An unprotected branch, or
- Callers: they need no edits and no declared names.
required-checksremains for tokens that can read neither source.
Evidence
| Acceptance criterion | Evidence |
|---|---|
| A classic protection 403 falls back to the summary's required checks, including app bindings | New test, cases "required context passes" and "summary app binding holds" (app 8 against required app 7 → head_checks_failed) |
| Unprotected or switched-off classic checks add nothing | Cases "unprotected branch" and "required checks switched off" → fallback |
| Missing details stay unavailable; an invalid flag is refused | Cases "protected without check details" and "without a protection object" → required_checks_unverified; "unverifiable protected flag" → head_evidence_unavailable |
| A scheduled caller closes with no declared checks | The same test applies closeout with protection 403 and summary 200 → closed: 1 |
| The fix fails its regression when reverted | Returning before the summary read fails "required context passes" |
- Real data:
- An anonymous
GET /repos/unbraind/pm-lint/branches/mainreturnstest (22),test (26)andcodeql, while the protection endpoint returns 401. - With the owner token, a scratch clone's dry run plans pm-lint-4tem (PR #41) as
head_checks_passed, and--applycloses it, on both 2026.10.27 and pm-lint's pinned 2026.10.16.
- An anonymous
- Tests: the closeout, changelog-placement and scheduled-refusals suites pass 553/553. Existing denied-protection tests keep their meaning, because the mock's branch summary also denies unless a test grants it.
- Gates: lint, typecheck, docstring, duplication, privacy and
changelog:checkpass. CI runs the coverage gate.
Summary by Sourcery
Enable scheduled closeout to verify and close delivered items using branch-summary protection metadata when classic protection reads are unavailable.
New Features:
- Fall back to branch-summary metadata to determine classic required checks and app bindings when the administration-only protection endpoint is unavailable.
Bug Fixes:
- Allow scheduled closeout to process delivered items with GITHUB_TOKEN without requiring callers to declare required checks.
- Preserve fail-closed behavior when branch protection details are missing, unverifiable, or otherwise unreadable.
Enhancements:
- Clarify that the required-checks override is only needed when both classic and ruleset policy metadata cannot be read.
Documentation:
- Update README and workflow and policy documentation to describe branch-summary fallback and the revised required-checks guidance.
Tests:
- Add coverage for branch-summary requirements, app bindings, unprotected and disabled checks, incomplete metadata, invalid protection state, and scheduled closeout without declared checks.
Chores:
- Record the tracker issue and history for the closeout fix.
Summary by cubic
Fixes scheduled closeout failing in fleet callers whenever there is a delivered item to close: GITHUB_TOKEN cannot read the administration-only branch-protection endpoint, so every closable row became required_checks_unverified and the workflow refused. Closeout now falls back to the branch summary, which returns the same required contexts and app bindings with repository read access.
- Callers need no edits and no
required-checksinput; the input is now documented as needed only when both the classic source (protection or branch summary) and the ruleset metadata are unreadable. - Unprotected branches and
enforcement_level: "off"add no classic requirements; a protected branch whose summary omits its checks stays unavailable.