Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .agents/skills/nemoclaw-maintainer-day/MERGE-GATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For the full priority list see [PR-REVIEW-PRIORITIES.md](PR-REVIEW-PRIORITIES.md
2. **CI green** — all required checks in `statusCheckRollup`.
3. **No conflicts** — `mergeStateStatus` clean.
4. **No major CodeRabbit** — ignore style nits; block on correctness/security bugs.
5. **PR Review Advisor: merge_as_is** — `check-gates.ts` checks this automatically. The gate passes only when the latest advisor comment has `recommendation: merge_as_is`. All other recommendation values — including `blocked`, `needs_rework`, `merge_after_fixes`, `superseded`, `info_only`, and any unknown value — fail the gate. The referenced Actions run is validated (name, event, head SHA, run attempt, timestamp) before the recommendation is trusted. Correctness, security, acceptance, and test-depth findings block until addressed or explicitly judged false-positive by a maintainer.
5. **PR Review Advisor: merge_as_is** — `check-gates.ts` checks this automatically. The gate passes only when the latest advisor comment has `recommendation: merge_as_is`. All other recommendation values — including `blocked`, `needs_rework`, `merge_after_fixes`, `superseded`, `info_only`, and any unknown value — fail the gate. For `pull_request_target`, the comment and referenced Actions run must bind the exact workflow path and trusted workflow SHA, PR number, head and base SHAs, run attempt, event, comment ID, and update window before the recommendation is trusted. Legacy `pull_request` provenance remains accepted during migration. Correctness, security, acceptance, and test-depth findings block until addressed or explicitly judged false-positive by a maintainer.
6. **Risky code tested** — see [RISKY-AREAS.md](RISKY-AREAS.md). Confirm tests exist (added or pre-existing).

## Step 1: Run the Gate Checker
Expand Down
19 changes: 15 additions & 4 deletions .agents/skills/nemoclaw-maintainer-day/scripts/check-gates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,12 @@ function checkCodeRabbit(
// Gate 4: PR Review Advisor not blocked
// ---------------------------------------------------------------------------

function checkPrAdvisor(repo: string, number: number, headSha: string): PrAdvisorGateResult {
function checkPrAdvisor(
repo: string,
number: number,
headSha: string,
baseSha: string,
): PrAdvisorGateResult {
// --jq ".[]" emits one JSON object per line (NDJSON) — deterministic across pages
const raw = run("gh", [
"api",
Expand Down Expand Up @@ -550,7 +555,7 @@ function checkPrAdvisor(repo: string, number: number, headSha: string): PrAdviso
} catch {
return { pass: false, details: "Could not parse advisor run response — fail-closed" };
}
if (!validateAdvisorRun(runData, meta, latest.updated_at ?? "")) {
if (!validateAdvisorRun(runData, meta, latest.updated_at ?? "", number, baseSha)) {
return {
pass: false,
details: "PR Review Advisor run provenance check failed — fail-closed",
Expand Down Expand Up @@ -718,7 +723,7 @@ function main(): void {
"--repo",
repo,
"--json",
"number,title,url,body,files,statusCheckRollup,mergeStateStatus,headRefOid,author",
"number,title,url,body,files,statusCheckRollup,mergeStateStatus,headRefOid,baseRefOid,author",
]) as {
number: number;
title: string;
Expand All @@ -728,6 +733,7 @@ function main(): void {
statusCheckRollup: StatusCheck[];
mergeStateStatus: string;
headRefOid: string;
baseRefOid: string;
author: PrIdentity | null;
} | null;

Expand All @@ -740,7 +746,12 @@ function main(): void {
const conflicts = checkConflicts(prData.mergeStateStatus);
const coderabbit = checkCodeRabbit(repo, prNumber);
const riskyCodeTested = checkRiskyCodeTested(prData.files ?? []);
const prAdvisor = checkPrAdvisor(repo, prNumber, prData.headRefOid ?? "");
const prAdvisor = checkPrAdvisor(
repo,
prNumber,
prData.headRefOid ?? "",
prData.baseRefOid ?? "",
);
const contributorCompliance = checkContributorCompliance(repo, prNumber, prData.body ?? "");
const contributorApprovalHistory = fetchContributorApprovalHistory(repo, prNumber);
const contributorApprovalOverlap = checkContributorApprovalOverlap(
Expand Down
90 changes: 81 additions & 9 deletions .agents/skills/nemoclaw-maintainer-day/scripts/pra-gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ export interface PraComment {

export interface PraRun {
name?: string;
path?: string | null;
head_sha?: string;
event?: string;
run_attempt?: number;
run_started_at?: string;
created_at?: string;
updated_at?: string;
pull_requests?: Array<{
number?: number;
head?: { sha?: string | null } | null;
base?: { sha?: string | null } | null;
}> | null;
}

export interface PraMeta {
Expand All @@ -35,6 +41,11 @@ export interface PraMeta {
runId: number;
runAttempt: number;
commentId: number;
event?: string;
prNumber?: number;
workflowSha?: string;
baseSha?: string;
workflowPath?: string;
}

export interface PrAdvisorGateResult {
Expand All @@ -54,9 +65,12 @@ export interface PrAdvisorGateResult {
// "approved" is not a valid advisor recommendation; only "merge_as_is" is.
export const PRA_PASS_RECOMMENDATIONS = new Set(["merge_as_is"]);

const PRA_WORKFLOW_NAME = "PR Review / Advisor";
const PRA_WORKFLOW_PATH = ".github/workflows/pr-review-advisor.yaml";

// Full metadata line: all five fields must be present for a trusted comment.
const PRA_FULL_META_RE =
/head_sha:\s*([0-9a-f]+);\s*recommendation:\s*([a-z_]+);\s*run_id:\s*(\d+);\s*run_attempt:\s*(\d+);\s*comment_id:\s*(\d+)/i;
/head_sha:\s*([0-9a-f]+);\s*recommendation:\s*([a-z_]+);\s*run_id:\s*(\d+);\s*run_attempt:\s*(\d+);\s*comment_id:\s*(\d+)(?:;\s*event:\s*([a-z_]+);\s*pr_number:\s*(\d+);\s*workflow_sha:\s*([0-9a-f]+);\s*base_sha:\s*([0-9a-f]+);\s*workflow_path:\s*([^\s;>]+))?/i;

const PRA_REQUIRED_RE = /\*\*Open items:\*\*[^|]*?(\d+)\s+required/;

Expand All @@ -77,6 +91,11 @@ export function parsePraMeta(body: string): PraMeta | null {
runId: parseInt(m[3], 10),
runAttempt: parseInt(m[4], 10),
commentId: parseInt(m[5], 10),
event: m[6]?.toLowerCase(),
prNumber: m[7] === undefined ? undefined : parseInt(m[7], 10),
workflowSha: m[8]?.toLowerCase(),
baseSha: m[9]?.toLowerCase(),
workflowPath: m[10],
};
}

Expand Down Expand Up @@ -170,22 +189,75 @@ function isTimestampWithin(value: string, start: string, end: string): boolean {
return t >= s && t <= e;
}

function normalizeWorkflowPath(value: string): string {
return value.split("@", 1)[0];
}

/**
* Verify that a GitHub Actions run corresponds to the trusted PR Review / Advisor
* workflow for this PR head. Mirrors isTrustedAdvisorRun() in
* tools/pr-review-advisor/analyze.mts.
* workflow for this PR head.
*
* The pull_request branch preserves the original rollout contract: the run
* head_sha is the PR head. A pull_request_target run instead executes at a
* trusted base ref, so its PR identity and head SHA must come from exactly one
* run.pull_requests association. GitHub may return the workflow path with an
* @ref suffix; only the path portion identifies the workflow file.
*
* Pure function — the caller is responsible for fetching the run data.
*/
export function validateAdvisorRun(run: PraRun, meta: PraMeta, commentUpdatedAt: string): boolean {
export function validateAdvisorRun(
run: PraRun,
meta: PraMeta,
commentUpdatedAt: string,
prNumber: number,
baseSha?: string,
): boolean {
const startedAt = run.run_started_at ?? run.created_at;
const endedAt = run.updated_at;
if (!startedAt || !endedAt) return false;

if (
run.name !== PRA_WORKFLOW_NAME ||
(run.run_attempt ?? -1) !== meta.runAttempt ||
!isTimestampWithin(commentUpdatedAt, startedAt, endedAt)
) {
return false;
}

if (run.event === "pull_request") {
return (
(meta.event === undefined || meta.event === "pull_request") &&
(run.head_sha ?? "").toLowerCase() === meta.headSha
);
}

if (run.event !== "pull_request_target") return false;

if (typeof run.path !== "string" || normalizeWorkflowPath(run.path) !== PRA_WORKFLOW_PATH) {
return false;
}

if (
!Number.isInteger(prNumber) ||
prNumber <= 0 ||
meta.event !== "pull_request_target" ||
meta.prNumber !== prNumber ||
!meta.workflowSha ||
meta.workflowSha !== (run.head_sha ?? "").toLowerCase() ||
!meta.baseSha ||
meta.baseSha !== (baseSha ?? "").toLowerCase() ||
!meta.workflowPath ||
normalizeWorkflowPath(meta.workflowPath) !== PRA_WORKFLOW_PATH ||
!Array.isArray(run.pull_requests) ||
run.pull_requests.length !== 1
) {
return false;
}

const association = run.pull_requests[0];
return (
run.name === "PR Review / Advisor" &&
run.event === "pull_request" &&
(run.head_sha ?? "").toLowerCase() === meta.headSha &&
(run.run_attempt ?? -1) === meta.runAttempt &&
isTimestampWithin(commentUpdatedAt, startedAt, endedAt)
association.number === prNumber &&
(association.head?.sha ?? "").toLowerCase() === meta.headSha &&
(association.base?.sha ?? "").toLowerCase() === meta.baseSha
);
}
8 changes: 4 additions & 4 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ reviews:
enabled: true
drafts: false

# E2E recommendations intentionally do not live here. The E2E Advisor derives
# them from each PR diff and the current workflows instead of a duplicated,
# manually synchronized path-to-job catalog.
# E2E recommendations intentionally do not live here. The unified PR Review
# Advisor derives them from each PR diff and the current workflows instead of
# a duplicated, manually synchronized path-to-job catalog.
path_instructions:
- path: "docs/**"
instructions: &fern-doc-links |
Expand Down Expand Up @@ -238,7 +238,7 @@ reviews:
- Do not duplicate GitHub issue tracking, CI status, or another advisor's
responsibility.

- path: "tools/{pr-review-advisor,e2e-advisor}/**"
- path: "tools/{advisors,pr-review-advisor}/**"
instructions: *guardrail

knowledge_base:
Expand Down
Loading
Loading