Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
// ever public" boundary is preserved because the raw numbers never reach the output at all.

function clamp(value: number, min: number, max: number): number {
// Non-finite input fails toward `min` (safe end of the range) — mirrors governor clampFraction /
// finiteNonNegativeInt so a NaN agreementRate can never propagate a NaN readinessScore (#6627).
if (!Number.isFinite(value)) return min;
return Math.min(max, Math.max(min, value));
}

Expand Down Expand Up @@ -53,7 +56,11 @@ export function applyContributorCalibration(
calibration: ContributorCalibrationSignal | null | undefined,
): number | null {
if (baselineReadinessScore === null) return null;
if (!calibration || calibration.sampleSize < MIN_CALIBRATION_SAMPLES) return baselineReadinessScore;
// Non-finite sampleSize is "insufficient history" — NaN < N is always false in JS, so without this
// guard a malformed sample count would silently bypass cold-start and apply a full adjustment (#6627).
if (!calibration || !Number.isFinite(calibration.sampleSize) || calibration.sampleSize < MIN_CALIBRATION_SAMPLES) {
return baselineReadinessScore;
}
const agreementRate = clamp(calibration.agreementRate, 0, 1);
const rawAdjustment = (agreementRate - NEUTRAL_AGREEMENT_RATE) * 2 * MAX_READINESS_ADJUSTMENT;
const adjustment = clamp(rawAdjustment, -MAX_READINESS_ADJUSTMENT, MAX_READINESS_ADJUSTMENT);
Expand Down
12 changes: 12 additions & 0 deletions test/unit/predicted-gate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,18 @@ describe("applyContributorCalibration (#2349)", () => {
const perfect: ContributorCalibrationSignal = { sampleSize: 500, agreementRate: 1 };
expect(applyContributorCalibration(null, perfect)).toBeNull();
});

it("REGRESSION (#6627): a non-finite sampleSize is cold-start — baseline unchanged, never a silent adjustment", () => {
const nanSample: ContributorCalibrationSignal = { sampleSize: Number.NaN, agreementRate: 0.9 };
expect(applyContributorCalibration(70, nanSample)).toBe(70);
});

it("REGRESSION (#6627): a non-finite agreementRate fails toward 0 (clamp min) — returns a finite [0, 100] score, never NaN", () => {
const nanRate: ContributorCalibrationSignal = { sampleSize: 20, agreementRate: Number.NaN };
const result = applyContributorCalibration(70, nanRate);
expect(result).toBe(70 - MAX_READINESS_ADJUSTMENT);
expect(Number.isFinite(result)).toBe(true);
});
});

describe("buildPredictedGateVerdict — personalized calibration wiring (#2349)", () => {
Expand Down