Repository navigation
feat: implement issue #561 — [Phase 2b] Source-side admission gate: pre-open open-PR-count guard + bats - #565
Conversation
…re-open open-PR-count guard + bats
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 25 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Dev-Lead — review-changes (no-changes)No changes were needed for this PR. |
|
@donpetry-bot review |
|
@don-petry I'm on it — starting a fresh review now. Results will appear in a few minutes. |
There was a problem hiding this comment.
Code Review
This pull request introduces a reusable Bash library (scripts/lib/pr-limit-gate.sh) and corresponding BATS tests to implement a source-side PR-limit admission gate, which queries open non-draft automation PRs using the GitHub CLI and enforces configured caps. The reviewer feedback focuses on improving robustness and shell scripting best practices, including adding fallback values for jq parsing, validating that retrieved counts are valid integers before numeric comparisons, refining the branch search query with a trailing slash to avoid false positives, capturing exit statuses atomically, and using explicit return statements in functions.
donpetry-bot
left a comment
There was a problem hiding this comment.
Automated review — APPROVED ✓
Risk: LOW
Reviewed commit: 6f5c4da5899ebae9d1f757d94bef7c2adc2081b8
Review mode: triage-approved (single reviewer)
Summary
Phase 2b source-side PR-admission gate: new reusable bash lib scripts/lib/pr-limit-gate.sh (+239) plus bats coverage (+172) and two path-filter lines added to pr-limits-tests.yml. Read-only guard that counts open non-draft automation PRs via 'gh search prs' and returns allow/defer against caps in standards/pr-limits.json. Confirms the triage low-risk assessment.
Linked issue analysis
Closes #561 (Phase 2b admission gate). All 5 acceptance criteria are met: (1) sourceable set-euo-safe lib exposing plg_admission_gate, reading caps + exempt list from standards/pr-limits.json via jq and counting via 'gh search prs'; (2) exempt actors (incl. dependabot[bot]) always allowed and never counted; (3) DRY_RUN/DEV_LEAD_DRY_RUN prints the computed decision, returns allow, no side effects; (4) bats with the env-driven gh stub covering under-cap allow, at/over-cap defer, per-source sub-cap defer, exempt-over-cap allow, dry-run, and exempt-actor/label exclusion from the count; (5) workflow path filter extended to include the lib and tests. Wiring into the live PR-creation path is correctly deferred to #508.
Findings
No blocking findings. Verified the real standards/pr-limits.json (head + main) contains every key the gate reads (org_wide.automation_open_pr_cap, per_source_caps, exempt_actors, exempt_labels) — schema matches, so real-world use will not silently mis-read. Verified the gh stub at test/scripts/compliance-remediate/stubs/gh honors GH_STUB_STDOUT/GH_STUB_LOG exactly as the tests assume. No injection risk:
CI status
All required checks green: ShellCheck, Lint, CodeQL, Analyze (actions), Secret scan (gitleaks), Agent Security Scan, npm audit, SonarCloud (x3), CodeRabbit, Validate config, agent-shield/AgentShield, dev-lead/dispatch. Remaining entries are SKIPPED (ecosystem-gated audits, relay/mention stubs). mergeStateStatus BLOCKED only on the required human/automated review (this one).
Reviewed automatically by the PR-review agent (single-reviewer mode: fable 5). Reply if you need a human review.
Dev-Lead — fix-reviews (applied)Changes committed and pushed. |
c11b4b7
|
Dev-Lead — review-changes (no-changes)No changes were needed for this PR. |
donpetry-bot
left a comment
There was a problem hiding this comment.
Automated review — APPROVED ✓
Risk: LOW
Reviewed commit: c11b4b71e4599d5f99e2b6b7600cd084d9e86977
Review mode: triage-approved (single reviewer)
Summary
Adds the source-side PR-limit admission-gate library (scripts/lib/pr-limit-gate.sh) with plg_* functions that read caps + exempt list from standards/pr-limits.json, count open non-draft automation PRs via gh search prs, and return allow/defer against the org-wide cap and optional per-source sub-cap. Ships matching bats tests and extends the pr-limits-tests.yml path filter. Library is sourced-only (no live wiring; that is #508).
Linked issue analysis
Closes #561 (Phase 2b). All five acceptance criteria are met: (1) reusable sourceable lib returns allow/defer from jq-read caps + gh search prs counting, with org-wide and per-source sub-cap logic; (2) exempt actors are never blocked nor counted (plg_is_exempt_actor + count filters exclude exempt actors and exempt labels); (3) DRY_RUN / DEV_LEAD_DRY_RUN print the would-be decision, return allow, and perform no mutation; (4) bats cover under-cap allow, at/over-cap defer, per-source defer, exempt-over-cap allow, dry-run intent+allow with no gh mutation, and exemption-aware counting — using the env-driven gh stub (no live API); (5) the new test path and the lib are wired into pr-limits-tests.yml. Scope correctly stops at the library + tests; live PR-creation wiring is explicitly deferred to #508.
Findings
No blocking issues.
- Security: no auth/secrets/credentials/migrations touched. The gate uses only read-only gh search prs; tests assert no mutating gh subcommand is issued. Secret scan (gitleaks) CI check passed.
- Design: search failures fail-open (count treated as 0) — a documented, deliberate choice so a transient API error never wedges PR-creating automation. Acceptable for a soft queue cap.
- Note: the package-lock.json name field flip (pr-540 -> pr-565) is a harmless automated artifact.
- MCP run_secret_scanning tool not available in this environment; relied on the gitleaks CI check instead (passed). No fabricated result.
- Minor style: 'source' is used as a local variable name (shadows the bash builtin within function scope) — legal and ShellCheck-clean, non-blocking.
CI status
All required checks green. SUCCESS: Lint, ShellCheck, CodeQL, Analyze (actions), Validate config, agent-shield/AgentShield, Agent Security Scan, Secret scan (gitleaks), npm audit, SonarCloud, CodeRabbit, dev-lead/dispatch, pr-auto-review. SKIPPED (not applicable): pnpm/cargo/pip audit, govulncheck, dependabot-automerge, dev-lead/ci-relay. No failures. mergeStateStatus BLOCKED only because human review is still required.
Reviewed automatically by the PR-review agent (single-reviewer mode: fable 5). Reply if you need a human review.



Closes #561
Implemented by dev-lead agent. Please review.