Skip to content

feat(pr-reviewer): label + author gates and already-merged skip#21

Merged
khaliqgant merged 2 commits into
mainfrom
feat/pr-reviewer-gates
Jun 2, 2026
Merged

feat(pr-reviewer): label + author gates and already-merged skip#21
khaliqgant merged 2 commits into
mainfrom
feat/pr-reviewer-gates

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Jun 2, 2026

Copy link
Copy Markdown
Member

User description

What

Adds three agent-side gates to the pr-reviewer, evaluated before it reviews/fixes a PR:

  1. Label gate — skip the reviewer entirely when the PR carries a disabling label. Configurable via the new SKIP_LABELS input (comma-separated); defaults to no-agent-relay-review.
  2. Author allowlist — new REVIEW_AUTHORS input. When set, only review/fix PRs opened by those GitHub logins (e.g. only my own PRs). Unset = every author, so existing deployments are unaffected (mirrors the APPROVERS pattern).
  3. Already-merged/closed skip — don't post a stale review when the PR has already merged/closed by the time the handler runs.

How

  • Author + labels are read from the live PR meta.json via readJsonFile (the same pattern repo-hygiene uses), because the webhook payload doesn't carry them on every trigger — check_run.completed has neither author nor labels.
  • The meta read is best-effort: on failure it falls back to the payload author and proceeds (fail-open), so a flaky read never silently blocks reviews.
  • Gates apply only to the review/fix path. Merge-on-approval is unchanged and still governed by APPROVERS.
  • tsc --noEmit passes.

Scope / follow-ups

The already-merged skip is the cheap, agent-side half of the merge-race. Preserving the unpushed fixes via a recovery PR + Slack confirm needs platform work that isn't possible in this repo (no durable cross-turn session, and inbound Slack messages aren't delivered to agents) — tracked in AgentWorkforce/cloud#1659 (Slack delivery) and AgentWorkforce/cloud#1660 (CF continuation runtime).

Also drops a stale Daytona/Codex sandbox comment in persona.ts that was already modified in the working tree.

🤖 Generated with Claude Code


Summary by cubic

Add agent-side gates to the PR reviewer to skip runs based on labels, author allowlist, and already-merged state, reducing noisy or stale reviews.

  • New Features
    • Skip when PR is merged or closed; optional Slack notice via SLACK_CHANNEL.
    • Disable via label with SKIP_LABELS (default: no-agent-relay-review).
    • Only review authors in REVIEW_AUTHORS (comma-separated). Unset = review everyone.
    • Read author/labels/state from pulls/{n}/meta.json with fail-open fallback; accepts meta.author as a string or { login }, validates label names, and fails open when author is unknown; gates only affect review/fix and do not change merge-on-approval via APPROVERS.
    • Persona exposes REVIEW_AUTHORS and SKIP_LABELS.

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

Review in cubic


CodeAnt-AI Description

Skip review runs for closed PRs and PRs that should not be reviewed

What Changed

  • The PR reviewer now skips work when the PR is already merged or closed, avoiding stale comments and reviews
  • The reviewer can now be disabled by label and limited to specific PR authors through new settings
  • When a PR is skipped, it can post a Slack note explaining why
  • Several agents now send GitHub and Slack actions through shared helper clients instead of the older writeback flow
  • Linear, Slack, GitHub, and merge actions continue to behave the same for users, but with the updated helper-based routing

Impact

✅ Fewer stale PR reviews
✅ Fewer unwanted review runs
✅ Clearer skip messages in Slack

💡 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 2, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 98a0271a-e9d8-4029-b660-d073490b8a24

📥 Commits

Reviewing files that changed from the base of the PR and between ff52f70 and e7527d8.

📒 Files selected for processing (2)
  • review/agent.ts
  • review/persona.ts

📝 Walkthrough

Walkthrough

This PR adds a review gate mechanism to the PR review agent that evaluates skip conditions before reviewing. It loads PR state/labels from materialized metadata, checks for disabling labels and merged status, optionally enforces an author allowlist, and notifies Slack before skipping or proceeding to review.

Changes

