Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cdec7cc
fix: preserve valid AI review peers
100yenadmin Aug 24, 2026
ec8de28
fix(governance): close peer preservation blockers
100yenadmin Aug 24, 2026
5ad3126
fix(governance): bind replay checks to exact peers
100yenadmin Aug 24, 2026
885f8ec
fix(governance): authenticate actor and preserve target replay state
100yenadmin Aug 25, 2026
b297547
fix(governance): validate prior target before reset
100yenadmin Aug 25, 2026
31c3a21
fix(governance): isolate peer invalidity during reconciliation
100yenadmin Aug 25, 2026
6841db5
fix: final-read preserved AI review peers
100yenadmin Aug 25, 2026
707c505
fix: final-read invalid AI review peers
100yenadmin Aug 25, 2026
82b0cba
fix: renew invalid AI review target packets
100yenadmin Aug 25, 2026
bdb0cb9
fix(governance): fail known peers on validator errors
100yenadmin Aug 25, 2026
584de0a
fix(governance): reset peers on snapshot failures
100yenadmin Aug 25, 2026
2dfc4e2
fix(governance): reset peers before target guard
100yenadmin Aug 25, 2026
9641f37
fix(governance): preflight dispatch receipts
100yenadmin Aug 25, 2026
03a0932
fix(governance): require typed integration IDs
100yenadmin Aug 25, 2026
8aeec0b
fix(governance): fail the event-identified dispatch target when open-…
100yenadmin Aug 26, 2026
5af35bf
Merge branch 'main' into fix/ai-review-peer-preservation
100yenadmin Aug 26, 2026
c81a28e
fix(governance): reset all known peers when dispatch-path validation …
100yenadmin Aug 26, 2026
c470bae
Merge branch 'fix/ai-review-peer-preservation' of https://github.com/…
100yenadmin Aug 26, 2026
df57ff3
Merge branch 'main' into fix/ai-review-peer-preservation
100yenadmin Aug 27, 2026
79dc393
fix(ai-review-gate): treat a clean validator FAIL as complete; fail c…
100yenadmin Sep 4, 2026
1574046
Merge branch 'main' into fix/ai-review-peer-preservation
100yenadmin Sep 4, 2026
7a8dbd3
fix(ai-review-gate): fail the discovered live tuple on any error; rej…
100yenadmin Sep 4, 2026
0d7881e
fix(ai-review-gate): reset every known snapshot when the pre-validati…
100yenadmin Sep 4, 2026
01aefff
fix(ai-review-gate): fail the tuple the target re-snapshot discovers;…
100yenadmin Sep 4, 2026
71d8b0a
fix(ai-review-gate): an incomplete peer snapshot fails the head pulls…
100yenadmin Sep 4, 2026
230d129
fix(ai-review-gate): receipt freshness is acceptance-time only — a pr…
100yenadmin Sep 4, 2026
40e8489
fix(ai-review-gate): a non-object rejection inside a peer snapshot ca…
100yenadmin Sep 4, 2026
57c84bf
fix(ai-review-gate): a partial target re-snapshot fails the drifted h…
100yenadmin Sep 4, 2026
193da34
fix(ai-review-gate): both peer final-read helpers fail the drifted he…
100yenadmin Sep 4, 2026
946beb6
Merge branch 'main' into fix/ai-review-peer-preservation
100yenadmin Sep 4, 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
192 changes: 139 additions & 53 deletions .github/workflows/ai-review-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,74 +61,160 @@ jobs:
const listFiles = (prNumber) => github.paginate(github.rest.pulls.listFiles,
{owner, repo, pull_number: prNumber, per_page: 100})
.then(files => files.map(file => file.filename));
const listTimeline = (prNumber) => github.paginate(
github.rest.issues.listEventsForTimeline,
{owner, repo, issue_number: prNumber, per_page: 100})
.then(events => events
.filter(event => ['base_ref_changed', 'head_ref_force_pushed', 'closed',
'reopened', 'convert_to_draft', 'ready_for_review'].includes(event.event))
.map(event => ({event: event.event, id: event.id, created_at: event.created_at})));
const listTrustedChecks = (head) => github.paginate(github.rest.checks.listForRef,
{owner, repo, ref: head, check_name: 'AI review exact-head', filter: 'all', per_page: 100})
.then(runs => runs.filter(run => run.name === 'AI review exact-head')
.map(run => ({name: run.name, app_id: run.app?.id, external_id: run.external_id,
head_sha: run.head_sha, status: run.status, conclusion: run.conclusion,
output: run.output, output_summary: run.output?.summary})));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const runValidator = async (input, protectedSha) => {
const source = await github.rest.repos.getContent({owner, repo,
path: 'scripts/ai_review_gate.py', ref: protectedSha});
if (Array.isArray(source.data) || source.data.encoding !== 'base64') throw Error('validator unavailable');
fs.writeFileSync('/tmp/gate.py', Buffer.from(source.data.content, 'base64'));
const run = cp.spawnSync('python', ['/tmp/gate.py'], {input: JSON.stringify(input), encoding: 'utf8'});
if (run.error) throw run.error;
return {run, result: JSON.parse(run.stdout || '{}')};
};
const snapshot = async (prNumber, defaultBranch) => {
const live = await github.rest.pulls.get({owner, repo, pull_number: prNumber});
const pr = live.data;
const files = await listFiles(prNumber);
const unresolved = await unresolvedThreads(prNumber);
const timeline = await listTimeline(prNumber);
const checks = await listTrustedChecks(pr.head.sha);
return {repository: `${owner}/${repo}`, pr_number: pr.number,
base_ref: pr.base.ref, base_sha: pr.base.sha, head_sha: pr.head.sha,
changed_paths: files, timeline_events: timeline,
unresolved_threads: unresolved, check_runs: checks,
api_complete: true, pagination_complete: true,
draft: pr.draft, state: pr.state, default_branch: defaultBranch};
};
const reconcileOpenPullRequests = async (defaultBranch) => {
const open = await github.paginate(github.rest.pulls.list,
{owner, repo, state: 'open', base: defaultBranch, per_page: 100});
const failures = [];
const snapshots = [], failures = [];
for (const candidate of open) {
try {
const live = await github.rest.pulls.get({owner, repo, pull_number: candidate.number});
if (live.data.state !== 'open' || live.data.base.ref !== defaultBranch)
throw Error('PR is no longer an open default-base change');
await emit(live.data.number, live.data.base.sha, live.data.head.sha, 'failure',
'Protected base changed; fresh exact-base/head review receipts are required.');
} catch (error) {
try { snapshots.push(await snapshot(candidate.number, defaultBranch)); }
catch (error) {
failures.push(`${candidate.number}:${error.message}`);
snapshots.push({repository: `${owner}/${repo}`, pr_number: candidate.number,
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
api_complete: false, pagination_complete: false, api_error: true,
changed_paths: [], timeline_events: [], check_runs: []});
}
}
if (failures.length) core.setFailed(`Failed to reset PRs: ${failures.join(',')}`);
return failures;
return {snapshots, failures};
};
const repository = await github.rest.repos.get({owner, repo});
const defaultBranch = repository.data.default_branch;
const branch = await github.rest.repos.getBranch({owner, repo, branch: defaultBranch});
const protectedSha = branch.data.commit.sha;
const failures = await reconcileOpenPullRequests(defaultBranch);
if (failures.length) return;
if (context.eventName !== 'repository_dispatch') return;
let prNumber = null, base = null, head = null;
const dispatchEvent = context.eventName === 'repository_dispatch';
let prNumber = null, base = null, head = null, result = null;
let conclusion = 'failure', summary = 'Validation failed closed.';
try {
const dispatch = context.payload.client_payload;
if (!dispatch || typeof dispatch !== 'object' || Array.isArray(dispatch) ||
!Array.isArray(dispatch.receipts)) throw Error('dispatch payload invalid');
prNumber = Number(dispatch.pr_number);
if (!Number.isInteger(prNumber) || prNumber <= 0)
throw Error('dispatch PR number invalid');
if (context.ref !== `refs/heads/${defaultBranch}` || context.sha !== protectedSha)
throw Error('dispatch must execute from current protected default branch');
let pr = await github.rest.pulls.get({owner, repo, pull_number: prNumber});
base = pr.data.base.sha;
head = pr.data.head.sha;
await emit(prNumber, base, head, 'failure', 'Validation started; fail closed until complete.');
if (pr.data.base.ref !== defaultBranch || pr.data.state !== 'open' || pr.data.draft)
throw Error('pull request is not an open, ready default-branch change');
const files = await listFiles(prNumber);
const unresolved = await unresolvedThreads(prNumber);
const source = await github.rest.repos.getContent({owner, repo,
path: 'scripts/ai_review_gate.py', ref: protectedSha});
if (Array.isArray(source.data) || source.data.encoding !== 'base64') throw Error('validator unavailable');
fs.writeFileSync('/tmp/gate.py', Buffer.from(source.data.content, 'base64'));
const input = {repository: `${owner}/${repo}`, pr_number: prNumber,
base_sha: base, head_sha: head, changed_paths: files,
receipts: dispatch.receipts, unresolved_threads: unresolved,
api_complete: true, pagination_complete: true};
const run = cp.spawnSync('python', ['/tmp/gate.py'], {input: JSON.stringify(input), encoding: 'utf8'});
if (run.error) throw run.error;
const result = JSON.parse(run.stdout || '{}');
const live = await github.rest.pulls.get({owner, repo, pull_number: prNumber});
const liveBranch = await github.rest.repos.getBranch({owner, repo, branch: defaultBranch});
const liveFiles = await listFiles(prNumber);
const liveUnresolved = await unresolvedThreads(prNumber);
if (live.data.head.sha !== head || live.data.base.sha !== base ||
live.data.base.ref !== defaultBranch || live.data.state !== 'open' || live.data.draft ||
liveBranch.data.commit.sha !== protectedSha ||
context.ref !== `refs/heads/${defaultBranch}` || context.sha !== protectedSha ||
JSON.stringify(liveFiles) !== JSON.stringify(files) || unresolved !== 0 ||
liveUnresolved !== 0) throw Error('PR, protected-base, files, or threads drift');
if (run.status !== 0 || result.decision !== 'PASS') throw Error('receipt validation failed');
conclusion = 'success';
summary = JSON.stringify(result);
const reconciled = await reconcileOpenPullRequests(defaultBranch);
const snapshots = reconciled.snapshots;
if (dispatchEvent) {
const dispatch = context.payload.client_payload;
const sender = context.payload.sender;
const run_attempt = Number(process.env.GITHUB_RUN_ATTEMPT || '1');
if (!dispatch || typeof dispatch !== 'object' || Array.isArray(dispatch))
throw Error('dispatch payload invalid');
if (typeof dispatch.pr_number !== 'number' || !Number.isInteger(dispatch.pr_number) || dispatch.pr_number <= 0) throw Error('dispatch PR number invalid');
prNumber = dispatch.pr_number;
const tuple = (await github.rest.pulls.get({owner, repo, pull_number: prNumber})).data;
base = tuple.base.sha; head = tuple.head.sha;
const priorTarget = snapshots.find(item => item.pr_number === prNumber);
if (!priorTarget || priorTarget.api_complete !== true ||
priorTarget.pagination_complete !== true || priorTarget.repository !== `${owner}/${repo}` ||
priorTarget.base_ref !== defaultBranch || priorTarget.base_sha !== base || priorTarget.head_sha !== head ||
priorTarget.state !== 'open' || priorTarget.draft)
throw Error('dispatch target missing or drifted from reconciliation');
const expectedExternalId = `ai-review-gate:${prNumber}:${base}:${head}`;
const priorExactChecks = (priorTarget?.check_runs || []).filter(check =>
check.app_id === 15368 && check.external_id === expectedExternalId &&
check.head_sha === head && check.status === 'completed' && check.conclusion === 'success');
if (priorExactChecks.length > 1) throw Error('DUPLICATE_TRUSTED_CHECK');
if (priorExactChecks.length === 1) {
const priorValidated = await runValidator({schema_version: '2', mode: 'peer_only', peers: [priorTarget]}, protectedSha);
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
if (priorValidated.run.status !== 0 || priorValidated.result.decision !== 'PASS' ||
priorValidated.result.peers?.length !== 1 || !priorValidated.result.peers[0].preserve)
throw Error('prior target packet invalid');
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
}
const priorDispatchIds = [];
for (const check of priorExactChecks) {
const stored = check.output_summary || check.output?.summary;
if (typeof stored !== 'string') throw Error('prior target packet missing');
try {
const packet = JSON.parse(stored);
if (typeof packet.dispatch_id !== 'string') throw Error('prior target dispatch ID invalid');
priorDispatchIds.push(packet.dispatch_id);
} catch (error) {
throw Error(`prior target packet invalid: ${error.message}`);
}
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
}
await emit(prNumber, base, head, 'failure', 'Protected base changed or stored packet invalid; validation started and fails closed until complete.');
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
if (sender?.login !== '100yenadmin' || Number(sender?.id) !== 239388517 ||
sender?.type !== 'User' || context.actor !== '100yenadmin' || Number(process.env.GITHUB_ACTOR_ID) !== 239388517)
throw Error('dispatch producer unauthenticated');
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
if (!Number.isInteger(run_attempt) || run_attempt !== 1)
throw Error('repository dispatch reruns cannot promote');
if (!Array.isArray(dispatch.receipts) || typeof dispatch.dispatch_id !== 'string')
throw Error('dispatch packet invalid');
if (context.ref !== `refs/heads/${defaultBranch}` || context.sha !== protectedSha)
throw Error('dispatch must execute from current protected default branch');
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
if (reconciled.failures.length) throw Error('open PR reconciliation incomplete');
const target = await snapshot(prNumber, defaultBranch);
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
const input = {schema_version: '2', target, peers: snapshots.filter(item => item.pr_number !== prNumber),
receipts: dispatch.receipts, producer: {login: sender.login, id: Number(sender.id), type: sender.type},
run: {id: process.env.GITHUB_RUN_ID, attempt: run_attempt},
dispatch_id: dispatch.dispatch_id, prior_dispatch_ids: priorDispatchIds};
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
const validated = await runValidator(input, protectedSha);
const run = validated.run; result = validated.result;
for (const peer of result.peers || []) {
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
if (!peer.preserve) {
const live = snapshots.find(item => item.pr_number === peer.pr_number);
if (live?.base_sha && live?.head_sha)
await emit(live.pr_number, live.base_sha, live.head_sha, 'failure',
JSON.stringify(peer));
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
}
}
const live = await github.rest.pulls.get({owner, repo, pull_number: prNumber});
const liveBranch = await github.rest.repos.getBranch({owner, repo, branch: defaultBranch});
const liveFiles = await listFiles(prNumber);
const liveTimeline = await listTimeline(prNumber);
const liveUnresolved = await unresolvedThreads(prNumber);
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
if (live.data.head.sha !== head || live.data.base.sha !== base ||
live.data.base.ref !== defaultBranch || live.data.state !== 'open' || live.data.draft ||
liveBranch.data.commit.sha !== protectedSha || context.ref !== `refs/heads/${defaultBranch}` ||
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
context.sha !== protectedSha || JSON.stringify(liveFiles) !== JSON.stringify(target.changed_paths) ||
JSON.stringify(liveTimeline) !== JSON.stringify(target.timeline_events) ||
liveUnresolved !== 0 || target.unresolved_threads !== 0)
throw Error('PR, protected-base, files, or threads drift');
if (run.status !== 0 || result.decision !== 'PASS') throw Error('receipt validation failed');
conclusion = 'success'; summary = JSON.stringify(result.packet);
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
} else {
const validated = await runValidator({schema_version: '2', mode: 'peer_only', peers: snapshots}, protectedSha);
const run = validated.run; result = validated.result;
Comment thread
100yenadmin marked this conversation as resolved.
Resolved
for (const peer of result.peers || []) {
if (!peer.preserve) {
const live = snapshots.find(item => item.pr_number === peer.pr_number);
if (live?.base_sha && live?.head_sha)
await emit(live.pr_number, live.base_sha, live.head_sha, 'failure', JSON.stringify(peer));
}
}
if (run.status !== 0 || result.decision !== 'PASS') throw Error('peer reconciliation incomplete');
return;
}
} catch (error) {
summary = `Validation failed closed: ${error.message}`;
}
Expand Down
Loading
Loading