The first real cohort found the leak: one artifact was calibrating every stat

Shadow converged at 18:09:07Z and the 19:00Z slot produced cohort 0353c551.
It immediately falsified something no test had asked: 513 PUBLISHED NON-HITS
rows came back CERTIFIED_CALIBRATED with a served probability drawn from the
mlb-hits curve — total_bases 246, runs 149, rbi 125, walks 109, outs 28,
strikeouts 24, hits_allowed 20, earned_runs 17.

Two bugs, one on top of the other. `mergeProbabilityContract` passed only
{model_version, p_win}, dropping the row's identity; and the service's resolve
then stamped the {sport, stat} it had been BUILT with onto every read. So all
3,000 rows in the batch resolved as mlb hits.

The governance tests could not see it. They asked "does build() refuse another
stat?" — it does, and always did — and then exercised the merge with
hits-only rows. Production sends one mixed batch. The regression test now drives
the REAL collector with hits, total_bases, rbi, runs, walks, strikeouts and
home_runs at the same p_win and requires hits certified and every other stat
neither certified nor numeric.

Fixed in three layers, because one would have been the same single point that
just failed:
  1. the service no longer substitutes its own identity — the row's decides,
     and a read naming no stat resolves to no contract, which is UNSUPPORTED;
  2. the merge carries the row's sport and stat;
  3. probabilityContract refuses an artifact whose own sport/stat disagree with
     the contract it is being used under, independent of plumbing.

NO USER IMPACT. Shadow only: every block carries servable:false, live serving is
OFF, CALIBRATION_DEPLOYED is [], and the anonymous payload showed zero
calibration fields before and after. But this is exactly the defect that would
have served a hits calibration curve for strikeouts on the day live was enabled,
and only a real cohort surfaced it.

Two teeth were themselves wrong. Both runners checked "retention identity
changes" by grepping the diff for `stat:`, which fired on `stat: r.stat` — a
line that READS identity to hand it to a reader, not one that changes what
identifies a row. A guard that cannot tell those apart blocks the fix for the
defect it exists to protect against. Both are now behavioural: build a row
through the real collector and compare the identity tuple.

Artifact unchanged: mlb-hits-isotonic@2026-09-03, knot 5ae940ea163b7da2.
Suite 405/405, 5,659 passed. Teeth 34/34 + 10/10 + 23/23.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQJeAG8vcDoL5zkiaJyVb8
This commit is contained in:
Kev
2026-09-03 16:07:39 -04:00
parent 044df7a426
commit 981b26010a
6 changed files with 166 additions and 10 deletions
+76
View File
@@ -198,3 +198,79 @@ describe('the runtime can name its artifact with the shadow OFF', () => {
.toBe(JSON.stringify(pc.shadowState({}).artifact));
});
});
describe('ONE ARTIFACT, ONE STAT — the cross-stat leak found by cohort 0353c551', () => {
const retention = require('../../src/services/retentionService');
/** The real collector, with a MIXED-STAT batch — the shape production sends. */
function mixedBatch() {
const c = retention.createCollector({
snapshotId: 's1', sport: 'mlb', modelVersion: ERA, codeSha: 't',
gameDate: '2026-09-03', gameIdFor: () => 'mlb:2026-09-03:AAA@BBB',
});
for (const stat of ['hits', 'total_bases', 'rbi', 'runs', 'walks', 'strikeouts', 'home_runs']) {
c.onGraded(
{ player: `P ${stat}`, stat_type: stat, line: 0.5, sport: 'mlb', over_odds: -110, under_odds: -110 },
[{ direction: 'over', grade: 'C+', p_win: 0.65, confidence: 65 }],
);
}
return c.rows;
}
it('calibrates hits and NOTHING else, even in one mixed batch', async () => {
const contract = await svc.build(null, { sport: 'mlb', stat: 'hits' });
const merged = retention.mergeProbabilityContract(mixedBatch(), contract);
const byStat = {};
for (const r of merged) {
byStat[r.stat] = byStat[r.stat] || { certified: 0, served: 0, other: 0 };
const st = r.probability_contract.probability_state;
if (st === pc.STATE.CERTIFIED_CALIBRATED) byStat[r.stat].certified++;
else byStat[r.stat].other++;
if (r.probability_contract.served_probability != null) byStat[r.stat].served++;
}
// hits: calibrated. p_win 0.65 sits inside certified support.
expect(byStat.hits.certified).toBeGreaterThan(0);
expect(byStat.hits.served).toBeGreaterThan(0);
// EVERY other stat: no certified state and no number, at the SAME p_win.
for (const stat of ['total_bases', 'rbi', 'runs', 'walks', 'strikeouts', 'home_runs']) {
expect(byStat[stat].certified).toBe(0);
expect(byStat[stat].served).toBe(0);
}
});
it('a non-hits row resolves UNSUPPORTED — the contract does not exist for it', async () => {
const contract = await svc.build(null, { sport: 'mlb', stat: 'hits' });
const [tb] = retention.mergeProbabilityContract(
mixedBatch().filter((r) => r.stat === 'total_bases'), contract);
expect(tb.probability_contract.probability_state).toBe(pc.STATE.UNSUPPORTED);
expect(tb.probability_contract.served_probability).toBeNull();
expect(tb.probability_contract.derived.available).toBe(false);
});
it('the resolver does not substitute its own identity for the row\'s', async () => {
const contract = await svc.build(null, { sport: 'mlb', stat: 'hits' });
// a read naming another stat must NOT be resolved as hits
expect(contract.resolve({ sport: 'mlb', stat: 'rbi', model_version: ERA, p_win: 0.65 })
.probability_state).toBe(pc.STATE.UNSUPPORTED);
// and a read naming NO stat resolves to no contract, never a fallback
expect(contract.resolve({ model_version: ERA, p_win: 0.65 })
.probability_state).toBe(pc.STATE.UNSUPPORTED);
});
it('an artifact for another stat is refused even with correct plumbing', () => {
const wrong = { ...good, stat: 'total_bases' };
const r = pc.resolve(read(0.65), { estimate: est, artifact: wrong });
expect(r.probability_state).toBe(pc.STATE.VERSION_MISMATCH);
expect(r.served_probability).toBeNull();
expect(r.reason).toContain('total_bases');
});
it('and an artifact for another sport is refused', () => {
const r = pc.resolve(read(0.65), { estimate: est, artifact: { ...good, sport: 'wnba' } });
expect(r.probability_state).toBe(pc.STATE.VERSION_MISMATCH);
expect(r.served_probability).toBeNull();
});
});