PR Review Gate with Skip Rules

Layer / File(s) Summary
Data contracts and payload parsing
review/agent.ts
Extends Pr type with optional state, merged, labels fields; adds PrMeta interface, default skip label constant, and VFS client setup. Updates readPr to extract and return additional pull_request event fields.
Skip gate implementation
review/agent.ts
Implements shouldSkipReview that computes skip reasons from merged/closed state, disabling labels (validated from meta.json), and optional author allowlist. Includes helpers to load metadata defensively, parse environment variables, resolve authors, normalize labels, and notify Slack.
Handler integration
review/agent.ts
Handler invokes shouldSkipReview before reviewAndFix; returns early with optional Slack notification when skip reason is detected.
Persona configuration
review/persona.ts
Adds REVIEW_AUTHORS and SKIP_LABELS optional inputs to persona schema with GitHub user and label picker metadata.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • AgentWorkforce/agents#1: Establishes the initial PR review agent handler in review/agent.ts and review/persona.ts; this PR extends that foundation with centralized skip-rule logic and new configuration inputs.

Poem

🐰 A gate stands firm where reviews once flowed,
Checking states and labels down the road,
Skip the noise, let authors choose their way,
And Slack knows well what the agent won't say! 📬

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% 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 clearly summarizes the main changes: adding label-based gates, author-based allowlist, and merged PR skip logic to the pr-reviewer.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the three gates (label, author, merged skip) and implementation details.
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 feat/pr-reviewer-gates

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 2, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request refactors several agents to use high-level client helpers from '@relayfile/relay-helpers' instead of low-level JSON file operations. It also introduces a review gate mechanism in the review agent to skip reviews based on PR status, configured labels, or author allowlists. Feedback is provided to defensively handle 'meta.labels' and label names in the review gate logic to prevent potential runtime errors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread review/agent.ts Outdated
Comment on lines +114 to +116
const prLabels = (meta?.labels ?? [])
.map((l) => l?.name?.trim().toLowerCase())
.filter((n): n is string => Boolean(n));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To prevent potential runtime errors if meta.labels is not an array or if a label's name is not a string, we should defensively check that meta.labels is an array and ensure l.name is a string before calling .trim().

Suggested change
const prLabels = (meta?.labels ?? [])
.map((l) => l?.name?.trim().toLowerCase())
.filter((n): n is string => Boolean(n));
const prLabels = (Array.isArray(meta?.labels) ? meta.labels : [])
.map((l) => typeof l?.name === 'string' ? l.name.trim().toLowerCase() : undefined)
.filter((n): n is string => Boolean(n));

Comment thread review/agent.ts
Comment on lines +36 to 42
interface PrMeta {
state?: string; // 'open' | 'closed'
merged?: boolean;
author?: { login?: string };
labels?: Array<{ name?: string }>;
[key: string]: unknown;
}

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: The PR metadata author shape is modeled incorrectly, so the authoritative author from meta.json is never read. In this codebase the metadata author is a string login (as used by repo-hygiene), but here it is typed as an object with login; that makes meta?.author?.login resolve to undefined and forces fallback to payload-derived author values, which can be wrong on check_run.completed. Update the meta contract to match the real schema and read the login from that field directly. [api mismatch]

Severity Level: Major ⚠️
- ❌ CI-triggered PR reviews skipped for allowlisted human authors.
- ⚠️ REVIEW_AUTHORS ignores authoritative author from PR metadata.
Steps of Reproduction ✅
1. Configure the pr-reviewer to use an author allowlist by setting `REVIEW_AUTHORS`
(consumed via `input()` at `review/agent.ts:52-55` and used in `reviewAuthorAllowlist()`
at `review/agent.ts:155-159`).

2. Note that `shouldSkipReview()` at `review/agent.ts:101-132` reads PR metadata via
`loadPrMeta()` (`review/agent.ts:135-146`) and expects `PrMeta.author` to be an object
with `login` (`review/agent.ts:36-42`) while the same `meta.json` endpoint is typed as
`author?: string` in `GithubPrMeta` at `repo-hygiene/agent.ts:28-35`.

