From 6deee65b7985031dd176ca1160deb58250d31483 Mon Sep 17 00:00:00 2001 From: bchanot Date: Sun, 18 Oct 2026 16:59:37 +0200 Subject: [PATCH] =?UTF-8?q?docs(docs):=20RUST.md=20=C2=A710.4=20browser=20?= =?UTF-8?q?results=20of=20the=20Rust=20import;=20TODO=20R4.2=20closed,=20j?= =?UTF-8?q?ournal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .claude/memory/journal.md | 1 + .claude/tasks/TODO.md | 5 ++- docs/development/RUST.md | 89 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index d045aaf2..8f2e2f1e 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -284,3 +284,4 @@ Owner validated R4.0 plan with conditions (BDR-057, plan §A.6, LRN-059/060). R3 - 2026-10-18 owner iPhone run of the Safari fix: all OK → check green (1015) → gitflow finish fcff92b. Owner go R4.1: feature/rust-r4-pdf-core cut from develop. - 2026-10-18 R4.1 freeze done on feature/rust-r4-pdf-core (eff5405..4439fd2): O1-O13 generators + oracles committed, ledger 299 rows (150 ported / 28 replaced / 88 kept / 33 deleted), browser harness scripts/browser (Chromium 156, Firefox 157, WebKit 27.2, 4 GiB RSS watchdog = not guaranteed limit). TS baselines: CAP export stopped by ceiling in all 3 engines, L peak content 0.8-1.35 GB, import 226 files same outcome everywhere; O9 browsers = Node on 26 rows. Repo +5.92 MB stored vs ~5 MB approved. Frozen step6/r2/r3 goldens untouched. .gitleaks.toml narrow allowlist for compare.json. Next: checkpoint report to owner, then R4.2. - 2026-10-18 owner validated R4.1 (fixtures 5.92 MB kept incl. real raster; gitleaks exception OK if narrow; decoy-first OD-4 kept in register, risk to explain before R4.3; UPNG/text oracles kept; headless OK for R4.1). Go R4.2 (reader, inflate, JSON pre-scan, UTF-8 parity, wasm facade, memory protections). Hard stop end of R4.2 before any import switch; budgets whole-browser; gains compared on identical perimeters. No merge, no R5, no release/prod. +- 2026-10-18 R4.2 done on feature/rust-r4-pdf-core (21d34fb..): pdf::read (scan, strings, stamp, inflate, probe), json_js, import_pdf, SheetHandle.import_pdf; O7 144/144, O9 38/38, O8 51 (4 declared: 3 OD-4 lone surrogate in overwritten dup value, 1 OD-3 values-1m), reference PDFs all import, through wasm too. OD-3: MAX_JSON_VALUES 400,000 (10 × CAP envelope 39,652), rescue copy guarded, --max-memory 1 GiB trap proven; hostile 16 MiB: 784 MiB → 16 MiB linear. Security gate BLOCK(1) (count stopped past depth cap → bypass) fixed 593893a, re-gate PASS. Browser run 3 engines: 666/678 agree, W4 max 68 MiB, W2 46 ms; open: after-GC residue 11.7 MiB first import (one-time), worker holds file twice on 50 MiB inputs (WebKit 324 MiB). Module 422 KB gzip. STOP before R4.3: owner to confirm thresholds. diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index d9905374..b0042f39 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -220,8 +220,9 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo - [x] R4.2b `pdf/read/inflate.rs` (miniz_oxide, zlib framing, DecompressionStream verdicts): cargo tests on O9 (26 rows) + O7 flate inputs; Node verdict pinned, browsers agree (inflate.browsers.json) - [x] R4.2c `pdf/json_js.rs`: `{` probe after BOM/whitespace, depth 64 + value-count pre-scan (OD-3 budget hook), lossy UTF-8 + one BOM (TextDecoder parity), overflow → null rewrite, lone-surrogate-neutralised probe through parse_json, versioned check; unit tests + text parity cases - [x] R4.2d `pdf/read/probe.rs` locate_attachment (shared 16 MiB budget, `break` on oversized, cancelled inflation not charged), `pdf/import.rs` (read → session::import_archive), op `pdf.import` + `SheetHandle.importPdf(bytes)` on the wasm facade, ts-rs `PdfImportKind`; cargo tests on O7 locate/readAttachedDocument/readReportArchive rows, O8 differential (51), Node tests through the wasm build on O2/O3/O8/hostile - - [~] R4.2e (Node part done: cap 400,000 = 10 × CAP envelope 39,652 values, rescue copy guarded, 1 GiB ceiling proven; browser run pending) OD-3: measurement harness (fresh wasm instance per case, time, linear memory; Node) on the hostile classes (16 MiB token-dense attachment, 16 MiB rescue copy, 50 MiB file, 16 MiB inflation, 32 candidates) + browser harness (worker page, content-process RSS, same perimeter as the TS import baseline); value budget = 10 × largest legitimate archive; `--max-memory`; W1 module size; thresholds table for the owner - - [ ] R4.2f record: RUST.md §10.3 (reader, parity, budgets, thresholds, residual risks), decoy-first (OD-4) risk explanation + proof it blocks no legitimate Faunosteo document, ledger `ported` targets exist, suites green (rust:check, wasm:build, check); STOP for the owner before R4.3 + - [x] R4.2e (Node part done: cap 400,000 = 10 × CAP envelope 39,652 values, rescue copy guarded, 1 GiB ceiling proven; browser run pending) OD-3: measurement harness (fresh wasm instance per case, time, linear memory; Node) on the hostile classes (16 MiB token-dense attachment, 16 MiB rescue copy, 50 MiB file, 16 MiB inflation, 32 candidates) + browser harness (worker page, content-process RSS, same perimeter as the TS import baseline); value budget = 10 × largest legitimate archive; `--max-memory`; W1 module size; thresholds table for the owner + - [ ] R4.2e follow-ups for R4.3: worker holds the File ArrayBuffer and its linear copy together (50 MiB file: WebKit content peak 324 MiB vs 76 TS) → release the buffer after the glue copy or read in chunks; after-GC residue 11.7 MiB first import (one-time, +1.9 then −0.2 on repeats) → owner decides the §B.3 criterion; `scripts/browser/lib/import-inputs.mjs` shortcut: copy of import-baseline's listing, fold into one module when import-baseline is retired (R4.8) + - [x] R4.2f (done 2026-10-18; RUST.md §10.3 + §10.4; STOP for the owner before R4.3) record: RUST.md §10.3 (reader, parity, budgets, thresholds, residual risks), decoy-first (OD-4) risk explanation + proof it blocks no legitimate Faunosteo document, ledger `ported` targets exist, suites green (rust:check, wasm:build, check); STOP for the owner before R4.3 - [ ] R4.3 import worker + rescue copy (B.1.5, OD-1 applied, browser proof per slice from here) - [ ] J1 owner checkpoint (plan A.4) - [ ] R4.4 layout → draw log diff --git a/docs/development/RUST.md b/docs/development/RUST.md index 27ba077e..f5ae325b 100644 --- a/docs/development/RUST.md +++ b/docs/development/RUST.md @@ -1194,3 +1194,92 @@ Residual risks and open points for the owner (R4.2 checkpoint): - The probe parses the candidate twice (version check, then the session), as the TypeScript did; the peak is one tree since the first is dropped. A single parse would need the gated session reader to take a value. + +### 10.4 R4.2: the Rust import in the browsers (2026-10-18, `scripts/browser/results/2026-10-18-r4-import.json`) + +Harness `scripts/browser/r4-import.mjs` (README there): the shape plan §B.1.5 +gives the application at R4.3, a module worker created for one import, the +compiled `WebAssembly.Module` posted by the main thread, the `File` read in +the worker, one `SheetHandle.import_pdf`, the worker terminated; the same +226 files, engines, groups and RSS metrics as the TypeScript baseline of +10.2 (`compare-imports.mjs` prints both side by side). Chromium 156 headless +shell, Firefox 157, WebKit 27.2 (WPE), headless only; the 4 GiB RSS watchdog +is not a guaranteed memory limit. Module `ba070c29…`, 1,252,727 B, memory +maximum 16,384 pages (1 GiB). + +Agreement: 666 of 678 (engine, file) pairs give the same outcome as the TS +import (editor ↔ `ok`, error ↔ a failure kind). The 12 others are the four +declared files in each engine: `values-1m` (OD-3), `surrogate-content- +overwritten`, `surrogate-version-overwritten`, `two-files-decoy-first` +(OD-4). Mapped to the §B.1.8 messages, no other difference. + +Legitimate groups, TS → Rust (median ms on the Node clock, with the Rust +page clock after the slash; max RSS growth MiB summed / content): + +| Engine | base | r3 | step6 | tolerance | read | +|---|---|---|---|---|---| +| Chromium ms | 53 → 65 / 32 | 63 → 80 / 43 | 61 → 65 / 41 | 57 → 63 / 31 | 66 → 68 / 29 | +| Chromium MiB | 28 / 23 → 17 / 15 | 44 / 38 → 16 / 16 | 39 / 33 → 17 / 17 | 105 / 99 → 18 / 16 | 75 / 68 → 117 / 115 | +| Firefox ms | 39 → 67 / 22 | 73 → 55 / 30 | 69 → 54 / 28 | 53 → 46 / 21 | 78 → 45 / 21 | +| Firefox MiB | 63 / 14 → 52 / 9 | 54 / 33 → 60 / 35 | 52 / 32 → 52 / 26 | 153 / 131 → 58 / 35 | 86 / 61 → 154 / 127 | +| WebKit ms | 52 → 45 / 25 | 62 → 55 / 37 | 66 → 50 / 33 | 59 → 44 / 26 | 75 → 43 / 24 | +| WebKit MiB | 52 / 50 → 61 / 59 | 54 / 52 → 71 / 67 | 53 / 51 → 60 / 59 | 102 / 100 → 70 / 67 | 101 / 99 → 324 / 299 | + +The durations are not strictly like for like: the TS baseline ran the whole +application (the core loads during the import), the Rust page compiles the +module at page load (8 to 25 ms) and builds a `SheetHandle` per import +(about 21 ms in Chromium). The hostile `tolerance` group costs a fifth of +the TS memory under Rust. The `read` group costs more: its 20 to 50 MiB +inputs are held twice in the worker, the `File`'s ArrayBuffer and the glue's +copy in linear memory (54 MiB), and WebKit adds more on top +(`size-exactly-50mib`: Chromium 117 against 56 MiB, Firefox 154 against 79, +WebKit 324 against 76). R4.3 releases the buffer after the copy or reads the +file in chunks. Chromium main-thread long tasks during the imports: 0 (W5). + +Hostile classes, Rust (Chromium / Firefox / WebKit; linear memory is the +instance's, the same in every engine; the GC delta is Chromium's content +process after the worker is terminated and a GC forced): + +| Class | Outcome | Page ms | Summed peak MiB | Content peak MiB | Linear MiB | GC delta MiB | +|---|---|---|---|---|---|---| +| L envelope | ok | 46 / 36 / 45 | 4 / 11 / 9 | 6 / 9 / 7 | 4.6 | 11.7 | +| CAP envelope | ok | 88 / 77 / 83 | 31 / 20 / 39 | 29 / 18 / 35 | 13.9 | 14.2 | +| 16 MiB dense numbers | attachment_stripped | 183 / 199 / 130 | 45 / 47 / 124 | 47 / 45 / 114 | 20.0 | 11.8 | +| 16 MiB dense strings | attachment_stripped | 153 / 188 / 122 | 43 / 48 / 122 | 47 / 45 / 113 | 20.0 | 11.1 | +| 16 MiB at depth 64 | attachment_stripped | 180 / 198 / 136 | 45 / 47 / 123 | 48 / 45 / 114 | 20.0 | 12.2 | +| 16 MiB rescue copy | invalid | 178 / 190 / 164 | 113 / 145 / 234 | 115 / 143 / 225 | 52.0 | 15.4 | +| 16 MiB inflation | attachment_stripped | 43 / 37 / 43 | 20 / 12 / 13 | 18 / 10 / 11 | 35.3 | 11.1 | +| 16 MiB + 1 bomb | attachment_stripped | 50 / 44 / 49 | 5 / 8 / 10 | 7 / 7 / 8 | 67.3 | 12.1 | +| 32 bombs | attachment_stripped | 218 / 221 / 203 | 68 / 64 / 81 | 66 / 61 / 77 | 67.9 | 12.6 | +| 50 MiB file | no_attachment | 176 / 217 / 127 | 113 / 115 / 317 | 115 / 113 / 295 | 53.9 | 11.3 | + +- W4: linear memory at most 67.9 MiB on every hostile class (budget 256). +- The ceiling: in the three engines, `allocate_for_test(256)` returns and + `allocate_for_test(1100)` throws `RuntimeError` (proofs build, linear + 257 MiB). Cap off, the 16 MiB dense document reaches 788 MiB of linear + memory and 817 to 851 MiB of content-process peak in about 1 s; with the + cap, 45 to 114 MiB. +- Worker start, median (max): Chromium 6.3 (40.6) ms, Firefox 10.0 (20.0), + WebKit 5.0 (8.0). W2: the L envelope imports in 46 ms page-to-result in + Chromium, CAP in 88 ms. The structured clone of the compiled Module works + in the three engines (236 of 236 workers ready from the clone). No CSP + violation in any page or worker under the production policy with + `'wasm-unsafe-eval'`. +- The §B.3 "content process back within 10 MiB after GC" check is not met + as written on a first import: 3 of 238 Chromium runs; the median delta is + 11.7 MiB (7.3 to 13.3; hostile max 15.4). It is a one-time cost, not a + leak: three imports in one page give +11.6, +1.9, −0.2 MiB (L) and +11.0, + +1.4, +0.2 (dense); an empty module worker leaves about 2 MiB, an + instantiated one 3.7, the cloned Module is not the cause (the same without + it). Firefox and WebKit got 5 s idle only (indicative: Firefox +4.8 then + flat, WebKit +24.5 / +43.2 then down to −3). Owner decision: the criterion + counts the first import, or the growth per import. +- Seen once in a WebKit smoke run before the full run: 2 of 3 repeated + imports of the 16 MiB dense document ended with a worker `error` event, + text not captured then; not reproduced in two targeted reruns nor in the + full run (0 failures across 242 WebKit workers). Error text is captured + now; to watch at J1. + +Not measured: real devices and browsers (J1), forced GC in Firefox and +WebKit, CPU throttling, the hostile classes on the TS side, the negative +CSP proof (without the keyword), the application's own worker (R4.3).