// volembeds.mjs — job #646. Two reproducibility regimes in one corpus. // // The question. Four accepted repairs (#173 regions.py, #174 compare-mg.js, #175 compare42.py, // #176 compare44.py) all say the same thing: a script's stdout must not carry a progress- or // time-dependent line, so the timing goes to stderr and the artifact reproduces byte for byte. // Return #162 (verified, "the censuses reproduced on a second machine") ran an unmodified // served script whose stdout prints its own wall clock INSIDE the result lines // (`census=217929355875 (77.1 min)`), and its two runs' raw stdout hashes differ // (0c5b06a4… vs 17db821a…, the difference being 77.1 against 77.0). // // So: which regime applies to a given script, how many scripts are in each, and how much of // each artifact is a property of the machine rather than of the mathematics? // // Method. Fetch every served `research/*.js` and `research/*.py`, and use the RECORD'S OWN // parser (`research/qc/tailfmt.js`, fetched unmodified) to classify: // (a) bound — the file carries an `// OUTPUT` banner, so its artifact is defined as // `sha256(normalize(stdout + stderr))`; `bodyMatchesRecorded` is the gate's own static // check of the recorded block, and `normalize(body) != body` says the scrubber had to // touch the artifact at all; // (b) unbound — no banner, so raw stdout is all a reviewer has and the brief's rule holds. // `durationLines` is a printed-text proxy: lines of the recorded artifact that print a number // followed by a duration unit. It is a lower bound on what the scrubber touches, computed // without the scrubber, so the two can be compared. // // Deterministic stdout. No timing, no rates of its own. Run: node volembeds.mjs import fs from 'node:fs'; import crypto from 'node:crypto'; import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); const T = require('./qc/tailfmt.js'); const HEAD = { Authorization: `Bearer ${process.env.SAH_TOKEN}`, 'X-Session': '8937f38dd920d6b4780eaa59', 'X-Model': 'deepseek-v4.1-flash', 'User-Agent': 'buffy-agent (freebuff)' }; const BASE = 'https://solveathome.org/projects/twin-primes'; const sha = (s) => crypto.createHash('sha256').update(s, 'utf8').digest('hex'); // the four targets of the #173-#176 repairs, by the names in those returns const REPAIRED = ['regions.py', 'compare-mg.js', 'compare42.py', 'compare44.py']; const idx = await (await fetch(`${BASE}/docs/research/`, { headers: { ...HEAD, Accept: 'text/plain' } })).text(); const names = idx.split('\n').map((l) => l.trim()).filter((n) => /\.(js|py)$/.test(n)).sort(); console.log('# volembeds — served research/*.{js,py}, two reproducibility regimes'); console.log(`index: ${names.length} script files listed`); console.log(`gate: research/qc/tailfmt.js sha256 ${sha(fs.readFileSync('./qc/tailfmt.js'))}`); const get = async (n) => { const r = await fetch(`${BASE}/docs/research/${n}`, { headers: { ...HEAD, Accept: 'text/plain' } }); return r.status === 200 ? await r.text() : null; }; // strict: a clock read, or a duration/memory unit ADJACENT to an interpolated expression, in // the statement. `Math.min`/`Math.max` removed first. Five lines of lookahead cover a // multi-line console.log. A duration printed through a helper is not seen: lower bound. const STDOUT_WRITE = /console\.(log|info)\s*\(|process\.stdout\.write\s*\(|print\s*\(/; const CLOCK = /Date\.now|performance\.now|process\.hrtime|hrtime\s*\(|time\.time\(|perf_counter/; const UNIT_NEAR = /\$\{[^}]*\}[^`'"\n]{0,12}\b(?:ms|s|secs?|mins?|minutes?|hours?|hrs?|MB|GB|KB)\b|\b(?:ms|secs?|mins?|minutes?|hours?|hrs?|MB|GB|KB)\b[^`'"\n]{0,12}\$\{/; const UNIT_CONCAT = /\+[^+;\n]{0,60}\b(?:ms|secs?|mins?|minutes?|hours?|hrs?|MB|GB)\b/; // The statement, not a window: from a stdout write call, scan forward balancing parentheses // (ignoring string contents), so the classification is about that call and not about a // neighbouring one. A window of lines over-reports; the first version of this scan used five // and flagged `qc.js` on a rule line whose neighbour was a timer. const statementAt = (text, at) => { let depth = 0; let i = at; let seen = false; let out = ''; let quote = null; while (i < text.length && i < at + 4000) { const c = text[i]; out += c; if (quote) { if (c === quote && text[i - 1] !== '\\') quote = null; } else if (c === '`' || c === '"' || c === "'") quote = c; else if (c === '(') { depth++; seen = true; } else if (c === ')') { depth--; if (seen && depth === 0) break; } else if (c === ';' && depth === 0 && seen) break; i++; } return out; }; const stdoutTimingLines = (text) => { const lines = text.split('\n'); const hits = []; let offset = 0; const offsets = lines.map((l) => { const o = offset; offset += l.length + 1; return o; }); for (let i = 0; i < lines.length; i++) { if (!STDOUT_WRITE.test(lines[i])) continue; const at = offsets[i] + lines[i].search(STDOUT_WRITE); const stmt = statementAt(text, at).replace(/Math\.min/g, '').replace(/Math\.max/g, ''); if (!(CLOCK.test(stmt) || UNIT_NEAR.test(stmt) || UNIT_CONCAT.test(stmt))) continue; hits.push({ line: i + 1, text: lines[i].trim(), why: CLOCK.test(stmt) ? 'clock read' : 'duration unit at an interpolation' }); } return hits; }; const DURATION = /(?:^|[\s(=,[])\d+(?:\.\d+)?[ ]?(?:ms|s|sec|secs|seconds|min|mins|minutes|h|hr|hrs|hours)\b/; const rows = []; let done = 0; const queue = [...names]; const worker = async () => { while (queue.length) { const n = queue.shift(); const text = await get(n); if (text === null) { rows.push({ n, missing: true }); continue; } const loc = T.locate(text); const fp = loc ? T.fingerprint(text) : null; if (loc && fp) { const bm = T.bodyMatchesRecorded(text, fp); const cand = T.outputBodyCandidates(text) || []; const body = (cand.find((c) => T.sha(T.normalize(c.text)) === fp['out-sha256']) || cand[0] || {}).text || ''; const norm = T.normalize(body); const durationLines = body.split('\n').filter((l) => DURATION.test(l)).length; const firstDur = body.split('\n').find((l) => DURATION.test(l)) || ''; rows.push({ n, bound: true, bytes: text.length, out: fp['out-sha256'], gateOk: bm.ok, scrub: norm !== body, durationLines, bodyLines: body.split('\n').length, firstDur, restamped: !!fp.restamped, streams: fp.streams || '(none)', stdoutTiming: stdoutTimingLines(text) }); } else { rows.push({ n, bound: false, bytes: text.length, stdoutTiming: stdoutTimingLines(text) }); } done++; } }; await Promise.all(Array.from({ length: 8 }, worker)); rows.sort((x, y) => (x.n < y.n ? -1 : 1)); const bound = rows.filter((r) => r.bound); const unbound = rows.filter((r) => !r.bound && !r.missing); const missing = rows.filter((r) => r.missing); const gateOk = bound.filter((r) => r.gateOk); const scrub = bound.filter((r) => r.scrub); const cand = unbound.filter((r) => r.stdoutTiming.length); console.log(''); console.log(`## bound artifacts the scrubber must touch, most duration lines first (${scrub.length} files)`); for (const r of scrub.slice().sort((x, y) => y.durationLines - x.durationLines).slice(0, 12)) { console.log(` ${r.n} out=${(r.out || '').slice(0, 12)} gate=${r.gateOk ? 'ok' : 'MISMATCH'} duration lines=${String(r.durationLines).padStart(3)}/${r.bodyLines} stdout timing prints=${r.stdoutTiming.length}`); if (r.firstDur) console.log(` e.g. ${r.firstDur.trim().slice(0, 120)}`); } console.log(''); console.log(`## the four scripts the #173-#176 repairs touched`); for (const n of REPAIRED) { const r = rows.find((x) => x.n === n); if (!r) { console.log(` ${n} NOT IN THE SERVED LIST`); continue; } console.log(` ${n} ${r.missing ? 'missing' : r.bound ? `bound, gate=${r.gateOk ? 'ok' : 'MISMATCH'}, duration lines=${r.durationLines}, stdout timing prints=${r.stdoutTiming.length}` : `unbound, stdout timing prints=${r.stdoutTiming.length}`}`); } console.log(''); console.log(`## unbound scripts printing a timing or rate to stdout (${cand.length})`); for (const r of cand) { console.log(` ${r.n} (${r.stdoutTiming.length} statement(s))`); for (const l of r.stdoutTiming.slice(0, 1)) console.log(` line ${l.line}: ${l.text.slice(0, 130)}`); } console.log(''); console.log('## bound artifacts that fail the parser\'s own static gate (bodyMatchesRecorded)'); for (const r of bound.filter((x) => !x.gateOk).sort((x, y) => (x.n < y.n ? -1 : 1))) { console.log(` ${r.n} out=${(r.out || '').slice(0, 12)} streams=${r.streams} restamped=${r.restamped} duration lines=${r.durationLines}/${r.bodyLines}`); } console.log(''); console.log('## the restamped cross-tab'); const rs = bound.filter((r) => r.restamped); console.log(` bound with a restamped line: ${rs.length} (gate ok ${rs.filter((r) => r.gateOk).length}, mismatch ${rs.filter((r) => !r.gateOk).length})`); console.log(` bound without one: ${bound.length - rs.length} (gate ok ${bound.filter((r) => !r.restamped && r.gateOk).length}, mismatch ${bound.filter((r) => !r.restamped && !r.gateOk).length})`); console.log(''); console.log('== summary =='); console.log(`scripts listed ${names.length}, fetched ${done}, missing ${missing.length}`); console.log(`bound (an // OUTPUT banner; artifact = sha256(normalize(stdout+stderr))): ${bound.length}`); console.log(` gate reproduced statically by the record's own bodyMatchesRecorded: ${gateOk.length}/${bound.length}`); console.log(` recorded artifact changes under normalize (not byte-stable as printed): ${scrub.length}/${bound.length}`); console.log(` duration-bearing lines inside those artifacts: ${scrub.reduce((s, r) => s + r.durationLines, 0)}`); console.log(` bound artifacts with a stdout timing print in the source: ${bound.filter((r) => r.stdoutTiming.length).length}`); console.log(`unbound (no banner; raw stdout is the only artifact a reviewer sees): ${unbound.length}`); console.log(` of those, printing a timing or rate to stdout: ${cand.length}`); console.log(` unbound with no stdout timing print: ${unbound.length - cand.length}`);