Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions .agents/skills/nemoclaw-maintainer-day/MERGE-GATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ For the full priority list see [PR-REVIEW-PRIORITIES.md](PR-REVIEW-PRIORITIES.md
1. **CI green** — all required checks in `statusCheckRollup`.
2. **No conflicts** — `mergeStateStatus` clean.
3. **No major CodeRabbit** — ignore style nits; block on correctness/security bugs.
4. **No unresolved actionable PR Review Advisor findings** — correctness, security, acceptance, and test-depth findings block until addressed or explicitly judged false-positive.
4. **PR Review Advisor not blocked** — `check-gates.ts` now checks this automatically; `allPass` will be false if the latest advisor comment has `recommendation: blocked`. Correctness, security, acceptance, and test-depth findings block until addressed or explicitly judged false-positive.
5. **Risky code tested** — see [RISKY-AREAS.md](RISKY-AREAS.md). Confirm tests exist (added or pre-existing).

## Step 1: Run the Gate Checker
Expand All @@ -18,7 +18,7 @@ For the full priority list see [PR-REVIEW-PRIORITIES.md](PR-REVIEW-PRIORITIES.md
node --experimental-strip-types --no-warnings .agents/skills/nemoclaw-maintainer-day/scripts/check-gates.ts <pr-number>
```

This checks the deterministic gates programmatically and returns structured JSON with `allPass` and per-gate `pass`/`details`. PR Review Advisor follow-up remains a manual review step; use [PR CI and Automated Review Follow-Up](../_shared/pr-follow-up.md) for the shared triage loop.
This checks all gates programmatically and returns structured JSON with `allPass` and per-gate `pass`/`details`, including the PR Review Advisor status. Use [PR CI and Automated Review Follow-Up](../_shared/pr-follow-up.md) for the shared triage loop when individual findings need investigation.

## Step 2: Interpret Results

Expand All @@ -29,16 +29,16 @@ The script handles the deterministic checks. You handle judgment calls:
- **CI failing but narrow:** Follow the salvage workflow in [SALVAGE-PR.md](SALVAGE-PR.md).
- **CI pending:** Wait and re-check. Do not approve while checks are still running.
- **CodeRabbit:** Script flags unresolved major/critical threads. Review the `snippet` to confirm it's a real issue vs style nit. If doubt, leave unapproved.
- **PR Review Advisor:** Read the latest sticky advisor comment and apply [PR CI and Automated Review Follow-Up](../_shared/pr-follow-up.md). Valid correctness, security, acceptance-coverage, and test-depth findings block approval unless explicitly judged false-positive.
- **PR Review Advisor blocked:** `gates.prAdvisor.pass` will be false and `allPass` false. Read the full advisor comment on the PR, apply [PR CI and Automated Review Follow-Up](../_shared/pr-follow-up.md), and do not approve until the required findings are addressed or explicitly judged false-positive by a maintainer.
- **Tests:** If `riskyCodeTested.pass` is false, follow [TEST-GAPS.md](TEST-GAPS.md).

## Step 3: Approve or Report

**Approve only when:** `allPass` is true, `mergeStateStatus` is not DIRTY, and the latest PR Review Advisor comment has no unresolved actionable findings. Approving a PR with conflicts is wasted effort — the rebase will invalidate the approval.
**Approve only when:** `allPass` is true and `mergeStateStatus` is not DIRTY. `allPass` now includes the PR Review Advisor gate, so a blocked advisor comment alone prevents approval. Approving a PR with conflicts is wasted effort — the rebase will invalidate the approval.

The correct sequence for a conflicted PR: **salvage (rebase) → CI green → approve → report ready for merge.**

**All pass + no conflicts + no actionable PR Review Advisor findings:** Approve and summarize why.
**All pass + no conflicts:** Approve and summarize why.

**Any fail:**

Expand Down
74 changes: 70 additions & 4 deletions .agents/skills/nemoclaw-maintainer-day/scripts/check-gates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/**
* Deterministic merge-gate checker for a single NemoClaw PR.
*
* Checks all 4 required gates and outputs structured JSON.
* Checks all 5 required gates and outputs structured JSON.
* Claude uses the output to decide: approve, route to salvage, or report blockers.
*
* Usage: node --experimental-strip-types --no-warnings .agents/skills/nemoclaw-maintainer-day/scripts/check-gates.ts <pr-number> [--repo OWNER/REPO]
Expand Down Expand Up @@ -36,6 +36,11 @@ interface CodeRabbitThread {
resolved: boolean;
}

interface PrAdvisorGateResult extends GateResult {
recommendation?: string;
openRequired?: number;
}

interface GateOutput {
pr: number;
url: string;
Expand All @@ -50,6 +55,7 @@ interface GateOutput {
conflicts: GateResult & { mergeStateStatus?: string };
coderabbit: GateResult & { unresolvedThreads?: CodeRabbitThread[] };
riskyCodeTested: GateResult & { riskyFiles?: string[]; hasTests?: boolean };
prAdvisor: PrAdvisorGateResult;
};
}

Expand Down Expand Up @@ -260,7 +266,66 @@ function checkCodeRabbit(
}

// ---------------------------------------------------------------------------
// Gate 4: Risky code has tests
// Gate 4: PR Review Advisor not blocked
// ---------------------------------------------------------------------------

// The PRA bot embeds machine-readable metadata in an HTML comment:
// <!-- nemoclaw-pr-review-advisor -->
// <!-- head_sha: ...; recommendation: blocked; ... -->
const PRA_META_RE = /recommendation:\s*([a-z_]+)/i;
const PRA_REQUIRED_RE = /\*\*Open items:\*\*[^|]*?(\d+)\s+required/;

function checkPrAdvisor(repo: string, number: number): PrAdvisorGateResult {
const raw = run("gh", ["api", `repos/${repo}/issues/${number}/comments`, "--paginate"]);

if (!raw) {
// run() returns "" on API failure — fail closed, same as CodeRabbit gate
return { pass: false, details: "Could not fetch PR comments (API error — fail-closed)" };
}

let allComments: Array<{ body?: string }>;
try {
allComments = JSON.parse(raw) as Array<{ body?: string }>;
} catch {
return { pass: false, details: "Could not parse PR comments (invalid JSON — fail-closed)" };
}

const praComments = allComments.filter((c) =>
(c.body ?? "").includes("nemoclaw-pr-review-advisor"),
);
Comment on lines +286 to +295

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Handle non-array API payloads to avoid a hard crash.

Line 286-295 assumes parsed JSON is always an array. If GitHub returns a JSON error object (valid JSON), allComments.filter(...) throws and bypasses fail-closed behavior.

Proposed fix
-  let allComments: Array<{ body?: string }>;
+  let allComments: Array<{ body?: string; user?: { login?: string } }>;
   try {
-    allComments = JSON.parse(raw) as Array<{ body?: string }>;
+    const parsed = JSON.parse(raw) as unknown;
+    if (!Array.isArray(parsed)) {
+      return { pass: false, details: "Could not parse PR comments (unexpected JSON shape — fail-closed)" };
+    }
+    allComments = parsed as Array<{ body?: string; user?: { login?: string } }>;
   } catch {
     return { pass: false, details: "Could not parse PR comments (invalid JSON — fail-closed)" };
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let allComments: Array<{ body?: string }>;
try {
allComments = JSON.parse(raw) as Array<{ body?: string }>;
} catch {
return { pass: false, details: "Could not parse PR comments (invalid JSON — fail-closed)" };
}
const praComments = allComments.filter((c) =>
(c.body ?? "").includes("nemoclaw-pr-review-advisor"),
);
let allComments: Array<{ body?: string; user?: { login?: string } }>;
try {
const parsed = JSON.parse(raw) as unknown;
if (!Array.isArray(parsed)) {
return { pass: false, details: "Could not parse PR comments (unexpected JSON shape — fail-closed)" };
}
allComments = parsed as Array<{ body?: string; user?: { login?: string } }>;
} catch {
return { pass: false, details: "Could not parse PR comments (invalid JSON — fail-closed)" };
}
const praComments = allComments.filter((c) =>
(c.body ?? "").includes("nemoclaw-pr-review-advisor"),
);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.agents/skills/nemoclaw-maintainer-day/scripts/check-gates.ts around lines
286 - 295, After parsing the JSON in the try block, add a type check to verify
that allComments is actually an array before calling the filter method. If the
parsed JSON is not an array (such as when GitHub returns an error object),
return the fail-closed response with an appropriate error message instead of
allowing the code to proceed to the filter call, which would throw an error on a
non-array value. Add this validation immediately after the JSON.parse assignment
and before the filter call on allComments.

if (praComments.length === 0) {
return { pass: true, details: "No PR Review Advisor comment found" };
}

// Use the last PRA comment (most recent re-run)
const body = praComments[praComments.length - 1].body ?? "";
Comment on lines +293 to +301

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Gate is spoofable because PRA detection trusts marker text without author validation.

Line 275-283 accepts any latest comment containing nemoclaw-pr-review-advisor. A non-bot commenter can post that marker with recommendation: approved and override a prior blocked bot comment.

Suggested fix
-  let allComments: Array<{ body?: string }>;
+  let allComments: Array<{ body?: string; user?: { login?: string; type?: string } }>;
@@
-  const praComments = allComments.filter((c) =>
-    (c.body ?? "").includes("nemoclaw-pr-review-advisor"),
-  );
+  const PRA_BOT_LOGIN = "nemoclaw-pr-review-advisor[bot]";
+  const praComments = allComments.filter((c) =>
+    (c.body ?? "").includes("nemoclaw-pr-review-advisor") &&
+    c.user?.login === PRA_BOT_LOGIN,
+  );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.agents/skills/nemoclaw-maintainer-day/scripts/check-gates.ts around lines
275 - 283, The praComments filter on line 275-283 only checks if the comment
body contains the text "nemoclaw-pr-review-advisor" without validating that the
comment was actually posted by the PR Review Advisor bot account itself. This
allows any user to spoof a bot recommendation by posting a comment with that
marker text. Modify the filter condition to also check that the comment author
is the actual PR Review Advisor bot account (by verifying the user or author
property of the comment object), ensuring that only authentic bot comments are
accepted for gate validation.


const metaMatch = PRA_META_RE.exec(body);
if (!metaMatch) {
return {
pass: true,
details: "PR Review Advisor comment found but no recommendation metadata",
};
}

const recommendation = metaMatch[1].toLowerCase();
if (recommendation !== "blocked") {
return { pass: true, details: `PR Review Advisor: ${recommendation}`, recommendation };
}

const requiredMatch = PRA_REQUIRED_RE.exec(body);
const openRequired = requiredMatch ? parseInt(requiredMatch[1], 10) : undefined;

return {
pass: false,
details: `PR Review Advisor: blocked${openRequired !== undefined ? ` (${openRequired} required item(s))` : ""}`,
recommendation,
openRequired,
};
}

// ---------------------------------------------------------------------------
// Gate 5: Risky code has tests
// ---------------------------------------------------------------------------

function checkRiskyCodeTested(
Expand Down Expand Up @@ -329,13 +394,14 @@ function main(): void {
const conflicts = checkConflicts(prData.mergeStateStatus);
const coderabbit = checkCodeRabbit(repo, prNumber);
const riskyCodeTested = checkRiskyCodeTested(prData.files ?? []);
const prAdvisor = checkPrAdvisor(repo, prNumber);

const output: GateOutput = {
pr: prNumber,
url: prData.url,
title: prData.title,
allPass: ci.pass && conflicts.pass && coderabbit.pass && riskyCodeTested.pass,
gates: { ci, conflicts, coderabbit, riskyCodeTested },
allPass: ci.pass && conflicts.pass && coderabbit.pass && riskyCodeTested.pass && prAdvisor.pass,
gates: { ci, conflicts, coderabbit, riskyCodeTested, prAdvisor },
};

console.log(JSON.stringify(output, null, 2));
Expand Down
6 changes: 4 additions & 2 deletions .agents/skills/nemoclaw-maintainer-day/scripts/triage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ function classifyPr(pr: PrData): ClassifiedPr {
const blocked = mergeState === "BLOCKED";
if (blocked && !hasConflict) reasons.push("merge-blocked");

// Simple CodeRabbit heuristic: check labels for major findings
// (Full CodeRabbit check is in check-gates.ts via GraphQL)
// CodeRabbit and PR Review Advisor are not checked here — fetching per-PR
// comments/threads for every open PR would make triage too slow. Both are
// checked as hard gates in check-gates.ts. A PR may appear as merge-now
// here but still fail the gate — always run check-gates.ts before approving.
const coderabbitMajor = false; // conservative — gate checker does the real check

// Classify into buckets
Expand Down