docs(docs): R4.1 freeze record (RUST.md §10 draft, fixtures README R4 section)

Oracle table with commits, ledger totals, repository weight, freeze findings,
TypeScript baselines in Chromium, Firefox and WebKit with the watchdog
caveat; TODO R4.1a-f ticked; journal line.
This commit is contained in:
bchanot committed 2026-10-18 15:13:19 +02:00
1 parent 4439fd2420
commit aada7997de
4 files changed
+171 -7

No files matched your search

+143
View File
@@ -904,3 +904,146 @@ imports it and restyles `data-state` in place as before.
targets the local stack over HTTP): exercise it before the deployment that
needs it.
- WASM budget: 396 KB of 600 KB used; R4 adds the PDF reader and writer.
## 10. R4: the PDF core in Rust (in progress; R4.1 freeze done 2026-10-18)
Plan and contract: `.claude/tasks/plans/2026-10-17-rust-r4-pdf-core.md`
(revision 2, validated by the owner 2026-10-18 with the conditions of its
§A.6). Branch `feature/rust-r4-pdf-core`, cut from develop at 66909b6. This
section is a draft until the switch: it records what R4.1 froze and the
TypeScript baselines every later slice is measured against.
### 10.1 R4.1: what is frozen, and where (no Rust yet)
Every oracle below was generated by the TypeScript code at the commits
listed, behind `MAKE_R4_ORACLES=1`; without the flag the same test asserts
equality with the committed file. None of them is regenerated without the
owner (plan §B.5.1). The Step 6, R2 and R3 goldens and the R3 oracles are
byte-identical to develop (`git diff --stat develop..HEAD` on those paths is
empty).
| Oracle | Content | Files | Commit |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| O11, O13 | frozen TS attachment scanner as the N-1 PDF reader (6 tests); synthetic reports L (60 observations, 120 views) and CAP (500, 1,000) | `packages/core-wasm/tests/n-1/scanner/`, `apps/app/tests/fixtures/r4/reports/{L,CAP}.json` | 7ecbee9 |
| O8 | differential tolerance corpus on the full R3 import path, 51 PDFs with the outcome and message of today | `crates/core/tests/oracles/r4/tolerance.json`, `apps/app/tests/fixtures/pdf/r4/tolerance/` | 7a42979 |
| O1, O2, O3 | 12 draw logs (every text, image, line, rectangle, link at full precision); 12 R3-build PDFs plus the real-raster export of `v2full` observation 1 (two PNGs and a manifest) and the store-path PDF with its report; 3 pre-R2 envelope PDFs | `apps/app/tests/fixtures/goldens/r4/draw.*.json`, `apps/app/tests/fixtures/pdf/r3/`, `apps/app/tests/fixtures/pdf/step6/envelope.*.pdf` | 87b8873 |
| O7, O9 | 155 reader inputs as bytes with their outcome (regex-semantics rows included); 24 zlib framing inputs, 26 verdict rows of `inflateFlate` in Node | `crates/core/tests/oracles/r4/{read,inflate}.json`, `apps/app/tests/fixtures/pdf/r4/{read,inflate}/` | 96df15e |
| O4, O5, O6 | text (`measure` 8 rows with units per glyph and a 200-row width sample, `wrapLines` 5, `safeText` 2, `upper` 4), AFM widths of Helvetica, Helvetica-Bold and Times-Roman over WinAnsi, dates (grid of 4 locales × forms, 22 others), 108 PNG gate and decode cases over 103 files | `crates/core/tests/oracles/r4/{text,afm,dates,png}.json`, `crates/core/tests/fixtures/png/r4/` | 516342b |
| O10 | 230 `report:compare` invocations over 14 scenarios, 72 rows declared `r4Declared`; the test ledger | `crates/core/tests/oracles/r4/compare/`, `crates/core/tests/pdf/LEDGER.tsv`, `scripts/r4-ledger.mjs` | 4bdfda5 |
| O9 browsers, O12 | O9 verdicts in Chromium, Firefox and WebKit; the browser harness and the TS baselines of 10.2 | `crates/core/tests/oracles/r4/inflate.browsers.json`, `scripts/browser/` | 4439fd2 |
Ledger (`crates/core/tests/pdf/LEDGER.tsv`): 299 TypeScript cases at the
freeze, 150 `ported`, 28 `replaced`, 88 `kept`, 33 `deleted`; the census
check of plan §B.6 runs from R4.2 on.
Weight added to the repository by the freeze: 421 blobs, 11.63 MB raw,
5.92 MB stored (plan §A.2 OD-7 said about 5 MB; the overshoot is the
real-raster set and the browser results file, 0.65 MB raw, 45 KB stored).
`.gitleaks.toml` allowlists one generated file, `compare/compare.json`,
whose fixture names contain `key` next to sha256 digests.
Findings of the freeze, each one a declared difference or a port
constraint for the later slices (none changes the TypeScript):
- UPNG deviates from the PNG specification on two inputs (interlaced
filter-3 first row; 16-bit grey tRNS alpha offset); the gate accepts a
palette image without PLTE and pdf-lib then throws; `raster-bad-adler` is
refused by the gate but UPNG decodes it. R4.4 follows the oracles.
- `safeText` maps U+0178 to `ydieresis` (159) and drops the soft hyphen;
`numberToString(1e-7)` gives `0.00000009999999999999999`;
`formatDate("0000-01-01")` gives « 1 janvier 1900 » (years 0 to 99,
arbitration A3: unchanged).
- O8: the decoy-first attachment that R3 imports will be refused by R4
(OD-4 class, to present before the switch); an invalid byte between
tokens, a `/V` number followed by a string and a depth of 65 all give
`attachment_stripped` today.
- The APAFML notice is not in `@pdf-lib/standard-fonts`; R4.4 decides the
AFM source.
- The zlib-dependent verdicts of O9 depend on Node's bundled zlib
(1.3.2.1); the browser columns agree on every row (10.2).
### 10.2 TypeScript baselines (2026-10-18, `scripts/browser/results/2026-10-18-ts-baseline.json`)
Harness: `scripts/browser/` (README there), Playwright 1.64.0 outside the
repository, build `SHEET_BUNDLE=draft` at 87b8873 (the app, engine and
module sources are identical at 516342b, the recorded HEAD), served on
127.0.0.1 with the DEPLOY.md CSP plus `'wasm-unsafe-eval'`, locale fr.
Engines: Chromium headless shell 156.0.8078.4, Firefox 157.0, WebKit 27.2
(WPE MiniBrowser); none is a branded browser or a phone. Host: i7-11700B,
15.1 GB RAM, 8.4 GB available at start, no CPU throttling.
**The 4 GiB RSS watchdog is not a guaranteed memory limit.** It samples the
browser's process tree every 50 ms, so a faster allocation can overshoot
before the kill; summed VmRSS counts shared pages once per process; a
process outside the tree is not seen. It keeps the shared host away from
the kernel OOM killer; `stopped_by_ceiling` is a recorded result.
Export (TS engine). Medians over 3 runs, range in brackets; CAP one run.
"PNG blobs" counts every blob the rasteriser encoded, the first being the
partner SVG logo; the time runs on the page clock from the click to the
PDF Blob's object URL.
| Engine | Report | Outcome | Export s | PDF MB | PNG blobs | View PNG sum MB | View PNG KB | Stopped at |
| -------- | ------ | ------------------ | ---------------- | ------ | --------- | --------------- | ----------- | ----------------------------- |
| Chromium | demo | downloaded | 1.4 (1.4–1.4) | 2.7 | 8 | 3.7 | 508–614 | |
| Chromium | L | downloaded | 19.4 (19.4–19.5) | 41.9 | 121 | 65.8 | 508–614 | |
| Chromium | CAP | stopped_by_ceiling | | | | | | 4,102 MB at 101 s, ≥ 857 PNGs |
| Firefox | demo | downloaded | 1.6 (1.6–1.8) | 2.7 | 8 | 3.2 | 462–492 | |
| Firefox | L | downloaded | 35.3 (24.8–37.0) | 42.1 | 121 | 56.0 | 462–492 | |
| Firefox | CAP | stopped_by_ceiling | | | | | | 4,111 MB at 73 s, ≥ 577 PNGs |
| WebKit | demo | downloaded | 2.6 (2.6–2.6) | 2.4 | 8 | 2.4 | 345–371 | |
| WebKit | L | downloaded | 52.2 (52.2–52.2) | 36.8 | 121 | 42.1 | 345–371 | |
| WebKit | CAP | stopped_by_ceiling | | | | | | 4,101 MB at 384 s, ≥ 973 PNGs |
Export memory, MB. "Summed" is the browser tree, "Content" the content
processes. "Settled": forced GC through CDP plus 1 s in Chromium, 5 s idle
in Firefox and WebKit; the PDF Blob is still alive through its object URL
for 30 s (`download.ts`), so "after" includes it.
| Engine | Report | Summed before / peak / after | Content before / peak / after | JS heap before → after (CDP) |
| -------- | ------ | ------------------------------- | ------------------------------- | ---------------------------- |
| Chromium | demo | 473 / 640 (626–642) / 499 | 155 / 313 / 171 | 7.4 → 9.4 |
| Chromium | L | 475 / 1,128 (1,110–1,137) / 566 | 158 / 805 (787–814) / 201 | 8.1 → 11.1 |
| Chromium | CAP | 502 / 4,102 (stop) / – | 182 / 3,751 / – | 13.2 → – |
| Firefox | demo | 778 / 974 / 815 | 152 / 359 / 228 | |
| Firefox | L | 791 / 1,932 (1,929–1,998) / 943 | 160 / 1,351 (1,346–1,420) / 327 | |
| Firefox | CAP | 834 / 4,111 (stop) / – | 198 / 3,522 / – | |
| WebKit | demo | 499 / 815 / 778 | 306 / 617 / 581 | |
| WebKit | L | 512 / 1,370 (1,368–1,471) / 743 | 316 / 1,157 (1,154–1,209) / 510 | |
| WebKit | CAP | 574 / 4,101 (stop) / – | 375 / 3,895 / – | |
What the export rows say for the plan: CAP (1,000 views) does not complete
in any engine under 4 GiB with the TS engine, as §B.4 predicted; L costs
0.8 to 1.35 GB of content-process peak; browser PNGs are 0.35 to 0.61 MB
per view (WebKit about 40 % smaller than Chromium, hence the PDF sizes),
against the 0.54 MB resvg figure of §B.4.
Import (TS reader), 226 files × 3 engines (678 runs), a fresh context per
file; the duration runs on the Node clock from the file being set to the
first of editor, alert or inline error. No file gets a different outcome or
message in any engine. Every v2, v3, step6 and R3 PDF opens the editor in
39 to 112 ms. The largest growth is `tolerance/values-1m.pdf` (+105 / +153
/ +102 MB summed); the slowest inputs are the 20 to 50 MiB generated ones
(170 to 309 ms, all `error_no_attachment`). Chromium shows one long task on
9 files (52 to 173 ms), all among the 10 to 50 MiB inputs, `values-1m` and
`612-leaves`; Firefox and WebKit do not expose long tasks.
| Engine | Group (files) | Outcome | Duration ms median (range) | Max summed RSS growth MB | Max content growth MB |
| -------- | ------------------------------ | -------------------- | -------------------------- | ------------------------ | --------------------- |
| Chromium | base (3) / r3 (14) / step6 (3) | editor | 53 / 63 / 61 | 28 / 44 / 39 | 23 / 38 / 33 |
| Chromium | tolerance (51) | editor 33, error 18 | 57 (23–122) | 105 | 99 |
| Chromium | read (155) | editor 23, error 132 | 66 (22–309) | 75 | 68 |
| Firefox | base / r3 / step6 | editor | 39 / 73 / 69 | 63 / 54 / 52 | 14 / 33 / 32 |
| Firefox | tolerance / read | as Chromium | 53 (25–153) / 78 (25–286) | 153 / 86 | 131 / 61 |
| WebKit | base / r3 / step6 | editor | 52 / 62 / 66 | 52 / 54 / 53 | 50 / 52 / 51 |
| WebKit | tolerance / read | as Chromium | 59 (23–141) / 75 (22–238) | 102 / 101 | 100 / 99 |
O9 in the browsers: the 26 rows give the same verdict in Chromium 156,
Firefox 157 and WebKit 27.2 as in Node 24.21.0 (8 non-null, 18 null).
Not measured: CAP export time and PDF size (ceiling first); JS heap in
Firefox and WebKit (CDP is Chromium only, and Chromium's figure leaves out
ArrayBuffer memory); memory after an import settles (the §B.3 check belongs
to the R4 worker proof); real browsers and phones (J1 and the owner's
iPhone run). Seen on every page: the known `img-src` refusal of the
footer's external credit logo; no script or wasm violation.