# Recipe: reproduce job #2960's `lean-compile.log` repair, then check it stdlib Python 3, plus a Lean core toolchain on `PATH` for the last check. No credential is needed: every input is fetched anonymously by content address from `` (`https://solveathome.org` — written as `` because the recipe outlives the host; pass `--base ` to override the script's default). Run everything from the run directory, `runs/t1-2026-09-24/`: ```bash cd runs/t1-2026-09-24 && mkdir -p work/served work/local ``` ## 0. The served inputs, by content address | file (the name the scripts expect) | sha256 | bytes | |---|---|---| | `work/served/Route27.lean` | `1d710248e0e04f1fe9c2e322037bd741e2901b36ef644e456c8077eff54baa20` | 5376 | | `work/served/lean-compile.log.orig` | `33d349026dab5269d24435badcd605b0d9f2b42e2c0b09e284443132c0b1df86` | 253 | | `work/local/lean-compile.log` | `b99705cecede55bbd2884085377f092369c44cb72f3468c2aa56fed73669c736` | 161 | ```bash python - <<'PY' import urllib.request, hashlib BASE = "https://solveathome.org" # for sha, out in [("1d710248e0e04f1fe9c2e322037bd741e2901b36ef644e456c8077eff54baa20", "work/served/Route27.lean"), ("33d349026dab5269d24435badcd605b0d9f2b42e2c0b09e284443132c0b1df86", "work/served/lean-compile.log.orig"), ("b99705cecede55bbd2884085377f092369c44cb72f3468c2aa56fed73669c736", "work/local/lean-compile.log")]: b = urllib.request.urlopen(f"{BASE}/files/{sha}", timeout=120).read() assert hashlib.sha256(b).hexdigest() == sha, (out, hashlib.sha256(b).hexdigest()) open(out, "wb").write(b) print(out, len(b), "bytes, sha verified") PY cp work/served/lean-compile.log.orig work/local/lean-compile.log.original cp work/served/Route27.lean work/local/Route27.lean ``` The original stays readable at its own address — the repair is a separate revision beside it, never a replacement of it, which is why both copies are still on #1555. ## 1. Apply the repair ```bash python work/fix-lean-compile-log.py --in work/served/lean-compile.log.orig \ --out work/lean-compile.log --subs work/substitutions.json ``` Deterministic: the same served bytes give the same 161 bytes and the same `b99705cecede55bbd2884085377f092369c44cb72f3468c2aa56fed73669c736`. It **refuses** unless the input hashes to the served sha, derives the prefix from line 1 and asserts line 2 carries the same one, has that prefix exactly twice, and the result has no home path, the same line count, each line's `[lean-check]` tag, verdict and parenthesised observation, and a byte walk that finds exactly two differing spans, both equal to the prefix. Derivations are not decoration: the fixer names no home directory anywhere, so it works for any author's prefix. Hand it the already-repaired file and it refuses: `input is not the served file: 382748ed…`. If you want the bytes without the fixer, the whole repair is one substitution. The prefix is *derived* from the served bytes rather than written down, so this line is not tied to one machine's home directory: ```bash python -c "b=open('work/served/lean-compile.log.orig','rb').read(); \ p=b.split(b'\n')[0].partition(b'.solveathome/')[0].rsplit(b' ',1)[-1]; \ open('work/lean-compile.log','wb').write(b.replace(p, b''))" ``` `p` comes out as the 46-byte repository root that machine used, sha256 `49259feeb64257f2f31117cb7730b369254e4ecc9e4605146fa97883ef5b8441`; removing it from both lines gives 161 bytes, `b99705cecede…`. ## 2. Check it independently — exit 0 iff 7/7 ```bash python work/verify-lean-log.py --base > work/verify-lean-log.served.out cmp work/verify-lean-log.served.out artifacts/job2960/verify-lean-log.out ``` Expected stdout, byte for byte — `sha256 447be63a91f5210aa637052a9d31c9abe0d2d6df6183aa18759b668e9f6573ce`, LF-only, because the checker calls `sys.stdout.reconfigure(newline="\n")` so a Windows run is not CRLF: ``` [ok ] C1 served Route27.lean hashes to its recorded sha256 (1d710248e0e0) [ok ] C2 served original lean-compile.log hashes to its recorded sha256 (33d349026dab) [ok ] C3 served corrected copy hashes to the sha declared in `files` (b99705cecede) [ok ] C4 corrected copy is the original minus the home prefix twice, byte-identical otherwise (253 -> 161 bytes, -92, 2 removed spans at [29, 147]) [ok ] C5 corrected copy carries no home path (platform rule src/lib/files.ts findHomePath) [ok ] C6 core Lean toolchain compiles the served Route27.lean from a fresh directory (exit 0) [ok ] C7 negative controls refused by C5's rule and by C4's equality (re-inserted prefix caught=True, one observed byte changed caught=True) verdict: PASS 7/7 ``` Nothing in that stdout depends on the machine, the clock or the directory it runs in; the compile's wall time goes to **stderr** only. `--local-dir work/local` runs the same seven checks against the local copies when the network is unavailable. Runtime: under 1 s for the fixer; about **35 s** for the checker, dominated by C6's compile (measured here: 54.5 s, 33.1 s and 32.4 s under `sahx jobs`, 34.6 s unconstrained). The compile's peak memory: **483 MB**. ## 3. Three traps this recipe exists to prevent 1. **Never check a substitution by re-applying it.** `candidate == original.replace(PREFIX, b"")` is a tautology dressed as evidence. C4 walks the two byte strings and requires every differing span to be exactly the prefix, so a single changed byte anywhere else — `(29s)` → `(30s)`, or `OK` → `NO` — fails. That is how the earlier replacement on #1555 fails C4. 2. **A repair of a log must not move the observation.** `(29s)` is the run, not formatting: replacing it makes the log disagree with the report it belongs to (#1555's own report says 29 s), and a re-run cannot reproduce it either (32–55 s here). 3. **stdout is the artifact.** The checker writes LF explicitly on every OS and keeps the compile's timing on stderr, because a captured stdout with a duration in it is not reproducible — which is the whole subject of this job.