// verify151.mjs — adversarial re-check of return #151 (job #644). // // Question: does return #151's patch do what its report says, and is its reach claim right? // Method: fetch the return and the served documents; apply the patch backwards and forwards // with a local unified-diff applier (no external `patch`); check every string the report // quotes; then emit the sentence that names (4.9) at every site in the served note with // whether that sentence restricts it to the band piece. // // Inputs (network, project base): /return/151, /docs/research/fixed-endpoint-discrepancy.md, // /docs/research/research-round-validation.md. Deterministic stdout, no timing. // Run: SAH_TOKEN=... node verify151.mjs import crypto from 'node:crypto'; const BASE = 'https://solveathome.org/projects/twin-primes'; const HEAD = { Authorization: `Bearer ${process.env.SAH_TOKEN}`, 'X-Session': '8937f38dd920d6b4780eaa59', 'X-Model': 'deepseek-v4.1-flash', 'User-Agent': 'buffy-agent (freebuff)', }; const sha = (s) => crypto.createHash('sha256').update(s).digest('hex'); const get = async (p) => { const r = await fetch(BASE + p, { headers: HEAD }); const t = await r.text(); if (r.status !== 200) throw new Error(`${p} -> HTTP ${r.status}`); return t; }; // --- unified-diff applier (context-verified, both directions) --------------- const parsePatch = (diff) => { const lines = diff.split('\n'); const hunks = []; let i = 0; while (i < lines.length) { const m = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/.exec(lines[i]); if (!m) { i++; continue; } const h = { oldStart: +m[1], oldCount: m[2] === undefined ? 1 : +m[2], newStart: +m[3], newCount: m[4] === undefined ? 1 : +m[4], ops: [] }; i++; while (i < lines.length && !lines[i].startsWith('@@')) { const l = lines[i]; if (l === '') { i++; continue; } // the split's trailing element const tag = l[0]; if (tag === ' ') h.ops.push({ t: 'ctx', text: l.slice(1) }); else if (tag === '-') h.ops.push({ t: 'del', text: l.slice(1) }); else if (tag === '+') h.ops.push({ t: 'add', text: l.slice(1) }); else if (tag === '\\') { /* \ No newline at end of file */ } else break; i++; } hunks.push(h); } return hunks; }; const apply = (text, hunks, dir) => { const lines = text.split('\n'); const out = []; let idx = 0; for (const h of hunks) { const start = (dir === 1 ? h.oldStart : h.newStart) - 1; while (idx < start) out.push(lines[idx++]); for (const op of h.ops) { const t = dir === 1 ? op.t : op.t === 'del' ? 'add' : op.t === 'add' ? 'del' : 'ctx'; if (t === 'ctx') { if (lines[idx] !== op.text) throw new Error(`context mismatch at line ${idx + 1}`); out.push(lines[idx++]); } else if (t === 'del') { if (lines[idx] !== op.text) throw new Error(`delete mismatch at line ${idx + 1}`); idx++; } else out.push(op.text); } } while (idx < lines.length) out.push(lines[idx++]); return out.join('\n'); }; const flat = (s) => s.replace(/\s+/g, ' ').trim(); const sentences = (para) => { const out = []; let start = 0; for (let i = 0; i < para.length; i++) if (para[i] === '.' && (i + 1 === para.length || para[i + 1] === ' ')) { out.push(para.slice(start, i + 1)); start = i + 1; } if (start < para.length) out.push(para.slice(start)); return out; }; const verdicts = (t) => { const lines = t.replace(/\r\n/g, '\n').split('\n'); const res = []; let i = 0; while (i < lines.length) { if (lines[i].trim() === '') { i++; continue; } const start = i; const buf = []; while (i < lines.length && lines[i].trim() !== '') { buf.push(lines[i].trim()); i++; } const para = buf.join(' '); if (!para.includes('(4.9)')) continue; for (const s of sentences(para)) if (s.includes('(4.9)')) res.push({ line: start + 1, s: s.trim() }); } return res; }; // --- 1. the return and the served state ------------------------------------- const ret = JSON.parse(await get('/return/151')); const served = await get('/docs/research/fixed-endpoint-discrepancy.md'); const validation = await get('/docs/research/research-round-validation.md'); const patch = ret.patch; const hunks = parsePatch(patch); console.log('# verify151 — re-check of return #151'); console.log(`return #151: type ${ret.type}, status ${ret.status}, final_rung ${ret.final_rung}, duplicate_of #${ret.duplicate_of}`); console.log(`report claims revision sha ${ret.revision_sha}`); console.log(`files[] sha ${ret.files.map((f) => f.sha256).join(' ')}`); console.log(`served note sha ${sha(served)}`); console.log(`CHECK A: served note is the revision (audit integrated) ${sha(served) === ret.revision_sha ? 'PASS' : 'FAIL'}`); console.log(`CHECK B: files[0] sha equals revision sha ${ret.files.every((f) => f.sha256 === ret.revision_sha) ? 'PASS' : 'FAIL'}`); // --- 2. patch applied both ways --------------------------------------------- const pre = apply(served, hunks, -1); const preSha = sha(pre); const fwd = apply(pre, hunks, 1); console.log(`reverse-applied sha ${preSha} (report claims pre-image 19b6b12c…)`); console.log(`CHECK C: reverse application reproduces the claimed pre-image ${preSha.startsWith('19b6b12c') ? 'PASS' : 'FAIL'}`); console.log(`CHECK D: forward application from the pre-image is byte-exact ${flat(fwd) === flat(served) && fwd === served ? 'PASS' : 'FAIL'}`); const changed = patch.split('\n').filter((l) => (l.startsWith('+') && !l.startsWith('+++')) || (l.startsWith('-') && !l.startsWith('---'))).length; console.log(`hunks ${hunks.length}, changed lines ${changed} (report claims 5 hunks, 17 changed lines)`); console.log(`CHECK E: hunk and changed-line counts ${hunks.length === 5 && changed === 17 ? 'PASS' : 'FAIL'}`); // --- 3. the strings the report quotes --------------------------------------- const quotes = [ ['issue 1, ledger verdict', 'The absolute band statement (4.9) is one stronger sufficient input, not a necessary condition.'], ['issue 2, section 4.4', '(4.9) would suffice, but no inspected source states it. A bound for the actual signed weights could suffice without (4.9).'], ['issue 3, section 8', 'Examples of stronger sufficient inputs are (4.9) or a treatment of the exceptional moduli in the cited Maynard range that admits the Mobius weight.'], ['issue 4, header', 'See research-round-validation.md section 13.'], ['issue 4, section 7', '[research-round-validation.md section 13](research-round-validation.md) owns this review'], ]; const preFlat = flat(pre); for (const [label, q] of quotes) console.log(`CHECK F (${label}): quoted text is in the pre-image at the stated place ${preFlat.includes(flat(q)) ? 'PASS' : 'FAIL'}`); console.log(`CHECK G: neither citation survives in the revised note ${!/section 13/.test(served) && /section 12 \(consumer in 12a\)/.test(served) ? 'PASS' : 'FAIL'}`); // --- 4. the citation claim, checked against the served record --------------- const sections = validation.replace(/\r\n/g, '\n').split('\n').filter((l) => /^#{2,3} \d/.test(l)).map((l) => l.trim()); console.log('\n# served sections of research-round-validation.md'); for (const s of sections) console.log(` ${s}`); console.log(`CHECK H: section 12 is the review of the repaired Type I estimate, 12a its consumer, 13 the integrated decision ${/## 12\. A2: independent reading/.test(validation) && /### 12a\./.test(validation) && /## 13\. Integrated research decision/.test(validation) ? 'PASS' : 'FAIL'}`); // --- 5. reach: every sentence in the note that names (4.9) ------------------ console.log('\n# research/fixed-endpoint-discrepancy.md, served: sentences naming (4.9)'); let band = 0; let unq = 0; for (const v of verdicts(served)) { const isSuff = /sufficient/i.test(v.s); const hasBand = /band/i.test(v.s); if (isSuff) { if (hasBand) band++; else unq++; } console.log(` line ${String(v.line).padStart(4)} ${!isSuff ? 'not-a-sufficiency-claim' : hasBand ? 'band-restricted ' : 'UNRESTRICTED '} ${v.s.slice(0, 150)}`); } console.log(` sufficiency sentences: ${band} band-restricted, ${unq} unrestricted`); console.log(`CHECK I: no unrestricted sufficiency claim survives in the note ${unq === 0 ? 'PASS' : 'FAIL'}`);