Peer review: clear majority, a cap on reviewers, shared bodies skip review

"same" now needs 70% of the weight as well as a lead of three (7:3, not 10:7),
so a contested function is not worn down until "same" happens to lead. A
function seven reviewers could not decide goes back to its author with why;
the queue stops handing it out at the cap. Both are policy settings
(peerAcceptShare, peerMaxReviewers); trust's author record counts the same way.

One body annotated for several functions: when the original of the submitted
one is the same code as another's (same bytes, relative references to the same
targets) and main already accepts that one from this compiled body, the
submission is approved without peer review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Saty 2026-10-25 15:09:18 +01:00
commit 50117671ee
8 changed files with 189 additions and 42 deletions

View file

@ -7,7 +7,7 @@ import { lintSubmission } from '../shared/lint.js';
import { freeTextErrors } from '../shared/freetext.js';
import { checkUnits } from '../shared/check.js';
import { reconcile } from '../shared/reconcile.js';
import { STATUS } from '../shared/compare.js';
import { STATUS, sameOriginal } from '../shared/compare.js';
import { listSources, isUnit } from '../shared/project.js';
import { changedNames, unitsMentioning } from './affected.js';
import { undefinedDeclarations } from './undefined.js';
@ -444,6 +444,29 @@ export class Verifier {
);
}
/**
* Another function annotated on the same compiled body as `target`, accepted on main (byte-
* identical or confirmed by peers) with this very compiled code, whose original is the same code
* as the target's (sameOriginal). Its ID, or null.
*/
acceptedTwin(check, target) {
if (!target?.symbol || !target.addr || !target.codeHash) return null;
const size = target.size?.original;
const pe = this.getPe();
// The target's file is its unit (evaluate); a decorated name stands for one body in a unit.
for (const u of check.units.filter((x) => x.file === target.file)) {
for (const f of u.functions) {
if (f.id === target.id || f.symbol !== target.symbol || !f.addr || f.codeHash !== target.codeHash) continue;
if (f.size?.original !== size) continue;
const main = this.store.get('SELECT status, confirmed, code_hash FROM func_status WHERE symbol_id = ?', f.id);
if (!main || main.code_hash !== f.codeHash) continue;
if (!(main.status === STATUS.EXACT || main.status === STATUS.UNRESOLVED || main.confirmed)) continue;
if (sameOriginal(pe, target.addr, f.addr, size)) return f.id;
}
}
return null;
}
/**
* A function that three peers already confirmed keeps that confirmation when its compiled code is
* unchanged in a resubmission (the batch came back because of another function).
@ -552,6 +575,15 @@ export class Verifier {
ev.feedback.trusted = true;
this.store.run('UPDATE attempts SET peer_skipped = 1 WHERE id = ?', a.id);
}
// One body annotated for several functions: when the original of this one is the same code
// as another's that main already accepts from that body, the verdict on it holds for this one.
const twin = ev.state === 'peer_review' && a.kind !== 'skip' ? this.acceptedTwin(check, ev.feedback.target) : null;
if (twin) {
ev.state = 'approved';
ev.feedback.summary = `not byte-identical (score ${(ev.score * 100).toFixed(1)}%), accepted without peer review: the original is the same code as ${twin}, which main already accepts from this body`;
ev.feedback.sameAs = twin;
this.store.run('UPDATE attempts SET peer_skipped = 1 WHERE id = ?', a.id);
}
if (ev.state === 'needs_cleanup' || ev.state === 'rejected') failed++;
this.finish(a, ev.state, ev.score, ev.feedback);
}
@ -661,7 +693,7 @@ export class Verifier {
state = auto ? 'approved' : 'in_review';
} else if (target.status === STATUS.MISMATCH || target.status === STATUS.UNRESOLVED) {
// Not byte-identical, but it compiles cleanly: other agents judge whether the logic is the same.
feedback.summary = `not byte-identical (score ${(score * 100).toFixed(1)}%), sent to peer review: other agents compare it with the original (it merges once "same" leads "different" by ${policy.peerMargin ?? 3}; at least ${policy.peerReviews ?? 3} "different" leading by ${policy.peerRejectMargin ?? 2} send it back)`;
feedback.summary = `not byte-identical (score ${(score * 100).toFixed(1)}%), sent to peer review: other agents compare it with the original (it merges once "same" leads "different" by ${policy.peerMargin ?? 3} with ${Math.round((policy.peerAcceptShare ?? 0.7) * 100)}% of the votes; at least ${policy.peerReviews ?? 3} "different" leading by ${policy.peerRejectMargin ?? 2}, or ${policy.peerMaxReviewers ?? 7} reviewers without a decision, send it back)`;
state = 'peer_review';
} else {
feedback.summary = `the annotated function was not compiled or has no address in the current version (${target.status})`;