Skip to content

feat: implement issue #561 — [Phase 2b] Source-side admission gate: pre-open open-PR-count guard + bats - #565

Merged
don-petry merged 2 commits into
mainfrom
dev-lead/issue-561-20260630-2215
Jun 30, 2026
Merged

don-petry merged 2 commits into
mainfrom
dev-lead/issue-561-20260630-2215

Conversation

@don-petry

Copy link
Copy Markdown
Contributor

Closes #561

Implemented by dev-lead agent. Please review.

@don-petry
don-petry requested a review from a team as a code owner June 30, 2026 22:22
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@don-petry, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 25 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: bd556ba2-7ed2-403f-bd4d-f856a793a2fc

📥 Commits

Reviewing files that changed from the base of the PR and between 3ca1f86 and c11b4b7.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • .github/workflows/pr-limits-tests.yml
  • scripts/lib/pr-limit-gate.sh
  • test/scripts/pr-limits/pr-limit-gate.bats
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev-lead/issue-561-20260630-2215

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.

@don-petry

Copy link
Copy Markdown
Contributor Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry
don-petry enabled auto-merge (squash) June 30, 2026 22:23
@don-petry

Copy link
Copy Markdown
Contributor Author

@donpetry-bot review

@donpetry-bot

Copy link
Copy Markdown
Contributor

@don-petry I'm on it — starting a fresh review now. Results will appear in a few minutes.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread scripts/lib/pr-limit-gate.sh Resolved
Comment thread scripts/lib/pr-limit-gate.sh Resolved
Comment thread scripts/lib/pr-limit-gate.sh Resolved
Comment thread scripts/lib/pr-limit-gate.sh Resolved
Comment thread scripts/lib/pr-limit-gate.sh Resolved
Comment thread scripts/lib/pr-limit-gate.sh Resolved
Comment thread scripts/lib/pr-limit-gate.sh Resolved
Comment thread scripts/lib/pr-limit-gate.sh Resolved
Comment thread scripts/lib/pr-limit-gate.sh Resolved
Comment thread scripts/lib/pr-limit-gate.sh Resolved
@don-petry
don-petry disabled auto-merge June 30, 2026 22:26
donpetry-bot
donpetry-bot previously approved these changes Jun 30, 2026

@donpetry-bot donpetry-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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: is passed as an argv to 'gh search prs' (not interpolated into a shell string) and jq uses --arg/--argjson throughout. The gate is fail-open on API errors (logs + count 0), an intentional design choice so a transient error never wedges automation. Secret-scanning MCP tool was not exposed in this environment; diff contains no secret-bearing content (bash lib, bats, workflow path-filter lines). Non-blocking polish raised by gemini-code-assist (COMMENTED, not change-request): add a trailing slash to the head: query to avoid prefix false-positives, and extra integer-validation/jq fallbacks — reasonable hardening for the #508 wiring step, not required for this library delivery.

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.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 30, 2026
@don-petry

Copy link
Copy Markdown
Contributor Author

Dev-Lead — fix-reviews (applied)

Changes committed and pushed.

@don-petry
don-petry dismissed stale reviews from coderabbitai[bot] and donpetry-bot via c11b4b7 June 30, 2026 22:32
@don-petry
don-petry enabled auto-merge (squash) June 30, 2026 22:32
@don-petry
don-petry disabled auto-merge June 30, 2026 22:33
@sonarqubecloud

Copy link
Copy Markdown

@don-petry

Copy link
Copy Markdown
Contributor Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry
don-petry enabled auto-merge (squash) June 30, 2026 22:33

@donpetry-bot donpetry-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@don-petry
don-petry merged commit bc13c11 into main Jun 30, 2026
24 checks passed
@don-petry
don-petry deleted the dev-lead/issue-561-20260630-2215 branch June 30, 2026 22:38
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.

[Phase 2b] Source-side admission gate: pre-open open-PR-count guard + bats

2 participants