Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
eed7b14
fix(skills): use latest check-run attempts
cv Jul 16, 2026
4f8e083
merge(main): refresh merge-gate checker
cv Jul 16, 2026
65cfba8
merge(main): refresh merge-gate checker
cv Jul 16, 2026
efa3d73
fix(skills): validate current check evidence
cv Jul 16, 2026
c4daf2d
fix(skills): harden workflow evidence checks
cv Jul 16, 2026
140031c
fix(skills): validate action evidence
cv Jul 16, 2026
802f650
fix(skills): bind required check evidence
cv Jul 16, 2026
3f9a867
merge(main): refresh merge-gate checker
cv Jul 16, 2026
f19952a
fix(skills): make merge-gate evidence fail closed
cjagwani Jul 16, 2026
e1b7a1c
merge: refresh from main
cjagwani Jul 16, 2026
f991988
fix(skills): reject stale pull request bases
cjagwani Jul 16, 2026
b2d0647
merge: refresh from main
cjagwani Jul 16, 2026
4aac159
test(skills): distinguish stale check runs
cjagwani Jul 16, 2026
f8439e0
Merge remote-tracking branch 'origin/main' into codex/fix-merge-gate-…
cv Jul 16, 2026
bd0ab2a
fix(ci): require successful merge gates
cjagwani Jul 16, 2026
07a1e32
merge: refresh from main
cjagwani Jul 16, 2026
fa82094
fix(ci): align dependabot DCO identities
cjagwani Jul 16, 2026
b4cf995
fix(skills): bind merge-gate evidence to immutable revisions
cv Jul 16, 2026
1354447
Merge remote-tracking branch 'origin/codex/fix-merge-gate-check-attem…
cv Jul 16, 2026
86d9fce
fix(skills): align comparator DCO bypass
cjagwani Jul 16, 2026
3ee05c8
merge: preserve concurrent gate hardening
cjagwani Jul 16, 2026
46263f1
merge: refresh from main
cjagwani Jul 16, 2026
43b07d4
Merge remote-tracking branch 'origin/main' into codex/fix-merge-gate-…
cv Jul 16, 2026
87812d0
Merge remote-tracking branch 'origin/codex/fix-merge-gate-check-attem…
cv Jul 16, 2026
26005ca
fix(ci): align DCO exemption contract
cv Jul 16, 2026
4fec1fc
fix(skills): order checks by workflow creation
cv Jul 16, 2026
17de16c
merge(main): refresh v0.0.85 gate base
cv Jul 16, 2026
9fee992
merge(main): refresh v0.0.85 gate base
cv Jul 17, 2026
0c2754d
merge(main): include v0.0.85 dcode validation
cv Jul 17, 2026
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
333 changes: 326 additions & 7 deletions .agents/skills/nemoclaw-maintainer-day/scripts/check-gates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,20 +298,324 @@ function checkContributorApprovalOverlap(
// Gate 1: CI green
// ---------------------------------------------------------------------------

interface ExactDiffIdentity {
number: number;
headSha: string;
baseSha: string;
}

interface ActionRunMetadata {
attempt: number;
exactDiff: boolean | null;
}

interface CurrentCheckRollup {
checks: StatusCheck[];
incompleteAttemptEvidence: string[];
}

function currentCheckRollup(
statusCheckRollup: StatusCheck[],
repo: string,
exactDiff: ExactDiffIdentity,
): CurrentCheckRollup {
const actionRunMetadataById = new Map<string, ActionRunMetadata | null>();
const latestAttemptJobsByRun = new Map<string, Map<string, string> | null>();
const incompleteAttemptEvidence = new Set<string>();

const actionRunMetadata = (runId: string): ActionRunMetadata | null => {
if (actionRunMetadataById.has(runId)) return actionRunMetadataById.get(runId) ?? null;

const runData = ghJson(["api", `repos/${repo}/actions/runs/${runId}`]);
if (typeof runData !== "object" || runData === null || Array.isArray(runData)) {
actionRunMetadataById.set(runId, null);
return null;
}
const record = runData as Record<string, unknown>;
if (!Number.isSafeInteger(record.run_attempt) || (record.run_attempt as number) < 1) {
actionRunMetadataById.set(runId, null);
return null;
}

let exactDiffMatch: boolean | null = null;
if (Array.isArray(record.pull_requests)) {
exactDiffMatch = false;
for (const value of record.pull_requests) {
if (typeof value !== "object" || value === null || Array.isArray(value)) {
exactDiffMatch = null;
break;
}
const pull = value as Record<string, unknown>;
const head = pull.head;
const base = pull.base;
if (
!Number.isSafeInteger(pull.number) ||
typeof head !== "object" ||
head === null ||
Array.isArray(head) ||
typeof base !== "object" ||
base === null ||
Array.isArray(base) ||
typeof (head as Record<string, unknown>).sha !== "string" ||
typeof (base as Record<string, unknown>).sha !== "string"
) {
exactDiffMatch = null;
break;
}
if (
pull.number === exactDiff.number &&
(head as Record<string, unknown>).sha === exactDiff.headSha &&
(base as Record<string, unknown>).sha === exactDiff.baseSha
) {
exactDiffMatch = true;
}
}
}

const metadata = { attempt: record.run_attempt as number, exactDiff: exactDiffMatch };
actionRunMetadataById.set(runId, metadata);
return metadata;
};

const latestAttemptJobs = (runId: string): Map<string, string> | null => {
if (latestAttemptJobsByRun.has(runId)) return latestAttemptJobsByRun.get(runId) ?? null;

const metadata = actionRunMetadata(runId);
if (!metadata) {
latestAttemptJobsByRun.set(runId, null);
return null;
}
const pages = ghJson([
"api",
"--paginate",
"--slurp",
`repos/${repo}/actions/runs/${runId}/attempts/${metadata.attempt}/jobs?per_page=100`,
]);
if (!Array.isArray(pages) || pages.length === 0) {
latestAttemptJobsByRun.set(runId, null);
return null;
}

let expectedTotal: number | null = null;
const jobsById = new Map<string, string>();
let observedJobs = 0;
for (const page of pages) {
if (typeof page !== "object" || page === null || Array.isArray(page)) {
latestAttemptJobsByRun.set(runId, null);
return null;
}
const { jobs, total_count: totalCount } = page as Record<string, unknown>;
if (
!Number.isSafeInteger(totalCount) ||
(totalCount as number) < 0 ||
(expectedTotal !== null && totalCount !== expectedTotal) ||
!Array.isArray(jobs)
) {
latestAttemptJobsByRun.set(runId, null);
return null;
}
expectedTotal = totalCount as number;
observedJobs += jobs.length;
for (const value of jobs) {
if (typeof value !== "object" || value === null || Array.isArray(value)) {
latestAttemptJobsByRun.set(runId, null);
return null;
}
const { id, name } = value as Record<string, unknown>;
if (!Number.isSafeInteger(id) || (id as number) < 1 || typeof name !== "string" || !name) {
latestAttemptJobsByRun.set(runId, null);
return null;
}
jobsById.set(String(id), name);
}
}
if (
expectedTotal === null ||
observedJobs !== expectedTotal ||
jobsById.size !== expectedTotal
) {
latestAttemptJobsByRun.set(runId, null);
return null;
}
latestAttemptJobsByRun.set(runId, jobsById);
return jobsById;
};

const checksFromLatestAttempt = (runId: string, checks: StatusCheck[]): StatusCheck[] | null => {
const checkName = checks[0]?.name;
const jobsById = latestAttemptJobs(runId);
if (!checkName || !jobsById) return null;

const expectedIds = new Set(
[...jobsById].filter(([, name]) => name === checkName).map(([id]) => id),
);
if (expectedIds.size === 0) return null;

const selected: StatusCheck[] = [];
const selectedIds = new Set<string>();
for (const check of checks) {
const match = check.detailsUrl?.match(
new RegExp(`/actions/runs/${runId}/job/(\\d+)(?:[/?#]|$)`, "u"),
);
if (!match) return null;
if (expectedIds.has(match[1])) {
if (selectedIds.has(match[1])) return null;
selectedIds.add(match[1]);
selected.push(check);
}
}
return selectedIds.size === expectedIds.size ? selected : null;
};

const groups = new Map<string, StatusCheck[]>();
for (const check of statusCheckRollup) {
const identity = JSON.stringify([
check.__typename ?? (check.context ? "StatusContext" : "CheckRun"),
check.name ?? check.context ?? "(unknown)",
check.workflowName ?? "",
]);
const group = groups.get(identity) ?? [];
group.push(check);
groups.set(identity, group);
}

const current: StatusCheck[] = [];
for (const group of groups.values()) {
if (group.length === 1) {
current.push(group[0]);
continue;
}

if (group[0].__typename !== "StatusContext") {
const byRun = new Map<string, StatusCheck[]>();
for (const check of group) {
const runId = check.detailsUrl?.match(/\/actions\/runs\/(\d+)(?:\/|$)/)?.[1];
if (!runId) {
byRun.clear();
break;
}
const runChecks = byRun.get(runId) ?? [];
runChecks.push(check);
byRun.set(runId, runChecks);
}
if (byRun.size > 1) {
const runs = [...byRun].map(([runId, checks]) => {
const timestamps = checks.map((check) =>
Date.parse(check.startedAt ?? check.completedAt ?? ""),
);
return {
runId,
checks,
timestamp: timestamps.every(Number.isFinite) ? Math.min(...timestamps) : Number.NaN,
allSkipped: checks.every(
(check) =>
check.status?.toUpperCase() === "COMPLETED" &&
check.conclusion?.toUpperCase() === "SKIPPED",
),
};
});
if (runs.every(({ timestamp }) => Number.isFinite(timestamp))) {
const meaningfulExactDiffRun = runs.some(
({ runId, allSkipped }) => !allSkipped && actionRunMetadata(runId)?.exactDiff === true,
);
const candidates = meaningfulExactDiffRun
? runs.filter(
({ runId, allSkipped }) =>
!(allSkipped && actionRunMetadata(runId)?.exactDiff === true),
)
: runs;
const latestTimestamp = Math.max(...candidates.map(({ timestamp }) => timestamp));
const latestRuns = candidates.filter(({ timestamp }) => timestamp === latestTimestamp);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
if (latestRuns.length === 1) {
const latest = latestRuns[0];
const selected =
latest.checks.length > 1
? checksFromLatestAttempt(latest.runId, latest.checks)
: latest.checks;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
if (!selected) {
incompleteAttemptEvidence.add(latest.checks[0]?.name ?? "(unknown)");
}
current.push(...(selected ?? latest.checks));
} else {
current.push(...latestRuns.flatMap(({ checks }) => checks));
}
continue;
}
}

if (byRun.size === 1) {
const [runId, checks] = [...byRun][0];
const selected = checks.length > 1 ? checksFromLatestAttempt(runId, checks) : checks;
if (!selected) incompleteAttemptEvidence.add(checks[0]?.name ?? "(unknown)");
current.push(...(selected ?? checks));
continue;
}

const customCheckRuns = group.every(
(check) =>
!check.detailsUrl?.includes("/actions/runs/") &&
/\/runs\/\d+(?:[/?#]|$)/u.test(check.detailsUrl ?? ""),
);
if (customCheckRuns) {
const timestamped = group.map((check) => ({
check,
timestamp: Date.parse(check.startedAt ?? check.completedAt ?? ""),
}));
if (timestamped.every(({ timestamp }) => Number.isFinite(timestamp))) {
const latestTimestamp = Math.max(...timestamped.map(({ timestamp }) => timestamp));
current.push(
...timestamped
.filter(({ timestamp }) => timestamp === latestTimestamp)
.map(({ check }) => check),
);
continue;
}
}

// Keep duplicate jobs from one workflow run together. This prevents a
// later-starting matrix job from hiding another job's failure.
current.push(...group);
continue;
}

const timestamped = group.map((check) => ({
check,
timestamp: Date.parse(check.startedAt ?? check.completedAt ?? ""),
}));
if (timestamped.some(({ timestamp }) => !Number.isFinite(timestamp))) {
current.push(...group);
continue;
}
const latestTimestamp = Math.max(...timestamped.map(({ timestamp }) => timestamp));
current.push(
...timestamped
.filter(({ timestamp }) => timestamp === latestTimestamp)
.map(({ check }) => check),
);
}
return { checks: current, incompleteAttemptEvidence: [...incompleteAttemptEvidence].sort() };
}

function checkCi(
statusCheckRollup: StatusCheck[] | null,
repo: string,
exactDiff: ExactDiffIdentity,
): GateResult & { failingChecks?: string[]; pendingChecks?: string[]; missingChecks?: string[] } {
if (!statusCheckRollup || statusCheckRollup.length === 0) {
return { pass: false, details: "No status checks found" };
}

const { checks: currentChecks, incompleteAttemptEvidence } = currentCheckRollup(
statusCheckRollup,
repo,
exactDiff,
);

// Check that all required checks are present.
// Fork PRs from first-time contributors need "Approve and run" before
// pull_request workflows execute. Until then only pull_request_target
// checks (like check-pr-limit) and external bots (CodeRabbit) appear.
const presentNames = new Set(
statusCheckRollup.map((c) => c.name ?? c.context ?? "").filter(Boolean),
);
const presentNames = new Set(currentChecks.map((c) => c.name ?? c.context ?? "").filter(Boolean));
const missingChecks = REQUIRED_CHECK_NAMES.filter((name) => !presentNames.has(name));
if (missingChecks.length > 0) {
return {
Expand All @@ -325,7 +629,7 @@ function checkCi(
const failing: string[] = [];
const pending: string[] = [];

for (const check of statusCheckRollup) {
for (const check of currentChecks) {
const checkName = check.name ?? check.context ?? "(unknown)";

// StatusContext (e.g. CodeRabbit) uses `state` instead of `status`/`conclusion`.
Expand Down Expand Up @@ -363,7 +667,16 @@ function checkCi(
if (pending.length > 0) {
return { pass: false, details: `${pending.length} pending check(s)`, pendingChecks: pending };
}
return { pass: true, details: `All ${statusCheckRollup.length} checks green` };
if (incompleteAttemptEvidence.length > 0) {
return {
pass: false,
details: `${incompleteAttemptEvidence.length} check context(s) have incomplete latest-attempt evidence`,
failingChecks: incompleteAttemptEvidence.map(
(name) => `${name}: latest attempt evidence incomplete`,
),
};
}
return { pass: true, details: `All ${currentChecks.length} current checks green` };
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -659,7 +972,7 @@ function main(): void {
"--repo",
repo,
"--json",
"number,title,url,body,files,statusCheckRollup,mergeStateStatus,author",
"number,title,url,body,files,statusCheckRollup,mergeStateStatus,headRefOid,baseRefOid,author",
]) as {
number: number;
title: string;
Expand All @@ -668,6 +981,8 @@ function main(): void {
files: Array<{ path: string; status: string }>;
statusCheckRollup: StatusCheck[];
mergeStateStatus: string;
headRefOid: string;
baseRefOid: string;
author: PrIdentity | null;
} | null;

Expand All @@ -676,7 +991,11 @@ function main(): void {
process.exit(1);
}

const ci = checkCi(prData.statusCheckRollup);
const ci = checkCi(prData.statusCheckRollup, repo, {
number: prNumber,
headSha: prData.headRefOid,
baseSha: prData.baseRefOid,
});
const conflicts = checkConflicts(prData.mergeStateStatus);
const coderabbit = checkCodeRabbit(repo, prNumber);
const riskyCodeTested = checkRiskyCodeTested(prData.files ?? []);
Expand Down
4 changes: 4 additions & 0 deletions .agents/skills/nemoclaw-maintainer-day/scripts/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ export interface StatusCheck {
__typename?: string;
name?: string; // CheckRun field
context?: string; // StatusContext field
workflowName?: string; // CheckRun workflow identity
startedAt?: string; // CheckRun/StatusContext RFC3339 timestamp
completedAt?: string; // CheckRun RFC3339 timestamp
detailsUrl?: string; // CheckRun workflow-run identity when Actions produced it
status?: string; // CheckRun: COMPLETED, IN_PROGRESS, QUEUED, etc.
conclusion?: string; // CheckRun: SUCCESS, FAILURE, NEUTRAL, SKIPPED, etc.
state?: string; // StatusContext: SUCCESS, FAILURE, PENDING, ERROR
Expand Down
Loading