Skip to content

AR-99: add pr-reviewer merge-on-green handling#57

Merged
khaliqgant merged 2 commits into
mainfrom
ar-99-merge-on-green-agents
Jun 16, 2026
Merged

AR-99: add pr-reviewer merge-on-green handling#57
khaliqgant merged 2 commits into
mainfrom
ar-99-merge-on-green-agents

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Jun 10, 2026

Copy link
Copy Markdown
Member

Summary

  • add merge-on-green handling inside the review pr-reviewer agent across AgentWorkforce repos
  • evaluate current PR state before merging: label present, checks complete/passing, requested bot reviewers approved, no bot changes-requested
  • merge with the current head SHA through the existing GitHub helper
  • add Slack merge-request handling that replies with blockers when a mentioned merge request is not green/satisfied

Validation

  • npm test
  • npm run typecheck

cloud#2061 was closed unmerged per dispatcher correction. Do not merge this PR without human approval.


Summary by cubic

Adds merge-on-green to the PR reviewer so PRs in the AgentWorkforce org auto-merge when labeled and all gates pass. Also lets Slack users ask the reviewer to merge; it merges if green or replies with blockers. (Linear AR-99)

  • New Features

    • Merge-on-green gate: label merge-on-green, PR open and not draft, no conflicts, green checks, requested bot reviewers approved, and no bot “changes requested”.
    • Listens to issues.labeled, commit status, check_run.completed, review submissions, and sync/open events; resolves PRs from commit-status SHAs.
    • Merges using the current head SHA via the existing GitHub helper.
    • Slack: parses “please merge …PR URL” in the configured channel; merges when ready or replies with specific blockers.
  • Refactors

    • Extended PR parsing to handle issue-labeled payloads and normalize label reads.
    • Added decision helpers for merge-on-green evaluation and Slack reply handling, with tests.
    • Kept the persona Slack scope on /slack/channels/** so channel writebacks work for merge replies.

Written for commit 752976a. Summary will update on new commits.

Review in cubic

@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 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR implements merge-on-green automation with Slack support. The agent now evaluates PR readiness based on labels, checks, and bot approvals, routes Slack messages to a dedicated merge handler, extends webhook parsing for issue-based PR references, and orchestrates merge decisions through a centralized event gate.

Changes

Merge-on-green with Slack integration

Layer / File(s) Summary
State machine foundation and constants
review/agent.ts
Documented merge-on-green control flow path and defined controlling org/label constants used throughout the merge gate logic.
Webhook payload parsing extension
review/agent.ts
Extended readPr to recognize issue-wrapped pull_request payloads and extract labels from either pull_request.labels or issue.labels, enabling PR data reading from issue-based webhook event shapes.
Merge-on-green readiness evaluation
review/agent.ts
Extended PullRequestReadyState with draft/review/labels/check/sha fields and implemented evaluateMergeOnGreenState to compute ready/blocked/pending outcomes based on PR openness, draft status, required label, merge conflicts, check completion/pass, and bot approval derived from reviews and requests.
Slack merge request handling
review/agent.ts
Added SlackMessage type, implemented parseSlackMergeRequest to extract PR URLs from Slack text, and exported handleSlackMergeRequest to parse messages, filter bots/subtypes, compute merge decisions, execute merges, and post threaded confirmations or blocking reasons.
Agent handler orchestration and control flow
review/agent.ts
Refactored main agent handler to route Slack messages to handleSlackMergeRequest, extended merge-on-green routing to handle both direct PR events and status-derived PR lists via a centralized event-type gate, and rewired PR parsing/decision logic to support label/status/check/review/sync/open triggers.
Slack integration documentation
review/persona.ts
Updated pr-reviewer persona comment to clarify that the full channels subtree must remain mounted so both ready/merge pings and merge-request reply messages reach the writeback worker.
Test implementation and coverage
tests/review-agent.test.mjs
Added imports for new exported functions (evaluateMergeOnGreenState, handleSlackMergeRequest, parseSlackMergeRequest) and comprehensive test cases covering readPr from labeled issues, readiness evaluation outcomes, Slack PR URL parsing, and threaded merge-blocked replies.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • AgentWorkforce/agents#48: Both PRs modify review/agent.ts readiness/merge gating logic around PullRequestReadyState by using gh pr view/status-check rollups and mergeability to decide whether a PR is "ready" for human/merge notifications, so the changes overlap at the core readiness-evaluation code level.

Suggested labels

size:L

Poem

🐰 A rabbit hops through checks and labels green,
Slack messages routed to merge machine,
Draft states reviewed, bot approvals weighed,
Thread replies sent, decisions are made! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.33% 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 'AR-99: add pr-reviewer merge-on-green handling' clearly and specifically describes the main change: adding merge-on-green functionality to the PR reviewer agent.
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.
Description check ✅ Passed The PR description clearly relates to the changeset, detailing merge-on-green functionality, PR state evaluation, merge execution, and Slack merge-request handling.

✏️ 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 ar-99-merge-on-green-agents

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.

@agent-relay-code

Copy link
Copy Markdown
Contributor

pr-reviewer could not complete review for #57 in AgentWorkforce/agents.
The review harness exited with code 1.
No review was posted; this needs operator attention.

@agent-relay-code

Copy link
Copy Markdown
Contributor

ℹ️ pr-reviewer: review only — no file changes were applied to the PR (nothing to commit after review). The notes below are advisory and were not pushed.

pr-reviewer could not complete review for #57 in AgentWorkforce/agents.
The review harness exited with code 1.
No review was posted; this needs operator attention.

@khaliqgant khaliqgant merged commit ee76b6f into main Jun 16, 2026
2 checks passed
@khaliqgant khaliqgant deleted the ar-99-merge-on-green-agents branch June 16, 2026 11:20
@agent-relay-code

Copy link
Copy Markdown
Contributor

pr-reviewer could not complete review for #57 in AgentWorkforce/agents.
The review harness exited with code 1.
No review was posted; this needs operator attention.

4 similar comments
@agent-relay-code

Copy link
Copy Markdown
Contributor

pr-reviewer could not complete review for #57 in AgentWorkforce/agents.
The review harness exited with code 1.
No review was posted; this needs operator attention.

@agent-relay-code

Copy link
Copy Markdown
Contributor

pr-reviewer could not complete review for #57 in AgentWorkforce/agents.
The review harness exited with code 1.
No review was posted; this needs operator attention.

@agent-relay-code

Copy link
Copy Markdown
Contributor

pr-reviewer could not complete review for #57 in AgentWorkforce/agents.
The review harness exited with code 1.
No review was posted; this needs operator attention.

@agent-relay-code

Copy link
Copy Markdown
Contributor

pr-reviewer could not complete review for #57 in AgentWorkforce/agents.
The review harness exited with code 1.
No review was posted; this needs operator attention.

@agent-relay-code

Copy link
Copy Markdown
Contributor

ℹ️ pr-reviewer: review only — no file changes were applied to the PR (nothing to commit after review). The notes below are advisory and were not pushed.

pr-reviewer could not complete review for #57 in AgentWorkforce/agents.
The review harness exited with code 1.
No review was posted; this needs operator attention.

khaliqgant added a commit that referenced this pull request Jun 18, 2026
* fix(pr-reviewer): read PR state from GitHub VFS instead of gh CLI

The sandbox snapshot ships no `gh` binary, so the two `gh pr view` calls
added by the READY-sentinel guard (e981031) and merge-on-green (#57) failed
every run with `spawn gh ENOENT` — breaking the ready ping and auto-merge.

Rebuild the same PullRequestReadyState the gates consume from the
github adapter's VFS projection instead:
  • pulls/{n}/meta.json            → state, draft, labels, head.sha
  • pulls/{n}/checks/_summary.json → the aggregated CI rollup
  • pulls/{n}/reviews/*.json       → latest review per author

The adapter doesn't project mergeability, so conflict detection is
delegated to the merge API (mergePullRequest throws on a dirty PR — never
auto-merges). All reads fail closed: a missing/empty projection yields a
state the gates treat as not-ready/pending, never a green light. The tested
pure evaluators are unchanged; only the data source moved off gh.

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

* fix(pr-reviewer): harden VFS review/check parsing (PR #73 review)

- loadReviews: guard the map so a malformed reviews/*.json entry can't throw
  out and blank the whole review set (which would drop an active
  CHANGES_REQUESTED and risk merging a blocked PR).
- rollupFromCheckSummary: derive `total` from failed+pending+passed when it's
  missing/malformed, so a summary with real counts but no `total` still reports
  the actual check states instead of being treated as "no checks".
- Document why mergeable defaults to MERGEABLE (VFS doesn't project it) and that
  safety rests on the merge API rejecting a conflicted PR, not on this field.

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

---------

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