3. Open a PR in a repo where CI emits `check_run.completed` events; when such an event
arrives, the handler in `review/agent.ts:50-92` calls `readPr()`
(`review/agent.ts:262-282`), which sets `pr.author` from the webhook payload
(`p?.pull_request?.user?.login ?? p?.sender?.login ?? 'unknown'`).

4. For `check_run.completed` payloads, `p.pull_request` is often absent and
`p.sender.login` is typically the app (for example, `github-actions[bot]`), so `pr.author`
is not the human PR opener, while the `meta.json` `author` field (typed as `string` in
`GithubPrMeta` at `repo-hygiene/agent.ts:28-35`) contains the correct opener login.

5. When `shouldSkipReview()` runs for that event, `loadPrMeta()` successfully returns a
`PrMeta` whose runtime `author` value is a string, making `meta?.author?.login`
(`review/agent.ts:126`) evaluate to `undefined`; the expression `(meta?.author?.login ??
pr.author)` therefore falls back to `pr.author` (the app login), causing the allowlist
check `!allow.has(author)` (`review/agent.ts:127`) to skip the review even though the
correct human author in `meta.json` would have passed `REVIEW_AUTHORS`.

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:** 36:42
**Comment:**
	*Api Mismatch: The PR metadata author shape is modeled incorrectly, so the authoritative author from `meta.json` is never read. In this codebase the metadata author is a string login (as used by `repo-hygiene`), but here it is typed as an object with `login`; that makes `meta?.author?.login` resolve to `undefined` and forces fallback to payload-derived author values, which can be wrong on `check_run.completed`. Update the meta contract to match the real schema and read the login from that field directly.

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
Comment on lines +124 to +129
const allow = reviewAuthorAllowlist(ctx);
if (allow.size > 0) {
const author = (meta?.author?.login ?? pr.author).trim().toLowerCase();
if (!allow.has(author)) {
return { reason: `author @${author} is not in REVIEW_AUTHORS` };
}

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: The author allowlist gate is not actually fail-open when metadata loading fails: it still enforces REVIEW_AUTHORS against fallback payload author values (often sender/unknown for non-PR payload shapes), which can incorrectly skip eligible PRs during transient meta read failures. Only enforce this gate when a reliable PR opener is available from metadata, or explicitly bypass the gate when metadata is unavailable. [logic error]

Severity Level: Major ⚠️
- ❌ Transient meta read failures can block allowed PR reviews.
- ⚠️ REVIEW_AUTHORS behaves fail-closed on metadata errors.
Steps of Reproduction ✅
1. Enable an author allowlist for pr-reviewer by setting `REVIEW_AUTHORS` so that
`reviewAuthorAllowlist()` at `review/agent.ts:155-159` returns a non-empty `Set`,
activating the gate in `shouldSkipReview()` at `review/agent.ts:124-130`.

2. Observe that `loadPrMeta()` at `review/agent.ts:135-146` reads `meta.json` via
`readJsonFile<PrMeta>()` and catches all errors, returning `undefined` on any failure
(e.g., transient VFS or adapter issues).

3. When a GitHub event (for example, `check_run.completed` listed in `triggers` at
`review/agent.ts:55-60`) arrives during such a transient failure, `loadPrMeta()` returns
`undefined`, so `meta` is falsy in `shouldSkipReview()` (`review/agent.ts:101-132`): the
merged/closed and label gates effectively no-op, but the allowlist gate still executes.

4. In this meta-failure case, the allowlist gate computes `author` as
`(meta?.author?.login ?? pr.author).trim().toLowerCase()` at `review/agent.ts:126`, which
reduces to `pr.author` because `meta` is `undefined`; `pr.author` comes from `readPr()`
(`review/agent.ts:262-282`) and, for `check_run.completed`, is often the app or `sender`
login (e.g., `github-actions[bot]`) or `'unknown'`, not the actual PR opener.

5. Because `REVIEW_AUTHORS` is defined in terms of human opener logins, the
`allow.has(author)` check at `review/agent.ts:127` fails when `author` is this fallback
value, causing `shouldSkipReview()` to return a skip reason and the handler at
`review/agent.ts:79-85` to skip `reviewAndFix()` despite the PR having an allowlisted
opener; this violates the intended best-effort/fail-open behavior when metadata loading is
unreliable.

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:** 124:129
**Comment:**
	*Logic Error: The author allowlist gate is not actually fail-open when metadata loading fails: it still enforces `REVIEW_AUTHORS` against fallback payload author values (often `sender`/`unknown` for non-PR payload shapes), which can incorrectly skip eligible PRs during transient meta read failures. Only enforce this gate when a reliable PR opener is available from metadata, or explicitly bypass the gate when metadata is unavailable.

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 2, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

@cubic-dev-ai cubic-dev-ai 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.

3 issues found across 11 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread review/agent.ts Outdated
Comment thread review/agent.ts Outdated
Comment thread review/agent.ts Outdated
Add three agent-side gates to the pr-reviewer before it reviews/fixes a PR:

- Label gate: skip entirely when the PR carries a disabling label
  (configurable via the new SKIP_LABELS input; defaults to
  "no-agent-relay-review").
- Author allowlist: new REVIEW_AUTHORS input — when set, only review/fix
  PRs opened by those logins (e.g. "only my own PRs"). Unset = every author,
  so existing deployments are unaffected.
- Already-merged/closed skip: don't post a stale review when the PR has
  already merged/closed by the time the handler runs (the cheap, agent-side
  half of the merge-race; recovery-PR preservation is tracked in
  AgentWorkforce/cloud#1659 / #1660).

Author and labels are read from the live PR meta.json via readJsonFile,
because the webhook payload doesn't carry them on every trigger
(check_run.completed has neither). The read is best-effort: on failure it
falls back to the payload author and proceeds. Gates apply only to the
review/fix path; merge-on-approval still flows through APPROVERS unchanged.

Review feedback addressed:
- meta.author accepted as either a login string or { login } object, so a
  shape mismatch can't silently bypass the allowlist.
- labels validated with Array.isArray + a string check on label.name before
  trimming, to avoid runtime errors on malformed metadata.
- author allowlist fails open: an undeterminable author ('unknown'/empty)
  no longer blocks the review.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@khaliqgant khaliqgant force-pushed the feat/pr-reviewer-gates branch from d35c65a to 0696b7b Compare June 2, 2026 12:34
@agent-relay-code

Copy link
Copy Markdown
Contributor

pr-reviewer applied fixes — committed and pushed e7527d8 to this PR. The notes below describe what changed.

Fixed the PR gate behavior in review/agent.ts.

What changed:

  • readPr now preserves state, merged, and labels from pull_request payloads.
  • shouldSkipReview now falls back to webhook payload data when meta.json is unavailable.
  • Closed-state checks are case-insensitive.
  • Skip-label parsing is centralized and still validates label shape defensively.

Validation:

  • npm run typecheck passed.
  • npm audit --omit=optional --json reported 0 vulnerabilities.
  • I did not keep a local agentworkforce CLI dependency: the current CLI made compile pass but introduced high-severity transitive audit findings; the older CLI did not support persona compile.

@agent-relay-code agent-relay-code 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.

pr-reviewer applied fixes — committed and pushed e7527d8 to this PR. The notes below describe what changed.

Fixed the PR gate behavior in review/agent.ts.

What changed:

  • readPr now preserves state, merged, and labels from pull_request payloads.
  • shouldSkipReview now falls back to webhook payload data when meta.json is unavailable.
  • Closed-state checks are case-insensitive.
  • Skip-label parsing is centralized and still validates label shape defensively.

Validation:

  • npm run typecheck passed.
  • npm audit --omit=optional --json reported 0 vulnerabilities.
  • I did not keep a local agentworkforce CLI dependency: the current CLI made compile pass but introduced high-severity transitive audit findings; the older CLI did not support persona compile.

@khaliqgant khaliqgant merged commit 1b07350 into main Jun 2, 2026
2 checks passed
@khaliqgant khaliqgant deleted the feat/pr-reviewer-gates branch June 2, 2026 20:14
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