Skip to content

Guard pr-reviewer READY sentinel on CI and mergeability#48

Merged
khaliqgant merged 1 commit into
mainfrom
fix/ready-sentinel-premature-notification
Jun 5, 2026
Merged

Guard pr-reviewer READY sentinel on CI and mergeability#48
khaliqgant merged 1 commit into
mainfrom
fix/ready-sentinel-premature-notification

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Jun 5, 2026

Copy link
Copy Markdown
Member

User description

Summary

  • tighten the review harness READY instruction so pending/in-progress checks and merge conflicts block READY
  • verify a harness READY sentinel with live GitHub mergeability and statusCheckRollup data before Slack notification
  • downgrade READY and log a warning when GitHub reports conflicts, unknown mergeability, pending checks, in-progress checks, or failed checks

Tests

  • npm test

Summary by cubic

Guard the READY sentinel so we only ping Slack when the PR is mergeable and all required checks are complete and passing. READY is now verified against GitHub mergeability and statusCheckRollup; if not satisfied, we downgrade and log instead of notifying.

  • Bug Fixes

    • Verify harness READY via GitHub (mergeable, statusCheckRollup) using gh pr view; suppress Slack ping and log a warning when checks are pending/in‑progress/failed or the PR isn’t mergeable.
    • Tighten the prompt to only allow READY when all checks are complete/passing and no merge conflicts; add tests for prompt text and READY gating.
  • Migration

    • Ensure the runtime has the GitHub CLI (gh) installed and authenticated; the agent calls gh pr view --json mergeable,statusCheckRollup.

Written for commit cfba4f1. Summary will update on new commits.

Review in cubic


CodeAnt-AI Description

Only send READY when the PR is actually mergeable and checks are finished

What Changed

  • The review flow now ignores a READY signal unless GitHub shows the PR can be merged and every required check has finished and passed.
  • If checks are still pending, in progress, failed, or the PR has merge conflicts, the READY signal is downgraded and Slack is not notified.
  • The review prompt now tells the agent not to print READY until those conditions are met.
  • Added coverage for READY gating and for the updated prompt wording.

Impact

✅ Fewer premature READY alerts
✅ Fewer Slack pings on blocked PRs
✅ Clearer handoff only when review can move forward

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@codeant-ai

codeant-ai Bot commented Jun 5, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The PR adds verification logic to validate that a PR is actually mergeable and all required status checks are passing/completed before allowing the READY state. A new prReadyStateAllowsHumanReview function is exported and integrated into harness output handling to gate readiness and Slack notifications on actual PR readiness.

Changes

PR Readiness Verification

Layer / File(s) Summary
Process execution and readiness verification logic
review/agent.ts
Imports Node execFile utilities and defines PullRequestReadyState shape, parsing logic for gh pr view JSON (mergeable, statusCheckRollup), and exports prReadyStateAllowsHumanReview(state) to determine whether checks are completed with success/neutral semantics and PR is mergeable.
READY prompt instruction gating
review/agent.ts
Updates reviewHarnessPrompt to explicitly prevent READY emission when any check is pending/in-progress/failed or merge conflicts are detected.
Harness output handling and verification integration
review/agent.ts
Modifies harness output processing to distinguish harnessReady from final ready decision, post the review body as a GitHub comment when non-empty, and conditionally run verifyReadyForHumanReview to validate READY before Slack notification; logs warnings on downgrades or gh CLI failures.
Readiness logic test coverage
tests/review-agent.test.mjs
Adds tests asserting that reviewHarnessPrompt only emits READY after all required checks are completed/passing and PR is mergeable, and that prReadyStateAllowsHumanReview returns false for pending checks or conflicting state, and true for mergeable PRs with completed passing checks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • AgentWorkforce/agents#10: Both PRs modify review/agent.ts's harness-output handling around the READY sentinel (parsing/stripping and using that result to decide whether to proceed with review/Slack actions, including new failure behavior on empty output), so this PR builds on the same readiness pipeline changes.

Suggested labels

size:L

Poem

🐰 A harness says ready, but wait, let me check—
Is the PR mergeable? Do checks have your back?
With gh pr view I peek at the state,
No pending, no conflicts—now we're truly great! ✨
The readiness pipeline flows clean and true,
Your review is validated—I'll Slack it to you! 💬

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly summarizes the main change: adding validation to the READY sentinel based on CI status and PR mergeability.
Description check ✅ Passed The description is well-related to the changeset, explaining the intent to guard the READY sentinel, verify mergeability, and suppress premature notifications.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ready-sentinel-premature-notification

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.

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Jun 5, 2026
@khaliqgant khaliqgant merged commit e981031 into main Jun 5, 2026
1 of 2 checks passed
@khaliqgant khaliqgant deleted the fix/ready-sentinel-premature-notification branch June 5, 2026 14:57
Comment thread review/agent.ts
Comment on lines +324 to +325
const checks = Array.isArray(state.statusCheckRollup) ? state.statusCheckRollup : [];
return checks.every(checkPassedAndComplete);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: statusCheckRollup is treated as optional and silently coerced to an empty array when missing or in an unexpected shape, and every() on an empty array returns true. That can incorrectly mark a PR as human-ready and send Slack READY notifications even when check data is unavailable/unknown. Treat missing or non-array check data as not-ready instead of ready. [incorrect condition logic]

Severity Level: Major ⚠️
- ⚠️ Slack channel pings even when CI status data missing.
- ⚠️ Humans may review before confirming all required checks passed.
Steps of Reproduction ✅
1. Trigger any GitHub event handled by the agent (e.g., `pull_request.synchronize`) so the
default handler in `review/agent.ts:66-108` calls `reviewAndFix(ctx, pr)` at
`review/agent.ts:208-246` for an open PR.

2. Let the review harness complete successfully and emit output whose last line is exactly
`READY`, so `reviewAndFix` sets `harnessReady` to true and calls
`verifyReadyForHumanReview(ctx, pr)` at `review/agent.ts:223-232`.

3. Ensure the runtime's `gh pr view --json mergeable,statusCheckRollup` invocation in
`verifyReadyForHumanReview` (`review/agent.ts:279-289`) returns JSON where `mergeable` is
`"MERGEABLE"` but `statusCheckRollup` is missing or `null` (e.g., due to an older `gh`
version or an API shape change), so `parsePrReadyState` (`review/agent.ts:317-320`)
produces `{ mergeable: 'MERGEABLE' }` with `statusCheckRollup` undefined.

4. Observe `prReadyStateAllowsHumanReview` at `review/agent.ts:322-325` treat the missing
`statusCheckRollup` as an empty array (`checks = []`), so
`checks.every(checkPassedAndComplete)` returns `true`; `verifyReadyForHumanReview` returns
`true`, causing `reviewAndFix` to set `ready` to `true` and send the READY Slack
notification at `review/agent.ts:233-245`, even though the code had no usable check-rollup
data to confirm CI status.

Fix in Cursor | Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** review/agent.ts
**Line:** 324:325
**Comment:**
	*Incorrect Condition Logic: `statusCheckRollup` is treated as optional and silently coerced to an empty array when missing or in an unexpected shape, and `every()` on an empty array returns `true`. That can incorrectly mark a PR as human-ready and send Slack READY notifications even when check data is unavailable/unknown. Treat missing or non-array check data as not-ready instead of ready.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment thread review/agent.ts
if (state) return state === 'SUCCESS' || state === 'NEUTRAL';
const status = normalizeState(record.status);
const conclusion = normalizeState(record.conclusion);
return status === 'COMPLETED' && (conclusion === 'SUCCESS' || conclusion === 'NEUTRAL');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: Check runs with conclusion: SKIPPED are currently treated as failing because only SUCCESS and NEUTRAL are accepted. In GitHub check semantics, skipped checks are non-failing (and this file already treats skipped as non-failure in ciFailed), so this logic can wrongly downgrade READY and suppress valid human-review notifications. [api mismatch]

Severity Level: Critical 🚨
- ❌ READY Slack notification suppressed when checks finish with SKIPPED.
- ⚠️ Humans may not be notified about review-ready pull requests.
Steps of Reproduction ✅
1. Configure a GitHub check or workflow that can legitimately finish with `conclusion:
"skipped"` (e.g., via a conditional job), so GitHub's `statusCheckRollup` for a PR can
contain entries with `status: "COMPLETED"` and `conclusion: "SKIPPED"`.

2. For that PR, trigger the agent (e.g., with `pull_request.opened` or
`pull_request.synchronize`) so the handler in `review/agent.ts:66-108` calls
`reviewAndFix(ctx, pr)` at `review/agent.ts:208-246`, and ensure the harness emits output
ending in `READY` so `verifyReadyForHumanReview(ctx, pr)` is invoked
(`review/agent.ts:223-232`).

3. When `verifyReadyForHumanReview` runs `gh pr view --json mergeable,statusCheckRollup`
and parses the result via `parsePrReadyState` (`review/agent.ts:279-320`), it passes the
`statusCheckRollup` list to `prReadyStateAllowsHumanReview` (`review/agent.ts:322-325`),
which calls `checkPassedAndComplete` for each check at `review/agent.ts:328-335`; for a
`COMPLETED`/`SKIPPED` check, `normalizeState` (`review/agent.ts:338-340`) yields `status
=== 'COMPLETED'` and `conclusion === 'SKIPPED'`, causing `checkPassedAndComplete` to
return `false` because it only accepts `SUCCESS` or `NEUTRAL`.

4. Because at least one check returns `false` from `checkPassedAndComplete`,
`prReadyStateAllowsHumanReview` returns `false`, `verifyReadyForHumanReview` logs a
`pr-reviewer.ready-sentinel.downgraded` warning at `review/agent.ts:292-299`, and
`reviewAndFix` sets `ready` to `false` at `review/agent.ts:231-245`; as a result, even
though all checks are non-failing (consistent with `ciFailed` treating `skipped` as
non-failure at `review/agent.ts:525-528`), the READY Slack notification is never sent for
this PR.

Fix in Cursor | Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** review/agent.ts
**Line:** 335:335
**Comment:**
	*Api Mismatch: Check runs with `conclusion: SKIPPED` are currently treated as failing because only `SUCCESS` and `NEUTRAL` are accepted. In GitHub check semantics, skipped checks are non-failing (and this file already treats skipped as non-failure in `ciFailed`), so this logic can wrongly downgrade READY and suppress valid human-review notifications.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codeant-ai

codeant-ai Bot commented Jun 5, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

@agent-relay-code

Copy link
Copy Markdown
Contributor

⚠️ pr-reviewer push failed (exit 1) — fixes were not applied to the PR. The notes below are advisory and were not pushed.

Fixed one readiness-gate bug: prReadyStateAllowsHumanReview no longer treats an empty or missing statusCheckRollup as ready. Added regression coverage in tests/review-agent.test.mjs.

Validation passed locally:

npm run test:review
npm run typecheck
npm test

I did not verify remote CI or GitHub mergeability from here.

agent-relay-code Bot added a commit that referenced this pull request Jun 5, 2026
@agent-relay-code

Copy link
Copy Markdown
Contributor

Fixed the validated review findings in the checked-out PR code:

  • review/agent.ts: prReadyStateAllowsHumanReview now treats missing or empty statusCheckRollup as not ready.
  • review/agent.ts: completed checks with conclusion: "SKIPPED" now count as non-failing.
  • tests/review-agent.test.mjs: added regression coverage for missing/empty rollup data and skipped checks.

Validation passed locally:

npm run test:review
npm run typecheck
npm test

I also checked the public PR page and it now shows PR #48 as merged on June 5, 2026, so I’m not ending with READY: #48

@agent-relay-code

Copy link
Copy Markdown
Contributor

⚠️ pr-reviewer push failed (exit 1) — fixes were not applied to the PR. The notes below are advisory and were not pushed.

Fixed the validated review findings in the checked-out PR code:

  • review/agent.ts: prReadyStateAllowsHumanReview now treats missing or empty statusCheckRollup as not ready.
  • review/agent.ts: completed checks with conclusion: "SKIPPED" now count as non-failing.
  • tests/review-agent.test.mjs: added regression coverage for missing/empty rollup data and skipped checks.

Validation passed locally:

npm run test:review
npm run typecheck
npm test

I also checked the public PR page and it now shows PR #48 as merged on June 5, 2026, so I’m not ending with READY: #48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant