Skip to content

fix(branch-protection-sync): exit-code state detection + preserve existing checks - #1767

Merged
POWERFULMOVES merged 1 commit into
mainfrom
fix/branch-protection-state-detection
Jun 10, 2026
Merged

POWERFULMOVES merged 1 commit into
mainfrom
fix/branch-protection-state-detection

Conversation

@POWERFULMOVES

Copy link
Copy Markdown
Owner

Follow-up to #1760. Found three bugs by verifying the dry-run (run 27227095327) before any fleet-wide apply — none would have surfaced in dry-run alone:

  1. State detection brokengh api prints the 404 error JSON to stdout, so testing output-emptiness mis-read every branch as "protected" → only_unprotected would skip everything. Now branches on the gh api exit code.
  2. Regression risk — the policy nulled required_status_checks unconditionally; a broad apply would wipe the checks on the 3 forks that actually gate on CI (Agent-Zero=3, Archon=2, DoX=2). Now preserves existing required checks; naked branches stay null.
  3. Heredoc bugpolicy()'s <<JSON terminator was indented (needs col-0), so it would never terminate on the first real apply (dry-run returns before calling it, so it was latent). Rebuilt with jq — always-valid JSON, $rsc injected as real JSON.

Plus: private repos that 403 with "Upgrade to GitHub Pro" are now skipped + counted (not mis-blamed on a missing admin grant — PMOVES-space-agent).

Verified locally against the live API before pushing:

Fork Detected Preserved checks
supabase protected[checks=0] null
Agent-Zero protected[checks=3] {"contexts":["audit","lint","security-scan"]}
tensorzero UNPROTECTED null
space-agent SKIP(needs-pro)

After merge: dry-run → apply only_unprotected=true to protect the ~33 naked forks (preserving the 3 good ones).

🤖 Generated with Claude Code

…sting checks

Three bugs found verifying the dry-run before any fleet-wide apply:
1. State detection read output-emptiness, but `gh api` prints the 404 error JSON
   to stdout — so every branch mis-read as "protected" and only_unprotected would
   skip everything. Now branches on the gh api EXIT CODE.
2. The policy nulled required_status_checks unconditionally — a broad apply would
   WIPE the checks on the 3 forks that actually gate on CI (Agent-Zero/Archon/DoX).
   Now reads + PRESERVES existing required checks; naked branches stay null.
3. The policy() heredoc terminator was indented (`<<JSON` needs col-0), so it would
   never terminate on the first real apply. Rebuilt with jq — always-valid JSON,
   $rsc injected as real JSON.

Also: private repos that 403 with "Upgrade to GitHub Pro" are now SKIPPED + counted
(not mis-attributed to a missing admin grant). Verified locally against the live
API: supabase=protected[0], Agent-Zero=protected[3] (checks preserved verbatim),
tensorzero=UNPROTECTED, space-agent=SKIP(needs-pro).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@POWERFULMOVES, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 44 minutes and 17 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 42adbc95-96be-42ac-b186-886ab5c1fe57

📥 Commits

Reviewing files that changed from the base of the PR and between a6ec3b8 and ff50ac5.

📒 Files selected for processing (1)
  • .github/workflows/branch-protection-sync.yml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/branch-protection-state-detection

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@POWERFULMOVES
POWERFULMOVES merged commit 8201dba into main Jun 10, 2026
15 of 19 checks passed
@POWERFULMOVES
POWERFULMOVES deleted the fix/branch-protection-state-detection branch June 10, 2026 21:02

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff50ac5399

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# Preserve existing required checks verbatim.
rsc=$(printf '%s' "$cur" | jq -c 'if .required_status_checks then {strict: .required_status_checks.strict, contexts: .required_status_checks.contexts} else null end' 2>/dev/null)
[ -z "$rsc" ] && rsc="null"
elif grep -qiE 'Upgrade to GitHub Pro|make this repository public' /tmp/bp_err; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check stdout for Pro-only protection errors

Here grep only examines /tmp/bp_err, but this GET captures gh api stdout into cur and redirects only stderr; the new comment above also notes that gh api prints HTTP error JSON to stdout, and the gh api manual describes the command as printing the API response. For private repos whose 403 body contains “Upgrade to GitHub Pro” on stdout, this branch never matches, so dry-runs report them as UNPROTECTED and apply runs try the PUT and count a failure instead of the intended s skipped(needs-pro). Check cur as well, or capture stdout and stderr into the same buffer before falling through.

Useful? React with 👍 / 👎.

POWERFULMOVES added a commit that referenced this pull request Jun 11, 2026
…k-sync campaign

Control-Body bookkeeping for the 2026-06-09→11 Z890 main-infra campaign (the docs
lagged it by a week). For 4090-CLAUDE pair-review.

- Claim register: new RELEASE section logging the campaign — supabase CRITICAL sync
  (#1761/#1768), branch-protection automation (#1760/#1767, 31 forks), full
  fork-sync clearance (auto-tier + high-ahead + ClawZ 8354c/Creator), Archon CI
  green (#19 lint / #20 E2E), space-agent public+protected.
- README Known Gaps: retire stale entries — OBSERVABILITY_MAP.md now on main (P2
  resolved), A2A exposure wired into compose (P0 → runtime-verify only), NATS-auth
  closed NON-URGENT (#1690, 23 refs left). Added fleet-governance state note.
- SITREP: +2 June wave rows (Main-Infra Pass, Fleet Fork-Sync + Governance),
  refreshed date 2026-05-27 → 2026-06-11, title Apr–May → Apr–Jun.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
POWERFULMOVES added a commit that referenced this pull request Jun 12, 2026
…k-sync campaign (#1786)

Control-Body bookkeeping for the 2026-06-09→11 Z890 main-infra campaign (the docs
lagged it by a week). For 4090-CLAUDE pair-review.

- Claim register: new RELEASE section logging the campaign — supabase CRITICAL sync
  (#1761/#1768), branch-protection automation (#1760/#1767, 31 forks), full
  fork-sync clearance (auto-tier + high-ahead + ClawZ 8354c/Creator), Archon CI
  green (#19 lint / #20 E2E), space-agent public+protected.
- README Known Gaps: retire stale entries — OBSERVABILITY_MAP.md now on main (P2
  resolved), A2A exposure wired into compose (P0 → runtime-verify only), NATS-auth
  closed NON-URGENT (#1690, 23 refs left). Added fleet-governance state note.
- SITREP: +2 June wave rows (Main-Infra Pass, Fleet Fork-Sync + Governance),
  refreshed date 2026-05-27 → 2026-06-11, title Apr–May → Apr–Jun.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant