Files
faunosteo/docs/development/RUST.md
T

269 KiB
Raw Blame History

Rust in the Faunosteo monorepo

Status: plan R0 (foundation, validated 2026-10-13), R1 (the Step 8 worker, validated 2026-10-13) and R2 (the domain core, validated and merged 2026-10-14) and R3 (the anatomy core, validated after the owner's LAN acceptance and merged 2026-10-17). Rule and roadmap: RUST_ARCHITECTURE_REVIEW.md (rule "Rust by default", Part III boundary rules, Part IV the worker, Part VI phases R0–R5, Annex B R0 scope, Annex C owner amendments). R0 shipped the toolchain, the workspace skeleton, the worker's sandboxed child, the browser module loader and seven experimental proofs; R1 ships the worker's job loop and sweeper for the avatar pipeline (STORAGE.md §3); R2 moves the application's domain rules into crates/core and switches the application to them (§8).

1. Toolchain: native on the development machine, reproducible in Docker, never on the VPS

Three environments, three roles (owner decision of 2026-10-13, review Annex C addendum). The development machine is a self-hosted Ubuntu server (native, not WSL, not the VPS) with Docker rootless.

Environment Role Rust
Ubuntu development machine, native daily development (cargo check / test / build / clippy / fmt), the browser module build, every check before a merge (pnpm check:all) user-level rustup in ~/.cargo and ~/.rustup, channel pinned by rust-toolchain.toml
Docker on that machine the Supabase stack, the worker's sandbox tests and seccomp derivation, integration tests, the application and worker images, and the reproducible run of the same Rust scripts through the builder image inside images only
Production VPS runs images; never compiles none

1.1 Native toolchain (the primary path)

Everything lives in the user's home: no global package, no sudo. Checked on 2026-10-13 (Ubuntu 26.04.1, x86_64): build-essential (gcc 15, the C compiler that builds the worker's vendored libwebp), libc6-dev, pkg-config, libssl-dev and strace were already installed; no system package is missing.

# once: rustup, the user-level installer (https://rustup.rs); ~/.bashrc and ~/.profile source ~/.cargo/env
rustup show                                                   # from the repository: installs 1.99.0 + rustfmt + clippy
rustup target add wasm32-unknown-unknown                      # browser build of crates/wasm
cargo install wasm-bindgen-cli --version 0.2.129 --locked     # = the wasm-bindgen crate in Cargo.lock
cargo install cargo-deny --version 0.20.2 --locked

rustup show run inside the repository installs the channel of rust-toolchain.toml (rustup auto-install), so cargo here is always 1.99.0 whatever the default toolchain of the machine. Non-interactive shells (editor tasks, git hooks, agent shells) skip ~/.bashrc and start without ~/.cargo/bin on PATH: the scripts source scripts/rust-env.sh, which prepends it when cargo is not found.

Piece Native Builder image Pinned by
Rust 1.99.0, edition 2024, rustfmt, clippy rustup show (auto-install) FROM rust:1.99.0-bookworm + rustup component add rust-toolchain.toml
wasm32-unknown-unknown rustup target add RUN rustup target add same channel
wasm-bindgen-cli 0.2.129 cargo install --locked same wasm-bindgen = "=0.2.129" in Cargo.toml; scripts/wasm-build.sh refuses to run when Cargo.lock and the CLI on PATH differ
cargo-deny 0.20.2 cargo install --locked same deny.toml
worker builder (musl, libwebp) not native: sandbox tests run in Docker only crates/worker/Dockerfile (FROM rust:1.99.0-alpine3.24, build-base) same channel

Commands (root package.json; every Rust script is one file run natively or inside the builder image):

pnpm rust:check          # scripts/rust-check.sh, native: fmt --check, clippy -D warnings (all targets),
                         # cargo test (core, wasm, worker unit tests), ts-rs export, cargo deny licenses/bans/sources
pnpm wasm:build          # scripts/wasm-build.sh, native: crates/wasm → packages/core-wasm/pkg (git-ignored), sizes printed
pnpm check:all           # scripts/check-all.sh: the pre-merge gate (§4): rust:check, types drift, wasm:build,
                         # pnpm check, application image, worker:test, worker:image started read-only
pnpm rust:check:docker   # the same rust-check.sh inside the builder image (reproducible run)
pnpm wasm:build:docker   # the same wasm-build.sh inside the builder image
pnpm rust:builder        # builds faunosteo_rust_builder:1.99.0 once (about 6 minutes cold)
pnpm worker:test         # Docker only: crates/worker/Dockerfile stage test, 16 sandbox tests + seccomp derivation
pnpm worker:image        # Docker only: runtime image faunosteo_worker:dev (distroless/static:nonroot)
bash docker/rust-run.sh cargo <anything>   # any cargo command in the builder
cargo check | test | build | clippy | fmt  # the inner loop, from the repository root

The native target/ (git-ignored, .dockerignored) and the builder's named volumes faunosteo_cargo_registry / faunosteo_rust_target are two separate caches; neither invalidates the other.

1.2 What stays in Docker, and why

  • The worker's sandbox tests (crates/worker/tests/sandbox.rs) are gated by the test-hooks feature: a native cargo test compiles that target empty and runs the worker's unit tests only. The seccomp allowlist is derived by strace on the musl static binary that ships, inside the Alpine test stage, and glibc would need other syscalls (brk, mprotect, futex): running the sandbox natively would either kill a legitimate decode or prove nothing about the shipped binary. pnpm worker:test is the only path, and the worker keeps running in its container.
  • The Supabase stack, the application image, the worker image and the integration tests on them: pnpm db:start, docker build -t faunosteo ., pnpm worker:image.
  • The builder image stays as the reproducible alternative (same compiler, same tools, a clean environment) and as the reference a future runner uses; it is not needed for a compile or a test on the development machine.

Exposure change, stated for the record: a native build runs the build scripts and proc-macros of the dependencies under the user account (the builder container ran them with the repository mounted read-write, so the difference is the rest of the home directory). Mitigations in place: --locked everywhere, deny.toml [sources] limited to crates.io with unknown registries and git sources denied, cargo deny check licenses bans sources in every check.

2. Workspace

Cargo.toml              workspace (resolver 3), pinned [workspace.dependencies], lints, profiles
rust-toolchain.toml     channel 1.99.0, components rustfmt + clippy
rustfmt.toml            edition 2024, max_width 100
clippy.toml             disallowed-methods: std::time::*::now, std::fs::*, std::env::var* (the core)
deny.toml               licences allow-list, bans (duplicates warn, wildcards deny, path deps allowed), sources
.cargo/config.toml      wasm shadow stack 1 MiB (explicit), TS_RS_EXPORT_DIR = packages/core-wasm/types
crates/core             faunosteo-core: lib, no I/O (lint), serde + serde_json + url (Zod's .url())
crates/wasm             faunosteo-wasm: cdylib facade over core (wasm-bindgen)
crates/worker           faunosteo-worker: bin + lib (image, libwebp-sys, seccompiler, rlimit)
packages/core-wasm      runtime (lazy, poison, recovery), Node source, generated types (committed), N-1 reader, tests

Lints: unwrap_used, expect_used and disallowed_methods are errors in the libraries (tests allow them explicitly at the top of the file); unsafe_code is forbidden everywhere except the worker (libwebp FFI, each block with a SAFETY comment). Dependencies are optimised even in debug builds (profile.dev.package."*") because the sandbox tests decode 4096² images under a 10 s CPU limit.

2.1 Boundary rules in code (review III.3)

  • faunosteo_core::facade::call(op, json) -> json and call_with_sheet(sheet, op, json): one operation name, one JSON text in, the outcome envelope out ({"ok":true,"value":…} or {"ok":false,"kind":…,"detail":…[, "found":<number>]}), never a panic on content. The operations of R2 are listed in §8.2 (crates/core/src/ops.rs).
  • faunosteo_core::json: js_number(f64) prints floats as ECMAScript Number::toString; to_js_pretty / to_js_compact produce JSON.stringify(v, null, 2) / JSON.stringify(v) byte for byte (proof §5.2). Every facade output goes through them.
  • faunosteo_core::domain::js: the JavaScript and Zod semantics the contracts depend on (JSON.parse duplicate keys, a lone surrogate escape refused as lone_surrogate (L1, §8.7), .int() as JsInt, UTF-16 lengths, the id / region / colour / sha256 / base64 / uuid / URL patterns, optional fields absent and never null, nullable fields required). Fields are declared in the Zod schema order (D-R11). cargo test -p faunosteo-core --features ts writes the TypeScript types to packages/core-wasm/types (committed; the drift gate of check:all fails on any change).
  • packages/core-wasm: CoreRuntime (browser-safe) and the Node source (@faunosteo/core-wasm/node); a fresh instance is a new glue module record (cache-busting import), never the trapped one (§8.3).

3. The worker (R0 sandboxed child, R1 job loop)

faunosteo-worker is one static musl binary with subcommands dispatched by a plain main (no async runtime, no thread), so decode installs its sandbox in a single-threaded process. R1 (Step 8) adds the keyed parent: run polls claim_avatar_jobs through PostgREST every 2 s, downloads the quarantine object, feeds it to a decode child, uploads the 512 × 512 WebP at the final key, commits the row (complete_avatar_job with the lease token), deletes the quarantine object, and sweeps (expired uploads, the purge queue, quarantine leftovers) every 10 minutes. Modules: config (env, secret newtype that no Debug output prints, JWT expiry), log (JSON lines, field allowlist, child stderr escaped and cut at 200 bytes), keys (strict four-segment key shapes validated before any URL), backend (trait, closed BackendError), http (ureq 3 on rustls + ring with the bundled roots, 30 s global / 5 s connect timeouts, no redirect, P0001 bodies → closed refusals, the Storage API's HTTP 400 + statusCode 404 → 404), decoder, job (the STORAGE.md §3.4 mapping), sweep (§3.5), watchdog (per-stage deadlines, exit 21 on overrun; Broken child → exit 20), run (WORKER_ONCE, --check). Library choice recorded against the review's Part V list: ureq instead of tokio + reqwest, hand-written JSON lines instead of tracing, a 25-line base64url decoder instead of base64: the loop is sequential, nothing needs an async runtime, and the keyed process keeps a smaller dependency tree (34 → 84 crates, aws-lc-rs absent, no cmake on Alpine). The decode child's traced syscall set did not change with the parent's TLS code (§5.4 re-run at R1: the same seven). Image 11.6 MB (8.7 MB at R0: ring + rustls). Tests: crates/worker/tests/job_loop.rs (11, fake backend + fake decoder) and the module unit tests run natively; the real-stack end-to-end runs through pnpm e2e:avatar (STORAGE.md §6).

The sandboxed child, unchanged from R0:

  • decode: refuses a non-empty environment; checks Threads: 1 in /proc/self/status; disables core dumps (PR_SET_DUMPABLE 0, RLIMIT_CORE 0: a dump would hold the uploaded photo); RLIMIT_AS 512 MiB, RLIMIT_CPU 10 s soft / 12 s hard (soft = hard made the kernel SIGKILL first, finding §5.4); seccomp allowlist installed with TSYNC, KillProcess on anything else, with argument filters: tkill/tgkill may only send SIGABRT to the child's own pid (never a signal to the keyed parent or a sibling), mmap may not map PROT_EXEC; then reads ≤ 5 MiB on stdin, sniffs the format (JPEG, PNG, WebP), decodes with image::Limits (sides ≤ 4096, alloc 256 MiB), applies the EXIF orientation, resize_to_fill 512 × 512, encodes lossy WebP (q 82) through libwebp-sys (C, this process only), writes stdout. Exit codes in exit_codes.rs (10–19, never 1, 101 or a signal number); every decode-time error maps to a content code (unsupported_type, decode_failed, dimensions, resource_limit), so no upload can produce a broken-environment code.
  • the parent side (spawn::Spawner, used by the tests now and by R1): env_clear, stdin/stdout/stderr piped, output read up to 512 KiB (the child is killed past it), 20 s deadline, classification of every exit (Produced, Rejected{code} for the content codes (exit_codes::is_content_rejection, an explicit list), Broken{code} when the child could not run properly (usage, non-empty environment, sandbox failure, encode or output failure, internal: R1 alerts instead of blaming the upload; no content can produce it), Signalled{signal}, OutputOverflow, Timeout, Failed). The parent never decodes: webp_check::inspect parses the RIFF container only (chunk allowlist VP8X, VP8 , VP8L, ALPH; the encoder's structure enforced: optional VP8X first, optional ALPH only in an extended file, exactly one frame; canvas size from the headers, the frame size must agree with the canvas; any EXIF, XMP , ICCP or unknown chunk refuses the output; owner amendment of D-R4). The child's stderr (≤ 4 KiB) is child-controlled text: R1 never logs it raw (LRN-044).
  • run --check: prints the resolved configuration without secrets (which variables are set, the linked libwebp version, refused below 1.6.0, the JWT expiry of the service key); exit 0 when startable or when no worker variable is set at all, 2 on a partial configuration. run starts the loop (STORAGE.md §3.2 for the variables).
  • version: binary, workspace and libwebp versions.
  • test hooks (--features test-hooks, never in a release build): fixtures generated in memory (no binary in git), --no-seccomp (rlimits only, prints the SECCOMP-MARKER line for the strace derivation), --violate (getcwd after the filter), --flood, --alloc-gib n, --spin, print-allowlist.

Image: crates/worker/Dockerfile, stages build (release, static), test (sandbox tests and scripts/derive-seccomp.sh on the release profile with the test-hooks feature, so the binary under test differs from the shipped one by the feature-gated hooks only), runtime (gcr.io/distroless/static-debian12:nonroot, USER nonroot, ENTRYPOINT /faunosteo-worker, CMD run --check). Measured 2026-10-12: image 8.7 MB (one static binary), run --check exits 0 with --read-only --cap-drop ALL --security-opt no-new-privileges:true.

4. Checks before a merge, and the workflow files (prepared, no CI active)

No CI/CD runs on the forge today (2026-10-13): no runner, no secret, no registry. The YAML files under .gitea/workflows/ are kept as prepared material for that separate decision; a green workflow is never claimed until one has actually run on the forge. Until then the gate is local:

pnpm check:all   # scripts/check-all.sh, stops at the first failure

Stages, in order: scripts/rust-check.sh (native), the ts-rs types drift (git status --porcelain --untracked-files=all -- packages/core-wasm/types must be empty: a modified or a new type file both fail, whatever the git configuration), cargo deny check advisories (warn-only: out of the blocking path by design, review VIII.3, but printed here because no nightly job runs yet; needs the network), scripts/wasm-build.sh (native), pnpm check (typecheck, tests including the core-wasm proofs on the module just built and the pgTAP suite on PGlite, lint, build), the application image, pnpm worker:test (sandbox tests and seccomp derivation on the musl binary), pnpm worker:image started once with --read-only --cap-drop ALL. The local Supabase stack is not required; pnpm db:test is the real-stack complement after a change under supabase/.

Workflow files, each mapping onto those stages so a future runner calls the same scripts:

  • ci.yml (push on main/develop, pull requests): job rust (builder image, scripts/rust-check.sh, types drift, scripts/wasm-build.sh), job check (module built the same way, then the Node pipeline), job docker (application image, worker test stage, worker runtime started read-only), job supabase (real stack, pgTAP, generated types diff).
  • rust-advisories.yml: nightly and manual cargo deny check advisories, out of the blocking path on purpose.
  • release-images.yml: manual only; the dispatch input is a typed choice re-validated through an environment variable; the RustSec and npm (pnpm audit --prod) advisories gates run first in a job without secrets; a named ephemeral buildx builder (--builder, no silent fallback) with its own cache builds the images; the registry token reaches the login step only, into a per-job DOCKER_CONFIG under RUNNER_TEMP created before any step and removed by a literal path; digests read from the build metadata; actions/checkout pinned to a commit. The if: github.ref line is not a boundary (push access and the token's scope are; a dedicated release runner label is the Step 27 operation). It would push faunosteo_app:<sha> and faunosteo_worker:<sha> and print their digests. Deploys nothing (DEPLOY.md "Image deploy by digest").

Target of the future CI/CD step (planned, not yet built; recorded so the scripts stay compatible): tests on every push and pull request, Rust and TypeScript checks, PostgreSQL/RLS tests, Docker builds, security checks, branch verification before a merge, image publication only in an explicitly authorised workflow.

Not measured: the forge runner's cache behaviour, cold build times and the workflow syntax (job-level env, GITHUB_ENV path) have never run. The builder image build took about 6 minutes cold on the development host; both image builds reuse BuildKit cache mounts (faunosteo_cargo_registry_musl, faunosteo_target_musl).

5. R0 proofs (2026-10-12, development host, Docker 29.8 rootless, kernel 7.0)

Each proof is a permanent test; the numbers are what the run produced.

5.1 Panic strategy on wasm32 (packages/core-wasm/tests/panic.test.ts)

  • A Rust panic reaches JavaScript as WebAssembly.RuntimeError (unreachable): the module is panic = abort, catch_unwind cannot be used there.
  • Exhausting the 1 MiB shadow stack (2 000 000 frames of 128 bytes) traps (RuntimeError) instead of corrupting memory.
  • After a stack-exhaustion trap, the next call on the same instance fails in the allocator (memory access out of bounds, deterministic). After a plain panic the same instance still answers, with a stack pointer that was never unwound: the dangerous case. Rule for R2: no instance is reused after any trap; a fresh instance is a new module record (the wasm-bindgen glue caches its instance in a module variable, and the ESM cache returns the same module for the same URL: loadCore() imports with a cache-busting query; in the browser the glue must be a static asset imported the same way, or the core runs in a Worker recreated on trap).

5.2 Serialisation contract (tests/serialisation.test.ts, crates/core/tests)

  • Byte equality with JSON.stringify(JSON.parse(text), null, 2) on report-v3.demo.json, report-v2.full.json, the 296 KB equine document.json and the 84 KB report-migration-map.json, plus a number corpus (1523, 1715.4285714285713, 0.85, 1e+21, 1e-7, 0.000001, -0 → 0, 123456789012345680000, 5e-324, 1.7976931348623157e+308).
  • Finding: serde_json's default float parser is a documented fast path that can be one ULP off; the first run printed 1715.428571428571 and 123456789012345670000. The float_roundtrip feature (enabled in Cargo.toml) fixes it; the module grew from 187 KB to 225 KB raw.
  • Optional fields absent, nullable fields null, unknown keys ignored, unresolved: false refused; the current ReportZoneSchema and SheetRefSchema (Zod 3, @faunosteo/domain) parse what the core writes.

5.3 musl static binary with libwebp (crates/worker/Dockerfile)

Builds on rust:1.99.0-alpine3.24 with build-base; libwebp-sys 0.14.4 compiles its vendored libwebp with cc; WebPGetEncoderVersion() reports 1.6.0 (logged by run --check, test the_linked_libwebp_is_recent_enough). The runtime image carries the one static binary.

5.4 seccomp allowlist, derived and proven (crates/worker/tests/sandbox.rs)

  • Derivation (scripts/derive-seccomp.sh, strace over png, jpeg, webp, a 4096 × 4096 JPEG and a 3000 × 3000 PNG, after the marker): exactly read write mmap munmap mremap exit_group getrandom. musl's mallocng used neither brk nor mprotect; no futex in a single-threaded decode. The allowlist is that set plus the abort path (rt_sigaction, rt_sigprocmask, getpid, gettid, tkill, tgkill, exit).
  • Proven on the release-profile musl binary with the test hooks, inside Docker's default seccomp profile: 16 tests green (png_jpeg_and_webp_decode_through_the_full_sandbox, inputs_at_the_caps_decode_within_the_limits (4096²), dimensions 32 px and 20 000² header, GIF and SVG refused, truncated PNG, non-empty environment refused, --violate → SIGSYS 31, --flood → output cut, --alloc-gib 2 → SIGABRT 6 under RLIMIT_AS, --spin → parent deadline, --spin → SIGXCPU 24 at the CPU soft limit, libwebp ≥ 1.6.0; negative proofs of the argument filters: --signal-parent (tkill to the parent) and --mmap-exec → SIGSYS; an iCCP bomb of 300 MB inflated → a content rejection, never a broken-environment outcome).
  • Findings: with RLIMIT_CPU soft = hard the kernel sends SIGKILL (hard limit checked first), indistinguishable from the parent's deadline kill; the soft limit is now two seconds below the hard one. The 4096² decode exceeded 10 s of CPU in an unoptimised debug build: dependencies are optimised in every profile.

5.5 CSP with 'wasm-unsafe-eval' (docker/csp-proof/run.sh)

Served packages/core-wasm/pkg through nginx:1.31-alpine with docker/nginx.conf plus the exact Content-Security-Policy of DEPLOY.md, loaded by headless Chrome for Testing 156:

Header Result
production (script-src 'self') FAIL WebAssembly.instantiateStreaming(): Compiling or instantiating WebAssembly module violates the following Content Security policy directive because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self'"
script-src 'self' 'wasm-unsafe-eval' OK 0.1.0 (module instantiated, core_version() answered)

The keyword allows WebAssembly compilation only: an inline <script> variant stayed blocked under both headers. nginx serves .wasm as application/wasm out of the box.

5.6 Served size and instantiate time (tests/size.test.ts)

faunosteo_wasm_bg.wasm: 224 713 bytes raw, 85 396 bytes gzip-9 (with float_roundtrip; 186 805 / 72 917 without), instantiate 2.7 ms in Node 24. The D-R13 budget (600 KB compressed) is asserted by the test from R0 on.

5.7 Runner caches and build times

Not measurable from this host (no forge runner here). Recorded instead: builder image cold build about 6 minutes; worker test stage cold about 2 minutes, warm under 30 s with the BuildKit cache mounts; the wasm build under 10 s warm. The first run on the forge records its own numbers here.

5.8 Native toolchain run (2026-10-13, Ubuntu 26.04.1, rustup 1.29.1, 16 cores)

Same proofs, native toolchain (rustc 1.99.0 (b940084d7 2026-09-28), cargo 1.99.0, clippy 0.1.99, rustfmt 1.10.0-stable, wasm-bindgen 0.2.129, cargo-deny 0.20.2), compared with the builder image runs above:

Measure Native Builder image (R0)
cold cargo build --workspace --all-targets (libwebp compiled by gcc 15) 31.5 s not timed at R0
cold wasm release build 4.3 s under 10 s warm
scripts/rust-check.sh warm (fmt, clippy, tests, ts export, deny) 32 s 2.2 s warm volumes (same script, same results)
cargo tests core 10 + 2, worker unit 9, core with ts 14 + 2, all green identical counts
committed ts-rs types unchanged after the export unchanged
faunosteo_wasm_bg.wasm raw 224 777 B 224 713 B
gzip -9 84 924 B (gzip), 85 390 B (the vitest measure) 84 927 B / 85 396 B
sha256 2d559a6b…bb3a 451d49c1…a752
core-wasm proofs 14 passed, instantiate 3.9 ms 14 passed, 2.7 ms

The 64-byte difference and the distinct hashes come from the source paths embedded in the panic locations (/home/<user>/Documents/faunosteo/… natively, /w/… in the builder): the module is not bit-reproducible across build roots without --remap-path-prefix, which R0 does not set. The builder image is the reference when two builds must match byte for byte. cargo deny prints the same warnings in both environments (license-not-encountered for six allowed licences, duplicate miniz_oxide and syn): policy warn, not failures.

6. Reproduction

pnpm rust:check                                            # §2, §5.2 (cargo side), native
pnpm wasm:build && pnpm --filter @faunosteo/core-wasm test:run   # §5.1, §5.2, §5.6, native module
pnpm rust:builder && pnpm rust:check:docker && pnpm wasm:build:docker   # the same, reproducible in the builder
pnpm worker:test                                           # §5.3, §5.4 (tests + derivation in the build log)
pnpm worker:image && docker run --rm --read-only --cap-drop ALL faunosteo_worker:dev   # §3
CHROME=<chromium binary> bash docker/csp-proof/run.sh      # §5.5 (playwright-core on NODE_PATH)
CHROME=<chromium> PLAYWRIGHT_NODE_MODULES=<dir> bash docker/csp-proof/app-image.sh   # §8.5, the R2 image
pnpm check:all                                             # everything above but the CSP proofs, in one command

7. What stays hypothetical after R0

  • Follow-ups from the R0 security audit, owned by R1 unless stated: base images pinned by digest in the three Dockerfiles (today by tag, as the existing Dockerfile); a verification decode of the child's output in a second sandboxed child (the RIFF check validates the container, not the bitstream); the shared BuildKit cache mounts of the CI builds (the release workflow already uses its own builder); actions/*@v4 tags in ci.yml (pre-existing practice) to pin by commit at Step 27.
  • The browser-side fresh-instance mechanism is built at R2 (§8.3): the glue is a Vite asset imported with a query per instance, one spare record imported in advance.
  • HTTPS from the worker: R1 links ureq with rustls and the bundled webpki-roots (distroless has no CA bundle; none is needed), but every run so far targets the local stack over plain HTTP on the Docker network; the first managed (HTTPS) target proves the roots.
  • The forge runner's cache and timings (§5.7), and the workflow files themselves: no runner exists, none of the three workflows has ever run (§4).
  • The allowlist is x86_64; an aarch64 host would need its own derivation (target_arch selects the seccomp architecture, the syscall numbers come from libc).

8. R2: the domain core in Rust, used by the application (2026-10-14)

Plan and contract: .claude/tasks/plans/2026-10-13-rust-r2-domain-core.md (revision 2 after three plan challenges). The application's domain rules run in crates/core, reached through crates/wasm and packages/core-wasm; React, the DOM, the forms, Zustand and supabase-js stay TypeScript.

8.1 What runs in Rust, and who calls it

Former TypeScript Rust (crates/core/src) Application consumer
sheet document schema (Zod, strict) domain/sheet/schema.rs SheetHandle load (useSheet), snapshot gate, publish check
validateSheetDocument (21 rules), isPublishable, createEmptySheetDocument domain/sheet/{validate,check,create}.rs sheet.check → publishSheetVersion (packages/supabase), snapshot integrity
buildSheetIndex (closures over Maps) domain/sheet/{index,index_data}.rs, SheetHandle useSheet → SheetIndex (precomputed tables, no call in a render)
report v3 / v2 / identity / migration map (Zod) domain/report/{v3,v2,identity,migration_map}.rs every op that takes or returns a report
migrateReportV2ToV3, readReportDocument domain/report/read.rs draft restore, import
rebaseReportOnSheet (gated, D-R12) domain/report/rebase.rs draft restore, import
snapshot / branding / labels / envelope schemas, buildSheetSnapshot, assertSnapshot, readArchiveDocument (gated, D-R12) domain/archive/* export (archive.snapshot), import (archive.import), draft restore (archive kept beside the draft)
services/zoneInteraction.ts (click decision, 7 reducers, collectVertebrae, syncVertebrae) domain/editor/zone.rs EditorRoute click chain, ObservationPickers, zone chips
FindingsTreePicker.toggleLeaf (Finding builder) domain/editor/finding.rs ObservationCard → findings picker
VertebraPicker toggle / all / none domain/editor/vertebra.rs VertebraPicker tap handlers
store newReport, emptyObservation, add / remove / move domain/editor/report_ops.rs reportStore actions (answer { ok })
persistence draft / archive parsing domain/session.rs (restore_draft) reportStore.restoreDraft (quarantine on content kinds)
engine readReportArchive (layered part) domain/session.rs (import_archive) HomeRoute import after the engine's byte scan

8.2 Facade operations (crates/core/src/ops.rs, facade.rs)

Free (call): sheet.check, report.new, report.add_observation, report.remove_observation, report.move_observation, vertebra.select; R0 proofs kept: core_version, pretty_json, sheet_ref, report_zone. On the session's sheet (SheetHandle.call): index_data, zone.click, zone.add_sides, zone.remove_at, vertebra.initial, vertebra.sync, finding.toggle, draft.restore, archive.import, archive.snapshot. Closed failure kinds: invalid_json, invalid_shape, unknown_op, internal, invalid_sheet (handle), invalid / unsupported_version / rebase_failed (restore), incompatible_version (with found) / no_attachment / invalid (import), unknown_annotation, unknown_zone, unknown_node, invalid_index, invalid_count (editor); the runtime adds core_unavailable. Input contracts are exported as TypeScript types.

8.3 Runtime in the browser (packages/core-wasm/src/runtime.ts, apps/app/src/core/)

  • Lazy: the glue (10 KB) and the module are Vite assets (?url), never in a route chunk; nothing is fetched before ready(). Callers: the editor (useSheet), the new-report submit, the PDF import. /login, /app/*, Mon compte and Home never request it (proven, §8.5); Home and /new read the sheet availability from the bundle alone.
  • Synchronous calls once ready. A WebAssembly.RuntimeError poisons the instance: the call answers internal, the instance is dropped, a fresh one is created from the compiled module kept in memory and a glue record imported in advance (no network needed), at most 3 times per page; calls made meanwhile answer core_unavailable. Sheet handles carry the instance generation and are rebuilt from the retained payload, never called on a dropped instance. A recovery that fails below the cap (network lost, spare record missing) is not final: the next call or ready() restarts the runtime, reusing the compiled module; a restart is not a recovery and does not touch the counter. A failed first load is restarted by retry() only. subscribe(listener) reports status changes after a microtask (a throwing listener changes nothing); the pages follow stopped through it.
  • A load failure (CSP, network, old browser) gives core_unavailable; the editor and the new-report page show the notice with "Réessayer" (the retry clears the runtime, useSheet and provider caches), never redirect, never read or write the draft. Once the engine stopped, the notice is the stopped one (§9.4 item 7), without a retry.
  • Editor, storage full while the engine runs: the editor.save_failed banner gains the engine-free "Télécharger une copie" button, and a beforeunload guard (app/useUnsavedGuard.ts, called once in App, on every page) asks before a reload, a close or a full-page redirect while the report is only in memory.
  • Two builds: pkg/ ships (no trap export, checked by scripts/wasm-build.sh and a test), pkg-proofs/ carries the trap exports for the tests. Both carry BUILD_STAMP (hash of the Rust sources); the vitest global setup of core-wasm, app and supabase refuses to run on a missing or stale module (pnpm wasm:build first).

8.4 TypeScript deleted, kept, frozen (census)

  • Deleted at R2: apps/app/src/services/zoneInteraction.ts and its suite (13 cases ported to crates/core/tests/editor_rules.rs), the Finding builder of FindingsTreePicker, the selection rules of VertebraPicker, the store's report construction and list rules, the Zod parsing in persistence.ts and sheets/provider.ts, the domain re-exports of services/sheetIndex.ts, hydrateReport, the publish gate's assertPublishable call.
  • Kept TypeScript, each with its constraint (review II.2 class C): display helpers over core data (zoneLabel, describeZone, zoneTrees, unresolvedFindings, the findings picker's matches / isLeafSelected / countSelectedUnder, the vertebra grid extent and chip state, import message lines, isIdentityComplete, pickLabel = pickLocaleLabel); form glue (D-R7: identity, texts, comment, severity and free-findings assignments, FreeTextFindingInput trimming, the practitioner prefill schema of practitionerCache.ts); storage adapters (persistence.ts, quarantine writes); isObservable (a type guard); the SheetIndex class (reads precomputed tables only); the runtime and its sources (Vite asset URLs, dynamic import).
  • Frozen TypeScript, still used, never extended: packages/domain (PDF engine and apps/app/scripts/compare-reports.ts until R4, pipeline until R5), packages/pdf (byte scan and writer, R4), packages/anatomy/render (canvas and engine, R3). The report:compare CLI reads the sheet with the frozen domain (apps/app/scripts/compare/sheet.ts).
  • Census: grep -rn "@faunosteo/domain" apps/app/src returns nothing, enforced by ESLint (no-restricted-imports on apps/app/src).

8.5 Proofs and tests (2026-10-14)

  • Cargo: 135 core tests (contracts byte-equal to the Zod output on the curated and legacy sheets, the demo report and the three frozen archive envelopes; the ported domain suites; 49 editor cases, 84 report and archive cases and 765 Zod verdicts frozen from the TypeScript; 26 conformance fixtures; the 612 legacy leaves), 32 wasm + worker unit tests.
  • Node: 906 tests (app 313 on the real core, core-wasm 25 incl. the runtime, trap, size and measurement tests, supabase 39 incl. the publish gate on the real core, domain 262 incl. the oracle generators, pdf 137, anatomy 130); the 39 step6 goldens and the seed golden unchanged.
  • SQL: supabase/tests/011_sheet_conformance.sql generated from the fixtures (cargo drift test), PGlite 12/12 files, real stack 446/446.
  • N-1: the Zod schemas of develop 1a7ee7d (packages/core-wasm/tests/n-1) parse every draft and archive the core-fed application writes; the three frozen envelopes are deep-equal to the R2 exports.
  • CSP on the real image (docker/csp-proof/app-image.sh, Chrome for Testing 156, DEPLOY.md header): with 'wasm-unsafe-eval' a report is created and a zone click is applied by the core with no script or wasm violation; without it the browser refuses the module (script-src wasm-eval), the editor shows the notice, stays on /editor and leaves the draft byte-identical; /login, /app/account and / request neither the glue nor the module (15/15). Recovery after a forced trap checked in the browser on the dev server and the production build; real traps on the proofs build in Node.
  • pnpm check:all: green in 2 min 17 s.

8.6 Measurements (development machine, Node 24, Chrome 156)

Measure Value
shipped module 1,044,559 B raw (native), 340,154 B gzip -9 (budget 600 KB); before the by-reference deserialisation of the security follow-up: 1,180,153 B raw / 372,275 B served by the image; after L1 (no rewrite pass, §8.7): 1,040,784 B raw / 339,933 B gzip -9
glue 10,171 B
load (compile + instantiate) 6 to 8 ms
sheet handle + index data (bundle 0.5 MB) 22 to 27 ms (TypeScript parse + index on the same input: 12 to 15 ms)
zone.click 0.03 ms
draft.restore (demo report) 0.26 ms
archive.import (demo envelope, 184 KiB) 2.4 ms (TypeScript layered read, without rebase: 1.0 to 1.1 ms)
archive.snapshot 0.4 to 0.5 ms
linear memory after the editor path 4.1 MiB
app image 104 MB (wasm stage: the Rust toolchain stays in the builder)

Pages without the core load nothing more than before R2; the sheet pages fetch about 351 KB more (glue + gzip module) once per session. JSON inputs are deserialised by reference (T::deserialize(&Value)): the imported attachment is never copied as a whole value (its strings are copied once into the typed contract), and one deserialiser instead of two keeps the module smaller. Operation inputs (parse_input) keep the parsed value alive while their strings are copied out: a transient, linear peak on inputs the application itself builds.

8.7 Behaviour differences (declared)

  1. L1 (owner decision 2026-10-14, BDR-051): a JSON text that escapes a lone UTF-16 surrogate is refused whole with the closed kind lone_surrogate, never altered (TypeScript kept the surrogate; a Rust string cannot hold it, and the U+FFFD replacement delivered first was refused). serde_json rejects the escape like any other error and js::parse_json classifies the failure with a strict escape scan, run on failures only. A draft goes to osteo:quarantine:draft verbatim with the existing quarantine notice; an archive kept beside a draft goes to osteo:quarantine:archive; an import is refused with home.import.error_lone_surrogate and the file is not modified; an editor action on a report holding one (only a pasted malformed text can bring it) is refused with core.action_failed and the report is left as it was; the publish gate reads it as invalid_shape. Keeping such a string byte for byte would need a JSON reader of our own and a lossless string type across the contracts (rejected for R2, the refusal leaves that door open: nothing is lost). Invariant of the boundary: callers pass JSON.stringify output only, which escapes a lone surrogate as \uXXXX; a raw JavaScript string handed to a wasm-bindgen &str parameter would be re-encoded with U+FFFD before the core sees it. The pretty_json proof op reads with serde_json directly and refuses such text as invalid_json.
  2. Drafts and the attachment's report are written in contract order instead of insertion order (D-R11); values unchanged, the N-1 reader parses them.
  3. An unreadable draft or archive is set aside under osteo:quarantine:* with the editor.draft_quarantined alert, instead of being dropped silently; a draft rebased with unresolved items keeps its raw text under osteo:quarantine:draft-pre-rebase. An unreadable draft goes there with the archive kept beside it, both or neither. A slot already holding another text is never replaced. Owner rule of 2026-10-14 (maintenance B): no session text is removed or overwritten implicitly when a save or a set-aside fails. Such a text stays in place and is held: nothing is opened over it (RestoreResult held: an unreadable draft, its companion archive, an unreadable archive, or the original of a draft to rebase), and the editor shows the resolution panel (download an exact copy, delete permanently or open the adapted version after a confirmation, retry). A new report or an import refuses to start (reason: 'held', alert, then the panel) while such a text is held, and first reads through the core any draft this page never opened: an unreadable one is set aside before the new session replaces it, a readable one is replaced as before. R3 final checks (2026-10-17): a draft the engine traps on (draft.restore answering internal, an out-of-memory trap on a very large draft) is held too, as the engine_failure row with its archive as companion (session.held.notice_engine), kept as is; the store remembers the (draft, archive) pair that trapped and answers held without calling the core again, from the editor, New report and Import alike (ActionResult.engine, alert session.held_blocked_engine), until the panel's "Réessayer" (retryTrapped) or a confirmed discard; other core failures keep their behaviour (core_unavailable: the reload screen). New report and the Home file pick ask first (ReplaceSessionDialog: cancel, open the bilan in progress, replace) whenever a report is in memory or a draft sits in the slot. The draft mirror is written only when the report changes (an unrelated store change never removes it); a refused write keeps the previous text and shows the editor.save_failed banner until a write succeeds; a refused archive write at a new session removes the replaced session's archive rather than leave it paired with the new draft, and shows the same banner (the tab's copy lacks it). The rescue download and the PDF export keep their object URL alive 30 s (WebKit cancels a download whose URL is revoked at once; both go through downloadBlob, apps/app/src/lib/download.ts).
  4. A core that cannot load leaves the editor on the degraded notice (before R2 a failed sheet chunk left it on "loading").
  5. Home and /new no longer load the sheet into memory on mount.
  6. Inputs the interface never produced get typed errors where the TypeScript would throw or corrupt a list (invalid_index on a move past the end, invalid_count beyond 65,535 vertebrae, unknown_*).
  7. A click on an existing spine zone no longer writes an identical observation back (the value is the same).
  8. The publish gate throws SheetPublishError with closed kinds (invalid_shape, not_publishable with the same message as before, validator_unavailable), never a raw ZodError.
  9. Superseded by item 3 (maintenance B, 2026-10-14): an unreadable draft that cannot be set aside shows the resolution panel, no longer the engine notice.

8.8 Residual risks

  • The import reads up to the 16 MiB attachment cap inside the long-lived instance (linear memory never shrinks) until R4 moves the reader into a terminated Web Worker.
  • No React error boundary: every core entry point catches, but an uncaught error elsewhere still blanks the page (unchanged since before R2).
  • The CSP proof runs Chromium only (no Firefox or WebKit build on this machine): the owner's manual run of the image on other browsers and the phone covers Safari and Firefox.
  • The module grows with each phase (340 KB of the 600 KB budget at R2; the url crate's IDNA tables are part of it): R3/R4 must keep measuring.
  • The quarantine slots (osteo:quarantine:*) keep verbatim copies of drafts (practitioner, owner and animal data) until the tab closes, the same exposure as osteo:draft itself (sessionStorage, tab and origin scoped); nothing clears them on a new report, by design (they exist to survive it). They have no interface yet: the practitioner cannot see or download a set-aside text, and it disappears when the tab closes (owner decision 2026-10-14: follow-up, not part of the maintenance fix).
  • "New report" from Home replaces the tab's readable draft without asking, as before R2 (a single draft per tab, the PDF is the saved copy); the maintenance fix only guards texts that are unreadable or held.
  • Base images by tag, the new rust:1.99.0-bookworm included (digest pinning is the Step 27 follow-up of R0).
  • The documented CSP refuses the footer's external credit logo (img-src), an older matter seen by the proof.

9. R3: the anatomy core in Rust, drawn by the editor canvas (2026-10-15)

Plan and contract: .claude/tasks/plans/2026-10-14-rust-r3-anatomy-core.md (revision 2 after three plan challenges, 32 findings folded). Status: validated by the owner's LAN acceptance (functional and graphical) and merged into develop on 2026-10-17. Residual risks are tracked in the project's blocker registry (BLK-011, BLK-012).

9.1 What runs in Rust, and who calls it

Former TypeScript Rust (crates/core/src/anatomy) Consumer
apps/app/src/anatomy/drawing.ts denylist + DOMParser parse of the asset (deleted) svg/{prescan,tree,sanitize,refs,number,serialize}.rs, svg::read_svg the sheet load (LoadedSheet, each drawing read once)
packages/anatomy/src/render/layer.ts (renderAnnotationLayer, viewBoxOf) layer.rs view.canvas; the highlight
the canvas composition of drawing.ts (fresh root, viewBox rules, layer last) compose.rs compose_canvas view.canvas → SheetIndex.canvasSvg → AnatomyCanvas
packages/anatomy/src/render/compose.ts (composeViewSvg, highlightLayer, halo) compose.rs compose_highlight none yet: proven against the engine (O3), wired at R4 in R4's snapshot-based call
packages/pdf/src/svg/sanitize.ts allowlist and value rules svg/sanitize.rs (same lists, same rules, declared additions 9.4) the canvas now; the engine keeps its TypeScript copy until R4

One facade operation on the sheet handle: view.canvas { viewId } → { svg }, failures unknown_view, no_asset, svg_rejected (reason in detail: too_large, doctype, malformed, not_svg, too_many_elements, too_deep, too_many_uses, too_complex, reference_cycle, or removed <names> when the allowlist would take something out of a product drawing), invalid_character. The result is constant for a loaded sheet: SheetIndex memoises it per view; AnatomyCanvas parses it with DOMParser, imports it and restyles data-state in place as before.

9.2 The SVG reader (read_svg)

  1. Bounds before any parser (prescan.rs, a markup state machine: comments, CDATA, PIs and quoted values skipped by the grammar, each closer searched after its whole opener so <!--> cannot hide markup, no regex): 2 MiB, a leading BOM refused, <!DOCTYPE/<!ENTITY anywhere, depth 64, 20,000 elements, 256 attributes per element and 100,000 in all, 16 namespace declarations, 100,000 raw < and 200,000 raw =. Reason: roxmltree 0.21.1 builds its tree recursively (measured: a 1 MiB stack overflows between 1,000 and 3,000 nesting levels; the iterative fix is unreleased), and it pre-allocates on the raw </= counts, checks duplicate attributes quadratically and copies inherited namespaces per declaring element.
  2. roxmltree 0.21.1 (DTD refused, node limit 200,000 as a backstop) into the core's own tree, names as written (the allowlist matches qualified names like the engine).
  3. The allowlist (sanitize.rs): the engine's 28 elements, 74 attributes, 27 presentation attributes and value rules (no backslash, every url( local, href to #id only, style without forbidden tokens or functions, the stdDeviation clamp with JavaScript Number() reproduced by hand), and the <use> count cap 256.
  4. The reference graph (refs.rs): tree edges plus every href/xlink:href and url(#id) to the first element of that id; a cycle is refused, and so is an expanded size over 50,000 elements (each reference adds its target's expanded subtree, saturating, iterative, early exit).
  5. The serialiser (serialize.rs): XML 1.0, & < > " and \t \n \r as references in attributes, & < > and \r in text; a re-read gives the same tree. A composed view over 4 MiB is refused.

9.3 Proofs and tests (oracles frozen with the TypeScript first)

  • O1 (apps/app/tests/fixtures/goldens/r3/canvas.*.json, 47c5f49): the canvas tree of each view and the layer of 14 state sets per view (the three reference reports). Green on the Rust composition in cargo (tests/anatomy_compose.rs), in the app suite on the mounted canvas (canvas.trees.test.tsx) and in Chromium 156 on the live page (scripts/visual-canvas.mjs dom): equal for both views.
  • O2 (oracles/r3/layer.json): 8 layer trees with attribute order (draft + an edge document: twin radius floor, 1e+21, path geometry, circle trigger without a name, colour fallback, laterality): exact, order included.
  • O3 (oracles/r3/highlight.json): 36 highlighted compositions (every observation and view of the three reports, an existing nested <defs>, a detail view with its own asset and no viewBox): tree-equal.
  • O4/O5 (oracles/r3/sanitiser.json): 42 hostile files (tests/fixtures/svg/hostile) and 10 generated cases: equal to the TypeScript verdict or a declared one (9.4); the 4 product SVGs (horse drawing, partner logo, 2 public logos) untouched, tree-equal. Mutation checks run on the oracle tests (a cap, the namespace rule, the twin floor, the halo placement): each mutant failed the suite.
  • Security audit pass 1: PASS with one MEDIUM in the prescan (a closer searched from inside its own opener: <!--> let crafted markup hide 5,000 nesting levels or 3,000 attributes, then roxmltree overflowed the stack), fixed with regression cases in cargo and through the shipped wasm; two LOW (Unicode-spaced href, root painting attributes) fixed the same way. Pass 2 on the fix: PASS (about 4 million differential documents, prescan against roxmltree: no undercount, no cap breach, no stack overflow on a 64 KiB stack; the old desync and its variants answer too_deep on the shipped module); its LOW (the same Unicode-space tolerance inside url() fixed.
  • Shipped wasm (packages/core-wasm/tests/anatomy.test.ts): the corpus plus floods (99,000 nesting levels, 20,001 nodes, 150,000 < in a comment, 257 attributes, 2 MiB + 1, a 12 × 20 <use> chain, 1.9 MiB of >), each in a fresh instance (50 cases): a closed outcome, no trap, slowest 24 to 37 ms over runs, largest linear memory growth 10.1 MiB.
  • Runtime: the SheetHandle constructor's closed refusal (<kind>: <detail> from a plain Error) is invalid_sheet; any other throw (RangeError, InternalError, a trap) poisons the instance (runtime.test.ts).
  • Visual, Chromium 156 (scripts/visual-canvas.mjs): 30 captures before (TypeScript canvas) and after (Rust), desktop 1280 × 800 and phone 390 × 844, no selection, each demo observation active, hover, main and head: 30/30 pixel-identical. The method's own noise floor: two captures of the same build 30/30 identical; its classifier flags a 10 × 10 change as a regression and a one-pixel edge nudge as anti-aliasing.
  • The Step 6 goldens (39) and the seed and review-drawing goldens are untouched: the engine and the pipeline still run the TypeScript renderer.

9.4 Behaviour differences (declared; none touches a product SVG)

  1. An element outside the SVG namespace is removed (<path xmlns="…">), and xlink:href must be in the xlink namespace whatever its prefix.
  2. Comments and processing instructions are dropped; non-whitespace text is kept only in title/desc, each at most 4 KiB (longer: refused whole).
  3. The root loses class and style (an inline SVG lives under the page's CSS: class="fixed inset-0 …" would cover the application) and transform, filter, mask, clip-path (they can paint outside the canvas box); an id outside [A-Za-z_][\w.:-]* is removed; an href is local only when it reads #name once ASCII whitespace is stripped, as the URL parser strips it (the TypeScript also trimmed Unicode spaces, so a no-break space before #a passed and resolved as a relative URL); inside url( only CSS whitespace is skipped before #, for the same reason.
  4. A reference cycle, an expansion over 50,000 elements, and the floods of 9.2 step 1 are refused; the TypeScript accepted them (size counted on the raw text, refused subtrees included).
  5. A product drawing the allowlist would alter is refused at sheet load for the views on that asset (svg_rejected, removed …); the TypeScript canvas dropped such parts silently.
  6. A label or path the document holds with a code point XML 1.0 cannot carry is refused (invalid_character); the DOM path drew it.
  7. When the canvas cannot be drawn, it says why, inside the canvas (owner decision 2026-10-15): the engine did not run (core_unavailable, internal: the existing sheet.core_unavailable notice with "Réessayer", the retry builds again on a fresh instance), the engine stopped after its three recoveries (CoreRuntime.stopped: no retry anywhere; the canvas shows the stopped text, and CoreStoppedNotice sits in the editor's banner slot in place of the storage-full text, at the top of Home and New report, and replaces the full-page CoreUnavailable retry. Two variants: the tab's copy of the report is saved, core.stopped with "Recharger la page"; the tab's storage refused the last write (saveFailed), core.stopped_unsaved with "Télécharger une copie" (the in-memory report as JSON, no engine needed), never the reload button. Action, export, import and new-report alerts say the same text instead of "try again"; "Réessayer" on the canvas restarts the engine before building again) or the view itself cannot be drawn (svg_rejected, no_asset, unknown_view, invalid_character, a parse failure: the canvas.view_unavailable notice, no retry since nothing would change). The technical kind and detail stay in the core's outcome and the DEV console; the refused drawing and the session are left as they are. Before R3 a failure there left the canvas blank (an uncaught error).
  8. A trigger without a name carries the opened view's name in each language (owner decision 2026-10-15: until then both name attributes and its title held the French name). Display only; the frozen oracles stay as frozen and the tests apply this declared change before comparing.
  9. R3 final checks (owner decisions 2026-10-17). The rescue copy (the "Télécharger une copie" JSON, byte format of osteo:draft) is importable: the Home picker accepts it beside the PDF, routed by content from the first KiB (%PDF- goes the PDF path), refused above MAX_ATTACHMENT_BYTES, decoded as strict UTF-8, read by the core's draft.restore (no archive) and opened like an import; a copy the core refuses is home.import.error_invalid_copy (file and session untouched), a rebased one shows editor.draft_rebased. The copy lacks the archive envelope, which the original PDF keeps. A draft that traps the engine opens the resolution panel and is read once (§8.7 item 3); importing the copy of a trapping draft runs the same input again.

9.5 Measurements

Measure Value
shipped module 1,188,310 B raw, 395,613 B gzip -9 at 23895b9 (+55.7 KB over R2; budget 600 KB; the app image's build root gives 395,541 B)
sheet handle with the drawing read (Node) 8 to 10 ms
view.canvas main, first (Node) 1.2 to 1.4 ms; head warm median 0.85 ms; 143 KiB of SVG
Chromium, preview build, CPU × 4, medians of 3 editor to canvas 503 ms (476 ms before R3); detail open 143 ms (125 ms before R3, runs 109 to 157); browser parse + import of the canvas text 21 ms (22 ms)
50 detail open/close cycles, CPU × 4 JS heap +0.72 MiB (+0.89 MiB before R3), DOM nodes +0 (+0)

9.6 TypeScript deleted, kept

  • Deleted: the canvas denylist sanitizeSvg, parseDrawing, the parse cache, assetOfView, the states input of the canvas build, the assets field of SheetIndex, the app's dependency on @faunosteo/anatomy.
  • Kept, with their consumers: packages/anatomy/src/render/** (PDF engine until R4, curation pipeline until R5), packages/pdf/src/svg/** (engine until R4), the R3 oracle generators (packages/anatomy/tests/ r3.layer-oracles.test.ts, packages/pdf/tests/r3.{highlight,sanitiser}- oracles.test.ts: they still pass on the TypeScript and keep the freeze honest until R4/R5).

9.7 Residual risks

  • The engine (PDF) still sanitises with the TypeScript allowlist and has no reference budget: the <use> expansion gate of PDF_IMPORT_HARDENING.md §5 is met in the core, closed for the PDF path only when R4 switches it.
  • roxmltree's recursion: safe behind the prescan depth cap (differentially fuzzed, 9.3); pin the release with the iterative parser when it ships.
  • References are checked inside one drawing; in the page #id resolves against the whole document (the detail modal imports a second copy of the drawing, as before R3). Drawings with their own assets (Step 13) should get ids scoped per view before external uploads are drawn.
  • Firefox and WebKit: not run here (no browser build); the owner's LAN run on the phone covers WebKit.
  • The worker's TLS path has not run against a real HTTPS endpoint (every run 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 (R4.1 freeze 2026-10-18, export and report:compare switched 2026-10-19, closed and merged 2026-10-21: §10.15)

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. §10.1 and §10.2 record what R4.1 froze and the TypeScript baselines every later slice was measured against; the slices follow in order, §10.15 is the close.

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.

10.3 R4.2: the reader in Rust (2026-10-18, no import switched yet)

What runs in Rust (crates/core/src/pdf, feature pdf-read, enabled by the wasm facade, never by the worker): the byte scan of scan.ts (read/scan.rs, strings.rs, stamp.rs, the JavaScript regex semantics reproduced by hand and pinned by the semantics.* rows of O7), the inflation on miniz_oxide (read/inflate.rs, non-wrapping output buffer growing to the limit plus one, trailing bytes refused, Adler-32 checked: the verdicts of DecompressionStream), the JavaScript-path side effects of the probe (json_js.rs: TextDecoder parity with one BOM dropped, overflow to null, the lone surrogate neutralised for the probe only, the depth and value pre-scan), the probe itself (read/probe.rs, one 16 MiB budget shared by the candidates, a cancelled inflation not charged) and pdf::import::import_pdf, which hands the text to the unchanged R2 session import. On the facade: SheetHandle.import_pdf(bytes) with the kinds of PdfImportKind (ts-rs). Nothing in the application calls it yet (R4.3).

Parity (every suite green on the committed oracles, cargo test -p faunosteo-core --features pdf-read and the core-wasm Node suites):

Oracle Rust check Result
O7 findEmbeddedFiles, hasArchiveStamp, decodePdfString pdf_scan 144 PDF inputs, 178 candidates, 19 string rows, all equal
O9 and the O7 flate rows pdf_inflate 26 + 12 verdicts equal to Node; the browser columns agree on every row
TextDecoder lossy decode pdf_json_js on fixtures/pdf/r4/utf8-lossy.json (400 cases, scripts/r4-utf8-oracle.mjs) 0 difference
O7 locateAttachment, readAttachedDocument, readReportArchive pdf_import 144 inputs equal (candidate, name, offset, bytes digest, parsed-object digest; origin, counters, snapshot rejection, report digest)
O8, the full R3 import path, 51 PDFs pdf_import natively and pdf-import.test.ts through the shipped module 47 equal, 4 declared differences below
Reference PDFs (Step 5, Step 6, R3, O2) pdf-import.test.ts every one imports

Declared differences, all on hostile files (plan §A.3):

  • OD-4, three O8 cases (surrogate-content-overwritten, surrogate-version-overwritten, two-files-decoy-first): the text holds a lone UTF-16 surrogate escape in a value that a later duplicate key overwrote. JSON.parse kept the last value, so the stringified object the core received no longer held the escape and R3 imported the file; the core refuses the text whole (lone_surrogate), nothing altered. Why the refusal is right: a Rust string cannot carry a lone surrogate, so reading such a text means either altering it silently (L1 forbids it) or reading only the parts that happen to survive duplicate-key resolution, which is reading a document other than the one in the file. In two-files-decoy-first R3 did not import the real envelope at all: it imported the decoy (conclusion « Leurre ») that sorted first. No legitimate Faunosteo document is affected: every PDF the product wrote comes from JSON.stringify of one object, which never emits a duplicate key, and a lone surrogate in a kept value is already refused by R3 (error_lone_surrogate); the proof is the O2, O3, O7 and Step 5 reference set above, imported identically, and the O8 corpus where the only lone-surrogate cases that import in R3 are the three duplicate-key constructions.
  • OD-3, one O8 case (values-1m): over the value cap (below). It is skipped like a candidate nested too deep, so the kind follows the stamp (attachment_stripped here, as depth-65 already answers in R3).
  • The archiveSha256 column of the O7 readReportArchive rows is not compared: the frozen TS domain stringified its Zod output, keys in schema order, where the core keeps the document's order (R2); the R3 application stored the core's form, which O8 pins and matches.

Memory protections (OD-3), measured in the shipped module, one fresh instance per case (packages/core-wasm/tests/pdf-import.budget.test.ts, R4_BUDGET_ALL=1 for the slow classes; values from cargo test --test pdf_budget -- --nocapture):

Document Bytes Values (json_js::prescan)
demo fr logos (R3 export) 305,938 2,559
v2full fr logos (R3 export) 298,035 2,232
612 leaves (O7 export) 739,316 23,803
L envelope (60 observations, 120 views, logos) 403,016 6,740
CAP envelope (500 observations, 1,000 views, logos) 1,164,658 39,652
hostile values-1m.pdf 2,006,973 1,000,364

The parser's tree costs about 100 bytes of linear memory per value (the final Vec doubling included). Cap off, a 16 MiB token-dense document (8.4 million values) takes 784 MiB of linear memory and 0.9 s in Node, what BLK-012 observed; every shape tried (numbers, empty strings, nesting at the depth cap, the rescue copy) lands at the same 784 MiB, under the 1 GiB ceiling, so the cap is the guard and the ceiling the backstop.

Thresholds set (to confirm before R4.3):

  • json_js::MAX_JSON_VALUES = 400,000, ten times the CAP envelope (the plan's rule), 17 times the 612-leaf export; applied in the attachment probe and in draft.restore (the rescue copy and the tab's draft: an over-budget text is invalid, set aside verbatim, never dropped). Worst case left: about 40 MiB of tree on top of the file copy.
  • --max-memory 1 GiB on the module (.cargo/config.toml): an allocation past it traps (allocate_for_test on the proofs build: 256 MiB returns, 1,100 MiB throws RuntimeError), and CoreRuntime poisons and re-creates the instance as for any trap. The ceiling applies to the export too; the R4.6 measurements must stay well below it (CAP export estimated at about 0.4 GB in §B.4).

Per class, cap on (Node, i7-11700B, shipped module; "linear" is the instance's growth, which never shrinks; "RSS" the Node process):

Case Outcome ms Linear MiB Node RSS MiB
L envelope (394 KB) ok 11 0.6 0.4
CAP envelope (1,138 KB) ok 40 10.0 14.9
demo fr logos (R3 export, 237 KB) ok 7 0.0 1.3
612 leaves (O7 export) ok 23 2.8 5.4
values-1m (O8 hostile, 2 MB attachment) attachment_stripped 11 3.1 3.0
16 MiB dense numbers (8.4 M values) attachment_stripped 103 16.1 16.0
16 MiB dense strings (5.6 M values) attachment_stripped 85 16.1 16.0
16 MiB at depth 64 attachment_stripped 92 16.1 16.0
16 MiB dense numbers as a rescue copy invalid 152 48.1 80.1
16 MiB at depth 65 as a rescue copy invalid 128 48.1 80.3
16 MiB inflation (zeros, not JSON) attachment_stripped 14 31.3 31.0
16 MiB + 1 inflation (bomb, refused) attachment_stripped 19 63.4 47.0
32 bombs (17 MiB each) before the attachment attachment_stripped 181 63.9 47.5
50 MiB file, attachment at the end no_attachment 73 50.0 50.0

Same classes, cap off: values-1m 109 ms and 98 MiB; the three 16 MiB documents 0.6 to 0.9 s and 784 MiB; the rescue copy 0.4 s and 792 MiB. W4 (≤ 256 MiB linear on every hostile class) holds with the cap on; the 16 MiB file copy and the inflation buffer dominate what is left.

Module: 1,251,849 B raw, 421,940 B gzip -9 (W1: +26 KB over R3, budget 600 KB, report line 550 KB).

Residual risks and open points for the owner (R4.2 checkpoint):

  • The thresholds above are set from fixtures at the collection caps; a report far denser than CAP per observation (hundreds of findings on each of 500 observations) would be refused as a hostile file. 400,000 values is 17 times the densest export seen (612 leaves on one observation).
  • The ceiling is a module-wide constant: it bounds the import worker and the main instance alike. If an R4.6 export measurement approaches it, the value must be revisited, never the cap.
  • The Node numbers measure the module, not a browser: the browser run of the same classes (content-process RSS, worker terminated, GC) is in 10.4.
  • Found by the independent security gate of R4.2 and fixed (593893a): the value count stopped at the depth cap, so a rescue copy nested 65 deep hid its 8 million values from the budget (792 MiB built, the cap-off figure). The count now runs to the end whatever the depth verdict, and the budget covers the archive text of draft.restore too. Reported, not blocking: the TypeScript import path and archive.import carry no budget until R4.3 replaces them (BLK-012, pre-existing); a 50 MiB file with 32 stream heads walks its whitespace 32 times (783 ms against 269 ms, bounded by MAX_CANDIDATES, as the TypeScript); the inflation buffer's capacity reaches 2 × limit during its last growth (the 63 MiB row); the 50 MiB size check runs after the glue copied the bytes, so the main thread's pre-check must stay on the R4.3 worker path.
  • 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).

10.5 R4.3: the import in a disposable worker (2026-10-18, application switched)

What runs where (apps/app/src/core/worker/, plan §B.1.5 with one amendment below): the page refuses up front when its own engine stopped, routes on the first KiB and checks the sizes as before, then creates a module worker (import.worker.ts, the glue bundled statically into a hashed /assets/ chunk that script-src 'self' allows), posts the task with the bundled sheet text and its runtime's compiled WebAssembly.Module (structured clone: 236 of 236 workers in R4.2e, every engine), reads the file in 1 MiB chunks with a BYOB reader and streams them to the worker (chunk / ack with the buffer transferred both ways: the page holds one chunk, the worker's FileBytes sink the only whole copy, no byte parsed on the page), posts end, and reads the first of result, failed, an error event (never masked), the start timer (10 s to ready), the task timer (20 s, paused while the page is hidden; the J1 hypothesis) or a cancel; the worker is terminated in every case. The worker answers ready, builds its SheetHandle, runs import_pdf_bytes or restore_copy_bytes (strict UTF-8, one BOM, the OD-3 budget) and answers the core's envelope; every throwable becomes one failed with its phase and kind. The page then loads its own index for hydrateImport, as before; a result is dropped when the session changed since the pick, leaving Home cancels the import, one import runs at a time, and the worker chunk is prefetched once the editor has loaded the engine so an offline import still starts.

Amendment to §B.1.5 item 3 ("the File itself, never read on the main thread"): the file is read on the page, chunk by chunk, because reading a file inside a WebKit worker costs about 180 MiB of content-process RSS whatever the method (arrayBuffer, default stream, BYOB; 14 MiB on the page, 13 to 15 in Chromium and Firefox workers), measured in R4.3a on a 50 MiB file: worker read 272 to 316 MiB against 76 for the TypeScript, page read feeding the worker's sink 106. The isolation stays: untrusted bytes are parsed in the worker only; the page moves buffers.

Messages (§B.1.8, OD-5), pinned on every file of the frozen corpora by routes.HomeRoute.messages.test.tsx through the real worker logic in-process: O8 51 PDFs (47 as R3, the four declared), the stored O7 inputs (over 130), the O2, O3 and Step 5 reference PDFs (editor), the 612-leaf export (editor); a worker trap, a timeout or a file the page cannot read is « Erreur de lecture du PDF. », a worker that cannot start is the engine message, and the page's own runtime stays ready after a worker trap. Suites: handler and client in-process (core.importWorker, core.importClient), the six existing Home / core-failure suites migrated to the real worker logic (53 cases, titles kept), 458 app tests.

Memory, large files (summed / content RSS growth MiB; TS reader · Rust, worker read, R4.3a page · Rust, page read, R4.3d application build):

File Chromium Firefox WebKit
50 MiB file (size-exactly-50mib) 56/55 · 65/66 · 75/73 79/59 · 67/65 · 103/78 76/60 · 272/251 · 145/126
32 MiB (32-raw-1mib-brackets) 46/40 · 48/48 · 75/70 53/52 · 49/47 · 88/62 50/39 · 185/170 · 124/112
20 MiB (32-open-streams) 27/26 · 38/36 · 61/55 26/25 · 35/34 · 63/44 35/28 · 127/116 · 96/88
10 MiB (one-10mib, opens) 58/53 · 26/26 · 35/33 61/38 · 26/25 · 58/36 79/73 · 81/74 · 76/72
16 MiB rescue copy (page) – · 33/33 · – – · 29/30 · – – · 133/124 · –
CAP envelope (page) – · 16/17 · – – · 19/16 · – – · 41/37 · –

The streaming sink removed the file's JavaScript copy; the page-side read brought WebKit from 272 to 145 MiB on a 50 MiB file (the probe without the application around it gave 106; the application build adds about 40, three samples 141 to 158). What remains in WebKit is its own cost of the module's linear memory (the sink alone, no file read, measured at 81 MiB for 55 MiB of linear memory) plus the worker; it cannot be removed without scanning the file without holding it, which the reader's contract (§B.1.2, one 16 MiB shared budget over candidates found anywhere in the file) does not allow cheaply. Note the 50 MiB cap is older than R4 (MAX_PDF_BYTES): an export of about 140 observations with rasters reaches it; L (121 views, 42 MB) imports.

Application build, the same 226 files and engines as the TypeScript baseline (R4.3d, scripts/browser/results/2026-10-18-r4-app-import.json, dist of e659924 built with SHEET_BUNDLE=draft; the hardenings of 8ddf185 are not in that build, they change no outcome): outcome and message identical on 666 of 678 pairs, the 12 others the four declared files; 0 page errors; W5: 0 Chromium long task over 50 ms (the TypeScript showed 91 and 173 ms); small files cost 25 to 35 ms more (the worker start and its sheet handle per import); the tolerance group costs half the TypeScript's memory. Duration medians, TS → Rust (ms): Chromium base 53 → 80, r3 63 → 100, step6 61 → 90, tolerance 57 → 82, read 66 → 75; Firefox 39 → 71, 73 → 107, 69 → 104, 53 → 79, 78 → 81; WebKit 52 → 80, 62 → 89, 66 → 91, 59 → 78, 75 → 77.

CSP (r4-app-csp.mjs): with the keyword the reference PDF opens the editor in the three engines (the known footer image violation only); without it, « Le moteur de lecture n'a pas pu être chargé. Réessayez l'import. » in the three engines, the button enabled again, no page error, every worker closed; Chromium and Firefox report the worker's wasm-eval refusal through report-uri, WebKit reports nothing for a worker.

Leak series on the application (R4.3d, content RSS, init = first import, then six imports of the same document with page.goto('/') and the replace dialog between them, 2 s idle each, 5 s at the end; init delta / growth over the last five / the same after the final idle, three repetitions): Chromium (forced GC) L 49 / 7.6, 9.7, 8.0 / 1.6, 3.6, 0.5; dense 10.6 / 2.1 ×3 / −0.6; copy 42 / 6.8, 11.0, 4.8 / −3.5, 1.1, −4.4, per-import deltas at or under 2 MiB after init. Firefox (idle only) L 72 / 42, 35, 44 / −5, −7, −13; dense 36 / 8.8, 9.1, 10.7 / −6; copy 60 / −2.6, 17.3, −5.0 / −21: a GC sawtooth reclaimed by the final reading, as its navigation-only control. WebKit (idle only) L 102 to 110 / 53, 67, 53 / 44, 65, 46; dense 44 / 38, 37, 34 / 40; copy 88 / 69, 35, 44 / 61, 35, 41: above the 10 MiB tolerance in every series, but the navigation-only control (same readings, no pick) grows 27 MiB too (about 5 MiB per same-tab navigation, the page cache), and a 12-import series on one page levels off at 365 to 382 MiB; a surplus over the control remains (about 2 MiB per import for the refused document, 6 for one that opens the editor) that cannot be called reclaimable without a forced GC. Twenty picks of the dense document on one WebKit Home page: 20 workers created and closed, 0 page error, content 330 → 379 MiB, peak 405.

Leak series (R4.3a measurement page, content RSS, init = first import): Chromium (GC forced) init 9 to 11 MiB, growth over the next five within ±0.5 on the three documents, three repetitions each; Firefox (idle only) init 5 to 7, swings of ±3 from its own GC timing, final idle delta 0; WebKit (idle only) init 17 to 38, the 16 MiB documents warm up in one or two steps (dense +17 to +20 once; copy +12 to +15 then +17 to +19) and drop 3 to 6 MiB at the fifth import, so the copy misses the 10 MiB window as written (+12.7 to +14.1 over the last five of six) while a 12-import series levels off (−2.3 over its last five). Twenty consecutive dense imports in WebKit: all refused, no worker error event (the one seen in an R4.2e smoke run did not reproduce).

J1 device run (2026-10-18, R4_J1.md, owner decisions BDR-059: both WebKit reserves accepted provisionally, PDF cap kept at 50 MiB): the owner reports the functional checks they executed on a computer as passed, no failure; iPhone / Safari iOS could not be run and is deferred, so it stays not tested and the final acceptance of R4.3 waits for it (OD-6). The browser and version, the checks covered, the timings (J1.8, J1.12) and the memory observations (J1.9, J1.10) are recorded in R4_J1_RESULTS.md as the owner confirms them. Headless engines never stand for Safari or a phone.

Residual risks and open points (R4.3, for the J1 checkpoint):

  • WebKit, 50 MiB file: 145 MiB of content growth against 76 for the TypeScript (BDR-058 gate "resolved or decided with numbers"): the owner decides between accepting it (an absolute peak of about 150 MiB, below the worker-read 324), lowering the PDF cap, or a streaming scanner later.
  • WebKit leak criterion: not demonstrable headless without a forced GC (above); the one-page series levels off; the device run at J1 gives the real signal (Safari's memory warning or a reload).
  • A hidden tab pauses the task timer by design (§B.1.5 item 3): a hostile file keeps the worker's CPU and up to about 51 MiB busy in the background until the tab is shown again; the core's own bounds (R4.2) are the only limit then.
  • The page reads the first KiB of the file to route it (unchanged since R3); nothing else of the file is parsed on the page.
  • The IMPORT_TIMEOUT_MS 20 s and the 10 s start timer are hypotheses to confirm on the owner's devices (plan §B.3 rule).
  • The import is 25 to 35 ms slower on small files (worker start and sheet handle per import); posting the handle's work is not worth a shared worker, which would keep hostile memory alive between imports.
  • The TypeScript reader stays in packages/pdf until R4.8 (parity and the full switch); apps/app/src/pdf/import.ts is now used by tests only.

10.6 R4.4: the layout in Rust (2026-10-18, nothing wired yet)

What runs in Rust (crates/core/src/pdf/write, feature pdf-write, enabled by the wasm facade and linked into the module only once R4.5 and R4.6 call it; the shipped size is unchanged until then): the text rules of packages/pdf/src/text.ts and render/text.ts (text.rs: safe_text with the Cc, Cf, Zl and Zp classes frozen from V8 in O4, not Rust's tables; js_upper from the O4 runs and specials; js_trim and the JS \s set; measure = Σ (WX or 250) + KPX over WinAnsi bytes, then × size / 1000 in that order; wrap_lines with JS split(/\s+/) semantics, empty words included), the AFM metrics and Unicode tables generated from O5 and O4 by scripts/r4-afm-data.mjs (afm_data.rs, 82 KB, deterministic), the dates of render/dates.ts (dates.rs: Date.UTC with years 0 to 99 mapped to 1900 to 1999 as A3 keeps them, proleptic Gregorian, fr-FR and en-US long forms), the input checks of export.ts (input.rs: branding and labels through their schemas, the snapshot gate with every asset through the R3 SVG reader, sheet mismatch, 500 observations and 8 views per observation) and the four layouts (layout/{header,footer,observation,conclusion}.rs) into a DrawLog (draw_log.rs: every text, image, line, rectangle call with its arguments at full precision, per page with the footer last, the links by page, the images in embed order with their pixel size read from the PNG header; the PNG gate and decode are R4.5).

Parity (cargo, pdf_text and pdf_layout):

Oracle Check Result
O4 measure 2,333 rows × 3 fonts × 8 sizes 55,992 widths equal; 4,800 recorded widths bit for bit
O4 wrapLines 73 cases × 2 sizes × 8 widths 1,168 wraps equal
O4 safeText every code point 0..0x10FFFF (the 2,048 surrogates excepted: not a Rust char; their row is question) 79 ranges equal
O4 upper every scalar value 1,580 changed code points equal; Rust's to_uppercase (Unicode 17) agrees with V8 on all of them
O5 every WX by byte and every kerning pair equal; WinAnsi pairs: Helvetica 1,295, Helvetica-Bold 1,181, Times-Roman 986
O6 6,468 grid cells × 2 locales, 22 others equal (1,355 refused cells)
O1 12 runs (3 reports × 2 locales × 2 logo modes), inputs = the envelope of each run's own R3 PDF, rasters = the goldens' stubs 2,124 calls equal at full precision, embeds and links equal
Step 6 text.* and images.* 24 goldens derived from the log in the engine's global call order (page contents, then footers), two decimals equal

Subtleties the port had to carry: U+00AD is WinAnsi (hyphen) but Cf, so dropped, while U+00A0 is kept; kerning goes by glyph name, so bytes 32/160, 45/173 and 255/159 share their pairs; a leading or trailing whitespace run gives an empty word to the wrap, which joins as a trailing space when it fits; words are split on raw JS whitespace before safeText runs (U+200B is dropped but not \s); Date.UTC applies the leap rule to the mapped year (0000-02-29 is refused, 1900 is not leap); the first-page link order of the saved file is per page (header, then footer), whatever the call order; the Step 6 text golden is in global call order, footers after every page.

Declared differences: none in the oracles. The snapshot assets go through the R3 SVG reader where the TypeScript ran its sanitiser (declared at R3, RUST.md §9.4, plan §A.3): a foreign archive the sanitiser cleaned and the reader refuses is snapshot_invalid with the reader's reason in the detail (the detail reaches the DEV console only).

Cost (release build, i7-11700B): L (60 observations) 61 pages, 2,377 calls, 124 embeds, checks 1 ms, layout 3 ms; CAP (500 observations) 501 pages, 19,625 calls, 1,004 embeds, checks 1 ms, layout 24 ms (debug: 29 and 222 ms).

Residual risks and open points (R4.4):

  • The PNG header alone sizes an image (embedPng's width and height); the UPNG acceptance rules and the branding PNG gate (pngIssue) are R4.5, with the O6 PNG cases (108). A PNG the header reads and UPNG refuses is not detected before R4.5.
  • rasterSizeOf (the raster request size from a viewBox, JS Number semantics) and numberToString are pinned in O4 but ported at R4.5 / R4.6 with the content emitter and the session.
  • The module size impact of the writer is measured when R4.5 links it (W1, the afm_data tables are 82 KB of source, the compiled tables about 12 KB).

10.7 R4.5: the serialiser in Rust (2026-10-18, nothing wired yet)

What runs in Rust (crates/core/src/pdf/write, with R4.4's layout): the content-stream emitter (content.rs: pdf-lib 1.17.1's operator sequences for the four calls, its cleanText, 24 TL, upper-case hex text, the doubled m of a line, h f of a filled rectangle; numberToString with its e-N / e+N branches and V8's Math.pow(10, k) one-ULP quirk at k = 23 and 210; WinAnsi encoding), the PNG side (png.rs: the branding gate pngIssue in its order, and a decoder that reproduces UPNG's decode and toRGBA8 with the deviations the O6 oracle pinned: the Average first-row pre-pass at absolute offsets, the 16-bit grey tRNS key at off + x, the 16-bit high byte, palette tRNS by declared length; pdf-lib's alpha drop; caps checked before any allocation; crafted files refused where UPNG spun or threw), a minimal object writer (objects.rs: numbered objects, streams, a classic xref, pdf-lib's string forms: UTF-16BE hex with a BOM, D: dates, hex ASCII URIs), the serialiser (serialize.rs: catalog with the names tree and /AF, the page tree, three Type1 WinAnsiEncoding fonts, one image XObject per embed with a DeviceGray /SMask /Decode [0 1] when an alpha is below 255, Link annotations /Border [0 0 0], the Info dictionary with Producer and Creator Faunosteo, the Flate EmbeddedFile with Params and its Filespec in clear, per-page resources listing only the images the page draws) and the driver (export.rs: the R4.4 checks, the envelope as JSON.stringify(_, null, 2) under 16 MiB, the layout, the file, then the self-check: the file re-read by the R4 reader must carry the envelope it was written with; export_from_envelope). The facade gets export_pdf_for_test on the proofs build only; the application's session is R4.6, so the shipped module is unchanged (426 KB gzip) until then.

Deviation from the plan, declared: pdf-writer is not used. The document has a dozen object kinds; a writer of 150 lines spells every number through numberToString (the B5 f32 difference the plan allowed never arises), keeps the string forms and key order under our control and adds no dependency to the module.

Parity (cargo pdf_content, pdf_png, pdf_serialize; Node pdf-export.test.ts, pdf-export.ts-engine.test.ts):

Check Result
Content streams of the 12 R3 PDFs (60 pages, 224,534 bytes) from the O1 logs equal byte for byte, resource names renamed only
O4 numberToString 703 cases equal
O6 PNG: 108 rows (gate verdicts, decode planes, error rows) equal; the 50 hostile files UPNG never ran return in under 20 ms
O2, 14 runs (12 stub-raster, the real-raster v2full-obs1, the store path): content after B3 name resolution, image planes and SMasks, links (rect spellings and URIs), Info but Producer/Creator, attachment bytes (store path: values; D-R11 order) equal
qpdf --check, pdfdetach -list clean, osteo-report.json listed, 14 files
poppler 150 dpi, R3 against R4, every page 0 of 150,193,611 pixels differ (14 runs)
R4 PDF → Rust import = R3 PDF → Rust import; report value equal to the envelope's 14 runs
re-export from the envelope byte-identical to the first export
wasm (proofs build) output the native digests, 14 runs (goldens/r4/pdf.*.sha256)
frozen O11 scanner and N-1 Zod readers (the R3 build and 0.2.0) read every R4 PDF; a stripped R4 PDF answers attachment_stripped
the TypeScript engine's reader the R4 PDFs give the R3 outcome, 12 runs
E2 (file ≤ R3 + 5 %) 12 runs: smaller every time
export-side security hostile SVG asset snapshot_invalid, URL injection refused by the schema and hex-only sink, a refused PNG logo fails alone with logo_failed

Cost, Node, stub rasters, same inputs for both (TS engine → Rust through the module): demo 198 → 36 ms, 29 → 3 MiB of RSS growth, 243 → 236 KB; L 772 → 57 ms, 50 → 1 MiB, 463 → 386 KB; CAP 5.7 s → 0.22 s, 155 → 9 MiB, 2.24 → 1.60 MB (the per-page resources: listing every embed on every page had cost 9 MB on CAP, fixed). Native release, L with a real 1200 × 943 raster on each of its 120 views: 46.5 MB file, 5.2 s (120 PNG decodes and deflates at pako's level 6; --ignored timing test).

Memory: linear memory of the proofs module after a one-shot export, stub rasters: demo 3.1 MiB, L 4.2, CAP 14.1. With the real raster on L, the one-shot proofs path reaches 524 MiB and 7.6 s: it receives the 120 PNGs as one JSON of base64 (85 MB as text, parsed to a value, decoded to 63 MB), the layout holds every PNG until the serialiser decodes it, and the file is assembled from the object bodies. That path is the test's, not the application's: R4.6's session (OD-2) must take each raster as bytes, decode and write its XObject on arrival and drop the PNG, so that the high-water mark is the file so far plus one decode (plan §B.4: ≈ 0.37 MB per view plus 9 MB). The serialiser is ready for that order (an image is written as its own object when given); the driver that interleaves the calls is R4.6.

Module size (W1): the writer linked (proofs build, which also holds the trap and allocation proofs) 1,652,719 B raw, 531,573 B gzip -9, +105 KB over the shipped module, inside the plan's estimate (+100 to 150 KB) and under 600 KB; above 550 KB it is to be reported, so R4.6 measures the shipped module again once the session links the writer.

Independent security gate (R4.5): PASS, 4 LOW, no blocker. Its probe ran 131,648 mutated or synthetic PNGs through the gate and the decoder (0 panic, 0 overflow, slowest 198 ms), 6.7 million rounds over the base64, date and number helpers, and hostile exports: report names holding PDF syntax reach the file as hex only (0 raw occurrence, qpdf --check clean, every /Length and xref offset exact), hostile URLs and exportedAt refused. Applied: the self-check scans without the reader's 50 MiB file cap (an export above it is a valid file the import refuses by size, as before); Ref(0) cannot underflow; pdf-write implies pdf-read. Reported: the self-check proves the attachment and the reader's read only (poppler covers the rendering of the corpus); the external-tools test skips on a host without qpdf and poppler (it ran here); the one-shot path holds each PNG twice and the file twice at the end (R4.6 input, OD-2); a view raster whose header reads but whose body fails to decode fails the export as self_check_failed where R4.6 makes it a per-key view_raster_failed warning.

Residual risks and open points (R4.5):

  • The one-shot export of L with real rasters is slow (5 s native, dominated by deflate level 6 of 400 MB of planes); E3 (≤ 1.2 × the TS export time in Chromium) is judged at R4.6 on the whole export; a lower deflate level would trade E2 (size) for time.
  • The decoder reproduces UPNG's accepted deviations on the oracle corpus; on files outside it (unusual interlace or tRNS combinations) UPNG's behaviour is reproduced by the code's structure, not pinned.
  • The self-check proves the file carries its envelope and that the R4 reader reads it; it does not render the pages. poppler's 0-pixel result covers the corpus only.
  • MAX_ATTACHMENT_BYTES keeps the 16 MiB envelope cap; an exportedAt that is not an ISO UTC timestamp is a new closed kind invalid_input, never reachable from the application.

10.8 R4.6: the application export on the core's session (2026-10-19, export switched)

What runs where. The core (crates/core/src/pdf/write/session.rs, views.rs) holds an ExportSession: new(input) runs the R4.4 checks, builds the envelope under 16 MiB and opens the file (header, Info, the three fonts); next_step() answers the rasters the next step needs (RasterRequest { key, svg, widthPx, heightPx }: the SVG logos in slot order, then each observation's views, main view first, composed by R3's compose_highlight at the size rasterSizeOf gives, the O4 cases pinned) or done; add_raster(key, png) and raster_failed(key) answer one key each; finish() lays out the conclusion page and the footers, writes the pages and the attachment, runs the self-check, and hands the file out in parts (take_part()). The refusals are closed kinds (unknown_key, duplicate_key, out_of_order), never a trap. The wasm facade exposes the same struct (crates/wasm: ExportSession, outcome envelopes); packages/core-wasm wraps it (CoreExportSession, openExportSession): every call goes through CoreRuntime.invoke, so a trap poisons the instance as any core call, and a session of a dropped instance answers core_unavailable without touching the dead handle. The application (apps/app/src/pdf/export.ts) drives it: the snapshot from the sheet handle, the bundled branding, the labels (labels.ts, moved verbatim from the engine, same key order), the clock, then the loop (browserRasterizer under Promise.all per batch, rasterFailed as each raster rejects, addRaster in request order once the batch settled, as the engine embedded), finish, a Blob of the parts, free() in finally; leaving the editor aborts the export (the session freed, no file). EditorRoute and its alerts are unchanged. exportReportToPdf keeps its signature but returns the Blob.

Buffers, ownership and lives (OD-2, the owner's R4.6 item 2):

Buffer Owner Lives Size
the ExportInput JSON the page (a string), copied into linear memory by the glue for new() the call report + snapshot + branding + labels (demo 338 KB)
CheckedInput (report, snapshot with its asset texts, index, the sanitised asset trees, branding, labels) the session until free() demo: 3.7 MiB of linear memory after new()
the envelope text the session until the self-check the attachment's size (demo 55 KB)
the file being written the session's Objects: chunks never reallocated, the target 1 MiB doubling to 8 MiB per chunk, an object larger than the target in a chunk of its own, a sealed chunk shrunk to its bytes until take_part() moves each one out (copied into the page, freed in the module) the file
a request's SVG text the core builds it, the page receives it as JSON the next_step() call (module side), the batch (page side) 143 KB per view
a raster PNG the page's Uint8Array, copied into linear memory by the glue for add_raster the call: decoded (RGBA, raw scanlines, RGB and alpha planes), deflated, written, then freed before the call returns 0.5 MB (PNG), about 10 MB of transients for a 1200 × 943 raster
a logo raster the session, until its batch completes (the branding embeds in slot order, as the engine did) the branding step the four logos
the draw log the session until finish() the text calls (KB)

So the module holds, at its highest, the file so far plus one decode plus the parsed input plus the open chunk's slack; nothing of the rasters once their object is written, nothing of the file once the parts are out. Measured on a fresh instance per run, the shipped module in Node, the growth of linear memory from before new() to after free() (linear memory never shrinks: the high-water mark), file in parts:

Run views PDF bytes parts linear before linear after growth / PDF ms
demo, 2 × 1 stub 7 235,948 1 1.25 MiB 5.9 MiB 20.6 52
L, stub 120 386,414 1 1.25 MiB 6.6 MiB 14.6 179
CAP, stub 1,000 1,599,445 2 1.25 MiB 13.7 MiB 8.2 1,195
demo, real 1200 × 943 7 3,282,540 3 1.25 MiB 18.0 MiB 5.4 499
L, real 120 46,464,887 8 1.25 MiB 62.3 MiB 1.38 7,062

L with real rasters: 62 MiB held for a 44 MiB file, where the 120 PNGs alone weigh 64 MB and the engine held every decoded plane until save() (plan §B.4: about 0.45 GB); the plan's estimate for the session was 53 MB (file + 9 MB). What the module holds beyond the file is bounded (the test asserts it under 24 MiB): the parsed input and trees (3.7 MiB), one decode (about 10 MiB), the open chunk's slack (up to 8 MiB). Stage by stage on L real: 1.3 MiB at start, 5.0 after new(), 15.5 after the second raster (the first decode), then 0.34 MB per raster for 0.364 MB of file per raster, 62.3 before finish(), 62.3 after, 62.3 after the parts are out and the session freed.

Two findings on the way, measured and kept:

  • A single growing Vec for the file (amortised doubling) spiked to 125 MiB on L real: the reallocation holds the old and the new buffer while it copies, and the decode transients sit between the file and the top of the heap, so dlmalloc could not grow it in place. Chunks never reallocated remove the spike.
  • Chunks of 1 MiB cost 0.12 MB of fragmentation per view (a long-lived allocation interleaved with 10 MB of transients every other raster: 74 MiB for the same file); 8 MiB chunks cost none (62.3 MiB). The target starts at 1 MiB and doubles per chunk up to 8 MiB, so a small file pays little slack (demo: one chunk).

Declared differences, each one a B2 or B4 class of plan §B.2.3, every O2 comparison and the poppler render re-run unchanged:

  • The catalog and the page tree (objects 1 and 2) are written last (the xref maps them); R4.5 wrote them first. The R4 digests (goldens/r4/pdf.*.sha256, the writer's own bytes, not a TypeScript oracle) were rewritten once for it, with the O2 suite, qpdf, pdfdetach and poppler (0 pixel) green on the new layout.
  • UTF-16BE hex strings are printed in upper case, as pdf-lib printed them (R4.5 printed lower case: B4, the same decoded value).
  • pdf-writer stays unused (R4.5).
  • A view raster the decoder refuses is that view's view_raster_failed warning, as embedPng throwing was in the engine; R4.5's one-shot path made it self_check_failed.
  • The self-check scans the bytes from the attachment stream object to the end of its chunk, behind the file header, with the R4 reader: the reader finds the attachment by scanning its bytes, never by the xref, and the file is never held whole in the module. The bytes scanned are the file's.

Parity and restoration (cargo pdf_session, pdf_serialize, pdf_layout; Node pdf-export.session.test.ts; the app suites):

Check Result
the session driven key by key = export_pdf one-shot (bytes, envelope, warnings); the file grows as the rasters arrive demo, equal
the 14 O2 runs through the shipped module and CoreExportSession the native digests
every view request = the TypeScript composeHighlightedViewSvg text of that (observation, view); every (observation, view) the snapshot holds requested once 14 runs, all views
the real-raster run: the two SVGs the R4.1 rasteriser drew (manifest.json svgSha256, 1200 × 263 and 1200 × 943) equal, sizes equal
rasterSizeOf, the O4 cases (JS Number() on the viewBox parts, the clamps) 57 cases equal
warnings: a raster that fails before any embed, then a PNG the decoder refuses, view order; a logo warning at its slot whatever the arrival as the engine recorded them
refusals: before next(), a key not in the batch, answered twice, next() with keys unanswered, finish() early or twice, after free(); garbage, empty and truncated PNGs closed kinds, no trap
a trap mid-session (proofs build) the instance poisoned, the session answers core_unavailable, free() safe, a new session on the recovered instance writes the digest
export Rust → import Rust (the module's import_pdf, the bundled sheet) 14 runs: envelope_v1, the report equal, not rebased
export Rust → the kept TypeScript reader (importReportFromPdf, the app suites) → the core the roundtrip, leaves, N-1 and envelope suites (27 cases): equal reports, the 612 leaves (29 unresolved) kept
N-1 (O11 scanner and the Zod copy: the R3 build and 0.2.0) every R4 PDF of the O2 runs read; a stripped one attachment_stripped (R4.5 suite, unchanged)
the app path (exportReportToPdf, stub rasters, the clock fixed at FIXED_EXPORTED_AT) the 12 R4 digests (3 reports × 2 locales × 2 logo modes)
the Step 6 goldens (text with page, position, size and font; images; links) read back from the app path's file 12 runs equal, in page order (the recorder listed every footer last; the file lists each page's footer after its content)
pdf.roundtrip (16), pdf.goldens (13), pdf.export.app (2), routes.EditorRoute.export (6, abort on unmount added), routes.coreStopped (15), state.coreFailures (5), migration.leaves (2), n-1.reader (6), archive.envelopes (3) green on the Rust export; the suites read the file's content streams (tests/helpers/pdfRead.ts) where they spied pdf-lib
the oracle generator r4.writer-oracles (17) still verifies the frozen O1 / O2 oracles against the TypeScript engine, called directly with the application's inputs

The engine leaves the application's export path: apps/app/src imports @faunosteo/pdf for the kept reader only (pdf/import.ts); pdf-lib is no longer in the application bundle (index chunk 922 KB). packages/pdf stays until R4.8 as the R3 reference of the oracle suites and the tests' reader.

E3 and E4 in the browsers (scripts/browser/export-baseline.mjs, 2026-10-19, results/2026-10-19-ts-export.json on the build of the last TypeScript-export commit, results/2026-10-19-r4-export.json on the R4.6 build; both under the same harness, the same host, the same evening, demo and L three runs each, CAP once; the production CSP; compare-exports.mjs prints the tables). Time is the page clock from the click to the PDF blob, the median of the runs:

Engine Report TS Rust Rust / TS TS file Rust file
Chromium 156 demo 1,372 ms 916 ms 0.67 2,852,004 2,823,275
Chromium L 19,286 ms 14,218 ms 0.74 43,893,082 43,536,994
Chromium CAP stopped by the 4 GiB ceiling after 818 PNGs 117.6 s 360,935,689
Firefox 157 demo 1,559 ms 1,035 ms 0.66 2,872,189 2,843,130
Firefox L 24,559 ms 16,574 ms 0.67 44,105,143 43,743,780
Firefox CAP stopped after 565 PNGs 138.0 s 362,665,313
WebKit 27.2 demo 2,626 ms 2,386 ms 0.91 2,493,691 2,473,027
WebKit L 52,251 ms 49,538 ms 0.95 38,557,714 38,286,426
WebKit CAP stopped after 962 PNGs 412.2 s 317,323,081

E3 (Rust ≤ 1.2 × the TypeScript on demo and L in Chromium): 0.67 and 0.74, met; Firefox 0.66 and 0.67, WebKit 0.91 and 0.95. E4: L completes on the three engines (it did with the engine); CAP completes on the three (1,001 rasters, a 361 MB file) where the engine was stopped by the harness ceiling on every engine, as at R4.1. The phone part of E4 is the owner's J2.6.

Where the time goes (medians; head = click to the first raster, raster phase = first toBlob start to last toBlob end, tail = last raster to the PDF blob; the Rust driver's User Timing adds the sum of its core calls and of its rasteriser awaits):

Engine Report TS head / raster phase / tail Rust head / raster phase / tail Rust core calls Rust raster awaits
Chromium demo 62 / 794 / 518 27 / 803 / 80 487 415
Chromium L 66 / 11,880 / 7,381 27 / 14,014 / 178 7,153 7,066
Chromium CAP 57 / 117,093 / 495 58,970 58,521
Firefox demo 62 / 841 / 650 20 / 942 / 74 455 573
Firefox L 67 / 14,762 / 9,731 25 / 16,382 / 173 6,684 9,862
Firefox CAP 60 / 137,464 / 474 55,024 82,803
WebKit demo 63 / 2,193 / 370 20 / 2,283 / 81 455 1,918
WebKit L 70 / 47,227 / 4,957 25 / 49,260 / 251 6,733 42,693
WebKit CAP 54 / 411,048 / 1,091 55,372 356,032

The engine's tail (its save(): every plane deflated at the end) is gone: the Rust tail is the conclusion page, the pages, the attachment and the self-check (80 to 250 ms on demo and L). The core's own work (decode, deflate at level 6, write) is 7 s on L and 59 s on CAP in Chromium, interleaved with the browser's rasterisation, which is the other half (7 s on L in Chromium, 43 s in WebKit); the export is bound by those two, in sequence per batch.

Memory in the browsers (content process RSS, MiB; growth = settled after − settled before, forced GC in Chromium, idle elsewhere):

Engine Report TS peak Rust peak TS growth Rust growth
Chromium demo 307 264 17 28
Chromium L 805 470 43 92
Chromium CAP 3,739 (stopped) 1,787 560
Firefox demo 378 291 77 78
Firefox L 1,397 819 183 264
Firefox CAP 3,487 (stopped) 1,914 826
WebKit demo 658 593 277 144
WebKit L 1,191 848 210 218
WebKit CAP 3,871 (stopped) 2,633 552

The peak falls everywhere (L: 805 → 470 MiB in Chromium, 1,397 → 819 in Firefox, 1,191 → 848 in WebKit). The settled growth after the export is higher on L and CAP: it is the module's linear memory, which never shrinks (plan §B.4 "the same high-water, until reload"): the file was held once in the module (44 MB on L, 361 MB on CAP) plus the transients, and that memory stays reserved for the page's next export instead of being returned. The engine's growth was JavaScript heap, collected. On CAP the page keeps about 560 to 830 MiB after the export; CAP is the cap, not a bilan, and the engine never finished it.

Release across exports (scripts/browser/r4-export-series.mjs, results/2026-10-19-r4-export-series.json, …-ts-export-series-chromium.json, …-r4-export-series-chromium-12.json): one editor tab, the start level, a first export (init) and six more, the content RSS read after each (forced GC in Chromium; idle elsewhere, indicative), the import series' criterion of 10 MiB over the last five:

Engine Report Init Per export Last 5 Peak content
Chromium, Rust demo 28.0 MiB 1.5 / 2.5 / 2.8 / 2.5 / 3.4 / 1.2 12.3 MiB 287 MiB
Chromium, Rust L 92.2 25.5 / 21.1 / 20.1 / 13.3 / 23.9 / 22.4 100.8 643
Chromium, TypeScript (control) demo 16.1 3.1 / 3.3 / 2.1 / 1.6 / 2.2 / 1.6 10.9 330
Chromium, TypeScript (control) L 44.6 20.7 / 14.8 / 19.6 / 18.3 / 22.1 / 22.7 97.6 957
Chromium, Rust, 12 exports L 95.2 19.7 / 27.3 / 11.1 / 29.5 / 14.0 / 28.4 / 16.7 / 22.6 / 4.4 / 1.5 / 3.4 / −4.3 27.6 (the last five) 686
Firefox, Rust demo 95.1 93.9 / −6.7 / 103.3 / −50.4 / 96.5 / −41.8 100.8 596
Firefox, Rust L 263.8 156.8 / 0.7 / 86.9 / −196.3 / 58.7 / 74.1 24.0 1,024
WebKit, Rust demo 139.8 91.5 / 225.9 / −216.8 / 108.3 / −90.4 / −0.3 26.9 946
WebKit, Rust L 326.7 153.7 / 14.7 / 1.2 / 1.1 / −0.4 / 2.3 19.0 1,992

Reading: the per-export growth of about 20 MiB on L in Chromium is the browser's, not the session's: the TypeScript build shows the same figures on the same page (control), and the module's linear memory, read in Node over seven L exports with real rasters on one instance, stays at 62.3 MiB from the first export to the last (the session frees everything at free() and the next export reuses it). Over twelve exports Chromium's growth stops after the eighth (the last five: 27.6 MiB, then a plateau), which points at a bounded cache (canvas backing stores or the blob URLs kept 30 s by downloadBlob), not at a leak that grows with use. Firefox and WebKit sawtooth without a forced GC, as in the import series; WebKit L settles after the second export. The criterion as written (10 MiB over five) is not met by either build on L in Chromium; the behaviour is the engine's, the module flat, the plateau reached. Kept as an observation for the owner (BDR-058's reserves extend to it), with the phone series J2.7 due.

Release on the other paths (cargo pdf_session, Node pdf-export.session.test.ts, the route test): success (every part out, free()), a refused input (no session, the runtime stays ready), a raster that fails (its warning, the export continues), a trap mid-session (the instance poisoned and recovered, the session answers core_unavailable, free() a no-op on the dead handle), a cancelled export (the editor left mid-way: the signal aborts the driver, free() in finally, no download, no alert). Dropping the session, finished or not, frees everything it holds (Rust ownership); nothing of the file survives free() in the module.

Module size (W1): the shipped module with the writer and the session linked, 1,535,289 B raw, 519,730 B gzip -9 (the proofs build 531.6 KB at R4.5 held the trap and allocation proofs too). Under the 550 KB report line and the 600 KB budget; from 426 KB at R4.3, +94 KB for the whole writer. DEPLOY.md's served-size note is updated at R4.8 with the final module.

Residual risks and open points (R4.6):

  • The settled growth after a large export is the module's linear memory (the file once, the transients, the chunk slack), kept until reload: 92 MiB after L and 560 MiB after CAP in Chromium. Within the plan (OD-2: "the same high-water, until reload"); the disposable export worker (S2) stays the fallback if a device fails L (J2.6).
  • The export is bound by the browser's rasterisation and the core's decode and deflate (level 6) in sequence per batch: L takes 14 s in Chromium and 50 s in WebKit (the engine: 19 and 52). A lower deflate level or overlapping the next batch's rasterisation with the core's writing would cut it, at the price of E2 or of a second copy in flight; not done.
  • The per-export RSS growth in Chromium is the browser's and plateaus; the 10 MiB criterion is not met by either build on L. Owner decision.
  • view_raster_failed now also covers a PNG the decoder refuses and a view that cannot be composed; a raster that never settles still hangs the export (the engine's residual, unchanged; the abort on leaving the editor frees the session).
  • The headless runs validate nothing on a device: J2 (R4_J2.md) on the owner's computer and iPhone, with the J1 import recette still due.

10.9 R4.7: the archive check tool on the core (2026-10-19, pnpm report:compare switched)

What runs where. crates/core/src/pdf/compare (feature cli, which enables the reader and the writer; never enabled by the wasm facade, so the shipped module is unchanged: 1,535,289 B raw, 519,795 B gzip -9) holds the tool without its file system: compare_bytes reads a PDF's attachment with the R4 reader (read_attached_document, no value cap, as the TypeScript had none), parses it as the session does (parse_json), reads it through the layered archive reader (read_archive_document, the R2 code the application imports with), and prints it as compare/report.ts did (lines.rs: zone and finding lines, !! UNRESOLVED with its reason, the migration lines of a v2 archive, the header with the sheet check and the counts, the footer, the --full texts), with esc on every untrusted string (V8's [\p{Cc}\p{Cf}

], the SAFE_TEXT_DROPPED table of R4.4); run.rs is main (parse_args, the loop over the entries, --summary, --diff, stdout, stderr and the exit code) over a Files trait. The binary src/bin/report_compare.rs (the one file of the crate allowed std::fs and std::env) loads the seed draft sheet (sheet-ref.json, document.json, report-migration-map.json; no drawing: the comparison needs none), resolves the arguments against INIT_CWD (the folder pnpm was typed in, as the TypeScript did) and implements Files (a folder stands for its .pdf files sorted; a missing, unreadable, irregular or oversized entry is a failed entry). pnpm report:compare runs scripts/report-compare.sh (rust-env.sh, then cargo run --release --locked -q --features cli --bin report-compare): the first run compiles the binary (25 s on the development machine), the next ones start at once. The TypeScript CLI (apps/app/scripts/compare-reports.ts, compare/*) and its vitest suite stay until R4.8 (the O10 generator still runs them), with the app's own report:compare script no longer behind the root one.

Parity (cargo pdf_compare, 15 tests, 1.6 s): the 230 invocations of the O10 oracle (tests/oracles/r4/compare/compare.json: every fixture PDF, the step6 folder with and without options, the argument errors, the 22 runs of the 11 scripts.compare.test.ts cases on their scenario PDFs) replayed in-process through run on the seed sheet. The 158 rows the plan does not declare match exactly (stdout, stderr, exit code); the 11 cases have one cargo test each (the ledger targets, pdf_compare::<case>, 0 pending rows left of 301). The real binary is spawned on the six cli and folder rows and on two scenario rows: byte-equal to the pure run and to the oracle. The 72 declared rows (§A.3) print one closed line each, exit 2:

TypeScript printed Rows Rust prints
a ZodError dump (the issues as JSON, escaped) 63 report document invalid: <the core's detail> (62: missing field \id`on the scan and read corpora,missing field `conclusion`, invalid type: null, expected f64` for the overflowing vertebra index); 1 decoy-first file whose decoy holds a lone surrogate: the refusal below, before any schema
the comparison, a lone surrogate kept in the content or a key, or overwritten by a duplicate (OD-4) 6 attachment refused: lone UTF-16 surrogate escape at byte N
report version Infinity cannot be read (2) and the report under archive v1 (snapshot rejected: unsupported_envelope) (1) 3 report version null cannot be read: the overflow reads as null in the core (rewrite_overflow_numbers), as the R3 application path already saw it (O8 no_attachment for the same three files)

Nothing else differs: the labels, the migration lines, the __proto__ ids, the control characters escaped (\u001b, \u000a, \u009b, ‮, 
, five-digit code points as 1), the --diff of the placeholder and --full forms, the usage and option errors on stderr with exit 1, the failed entries with exit 2.

Time and memory (release binary, the development machine): one PDF 7 ms (the seed read and indexed, the file compared), the three fixture folders (72 entries, the R3 real-raster PDFs and the tolerance corpus included) 185 ms, the r4/read corpus (131 files) 135 ms; 6 MiB resident on the step6 folder. Through pnpm report:compare the launch is cargo's (about 250 ms per invocation, the binary already built); the TypeScript CLI took 270 ms for one PDF and 410 ms for the three folders under tsx.

Declared behaviour (plan §A.3, no other): the three lines above. The output of every other row is the TypeScript's. --locale, --summary, --full, --diff and the folder expansion keep their meaning; the exit codes keep theirs (0, 1 usage or option, 2 failed entries).

Residual risks and open points (R4.7):

  • The tool reads the seed from the repository checkout (CARGO_MANIFEST_DIR/../../supabase/seed/…), as the TypeScript read it from its script folder: the binary is not relocatable. A copied binary prints the missing seed path and exits 1.
  • The report document invalid line carries the core's serde detail (missing field …, invalid type …, unknown variant …): the field name or the offending value of the file, escaped; the TypeScript's ZodError dump carried the same and more.
  • A PDF over 50 MiB is refused by the entry check (file too large) before the reader, as before; the reader's own cap would say not a readable PDF.

10.10 R4.8: the TypeScript PDF engine deleted (2026-10-19)

Audit before every deletion (owner's R4.8 brief §2): every importer of @faunosteo/pdf, pdf-lib, @pdf-lib/*, @resvg/resvg-js, @xmldom/xmldom and @faunosteo/domain was listed across the application, the glue package, the tests, the scripts, the pipeline, the workspace files, the Dockerfile, the CI files and the docs (grep census, now the r4.census suite). The application's last consumer of the engine (the TypeScript import path, tests only since R4.3) and the glue's (the session suite's compose check, the engine comparison) were moved onto the core or deleted first; the pipeline's consumers (packages/anatomy/src/curation/app-review.ts → render/compose.ts, 22 files → @faunosteo/domain) stay until R5.

Deleted (70 files, 12,010 lines of TypeScript):

  • packages/pdf/** (3,122 lines of engine, 8,211 of tests): the export, the layered reader, the byte-scan attachment reader, the SVG sanitiser and the view composition, the page renderers, the branding gate, the labels, the 140 engine cases and the R3 and R4 oracle generators (r3.{highlight,sanitiser}-oracles, r4.{dates,inflate,png,reader,text}-oracles) with their helpers (resvg, the reader-input crafters).
  • apps/app/scripts/compare-reports.ts and compare/{report,sheet}.ts (589 lines, the TypeScript CLI replaced at R4.7), tests/unit/scripts.compare.test.ts.
  • apps/app/src/pdf/import.ts (the TypeScript scanner behind importReportFromPdf, tests only since R4.3) and tests/unit/pdf.import.test.ts.
  • tests/unit/pdf.export.app.test.ts (T2 and scenario 3 through the engine's exportFromEnvelope: the re-export from the envelope alone is cargo's export_from_envelope, whose signature takes no sheet and no branding, byte-equal to the R4 files on 13 runs).
  • The application's generators r4.{compare,tolerance,writer}-oracles and tests/helpers/r4-draw.ts (the pdf-lib draw recorder); the glue's pdf-export.ts-engine.test.ts (the Node timings against the engine, recorded in §10.7).
  • Dependencies: @faunosteo/pdf (app, core-wasm), pdf-lib, tsx and the app's report:compare script (app), @faunosteo/domain (app: its two incidental test uses moved to @faunosteo/core-wasm/types and the N-1 Zod copy), the Dockerfile's COPY packages/pdf/package.json. pnpm-lock.yaml holds no pdf-lib, @pdf-lib/* or @resvg/resvg-js any more; @xmldom/xmldom only under packages/anatomy.

Replaced in the tests (no case ignored, no golden regenerated):

Before After
pdf-lib parsed the app export's file (texts, images, page count, Info, Filespec) tests/helpers/pdfFile.ts, a reader of the writer's own format (objects, dictionaries, Flate streams through node:zlib, pages in /Kids order, Info, annotations, XObjects); pdfRead.ts keeps its content-stream parser on it
pdf-lib read the links of the file the same reader's annotations (goldens.ts readLinks)
pdf-lib built the foreign PDFs of the rejection cases buildPdfWithAttachment (a minimal file with one embedded file in clear) and the frozen hostile fixtures
pdf-lib's embedPng checked the golden rasters the XObject sizes read from the app export's file
the engine composed the views of the views.*.json goldens the SVGs the core's session asks the rasteriser for, captured at the mocked rasteriser in request order
the engine's scanner read the attachment of the envelope and N-1 suites the frozen O11 scanner, now exported by @faunosteo/core-wasm/n-1 (readAttachmentBytes, readAttachedDocument): the R3 build's reader, as a rollback would read
importReportFromPdf (TypeScript scanner + core) tests/helpers/pdfImport.ts: the module's SheetHandle.import_pdf on a handle of the bundled sheet, the envelope mapped by the worker's pdfImportOf (the same kinds HomeRoute shows); the main-thread session still never calls the reader (OD-1)
the session suite compared each request SVG with the engine's composeHighlightedViewSvg structural facts per request (the view's frame, the highlight, no editor attribute) and the real-raster manifest digests; the text itself is cargo's (pdf_session against compose_highlight, anatomy_compose against the frozen R3 trees)

Still TypeScript, with the reason (owner's R4.8 brief §6.4):

  • packages/anatomy (the curation pipeline, the legacy importer, the frozen renderer render/ and @xmldom/xmldom): R5's scope, consumed by pnpm import:equine and the seed golden; no app and no PDF consumer.
  • packages/domain: the pipeline's schemas until R5; the application and the glue no longer depend on it.
  • packages/core-wasm/tests/n-1/{domain,scanner}: the frozen N-1 readers (the R2 Zod schemas, the R3 byte-scan reader), never edited, permanent.
  • apps/app/src/pdf/{export,labels,branding,browserRasterizer}.ts: the application's side of the export (input assembly, the session driver, the browser's rasteriser), UI glue by the review's boundary.
  • apps/app/src/core/worker/**: the import worker (protocol, timers, outcome mapping), browser glue.
  • The test readers above (pdfFile.ts, pdfRead.ts, pdfImport.ts): tooling on the writer's own files, never product logic.
  • scripts/r4-afm-data.mjs: the generator of afm_data.rs from the frozen O4/O5 oracles (no pdf-lib: reads afm.json and text.json), kept so the tables stay reproducible.

Census and gates: apps/app/tests/unit/r4.census.test.ts (8 checks) fails on a reintroduced import of the engine, pdf-lib, the TS domain or xmldom under apps/app/src or packages/core-wasm/src, on a dependency added back, on a lockfile holding pdf-lib, on an export that does not open the core's session, on an import that does not go through the worker, on a root report:compare that is not the binary, and on a missing N-1 reader or oracle folder. The ledger (scripts/r4-ledger.mjs) now reads its 301 frozen cases from the committed TSV (the deleted suites cannot run), re-derives the dispositions and checks every cargo target against cargo test --list and every vitest (same case…) target against the live report of the surviving suites: 150 ported, 29 replaced, 89 kept, 33 deleted, 0 pending. Test counts after R4.8: apps/app 57 files, 427 cases (460 before: 42 of the deleted suites, 1 roundtrip case added, 8 census); packages/core-wasm 58 (60); packages/pdf 146 → 0; cargo unchanged (R4.7: the compare suite included). pnpm typecheck, pnpm -r lint, pnpm check and pnpm rust:check green; pnpm check:all (the app image, the worker test stage and image) recorded below.

Non-regression (owner's R4.8 brief §3), each with its proof:

Guarantee Proof
the application imports through the core's reader r4.census (HomeRoute → core/worker, handler.ts → import_pdf_bytes, no scanner identifier under src); the route and worker suites (routes.HomeRoute.{import,archive,rescueCopy}, core.importWorker)
the export runs on the core's session r4.census (export.ts → openExportSession); pdf.goldens: app-path bytes = the R4 digests at the fixed time
report:compare is the binary r4.census (root script → scripts/report-compare.sh → --features cli --bin report-compare); cargo pdf_compare spawns it
v2 and v3 archives stay compatible pdf.roundtrip (the frozen v2 PDFs migrated, unresolved items flagged), migration.leaves (612 leaves exported and read back through the module, 29 unresolved kept), cargo pdf_import O7/O8
historical PDFs stay readable cargo pdf_import and pdf_serialize::restoration_round_trip_loses_nothing on the Step 6 and R3 fixtures; pdf.goldens on report-v3.bare.pdf; the N-1 suites on the R4 files
the validated renders stay conformant pdf.goldens (Step 6 text, images, links read from the file; the R4 digests), cargo pdf_layout (O1), pdf_serialize (O2, poppler 0 pixel recorded at R4.5)
rescue copies and data-loss protections routes.HomeRoute.rescueCopy (13), routes.coreStopped (15), state.coreFailures (5), the quarantine suites, unchanged
no TypeScript engine active in parallel r4.census; the only TypeScript readers left are the frozen N-1 copies, read by tests only

Residual risks and open points (R4.8):

  • The test reader pdfFile.ts reads the writer's own format only (one dictionary per line, direct /Length, classic xref): a change of the writer's layout changes it too; it is tooling, pinned by the suites that use it.
  • tests/helpers/pdfImport.ts runs the module's reader on the test process's main instance (a throwaway handle, freed): the application never does (OD-1); the worker path keeps its own suites.
  • A stale packages/pdf/node_modules folder (git-ignored symlinks of the previous install) may linger on a development machine after the pull: rm -rf packages/pdf by hand; the census checks the package files, not the folder.
  • The open points of §10.8 stand: the Chromium per-export growth (BDR-063, an open reserve), J1 and J2 on real devices before any merge, the WebKit reserves BDR-058/059, the hostile-file protections (PDF_IMPORT_HARDENING §5 gate open), the module at 519,795 B gzip of a 600 KB budget. R4.8 measured nothing new on memory or time and claims nothing.

R5 prerequisites (the pipeline port): packages/anatomy (curation pipeline, importer, render/, the review drawings) and packages/domain are the last TypeScript business packages; their oracles (the seed golden, the 612-leaf semantics, the determinism and count suites, the R3 layer oracle) are in place; documentSha256 will change once (D-R5 rev 2; revised by the R5.1 study, §11.4 to §11.6) and every older archive will rebase on import; @xmldom/xmldom, tsx and prettier on generated files leave with them.

10.11 R4.9: final checks, memory bench, audits (2026-10-20)

The owner's R4.9 brief: final verification without new development, the memory bench before any merge (the R4.6 Chromium reserve stays open until measured), the import risks classified, the J1 / J2 recettes re-issued, the independent verifier and security audit. Contract .claude/tasks/contracts/2026-10-20-rust-r4-final-1000.md.

Memory bench (scripts/browser/r4-memory-bench.mjs, probes in lib/memory-probes.mjs, results scripts/browser/results/2026-10-20-r4-memory-bench*.json; build f36dbdd, module faunosteo_wasm_bg-9CH7GQ4e.wasm 1,535,289 B; i7-11700B, 16 threads, 15.8 GB; Chromium 156, Firefox 157, WebKit 27.2, headless). One editor tab per engine and report, the start level, the init export, then 6 exports (16 for the Chromium series below), then four rest windows: settled (5 s), after the 30 s downloadBlob revocation window, Home (the editor left by its link, the page and its runtime kept), Home idle (10 s); Chromium ends with a simulated critical memory pressure (CDP). Every reading tells apart (1) the module's linear memory, read on the page's live WebAssembly.Memory, (2) the renderer RSS (and the summed RSS of the browser tree), (3) the live canvases, images, bitmaps, Blobs and PDF Blobs (created − collected, FinalizationRegistry) and the object URLs (created − revoked), plus in Chromium the precise JS heap, the DOM counters and a heap snapshot census of the same classes, (4) the transient peak of the renderer during each export, (5) what each rest window keeps against the level after the init export. Chromium readings follow a forced GC; Firefox and WebKit are read after idle only (no forced GC: their RSS figures are indicative, their collection counts are not forced).

Renderer RSS, MiB (absolute; linear memory in the last column):

Engine Report Start After init After 6 Settled After revoke Home Home idle Max peak Linear after init (then flat)
Chromium demo 150 190 204 202 197 198 188 302 18.8
Chromium L 155 260 393 389 395 395 386 626 63.8
Firefox demo 160 241 461 426 332 331 287 628 18.8
Firefox L 168 516 432 420 280 280 237 1,147 63.0
WebKit demo 319 466 820 820 813 815 813 944 18.8
WebKit L 329 666 758 758 752 757 754 2,129 55.0

What each dimension shows:

  1. Linear memory: the init export grows it once (demo +14.2 MiB, L +50 to 59 MiB: the file held once plus the transients, OD-2), then 0.0 MiB on every later export in the three engines, through 16 exports in Chromium, and nothing after the rest windows or Home (it never shrinks, by design, until reload). One instance, never re-instantiated. The session frees everything it holds at free() and the next export reuses it.
  2. Renderer RSS: see below for Chromium. Firefox ends below its post-init level on L once the revocation window passes (−279 MiB at Home idle) and 46 MiB above it on demo, a sawtooth without forced GC. WebKit climbs over the first three demo exports, then stays flat (export 3 to 6: +0.1, +5.5, +0.3; Home idle 813 against 820 after the sixth) and grows 54 MiB over the last five L exports, flat over the rest windows: a high-water reached early, not a slope per use; no forced GC there, so the figure is the engine's lazy return.
  3. Canvases, images, Blobs, object URLs: every canvas, Blob and PDF Blob the exports created was collected in Chromium (847 / 847 on L), Firefox (L 847 / 847; demo 54 / 56 without a forced GC) and WebKit; the 4 images still alive are the page's own (header logos); every object URL was revoked once the 30 s window had passed (854 / 854 on L), none during it but the downloads'. The Chromium heap census holds one canvas element and no image beyond the page's own after the series; the precise JS heap stays at 6.8 to 8.4 MiB (7.4 at Home). No DOM node, document or listener accumulates (L: 3,364 nodes after every export).
  4. Transient peaks: per export, the renderer rises 86 to 112 MiB on demo and 220 to 390 MiB on L in Chromium, 350 to 600 MiB on L in Firefox and about 1.3 GiB on L in WebKit (its rasterisation, 50 s per export), then falls back; none approaches the harness ceiling.
  5. Durable retention: Chromium is the only engine whose settled level keeps rising with exports on L, so it got its own series and a control.

Chromium, L, 16 exports, and the raster-only control (--mode raster: after the init export, each step replays the rasteriser's own steps on the view drawings the init export drew, at its sizes, with no core call), renderer RSS after each step (MiB):

Run Init Steps 1 to 8 Steps 9 to 16 Last 5 Home idle After critical pressure
Export (core session + rasteriser) 264 287 → 428 (+20 per step) 439 → 436 −7.3 437 438
Control (rasteriser only, no core) 262 286 → 429 (+21 per step) 433 → 438 +3.8 436 437

Reading. The growth of about 20 MiB per L export in Chromium is the browser's raster path, not the session's: the control, which never calls the core, grows by the same amount at every step and reaches the same plateau (436 against 437 MiB); the module's linear memory is flat, the JS heap flat, no canvas, Blob or URL survives. Both runs stop growing after the eighth step and stay flat for eight more (last five: −7.3 and +3.8 MiB, inside the 10 MiB criterion of BDR-058). A simulated critical pressure does not return it, so it is memory the renderer keeps (an internal raster or decode cache, or allocator pages it does not release) rather than objects the page holds. The R4.6 observation is confirmed and now explained: bounded at about 170 MiB above the post-init level for 120 views of 1200 px per export, reached after about 8 L exports, identical without the core; the deleted TypeScript engine showed the same figures (§10.8 control). On demo the same path costs about 2 MiB per export.

Class: not a retention of the export (the core frees everything; the page keeps no canvas, image, Blob or URL); not blocking. Severity: a desktop tab that exports L eight times carries about 170 MiB more until it is closed; a phone that exports L repeatedly is J2.7 and J2.6's object (the device run, not the headless one, decides). Correction proposed only if a device shows it: draw every view on one reused canvas (or an OffscreenCanvas) instead of a new canvas per view, measured with this same bench against the control before any adoption; no change made at R4.9 (no measure says it would help, and the rasteriser's output is pinned pixel-identical).

Proof pnpm report:compare (J2.14 dry run): the R3 demo PDF and an R4 session export of the bilan it carries (shipped module, stub rasters): --diff prints identical v3 content, exit 0 (first run 25 s: the tool compiles); the single listing has no !! line, 0 unresolved.

Full checks (2026-10-20, f36dbdd): pnpm check:all green in 2 min 37 s: rust-check (fmt, clippy -D warnings, cargo test, ts-rs, deny; advisories ok), types drift none, wasm:build, Node typecheck + tests (app 427, core-wasm 58, domain 262, anatomy 131, supabase 40) + lint 0 + build, the application image, the worker sandbox tests and the read-only worker image. Ledger: 301 rows, 0 pending, every target present (node scripts/r4-ledger.mjs regenerates the committed TSV byte for byte). Frozen oracles and goldens: nothing frozen at R4.1 (aada799) differs but the two R4.2 additions; the R4 digests are unchanged since their declared R4.6 re-freeze (d492bf7). WASM size: 519,795 B gzip -9, the 600 KB budget and the 550 KB report line unchanged in packages/core-wasm/tests/size.test.ts.

Import security: the open points are classified in PDF_IMPORT_HARDENING.md §6 (fixed with proof, accepted temporarily, blocking before merge, before public exposure). J1 / J2: R4_J1.md and R4_J2.md re-issued on this build with the OD-6 device list; every result cell stays NON TESTÉ until the owner runs it.

Gates (2026-10-20). Verifier, fresh per pass, 16 criteria: pass 1 found the core alone no longer compiled with no feature (facade::restore_copy used the feature-gated reader's cap; the workspace run unified the wasm crate's features and hid it from rust:check and check:all): fixed, and rust:check now lints the core alone; pass 2 found the §6 register without the J2 merge-gate row: added; pass 3 CONFORME 16/16. The floor lists the test files R4.8 deleted (23 by git log --diff-filter=D on 0dc1ba2, the one deleting commit of the branch; the verifier counted 21, a census error): approved in the owner's brief, 22 traced case by case in the ledger with a present target, the glue's pdf-export.ts-engine.test.ts traced in §10.10; the owner's written approval is the R4.9 contract's header (2026-10-20) and BDR-064, and the owner confirmed on 2026-10-21 that it covers exactly these 23 files (§10.12 D). A [gated] line needs an explicit owner decision; the owner may delegate its writing. Security, fresh: pass 1 BLOCK(1) on the R4.1 .gitleaks.toml path allowlist, which carried no [gated] marker (the owner approved the exception on 2026-10-18 but had not yet decided the marker; Claude wrote it at R4.10h on the owner's explicit authorization, §10.12 D), and a MEDIUM, the recette server bound every interface on an empty --host; three targeted re-gates closed it: the host is resolved first and any wildcard result refused in every spelling, the server listens on the resolved address and re-checks the bound one, and report-compare reads at most the 50 MiB cap after checking the file's type. Last re-gate PASS, LOW residuals only (a local writer swapping a FIFO in between the CLI's stat and open can make it wait). Final pnpm check:all green on 49b812b (2 min 51 s).

10.12 R4.10: the J1 / J2 anomalies (2026-10-21, scripts/browser/results/2026-10-20-r4-offline-import.json)

The owner's run (computer: Chrome, Firefox, Brave; Android; Safari iOS not run) reported two failures. Results as declared: R4_J1_RESULTS.md, R4_J2_RESULTS.md.

A. J1.7, offline import (FAIL on Brave and Firefox, surface 2). Reproduced headless on the same build and server (reference PDF imported online, editor loaded, network cut, « Accueil », « Choisir un fichier », « Remplacer », same PDF), two ways to cut: Playwright's offline mode and the server process killed.

Engine Before (serve.mjs without cache lines) After (nginx.conf lines)
Chromium the worker chunk refused from the cache (net::ERR_ABORTED), inline line « Le moteur de lecture n'a pas pu être chargé. » editor, both cuts
Firefox editor (offline mode serves the stale entry) editor, both cuts
WebKit inline line inline line, both cuts

Cause found: scripts/browser/serve.mjs sent no Cache-Control and no validator on /assets/, where docker/nginx.conf sends public, max-age=31536000, immutable; without it a browser may not reuse the prefetched worker chunk offline. A recette surface defect, not an application one: production already sends the line. Fixed: the server sends the two nginx lines (env.js no-store, /assets/ immutable); scripts/browser/r4-offline-import.mjs re-runs the path on the three engines and both cuts and checks the headers (6 runs as expected; with the old server, Chromium fails both: exit 1). Headless WebKit never takes a worker script from the HTTP cache offline, even immutable: the page shows the inline line, stays usable, no data changes. Whether Safari iOS does the same is not known: J1.7 on the iPhone tells.

Not reproduced: the file picker that does not open and the browser that becomes unusable. In every headless run the page answers (picker event, editor or inline line, no page error). The picker is the operating system's dialog, which a headless browser replaces; the page's click handler calls input.click() synchronously, before any network call. A dialog that hangs when the network goes is consistent with a file dialog opening on a network folder (the kit read from a share) but nothing proves it yet: the mini-recette's discriminating step settles it (Ctrl+O offline in an empty tab, the kit copied to a local folder).

Settled by the owner (2026-10-21, mini-recette M1 and M2 on Firefox and Brave, the kit stored locally): with the system's network cut, the file dialog takes about one minute to open, from Ctrl+O in an empty tab as from the Faunosteo button alike, and the offline import then works. The symptom exists outside Faunosteo, so no proof of an application defect remains; J1.7 is a functional PASS with a performance reserve on the picker's opening. The cause of the minute is not established (the share hypothesis is not confirmed; nothing was measured or traced) and no application change follows without proof of a Faunosteo defect. The recette server's cache fix stays: a demonstrated defect on its own.

B. J2.3, export without logos (FAIL). The reference file 1-reference/r3-demo.fr.nologos.pdf carries an archive whose branding has the four logo slots null (the R3 oracle's nologos mode: the logo fetch answered 404, STEP6_PDF_ARCHIVE_ANALYSIS.md §17). The editor export builds its branding from apps/app/src/pdf/branding.ts (loadBranding(), the four bundled logos) on every export; the imported archive's branding is kept in the session (osteo:archive) but never handed to the writer. Same rule before R4: apps/app/src/pdf/export.ts at 66909b6 already passed loadBranding() to the TypeScript engine. The archived branding is used only by export_from_envelope (cargo, the oracles), never by the application. The writer draws the text fallback only for a null slot or a logo that failed to embed, which the application's bundled branding never has since the logos are bundled (Step 6, fetch removed). So the application behaves as specified, and the expected result of J2.3 written at R4.6 was wrong: it described the oracle's nologos file, not an editor export. Nothing changed (goldens, oracles, rules and the expected result untouched); an owner decision is needed: keep the rule and correct the expected result of J2.3, or make a re-export of an imported bilan reuse the archived branding (a product change). Owner decision (2026-10-21): option 1. A new export from the editor is a new document with the application's current branding; the archive keeps its own branding for a faithful reproduction by the tool (export_from_envelope). Only the expected result of J2.3 and the recette documents changed; the owner's observed result is acceptable under the corrected rule, subject to the logos shown being the current branding.

C. The footer's ZenQuality logo under the production CSP (2026-10-21, owner's ask). Footer.tsx loaded « Propulsé par » from https://zenquality.fr/assets/logo-horizontal-1024.png since the footer exists (caac149, 2026-05-21), and DEPLOY.md's CSP, img-src 'self' data: blob:, dates from the same day (98117b3). Impact: on an origin that sends that policy, the image is refused and its slot shows the alt text « ZenQuality » (or the browser's broken-image mark); the link itself still works, nothing else on the page depends on it. The exported PDF is not affected: pdf/branding.ts embeds the bundled zenquality-logo-fr.png, never a fetched file. Where the policy lives: the VPS reverse proxy (DEPLOY.md, nginx Option A or Caddy), not docker/nginx.conf, which sets no CSP; faunosteo.com answered with no Content-Security-Policy header on 2026-10-21 (HEAD request), so the live site does not refuse it today. Why the recettes did not report it: the J1 / J2 checklists carry no footer item, and the development server (pnpm dev) sets no policy; the headless CSP proofs did see it, on every page since the R2 app-image proof (§8) and in r4-app-csp.mjs (§10.3), recorded as "the one known violation" and excluded from their verdict. Fix (R4.10j): the same file bundled under src/assets/brand/zenquality-logo-horizontal.png (1024 × 237, the bytes fetched from zenquality.fr on 2026-10-21, sha256 8625f6b1…) and imported with ?url like the partner's drawing, so the pixels do not change and the CSP stays as documented; the hotlink no longer sends the visitor's address to a third party either. components.Footer pins it (every footer image served by the application; the test fails on the hotlinked version); r4-app-csp.mjs drops its known-host exception, any violation is now a problem: 12 passes, no violation, no report (results/2026-10-21-r4-csp.json); r4-offline-import.mjs 6 runs as expected on the same build (results/2026-10-21-r4-offline-import.json). The two ?inline PDF logos and the fr variant are untouched: the footer shows the file it always showed.

D. Owner decisions recorded (2026-10-21, after the R4.10 gates).

  • J1.7: M1 and M2 PASS, the file dialog opening after about 60 s with the system's network cut, the same through Ctrl+O outside Faunosteo; J1.7 a functional PASS with a documented performance reserve. M3 NON TESTÉ: it becomes a complementary control, not blocking, never reported PASS without a run. M4 and M5 NON TESTÉ in the mini-recette (the earlier J1 declarations stand); M6 NON TESTÉ. The Cache-Control fix and its proofs stay. No application work on the 60 s without proof of a cause specific to Faunosteo.
  • J2.3: option 1 is final. A new export from the editor carries the application's current branding, even when the imported archive has no logo; the corrected expected result of J2.3 is validated. Historical data, oracles and goldens are unchanged.
  • ZenQuality footer logo (dcc7940): validated, the same image, no visual change, no CSP relaxation, no dependency on zenquality.fr. The tests that refuse a CSP-forbidden external resource stay (components.Footer, r4-app-csp.mjs), and so does the hardened CSP proof: every violation is a failure, except a refusal a negative test expects explicitly.
  • [gated 2026-10-18] in .gitleaks.toml: valid. The marker needs an explicit owner decision; its writing can be delegated, and Claude wrote it under the owner's explicit authorization (R4.10h).
  • R4.8 deletions: the owner's authorization covers the 23 test files deleted by 0dc1ba2 (22 in crates/core/tests/pdf/LEDGER.tsv, the glue's pdf-export.ts-engine.test.ts in §10.10). The count 21 was a census error. No further file may be deleted under this authorization.
  • Safari iOS stays NON TESTÉ until the owner reports results from the real iPhone. A simulator never stands for it and is never a memory proof; nothing is reported PASS for it in the meantime (reported the same day, §10.15).

10.13 R4.11: dependency maintenance before the R4 merge (2026-10-21)

Owner's ask: three advisories reported by the R4.10 checks, verified and updated where the affected versions were present, minimal updates, one commit each, no architecture change, no exclusion to silence an alert.

Advisory Component, path Before After Audit Residual
RUSTSEC-2026-0382, rustls-webpki: certificate verification may accept distrusted intermediates the worker's HTTPS client only (ureq 3.4.2 → rustls 0.23.46 → rustls-webpki); the core and the wasm crate have no TLS 0.103.15 0.103.16 (7a7b71c, Cargo.lock only) cargo deny check advisories ok; tests/tls.rs below the worker talks to one managed Supabase origin over HTTPS; the advisory concerned a chain built through a distrusted intermediate, which only an attacker in the network path could present
RUSTSEC-2026-0381, webpki-roots: bundled roots allow trust in distrusted emSign intermediates same path (ureq → webpki-roots, the worker's trust store, no system store in the distroless image) 1.0.9 1.0.10 (7a7b71c) same same; the store is bundled at build time, so a future root change needs a rebuild of the worker image
GHSA-wrjc-x8rr-h8h6, react-router: open redirect via backslash in <Link> and useNavigate (moderate) the application (react-router-dom → react-router), BrowserRouter SPA 7.15.1 7.18.4 (c9dab63, ^7.18.4 in apps/app/package.json) pnpm audit --prod: no known vulnerability; app suite 59 files / 429 cases, the routing, guard, auth and redirect suites among them the only destination from untrusted data is the next query value, rebuilt by safeNextPath from a URL parsed against a sentinel origin (/\host and //host fall back): not reachable before the update either; every other to is a literal
GHSA-chx6-hx7r-mcp5, react-router: unauthenticated DoS via inefficient route matching (high) same 7.15.1 7.18.4 same server-side route matching; the application matches in the visitor's own tab, no server runs the router
GHSA-qwww-vcr4-c8h2 (RSC CSRF, high), GHSA-h8fp-f39c-q6mh (RSC error handler XSS), GHSA-337j-9hxr-rhxg (SSR hydration constructor injection) same 7.15.1 7.18.4 same RSC and SSR modes: the application uses neither (no loader, action, server or hydration)

React Router 7.16 to 7.18.4 are patch-level releases for this application (the 7.x changelog: framework-mode and data-mode fixes, precomputed route matchers, URL normalisation); no API the application calls changed, the typecheck and the suites pass unchanged, and the shipped module bytes are the same (1,535,289 B raw, 519,795 B gzip: the lockfile change touches no wasm input).

TLS proof (crates/worker/tests/tls.rs, a604c07): an in-process rustls server presents a self-signed certificate for 127.0.0.1; the HttpBackend built from https://127.0.0.1:<port> must answer Network naming the certificate, the service key must not appear in the message, and the server must see the connection dropped during the handshake, never a request. Negative run: with disable_verification(true) on the agent (a temporary edit of http.rs, reverted) the server answers [] and the call succeeds, so the test fails as it should. The proof covers validation being active on the worker's client with its bundled store, not the emSign distrust itself (that would need the distrusted chain). Dev-dependencies added for it: rustls (already in the tree through ureq, same features) and rcgen 0.14.10 (the rustls project's generator, ring provider, no pem): the test build adds rcgen, time and yasna; the lockfile also lists rcgen's optional x509-parser family, not compiled. The test runs natively in rust:check and in the worker image's musl test stage.

Checks on a604c07: pnpm rust:check green (fmt, clippy, tests, ts-rs, cargo deny check licenses bans sources); cargo deny check advisories ok (it was failing on the two RUSTSEC ids); pnpm audit --prod: no known vulnerability (the dev-only tinypool advisories of the full audit stay, vitest's, outside this maintenance); pnpm check:all green (17:27:54: Rust, wasm, Node, app image, worker sandbox tests and runtime image); the goldens, oracles and R4 digests untouched (git diff --stat 8943bf3 -- apps/app/tests/fixtures crates/core/tests empty). Nothing is called fixed because it compiles: the Rust ids are gone from the advisory check and the npm ones from the production audit, and the two reachable behaviours (certificate validation, next redirection) have a test each.

10.14 R4.12: the three pre-merge fixes of the Context7 review (2026-10-21)

Owner decisions on .claude/audits/CONTEXT7-2026-10-21.md: D1, D3 and D6 now, one commit each; D2 (Tailwind outline-hidden) and D5 (MotionConfig reducedMotion="user") for a separate accessibility chantier with a visual recette; D4 (vitest coverage block, jest-dom entry, defineConfig, forwardRef, the authStore comment) in the maintenance backlog; no major upgrade.

D3, safeNextPath (51a5a80). The URL parser's own normalisation turned /..//evil.test, /.//, /a/..//, /%2e%2e//, /.%2e//, /..\\ and a tab inside .. into //evil.test: same origin for the sentinel, yet a protocol-relative path once returned. The rebuilt value is now refused when it starts with // or no longer resolves to the sentinel origin, so the function's contract holds by itself. Consumers (LoginRoute, RedirectIfSignedIn, AuthCallbackRoute): with react-router 7.18.4, useNavigate checks the target (« External navigation is not allowed ») and <Navigate> collapses the slashes (resolvePath('//evil.test/app/account') = /evil.test/app/account), and the old function made the LoginRoute test fail without leaving the origin. The security gate read one more path in the installed package: history.push falls back to window.location.assign when pushState throws. So the router's guards are not a contract this code may lean on, and the fix does not rely on them. Tests: 4 new safeNextPath cases (12 dot-segment spellings, external schemes and escapes, encoded slashes kept literal and legitimate paths unchanged, idempotence) and a LoginRoute case through the real router (next=/..//evil.test/app/account lands on the dashboard); on the old function, 3 of them fail.

D1, worker runtime image (49b1849). gcr.io/distroless/static-debian12 → static-debian13:nonroot (the distroless README: only the Debian 13 tags are still published and updated). Provenance: the official gcr.io/distroless registry, digest sha256:d62067879de890a1def9da0e7766b7d20810a5e5555cef8506b752437d7a3e88 at the build; its cosign signature was not checked (no cosign on this machine). Same contents for the worker: user nonroot 65532, no shell (/bin/sh absent), CA bundle at /etc/ssl/certs (the worker's TLS uses the bundled webpki roots, not the system store). The build, the sandbox and seccomp test stage and the binary are unchanged. Proofs: pnpm worker:test (sandbox tests 11 + 16, TLS 1, seccomp derivation), pnpm worker:image (user nonroot, run --check, 12.1 MB), run --check under --read-only --cap-drop ALL --network none, and pnpm e2e:avatar against the local Supabase stack with this image: 5/5 (clean upload, replacement and purge, signed-URL leftovers, hostile and corrupted uploads refused with closed codes, removal); the stack was stopped afterwards (volumes kept).

D6, DEPLOY.md host nginx (60faac8). listen 443 ssl http2; → listen 443 ssl; + http2 on;. Incompatibility found and kept visible: faunosteo.com answers Server: nginx/1.24.0 (Ubuntu), and nginx 1.24 does not know http2 on (nginx -t in a throwaway nginx:1.24-alpine: unknown directive "http2"), while nginx 1.31 accepts it and warns that listen ... http2 is deprecated. The runbook gives the new form for nginx >= 1.25.1 and names the old one for 1.24, with nginx -v to choose; no other directive changed, no server touched.

Checks on 60faac8: pnpm check:all green (18:55:30; apps/app 59 files, 434 cases; the worker image on the Debian 13 digest; the TLS test native and in the musl stage); pnpm audit --prod clean; cargo deny check (all four) ok; the goldens, oracles and the PDF engine untouched (git diff --stat 8943bf3 -- apps/app/tests/fixtures crates/core/tests crates/core/src empty).

10.15 R4 closed: device acceptance, residual risks, merge (2026-10-21)

Owner's final validation (2026-10-21): J1 and J2 run on the computer (Chrome, Firefox, Brave), on Android with its browser and on a real iPhone with Safari iOS, reported as passed with no blocking anomaly; the R4.12 checkpoint and every earlier decision validated; the merge into develop authorised, subject to the usual final checks. Results as declared, with what was not given marked as missing rather than inferred: R4_J1_RESULTS.md, R4_J2_RESULTS.md, R4_MINI_RECETTE.md.

What the acceptance covers, and its limits:

  • Computer, Android, iPhone: a declaration per recette, no per-check or per-browser split beyond J1.7. For the iPhone, the model, the iOS and Safari versions, the surface, the timings (J1.8, J1.12, J2.6) and the memory observations (J1.9, J1.10, J2.6, J2.7) were not reported. The plan's OD-6 rule is met at the device level (every listed device was run on a real machine); the per-check measures it also asked for are the first follow-up below.
  • J1.7: functional PASS with the picker-delay reserve (about 60 s to open the file dialog with the computer's network cut, seen with Ctrl+O outside Faunosteo as well); cause not established, no application change (§10.12). M3 of the mini-recette not run: complementary, not blocking.
  • J2.3: PASS under the approved rule; a new export carries the application's current branding, the archive keeps its own (§10.12 B).

Residual risks accepted by the owner for the merge into develop, open until their own deadline (none is closed by the merge):

Risk Where Deadline
Worker base image referenced by tag (static-debian13:nonroot), not by digest; cosign signature not checked (no cosign on the build machine) §10.14 D1 before a production image is published
Semgrep partial parse of two test files (routes.LoginRoute.test.tsx, routes.coreStopped.test.tsx: the >() generic call syntax), test coverage gap only R4.12 security gate next security pass
Guardrails WARN outside the R4 diff: SB-POLICY-NOT-OWNER on species_select_active (migration 20261008110000, a catalog read policy by design) R4.12 security gate, /guardrails its own review, not an R4 item
Device timings and memory observations not reported (items 5, 6, 7, 9, 20 of PDF_IMPORT_HARDENING.md §6) PDF_IMPORT_HARDENING.md §7 before the import is offered to external users (item 18)
J1.7 picker delay offline, cause not established §10.12 A reopened only on a new proven defect
Chromium per-export growth of the browser's raster path (BDR-063) §10.11 a device observation, then one reused canvas if needed
Accessibility (D2 outline-hidden, D5 reduced motion) and the D4 configuration chores .claude/tasks/TODO.md separate chantiers, not scheduled

Checks on the final state before the merge (HEAD 22bbfb4, the code state of 60faac8 plus memory and documentation commits): pnpm check:all green at 22:15:50 (rust-check, types drift, wasm build, app 59 files / 434 cases, domain 262, core-wasm 58, anatomy 131, supabase 40, app image, worker test stage with the TLS test, worker image on the Debian 13 digest sha256:d62067…3e88); pnpm audit --prod clean (the full audit lists 54 advisories in the development tooling only: 26 on the pinned pnpm 10.13.1 itself, the rest on vite, vitest and their transitive packages; none reaches the production bundle); gitleaks on the 111 commits of the branch: no leak, and on the working tree one finding in the git-ignored .env.worker only; no /home/<user> path, personal identifier or LAN host in a versioned file (the LAN subnet of ENVIRONMENTS.md and the forge URL of DEPLOY.md predate the branch); git merge-tree develop HEAD clean; the Step 6 goldens untouched since 8b86b92 (identical on develop), the R4 oracles since 4439fd2 and the R4 digests since d492bf7 (the declared R4.6 re-freeze); 51 deletions on the branch, all in 0dc1ba2 (R4.8, authorised), none after. Merge: gitflow finish on feature/rust-r4-pdf-core (no-ff into develop, branch deleted local and remote), recorded in .claude/memory/journal.md. Release 0.2.0, faunosteo.com and R5 untouched.

11. R5: the anatomical pipeline in Rust (2026-10-22: R5.1 freeze and study, R5.1b, R5.2 importer, R5.3 draft)

Plan: .claude/tasks/plans/2026-10-22-rust-r5-pipeline-core.md. Branch feature/rust-r5-pipeline-core, cut from develop 9c0117a (R4 merged). The owner's brief of 2026-10-22 authorises R5.1 only: characterise and freeze the TypeScript pipeline, study the fingerprint decision D-R5, stop before any Rust pipeline code and before any change to documentSha256.

11.1 Inventory of the TypeScript pipeline

.claude/audits/R5_PIPELINE_INVENTORY.md. packages/anatomy: 43 source files, 4,897 lines (legacy importer 1,842, curation 2,329, frozen renderer 553, CLI 119), 131 test cases in 16 files, runtime libraries Prettier 3.8.3, @xmldom/xmldom 0.9.12 and Zod 3.25.76 (the first two declared as devDependencies). It emits 18 generated files: 7 JSON and 3 Markdown through Prettier, 5 SVGs through xmldom's serialiser (the cleaned horse.svg and 4 review drawings), 1 raw SQL template, 2 byte copies of the legacy SVGs. The authored changeset holds 45 changes (14 A, 22 B, 9 C), 687 ops (587 set, 45 cite, 33 rename, 18 add, 4 remove, 0 move) and 48 references. packages/domain is imported by packages/anatomy only (5 runtime symbols, each with its R2 counterpart); the crate tests read packages/domain/tests/fixtures/report-v2.*.json, and r4.census.test.ts pins xmldom under packages/anatomy: both move at the deletion slice. The upload tool (upload-sheet-assets.ts, 99 lines) depends on the assets.json contract only: bucket anatomical-sheet-assets, key <sha256>.svg, upsert: false, bytes re-hashed against the manifest, RPC confirm_sheet_asset_upload.

JavaScript facts a Rust port must reproduce or declare: key insertion order of the working document (review_status appended last, not the schema order a typed struct emits), JSON.stringify(v, null, 2) then Prettier (measured effect on today's data: short scalar arrays collapsed when they fit in 80 columns, a trailing LF; Markdown: table padding only, 134, 863 and 52 lines in the three reports), xmldom's serialiser (declaration kept, /> without space, attributes in document order, namespace declared once), deterministicUuid (first 16 bytes of sha256 of the name, version nibble 5, variant 10xx), slugify (NFD, combining marks U+0300 to U+036F stripped, toLowerCase, [^a-z0-9]+ → -, 64 chars; never fires on today's data), UTF-16 < sorting, Math.round toward +∞ on −x.5, Number('') = 0, Unicode \s, split(':', 2), fatal TextDecoder for the SVGs. No clock, no randomness, no localeCompare.

11.2 Oracles frozen (crates/core/tests/oracles/r5/)

Generator packages/anatomy/tests/r5.pipeline-oracles.test.ts (MAKE_R5_ORACLES=1 writes; otherwise the pipeline must still match its freeze; 6 cases, among them a two-run determinism check of every artifact and the ledger check against the committed folders). Never regenerated without the owner.

Oracle Content Size
pipeline.json the ImportResult without the document (sheetId, viewBoxes, stats, source digests, assets, 27 anomalies, issues, region inferences, zone stats, annotation rows), the DraftResult without the documents (46 change summaries, 825 records with before and after, stats before and after, issues, migration stats 792 = 571 + 180 + 7 + 34), the ledger of the 16 text artifacts (folder, file, bytes, sha256; the 2 legacy SVG copies are pinned by the golden test; for the 3 Markdown files the sha256 before Prettier and prettier_changed: true) 1.3 MB
ids.json deterministicUuid over the 3 pipeline names and 3 edges; slugify over 17 edge labels and every name.fr / name.en of both documents (801 rows) 87 KB
fingerprints.json per JSON artifact: today's file-bytes sha256, A (JSON.stringify(v, null, 2) with and without LF, compact), B (RFC 8785); for the two documents also the validated form (defaults filled) under A and B; the ES6 text of the 65 non-integer numbers; the two RFC 8785 vectors 13 KB

The committed generated folders stay the byte oracle (seed.golden.test.ts pins them to a fresh run); the migration semantics stay pinned by report-migration-map.json, the 612-leaf suite and the R2 oracle migration-map.draft.json; the review drawings by their xmldom bytes and the R3 layer and highlight oracles. pnpm import:equine was not run (it rewrites the folders; the golden proves the same bytes).

11.3 Tests and results

pnpm --filter @faunosteo/anatomy test:run: 137 cases in 17 files (131 of the frozen pipeline plus the 6 of the generator), green; @faunosteo/domain 262, green; lint and typecheck of the anatomy package green; git status shows no change under supabase/seed, the goldens, the R2 to R4 oracles or the R4 digests.

11.4 Historical results: no gap, one defect found in the core

Every generated file reproduces byte for byte from a fresh run. One fingerprint has ever been produced, 27c7383c…2660, unchanged since 0a17e39 (2026-10-10), carried by 99 of the 216 committed PDFs, 8 JSON fixtures and 6 Rust oracle files (.claude/audits/R5_DOCUMENT_SHA256_CENSUS.md).

F1, found by the study (crates/core/src/json.rs, js_number): the shortest digits come from format!("{:e}"), which rounds an exact decimal tie upward, where ECMAScript, Python and zmij (serde_json's formatter, already locked) round to even. 840.1692504882812 (legacy annotation cx, from Horse.svg, a float32-exact value) prints …813. Measured: 1 of the 8 long decimals of the legacy SVGs, 7,401 of 100,000 float32-exact values in 0..2000, 769 of 100,000 random doubles; zmij differs on none. Over the 134 JSON fixtures of the repository, Node and Rust JSON.stringify(v, null, 2) differ on 2 files, both the legacy baseline, both on that value. Invisible today: the curated draft holds no tie value, and the R2 contract test sheet_contract.rs re-prints its expected text through to_js_pretty, so it cannot see a number-printing difference. Reached by the canvas layer (R3), the PDF writer, the archive attachment and report-compare. Not fixed in R5.1: it changes core bytes for tie values (D-R11), so the fix (digits from zmij, the tie values as unit tests, zod_oracle compared against the recorded JS text) waits for the owner's go and precedes any Rust importer.

The §10.10 sentence "documentSha256 will change once (D-R5) and every older archive will rebase on import" describes D-R5 rev 2; the owner's Annex C amendment (BDR-045) supersedes it, and §11.5 studies both.

11.5 D-R5: the fingerprint, facts and comparison

Today: documentSha256 = sha256(Prettier(JSON.stringify(document, null, 2))), the exact bytes of draft/document.json in its input form (defaults omitted), copied into sheet-ref.json and the migration map, compared and never recomputed by the rebase (fingerprint only), the envelope invariant and the export (sheetId and fingerprint). The database stores the document as jsonb and no fingerprint.

Matrix on the real data (node scripts/r5-fingerprints.mjs; cross-checked by a throwaway Rust experiment on the core crate: to_js_pretty, to_js_compact and a 40-line RFC 8785 canonicaliser over js_number, RFC vectors passed, idempotent):

Artifact Today A to_js_pretty + LF B RFC 8785, input form B, validated form
draft/document.json 27c7383c…2660 90f668a3…aa1d a56e4a24…88a1 12d78872…74e2
legacy-import/document.json 91e459f4…14c2 8c94a464…adc2 d8b5f2cf…81eb 1217637e…c024
draft/report-migration-map.json 4139c51d…fce9 4139c51d…fce9 f082b66f…2ca6

Rust reproduces every draft digest byte for byte; the legacy digests differ through F1 only. The three columns of one row are three encodings of one value (parse and deep-compare); a content change moves every column. Keys: all ASCII in every artifact (UTF-16, code-point and byte order coincide; the Rust canonicaliser sorts by encode_utf16() and passes the RFC vector with U+0080, ö, €, 😀 and U+FB33). Numbers: 29 and 36 non-integer tokens, none negative, no exponent, no -0, none beyond 2^53, all already in ECMAScript Number::toString form (what JCS mandates). Unicode: 788 non-ASCII strings, all NFC, no control, no escape, no astral, no lone surrogate (I-JSON satisfied; a lone surrogate is refused by the core, L1). Cost: A costs nothing (to_js_pretty exists); B costs about 40 lines in json.rs, no crate (serde_jcs not needed; sha2 would become a normal dependency of the core or stay in the tool). Determinism: B is a pure function of the parsed value and Node 24 and Rust 1.99 agree on every draft artifact; A depends on the writer's layout rules. Database: a PostgreSQL 17 jsonb round trip (packages/supabase/scripts/r5-jsonb-fingerprint.mjs, PGlite) keeps B for both documents and breaks today's value and A (keys reordered, numeric scale kept): B is the only candidate a service could recompute from anatomical_sheet_versions.content.

A: bytes the Rust pipeline emits B: RFC 8785 of the validated document C: Rust reproduces Prettier's bytes
value at the switch changes once changes once unchanged
alias mechanism needed to avoid a visible migration yes yes no
survives a reformat, a writer change, a jsonb round trip no yes no
code 0 lines ~40 Rust + 15 Node, no crate a Prettier-json subset printer, bound to a formatter's layout
source D-R5 rev 2 Annex C, BDR-045 rejected rev 1 (Node form)

Recommendation to the owner: B over the validated form, the alias mechanism of §11.6, the convention named in sheet-ref.json, F1 fixed first. C is possible on this data (the only Prettier effect is the short-array collapse) but keeps the identity chained to a formatter.

11.6 Compatibility mechanism for the old fingerprints (proposal)

The sheet side carries the convention and the aliases; the report contract does not change. sheet-ref.json, the bundle payload ref and, at Step 13, the stored sheet version carry document_sha256 (the current convention's value) plus a fingerprint block: algorithm (rfc8785-sha256) and aliases, the fingerprints of the same content under earlier conventions, computed once at the switch from the frozen fingerprints.json (27c7383c…2660 for the current draft). The rebase, the envelope invariant and the export treat a fingerprint equal to the current value or to an alias as the same document (one membership test in report/rebase.rs, archive/read.rs, session.rs, pdf/write/input.rs: gated files, the owner's go per file). A new report is stamped with the current value; an archive stamped 27c7… opens with no message and no rebase; an archive on an older content revision rebases as today; no archive, fixture or oracle is rewritten. Report v3 keeps sheet.documentSha256 (64 hex): the N-1 reader and every fixture stay valid.

11.7 Residual risks of R5.1

F1 unfixed (declared, bounded: no tie value in the draft); the Rust canonicaliser exists as an experiment only (not in the crate); validated_equals_input: false in fingerprints.json records that the input and validated forms differ by the filled defaults, so the decided convention must name its form; supabase/seed/** is not in .prettierignore (a root pnpm format would reformat Rust-written files at the switch); the horse.svg asset bytes are xmldom's (re-cleaning with the R3 reader would change the asset sha, id, document, SQL and the Storage object); the slugify and region tables depend on ICU 78.3 (never exercised by today's data).

R5.1b F1 fix (owner's go). R5.2 legacy importer (crates/core curation/legacy, import-equine bin): document.json, legacy-id-map.json, assets.json byte-exact, IMPORT-REPORT by table padding or parsed tables. R5.3 changeset applier, migration map, stats, seed SQL: the draft JSON files and the SQL under the decided fingerprint, the 825 records equal, the 612-leaf suite ported. R5.4 review overlays and app drawings on the R3 layer and compose (parsed-tree comparison), CHANGELOG and REVIEW-REPORT. R5.5 upload-sheet-assets bin, operator runbook. R5.6 the D-R5 switch (convention, aliases, the membership test in the gated readers, seed regenerated once by the Rust tool, .prettierignore, CHANGELOG). R5.7 consumer census, fixtures moved, packages/anatomy and packages/domain deleted, xmldom and Prettier out of the anatomy lockfile, docs and ledger. R5.6 needs the D-R5 decision; R5.2 needs R5.1b.

11.9 R5.1b: F1 fixed (2026-10-22)

The owner's decisions of 2026-10-22 (« Validation R5.1, décision D-R5 et lancement du portage Rust »): D-R5 = option B, convention sha256-rfc8785-validated-v1 (applied at R5.6 only), aliases of the historical fingerprints established from trusted frozen documents only, F1 fixed first, byte-exact reproduction of the TypeScript artifacts by default, the historical SVG bytes kept, .prettierignore on the Rust-written paths, ureq preferred for the upload tool at R5.5.

js_number (crates/core/src/json.rs) now takes its shortest digits from zmij 1.0.23, the formatter serde_json 1.0.154 already used (a dependency edge, no new crate): among the shortest candidates it picks the closest and, on an exact decimal tie, the even one, which is ECMAScript's rule. The decimal layout (ECMAScript Number::toString steps 6 to 10) is unchanged.

Independent reference: crates/core/tests/oracles/r5/numbers.json, 44,322 rows written by V8 (scripts/r5-number-oracle.mjs, String(value)), each value given by its IEEE bits: edge values (zero, subnormals, extremes, the 1e21 and 1e-7 thresholds, powers of ten and two, integers around 2^53), the tie values of the study, 12,000 float32-exact values (where ties occur), 10,000 random doubles, each negated. tests/json_numbers.rs compares every row and characterises 840.1692504882812. Before the fix: 1,552 mismatches; after: none. The R2 helper zod_oracle now first checks the oracle's own bytes against the core's compact printing, so a number the core prints differently from V8 fails there instead of on both sides of the comparison: on the old printer it fails the legacy baseline oracle.

Consumers audited (grep js_number crates/core/src): the R3 canvas layer and sanitiser (anatomy/layer.rs, svg/number.rs, svg/sanitize.rs), the R2 editor and sheet rules (domain/editor/zone.rs, domain/js.rs, domain/sheet/validate.rs), the R4 writer (pdf/write/{content,views,layout/observation}.rs) and report-compare (pdf/compare). Result on the historical corpora: pnpm rust:check (every cargo suite, the R4 serialiser digests included), pnpm wasm:build and pnpm check (app 434, core-wasm 58, domain 262) green with no oracle, golden or digest changed: no historical output carries a tie value, so no contract moved and the porting went on as the brief allows. Effect on user data: an archive whose report holds a tie value now re-prints it as the JavaScript application wrote it (…812), where the R2 to R4 core would have printed …813; the value itself was never altered (the two texts parse to the same double).

11.10 R5.2: the legacy importer in Rust (2026-10-22)

crates/core/src/curation behind the feature curation (never enabled by the wasm module or the worker; scripts/rust-check.sh runs clippy and the suites with it), 3,187 lines:

Module Ports
text.rs Prettier's getStringWidth (the East Asian wide table transcribed row for row from prettier@3.8.3), the NFD fold of slugify and the region roots (icu_normalizer, already locked through url), UTF-16 ordering, Object.keys order (array indices first), Math.round
ids.rs sha256Hex, deterministicUuid, the asset and sheet ids
prettier_json.rs formatJson: Prettier's JSON layout over JSON.stringify(v, null, 2) (expanded objects, collapsed short arrays, filled number arrays, Prettier's exponent form 1e21)
markdown.rs cell, table, code and Prettier's table alignment (the only change it makes to the reports)
legacy/* svg, vertebrae, regions, categories, catalog, catalog_checks, annotations, authored_labels, importer, report (IMPORT-REPORT), render_artifacts
bin/import_equine.rs import-equine --check (compare with the committed legacy-import/, write nothing) and --out <dir> (write into an absent or empty folder; nothing is ever deleted)

Parity, every expectation written by the TypeScript tools:

  • the four text files of legacy-import/ byte for byte and the two SVG copies (tests/curation_legacy.rs); import-equine --check: 6 files, 0 differences; --out then diff -r against the committed folder: identical;
  • every intermediate value of the frozen run (oracles/r5/pipeline.json, section legacy: stats, anomalies in order, rows, inferences, zone stats, digests, view boxes); the raw report's sha256 equals the ledger's pre-Prettier digest; two runs byte-equal;
  • 10 synthetic cases run through the TypeScript importer (oracles/r5/legacy-synthetic.json, generator packages/anatomy/tests/r5.legacy-synthetic-oracles.test.ts): a generic sheet (integer-like zone keys, non-stable node ids slugified, missing FR and EN names, unknown laterality and special, a rect, odd polygon points, 0x10 and 1e1 coordinates, the tie value, -0, a duplicate formula key, a hyphen range) and a minimal one with a BOM, both byte for byte with every result part; 8 refusals (schema, zones missing, catalog with a BOM, region missing, no formula, inline sources, key ≠ id, a truthy non-boolean referral) refused alike;
  • the generic format probes (oracles/r5/{prettier-json,markdown-tables,js-semantics}.json, generator packages/anatomy/tests/r5.format-oracles.test.ts): 968 JSON layouts across depths, key widths and the 80-column boundary, 10 tables, 22 extra slug edges (İ, Kelvin, final sigma, ß, ligatures, fullwidth, Hangul, the 64-character cut), 7 uuid names, 39 Number() texts, 12 point lists, 18 Math.round values (bits kept, −0 included), 8 spaces, 3 key orders; the 7 generated JSON files of the seed (draft included) print byte for byte.

Differences declared (the port refuses where JavaScript accepted; none is reachable by the committed sources, since the equine folder is reproduced byte for byte):

Input TypeScript Rust
a text holding an emoji, in a table cell or a JSON string Prettier measures it with its RGI emoji table refused (UnsupportedWidth): the table is not reproduced (the only emoji of the sources, in Horse.svg, never reaches a generated text)
a malformed SVG, a DTD, a text over the core's SVG caps xmldom parsed leniently refused (the core's prescan, then roxmltree)
a catalog node whose id is not a string, a children, categories or sources that is not an array coerced or crashed refused with the node named
a category or label named like an Object.prototype member (constructor, toString) the prototype answered the lookup a plain table lookup

Kept as the TypeScript: invalid UTF-8 in the catalog and vertebrae texts becomes U+FFFD (Buffer.toString), a BOM there is kept (and JSON.parse refuses it); invalid UTF-8 in an SVG is refused and one BOM removed (TextDecoder fatal); a missing coordinate reads 0 (Number(null)); NaN and the infinities become null in the document and NaN / Infinity in the report rows.

Tests: cargo test -p faunosteo-core --features curation (formatting 6, importer 5, plus the crate's suites); the TypeScript keeps its 131 frozen cases and gains the 4 generators of R5.2 (anatomy 141). packages/anatomy, packages/domain and pnpm import:equine stay: the TypeScript still writes both folders until the switch.

11.11 Checkpoint R5.2

Residual risks: the emoji refusal (a label with an emoji would stop the pipeline, visibly); Prettier's markdown changes other than table alignment are not reproduced (none occurs in the three reports; a future content with emphasis or escapes could differ, and the R5.4 byte comparison of CHANGELOG and REVIEW-REPORT will show it); the NFD and lowercase tables follow icu_normalizer 2.3 and Rust 1.99 (Unicode 16 or 17) where Node uses ICU 78.3: equal on every frozen label and edge, a character added by a later Unicode version could differ; the binary has no pnpm script yet (a public name, the owner's call).

Conditions for R5.3: the owner's validation of this checkpoint; the draft side reads the same inputs (curation/changes.json, references.json) and its oracles are frozen (pipeline.json draft section: 46 changes, 825 records, migration stats; the draft folder byte for byte except sheet-ref.json's fingerprint, which stays 27c7383c…2660 until R5.6); the cleaned horse.svg is kept as frozen bytes (owner decision), so R5.3 reads it instead of re-cleaning the legacy drawing; the review drawings (xmldom bytes) wait for R5.4.

11.12 R5.3: the curated draft in Rust (2026-10-22)

Owner go « Validation R5.1b / R5.2 et autorisation R5.3 » (2026-10-22): pnpm r5:import-equine names the Rust binary and forwards its arguments, pnpm import:equine keeps writing the seed until the switch; no fingerprint change; the cleaned horse.svg is read as frozen bytes, never re-cleaned; the review drawings and the two Markdown reports are R5.4. Contract .claude/tasks/contracts/2026-10-22-rust-r5-draft.md.

crates/core/src/curation/draft (2,908 lines at the R5.3 close, feature curation):

Module Ports
schema.rs ChangesetSchema, ReferencesFileSchema: strict objects, optional keys .optional() (absent accepted, null refused), the CHG-\d{3,} id, priority defaulted to medium, the level C question, duplicate change and reference ids refused; the op discriminator read first, then the variant parsed strictly; re-emitted in the Zod shape order (question before priority, options absent)
targets.rs the target grammar, resolution on the plain JSON document (a located item is a path of keys and indices, resolved again at each use where the TypeScript held object references), zoneFindings, allFindings, findingScope, childList (a lean leaf gets children: [] appended on demand)
fields.rs the settable table per item kind, dot paths, readField / writeField (missing intermediate objects created)
records.rs ChangeRecord, the touch marks ("\0touched": a transient key holding the first-touch order, removed at the end of each change and never written to a record), isDeepStrictEqual on JSON values (Object.is on numbers), String(value)
ops.rs, rename.rs the six ops with their checks and messages, the rename cascade (one record per rewrite; a reference rename rewrites the citations)
apply.rs applyChangeset: references replaced first, every op refused with the change id and op index, the review rule (touched findings and annotations of a B or C change set to_confirm in first-touch order, items already to_confirm or gone skipped), then the R2 strict parse (AnatomicalSheetDocument) and validate_sheet_document (errors refuse, warnings returned)
migration_map.rs buildReportMigrationMap: the 792 legacy paths replayed through the rename, remove and move records, zone renames, annotation and view renames, the final-paths check, unique re-homing, the five stats; Object.keys order through js_object
stats.rs documentStats: 17 fields in the TypeScript order, the fixed-key counters extended by unlisted values
seed.rs renderDraftSeedSql: header, sheet insert, asset inserts, insert_sheet_draft, converging update, the dollar-tag refusal, trimEnd
pipeline.rs buildEquineDraft (CHG-000 from the frozen asset's sha256, byte size and uuid, the head view box parsed from the legacy SVG; the reserved id refused), renderDraftArtifacts for the R5.3 files (document.json, assets.json, sheet-ref.json with document_sha256 = sha256 of the document.json bytes, report-migration-map.json, equine_draft.sql), parseViewBox
bin/import_equine.rs both folders; --check compares the produced files with the committed seed and lists the six R5.4 files of the draft as pending (shortcut: comment, removed at R5.4); --out <dir> writes <dir>/legacy-import and <dir>/draft into a destination that is absent or an empty folder; it refuses an empty path, a path holding .., a missing parent folder, a destination inside the seed folder, a symbolic link (a trailing / or /. included), a path that is not a folder and a folder holding any entry; the parent's symbolic links are resolved and the canonical destination is printed before the first write; every folder under it is created with create_dir and every file with create_new, so an entry that appears after the claim (file, folder or symbolic link) is refused, never followed or truncated; a relative path is typed from INIT_CWD when absolute, else the current folder (the repository root when scripts/import-equine.sh is run directly, since it moves there; pnpm r5:import-equine is the reference); a non-UTF-8 argument is a usage error; nothing is ever deleted

Parity, every expectation written by the TypeScript (tests/curation_draft.rs, 16 tests):

  • the five R5.3 text files of the committed draft/ byte for byte, the frozen horse.svg described by its sha256, size and asset id; pnpm r5:import-equine --check: 12 files, 0 differences; --out then diff -r: legacy-import/ identical, draft/ identical but for the six R5.4 files;
  • sheet-ref.json's document_sha256 equals the sha256 of the produced document.json and the historical 27c7383c…2660 (by construction: same bytes, same rule);
  • the draft section of oracles/r5/pipeline.json: sheetId, the 46 change summaries (CHG-000 included), the asset, statsBefore and statsAfter, the empty issue list, the migration stats (792 nodes: 571 identical, 180 remapped, 7 re-homed, 34 removed) and the 825 records one by one under the JavaScript compact print; two runs byte-equal;
  • the 612 legacy leaves through the core's read_report_document on the produced map: 442 identical, 141 moved, 29 removed, every resolved leaf a leaf of the produced document, the 29 flagged paths exactly those the map sends to null, the FR snapshots kept;
  • 82 synthetic changesets on the mini sheet (oracles/r5/curation-synthetic.json, generator packages/anatomy/tests/r5.curation-synthetic-oracles.test.ts): 14 accepted cases (every op kind, numeric and anchored positions, subtree scopes with skipped equal values, the review rule on levels A, B and C, the five rename cascades and a reference rename, re-homing, two chained changes, the two migration-map debt cases below, the three JSON.parse cases of the aligned paragraph) byte for byte on the formatted document, the records, the stats, the migration map and the seed SQL; 63 refusals (23 schema, among them schema-set-without-value, which the TypeScript refused at the gate and the port at parse, the declared family below; null on scope, position and field and the shape family below included, 40 applier, integrity and shape gates included) refused alike, with the same reason: the same message for an op or change refusal (change id and op index included), the same stage for a schema or gate refusal; 7 references files refused alike; five declared synthetic cases below (four refusals, one acceptance), each held by its own test (14 compared + 63 refused alike + 5 declared = 82).

Differences declared (none reachable by the committed files, since the folders are reproduced byte for byte):

Input TypeScript Rust
a set op without value z.unknown() accepted the missing key; the op wrote undefined and JSON.stringify dropped the field (synthetic case declared-set-without-value-drops-key: description: {}) refused at parse (missing field value)
a position written as 1.0 or -0 accepted (Number.isInteger) accepted alike (parsed as a JavaScript number, then integral and non-negative)
a lone surrogate escape ("\ud800") in any string of the two files JSON.parse kept it refused (the core's L1 rule: no lone surrogate is ever read)
nesting deeper than 128 levels (an add of a 70-level finding chain) accepted refused at parse (serde_json's depth limit, kept as a resource bound)
a number beyond the double range (1e400) in a value a later op overwrites or removes JSON.parse read Infinity, the value was discarded, the change accepted (a surviving value is refused by both at the gate) refused at parse (serde_json's range check)
a set field path ending in an inherited Object.prototype member (name.constructor, name.toString, name.valueOf…) readField returned the inherited function and the record's structuredClone threw (… could not be cloned): change refused at the op the member is an ordinary missing key: written, before recorded as null. Kept alone, the shape gate refuses it (every object of the sheet contract is strict). Replaced by a later op of the run (a set name on the same item), or removed with its item, the change is accepted: the document is byte for byte the one the later op alone gives, one extra record traces the overwritten write. Nothing is bypassed: the settable table checks the first segment on both sides (constructor as a field: unknown field), no value is read through a prototype, the integrity gate runs on the final document (test an_inherited_member_name_is_a_plain_key_and_bypasses_nothing, four member names; __proto__ has its own row). Accepted by the owner 2026-10-23
a set field path holding a __proto__ segment (name.__proto__, name.__proto__.x) no key was ever written: at the end of the path the setter ignored a primitive or set the holder's prototype (change accepted, records with before: {}); in the middle, Object.prototype itself was polluted and every later object failed the strict gate (change refused) refused at the op (reserved key "__proto__"), with or without a later overwrite: no faithful reading exists (fifth final round; declared case declared-proto-segment-overwritten, test a_proto_segment_is_refused_at_the_op)
an authored key starting with NUL ("\u0000touched") in a value, or a field path segment starting with NUL (name.\u0000touched) refused at the strict document gate when the key reaches the document, accepted when a later op overwrites or removes it refused (reserved key): at parse for a value, at the op for a field path; the prefix is reserved for the applier's transient touch marks, which the cleanup strips at every depth, so a written key would be lost while a record claims it (found by the final gates, test a_reserved_or_unbounded_field_path_is_refused_without_writing)
a null, a string, a number or a boolean among the children or categories of an added item a TypeError where a walk met it (descendants, the review marking: refused), silently skipped by a rename's citation walk (accepted when a later op removed the item), refused by the gate when it stayed refused at the add (… entry that is not an object), whatever follows (three cases frozen from the TypeScript, one declared: declared-children-string-renamed-then-removed)
a children or categories of an added item that is present but not a list (an object, a string, null) replaced by [] when a later op added under the item (childrenOf): the author's value lost without a word; accepted as well when a later op removed the item refused at the add (… that is not a list); children_path never replaces a present value (declared case declared-children-object-then-added-to)
a set whose path goes through a non-object (a string, a number, a boolean, an array, null: name.fr.x): writeField replaces it by an object before recorded as undefined (null), the replaced string in no record; refused by the gate unless a later op overwrites the field the same (kept, recorded here)
a document of more than 200,000 values after an op (the equine document holds 6,374) accepted when valid refused at the op: a resource bound checked with the depth (test the_document_cannot_hold_more_values_than_the_bound)
a field path of more than 8 segments (the deepest settable path has 2) accepted, the gate refused the stray keys refused at the op: a resource bound (20,000 segments overflowed the stack before it)
a document nested more than 64 levels after an op (the equine document has 10), by repeated add or move, or a deep value accepted when valid refused at the op: a resource bound checked after every op with an iterative walk (test the_document_cannot_be_nested_past_the_bound_by_repeated_adds)

Technical debt, kept during R5 (owner decision 2026-10-23, reproduced as is, never corrected silently): applyRecord of the migration map reads record.op whatever record.target is. A cascade record of a view, zone, category or region rename whose target is an annotation of the legacy id map is replayed as a rename of that annotation; a reference rename's cascade on a cited finding is replayed as a rename of the finding's path. Measured on the mini sheet (TypeScript values, frozen; test the_migration_map_replays_cascade_records_by_their_op_as_the_typescript_does): renaming view:main sends legacy-hip and legacy-neck to principal and the legacy head view to principal; renaming a cited reference sends hip/hip-dysfunctions/mobility away, and re-homing brings it back, counted as 3 re-homed instead of 3 identical; combined with a finding rename (renames-cascade), hip/hip-dysfunctions/mobility maps to null where hip-joint/hip-dysfunctions/motion is the right target. The committed changeset renames findings only (33) and no reference, so the equine map is untouched. A future changeset renaming a view, zone, region, category or a cited reference must not be published before the fix (a declared behaviour change on both sides, after R5).

Aligned on JSON.parse, not a difference: an authored value keeps JavaScript's key order (array index keys such as "1" first, ascending, then the others in insertion order) and an integer beyond 2^53 is read as the double JavaScript holds (9007199254740993 → 9007199254740992), at parse (text::js_normalize) and when a field path writes a key (text::js_insert), so a record never holds a value its own document lacks (found by the fourth final verifier; cases js-index-key-in-value-overwritten, js-index-segment-overwritten, test an_integer_beyond_2_53_is_read_as_the_double_json_parse_gives).

Aligned on Zod, not a difference: serde's derives read a struct from a positional array ("title": ["Titre", "Title"], a whole change or reference as an array) and a unit enum variant from a one-key map ("level": {"A": null}, scope, review_status, laterality, the reference type); Zod refused both. Each authored file and the curated document are compared, by shape, with their typed reading serialised back (draft/shape.rs): an object stays an object, an array an array of the same length, a scalar a scalar of its kind (found by the final verifier's 55,000-changeset differential; 10 changesets and 2 references files frozen from the TypeScript). The R2 contracts carry the same derives (open item below).

Kept as the TypeScript: invalid UTF-8 in the two curation files becomes U+FFFD (readFile(path, 'utf8'), as R5.2 kept for the catalog); a repeated key in either file keeps its first position and its last value (JSON.parse, through the core's parse_json; tested on a change and a reference); ids compared as strings (entry[key] === id), a non-object entry never matches; String(x) of a missing id is "undefined"; the error messages of the ops (unknown target "…" (no "…"), position N out of range, …) are the TypeScript ones with the change id and op index prefixed.

Tests: cargo test -p faunosteo-core --features curation (draft 16, importer 5, formatting 6, plus the crate's suites); anatomy 142 (the generator added); pnpm rust:check green.

Gates: security auditor PASS (semgrep 0 findings, 6 LOW; fixed: the head view box read with get, the destination claimed then canonicalised, INIT_CWD taken only when absolute; kept: seed SQL built by string formatting as the TypeScript, from pipeline values only, and the suite's clippy allow line), .claude/audits/2026-10-22-rust-r5-draft-security.md. Fresh verifier, three passes (.claude/audits/2026-10-22-rust-r5-draft-verify.md): pass 1 found four unreachable divergences, two aligned (String(id) for finding targets, the exact JavaScript trimEnd set), one kept as both sides refuse (a position beyond 2^64, a different number printed; the second, an added item with a null child, proved wrong by the third final round and replaced by the non-object child row of the table); pass 2 found one reachable divergence, null accepted on the optional scope, position and field where Zod refused it, now refused alike (three synthetic cases added), and aligned the re-homing candidates on a set (a path met twice counts once); outcome-identical details kept: annotation_names reads a non-string name as empty, an unlisted counter key keeps insertion order, the parseViewBox error quotes its text. Pass 3 found a repeated key refused by serde's derive (now read as JSON.parse does), an authored NUL-prefixed key silently dropped by the mark cleanup (now refused at parse), a symbolic link typed with a trailing / followed by --out (the path is rebuilt from its components before the check), and three refusals by design now declared above (lone surrogate, depth, __proto__). Pass 4 met C1 to C12 and found the documentation incomplete: the curation files are now read lossily as the TypeScript read them (a Latin-1 byte had been refused), two contrived splits are declared above (1e400 in a discarded value, an inherited member in a field path), and the NUL-key row and the counts are corrected. Final round on 8654905 (owner 2026-10-23): verifier ECARTS(2) and security PASS with 2 MEDIUM, one shared root: a NUL-prefixed field path segment was written then stripped with the marks, its value lost while a record claimed it (fixed: refused at the op); 20,000 field segments overflowed the stack (fixed: 8 segments, 64 levels checked after every op); --out writes were not exclusive after the claim (fixed: create_dir and create_new); .., a missing parent and a destination inside the seed are refused, the destination printed before writing, a non-UTF-8 argument refused; the binary's refusals are tested against the built binary (out_refuses_every_unsafe_destination_and_writes_nothing). Second final round on 314cf04: verifier ECARTS(3) (the serde shape family above, in the authored files and the gate, plus a missing-list message) and security PASS (MEDIUM memory, LOW: quadratic depth walk, --check and reads following symbolic links, residual check-then-use window, write_exclusive accepting any component, lossy normalisation, a test aimed at the real seed). Fixed: the shape comparison; document has no list for a missing list; every read a regular file under 16 MiB whose canonical path lies in the seed folder (a link inside the seed is followed only if it stays there); --check lists a link without walking into it; write_exclusive takes plain names only and re-checks the claimed folder; the seed refusal tested on the pure check (inside), no test targets the real seed. Kept and declared: the measured residual risks above. Third final round on 42bbc48: verifier ECARTS(2) (C1, C2, C4 to C12 met; 82,000 random changesets, 13,758 accepted identical; one family: a non-object child of an added item, three splits, and the §11.12 sentence on the null child wrong) and security PASS with LOWs only (reads following folder links out of the seed, the shape comparison not enforcing array length, a folder appearing after the claim accepted, the seed guard tested only as a bare function, before: null over a replaced string). Fixed: non-object children refused at the add; reads confined to the seed by canonical path; array length compared; only folders this run created are used; claim_destination takes the seed and is tested on a fixture (the_claim_refuses_a_destination_inside_the_seed_and_creates_nothing). Declared: the replaced-string before, the memory factor. Fourth final round on 6c0fe88: verifier ECARTS(2) (C1, C2, C4 to C12 met, 0 accept/refuse split in 25,000 random changesets; records differing from the TypeScript on array index keys and on integers beyond 2^53; the declared-case count wrong) and security PASS with one MEDIUM (a present non-list children silently replaced by []) and LOWs (--check listing through a generated folder that is a link, a mount alias of the seed, the walk cost understated, the claim test fixture in the shared temporary folder). Fixed: js_normalize and js_insert; non-list children and categories refused at the add and never replaced; --check confined to the seed's folders; the identity guard; a 200,000-value bound; the fixture under target/. Fifth final round on 3ece1a6: verifier ECARTS(2) (C1, C2, C4 to C12 met; 120,000 random changesets, 40,494 accepted identical, every other split a declared family but one: a __proto__ segment, with the inherited-member row wrong for it; the test count stale) and security PASS with LOWs (the identity guard covering the seed folder only, quadratic id comparisons). Fixed: __proto__ segments refused at the op; the identity guard over every folder of the seed; hash sets.

11.13 Checkpoint R5.3

Open item for the owner (outside R5.3, gated readers): the serde leniency above is in the R2 derives of domain/sheet/schema.rs and very likely of the report and archive contracts, so the readers of imported PDFs (archive/read.rs, report/read.rs, pdf/import.rs) would accept an object written as an array or an enum written as a map where the frozen Zod reader refused it. Not probed on those readers, not changed: a fix there needs the owner's per-file go.

Residual risks, measured by the final security gates and kept: the document is bounded (64 levels, 200,000 values, checked after every op; the equine document has 10 and 6,374), but the records are not: a hostile changeset of subtree sets with a large value still costs memory in proportion to ops × items × value size (211 KB asked for more than 2 GB before the value bound; the port clones the op into every record where the TypeScript shared it, about twice its memory); the bound walk runs after every op (at most 200,000 values each, a few milliseconds; a 16 MiB changeset of tiny ops could take minutes); --out assumes a single-user machine (a concurrent process able to write the destination's parent could still swap a component between a check and its use, never overwriting: every file is create_new); invalid UTF-8 and repeated keys are read as the TypeScript read them. Residual risks of the slice: the --check allowance for the six R5.4 files hides nothing about the produced files but means the draft folder is not yet compared whole (R5.4 removes it); the seed guard of --out compares canonical paths, then the file identity (device, inode) of every ancestor of the destination with that of the seed folder and of every folder under it, so a second mount path of the seed or of any of its folders on the same device is refused too (a share mounted twice on distinct devices is not told apart; every write is still create_new); id comparisons use hash sets (cite, declared references, duplicate ids); --check refuses a generated folder that is not itself a folder of the seed (a link there is never listed through); the touch marks are a reserved prefix (a NUL character starts it), refused in any authored value at parse and in any field path segment at the op, and removed after each change, so no mark reaches a record or the document; the migration-map replay quirk above is reproduced, not fixed; the emoji, Markdown and Unicode-table risks of §11.11 stand.

Conditions for R5.4: the owner's validation of this checkpoint; the review drawings compared as parsed trees against the xmldom files (declaration, prefixes and whitespace declared), on the R3 layer and compose; CHANGELOG.md and REVIEW-REPORT.md byte for byte through markdown.rs (the pre-Prettier digests of the ledger as the intermediate check); the pending list of --check removed so the draft folder is compared whole.

11.14 R5.4: the review files in Rust and the whole-draft check (2026-10-23)

Owner go « Validation R5.3 et autorisation conditionnelle R5.4 » (2026-10-23), conditional on a fresh verification of the final R5.3 state: met on c6e0d85 (CONFORME 13/13, security PASS with LOWs only, §11.12). Contract .claude/tasks/contracts/2026-10-23-rust-r5-review.md.

crates/core/src/curation/draft gains 1,698 lines (4,606 in all), plus curation/report_guard.rs (258):

Module Ports
labels.rs the French labels of kinds, levels and priorities (labels.ts)
stats.rs stat_rows statRows: labelled rows, fixed order, counters in their key order
changelog.rs compactValue (labels as fr / en, other values as JSON.stringify, cut to 120 UTF-16 units with …, a cut inside a surrogate pair giving U+FFFD as the file write did), recordSubject, the comparison, migration and per-level tables, the intro
review_report.rs the ten sections of review-report.ts: initial quality, errors, corrections, additions, restructures, uncertain items, translations, clinical vigilance (changed vet flags, flags per zone), bibliography (URL and DOI, citation counts), professional decisions (priority then id by UTF-16 units, stable)
drawing.rs the frozen horse.svg read by the core's one SVG reader (refused if anything is removed), its prolog (the XML declaration and its line break) kept verbatim in front of every drawing
overlay.rs renderReviewOverlay: the view's frame, the markers (unchanged, moved, added, removed, the previous position of a moved one), shapes, titles, labels, the legend, the font size from the frame width; numbers printed as String(number)
app_review.rs renderAppReviewDrawing on the R3 layer (render_layer, view_box_of) the editor canvas uses
svg_compare.rs how a produced drawing is compared with the committed xmldom file: bytes, else parsed trees after the one declared rule
pipeline.rs render_draft_artifacts complete, in the TypeScript order: document, assets, sheet-ref, migration map, the overlays and the application's drawings per view, CHANGELOG, REVIEW-REPORT, seed SQL
bin/import_equine.rs --check compares the 6 + 12 files with explicit criteria (byte identity; the application's drawings may fall back on parsed trees under the declared rule, printed as declared:); a file missing, not produced or different fails; the pending list and its shortcut: are gone; --out writes the 18 files

Parity, every expectation written by the TypeScript (tests/curation_review.rs, 12 tests):

  • CHANGELOG.md (1,114,533 bytes) and REVIEW-REPORT.md of the committed draft byte for byte; their raw texts equal the ledger's pre-Prettier digests, the aligned texts its digests;
  • review/annotations-main.svg, review/annotations-head.svg and review/app-head.svg byte for byte with the xmldom files;
  • review/app-main.svg: the one declared difference, measured to the byte (test app_main_differs_only_by_the_r3_trigger_names): the head trigger, which has no name of its own, carries data-anno-name-en="Head (left lateral view)" and the title Tête (vue latérale gauche) / Head (left lateral view), where the TypeScript renderer wrote the French name twice; this is the R3 owner decision of 2026-10-15, the name the editor canvas already shows (a tooltip and a data attribute: no shape, colour, position or frame changes);
  • four synthetic cases written by the TypeScript on the mini sheet and a small drawing (oracles/r5/review-synthetic.json, generator packages/anatomy/tests/r5.review-synthetic-oracles.test.ts): pipes and line breaks in cells, a value over 120 units, accents and guillemets, a vet flag change, a translation, a level C question at priority high and at low, a restructure, a removal, cited references (their URLs null; the URL and the medium priority are covered by the equine report: 35 URL lines, 5 medium-priority questions), a moved, an added and a polygon marker, a path marker on a detail view framed by its view box, a sheet with nothing but a level A change: raw and aligned Markdown byte for byte, the overlays byte for byte, the application's drawings byte for byte or under the declared rule; an emoji in a cell gives the same raw text and a declared refusal: the report guard refuses it first (UnsupportedMarkdown, a character outside the allowlist), before the aligner's UnsupportedWidth (R5.2) is reached;
  • two runs byte-equal; an undeclared difference (a colour, a coordinate) refused with and without the rule.

pnpm r5:import-equine --check: legacy-import: 6 files, 0 differences; draft: declared: review/app-main.svg (byte-identical once the R3 trigger-name rule is applied); draft: 12 files, 0 differences. --out then diff -r: legacy identical; draft identical but app-main.svg.

R5.3 carry-over (final gate LOWs, not applied to the verified state): an existing destination folder is itself identity-checked against the seed's folders; a failed seed walk reads the seed folder cannot be read instead of inside the seed folder; the cite check against the item's existing citations is hashed; the stale test comment fixed; the §11.12 nits (the inherited row covers a later removal; the 200,000-value row; the line count at the close; the set-without-value case counted among the schema refusals).

Markdown beyond the table alignment (found by the R5.4 gates: three verifier differentials and three security probes, each round finding a Prettier rewrite the previous rules missed). Prettier also rewrites Markdown in authored text (escapes, emphasis, whitespace, links); the port reproduces only the table alignment. After a denylist that leaked round after round, the guard of the draft's two reports (curation/report_guard.rs, format_report; the R5.2 import report keeps format_markdown, verified at R5.2, which gained at R5.4 the cell-count refusal and the table bound below, both shared with the import report) is an allowlist: outside code spans, letters and digits, single spaces (none at a line end), the punctuation .,;:!?'"«»()[]{}/-–—…%°≠=+#<>’‘“”±→×≤≥|, an & before a space or as a URL's query separator (&name= in a bare URL, the name starting with an ASCII lowercase letter and not with one of HTML's 106 legacy references, which Prettier decodes without a ;), an underscore between two ASCII letters or digits and not glued to a URL (http://, https://, www.), a backslash before " or | (a JSON quote, the cell escape), **word** with one run of letters between spaces or line edges (the import report's form), and no inline construct (an inline link, image or reference ](, ][; an image reference ![; a [[ before a space with a ]] after it, or a ]] after a space with a [[ before it; < before an ASCII letter, /, ! or ?: an HTML tag or an autolink; a character reference &name;, &#n;; a liquid bracket {% or %}); no plain underscore followed later on its line by one that can close an emphasis (inside a later code span, before anything but an ASCII letter or digit: Prettier's parser paired to_do … \ref_`across the span); an authored text holds no backtick (titles, rationales, questions, citations, URLs, DOIs, values), so code spans are written by the generator from ids, targets, field names and file paths; a code span admits only that alphabet,[A-Za-z0-9_:/. -], never empty, no outer space (the template's pnpm import:equineholds the one inner space), and a field segment an op names is limited to[A-Za-z0-9_-](refused at the op otherwise: a]there closed an author's[ across the span); a table row with another cell count than its header is refused; a list-item field (title, rationale, question, citation, URL, DOI, vet-flag value) shares its line with the change's other fields and code spans, so it refuses a control character and any wiki-link or liquid bracket ([[, ]], {%, %}) whole, wherever its partner sits on the line (a table cell is parsed on its own and keeps the per-cell rule). Everything else is refused with UnsupportedMarkdown`: a character outside the set is refused by default; the forms built from admitted characters are ruled one by one, so a form no rule names and no probe covers could still pass.

The guarantee is empirical, not a proof of Prettier's behaviour: the TypeScript sweep (oracles/r5/markdown-sweep.json, generator packages/anatomy/tests/r5.markdown-sweep-oracles.test.ts, digests of the raw and formatted reports) holds 798 probes: 48 characters in six positions, whitespace patterns, Markdown constructs, the families each gate round found (strong pairs, URLs, non-terminated references, image references, nested padded wiki links, authored code spans and underscores paired across them, with the cited reference named probe_ref and, for three probes, probe_ref_; eight construct pairs opened in the title, the rationale and the other fields and closed in the question: [[/]], padded and unpadded, {%/%}, [x/](y), *, _, <b/>), and 400 strings from a seeded generator over an alphabet that includes &#, &amp, &lt, ![, [[ and ]], each placed in a title, a rationale, a question, a citation, a label after a word and a label alone (a cell start). Result (test every_probe_is_formatted_as_the_typescript_or_refused): 268 probes byte for byte with the TypeScript, 530 refused, 0 silent difference; a probe made only of what the equine reports use, outside the constructs, is never refused (a polygon's [[10,10],…], the DOI's <0697:toih> and the URLs' inner underscores pass). The equine reports pass the guard unchanged.

Input TypeScript Rust
authored text outside the allowlist: Markdown Prettier rewrites (*x*, _x, x_**a**, **a****b**, Voir_https://…, a b, a non-ASCII space, a tab, a line break in a list item, ``, a|b, [a](<b>), [[ a ]], &#42;…), the constructs refused whole (links, HTML tags, autolinks, character references) and any character outside the admitted set (pictographs, symbols, combining marks without the Alphabetic property; an alphabetic mark such as U+0345 is a letter and Prettier aligns it alike) written, then rewritten by Prettier (escapes, _emphasis_, collapsed spaces, indented continuation lines, normalised links; a row with an extra cell), or kept refused (UnsupportedMarkdown), even where Prettier would have kept the text
a pictograph in a table cell (an emoji, and ©, ®, ™, ✓, ★, ⚠ and the other characters text::is_emoji_candidate lists) measured with Prettier's tables refused, loudly: in the draft's two reports by the guard first (UnsupportedMarkdown, outside the allowlist), the aligner's UnsupportedWidth (R5.2) applying there only to the alphanumeric candidates (Ⓜ, 🅰) and in IMPORT-REPORT; the set is wider than the emoji
aligned report tables past 32 Mi display columns in all (rows × padded row width, the CHANGELOG's three level tables summed; the equine CHANGELOG's widest table is about 0.5 MB): one long authored cell pads every row of its level, so an 80 KB rationale over 14,000 records asked for 1 GB (security gate R5.4 round 6) Prettier aligned it (the same amplification) refused (Guard): the CHANGELOG's tables are projected from their cells (bytes bound the display width) before the raw table is joined (test a_changelog_whose_alignment_would_explode_is_refused_before_it_is_built, through the pipeline), every other table in the aligner before any padded row is built (test an_aligned_table_past_the_bound_is_refused_before_it_is_built), import report included
records weighing more than 16 Mi units in all (records::record_weight, about the bytes in memory: 64 per JSON value and per string, plus one per byte of text, for the values, the change and the op, which each record clones; the equine records weigh 1,966,163; an add or a move also clones its position anchor): a rename or a remove records the whole item and one op, or the B/C marking, records once per item it reaches, so 400 renames of a 5,000-child item asked for 4.3 GB (round 7), a level B add of 10,000 children with a 128 KiB rationale 1.37 GB inside one marking, a 64 KiB value set over a subtree 2.0 GB (round 8), 200,000 one-character reference ids cloned into each record 948 MB at one unit per byte (round 9) recorded (the same copies) refused at the record that passes the bound, charged before the change and the op are cloned into it (records::charge, tests the_records_cannot_outgrow_their_bound, the_records_bound_holds_inside_one_op_and_the_marking); the raw report rows, built from the records, are bounded with them; the 200,000-value document bound now holds the baseline (test from a padded baseline)
review drawings past 64 MiB in all, projected as an upper bound before any is rendered (pipeline::review_drawings_bytes: per view, the cleaned drawing twice with 4,096 bytes each for the drawing's fixed parts (layer group, overlay group and legend), plus for each annotation of the view in the overlay's two documents and in the application's drawing 1,024 bytes and 24 times its JSON text and the longest view name, four copies escaped up to six times longer; the equine draft projects 1,406,812 bytes for 564,239 written): 2,000 views asked for 547 MB (security gate R5.4 round 8), unnamed triggers repeating a long opened view's names 131 MB from a 485 KB changeset (round 10) written refused before rendering (pipeline::MAX_REVIEW_DRAWINGS_BYTES, tests review_drawings_past_their_bound_are_refused_before_rendering, unnamed_triggers_repeating_a_long_view_name_are_refused_before_rendering; the projection bounds what is written, a draft without annotations included: test the_drawings_projection_bounds_what_is_written)
an id an add writes (the item's, and those nested in its children or categories) or a rename id that is not a stable id (a region code for a region), or a field segment outside [A-Za-z0-9_-] (a control character, NUL included, a backtick, a ], a space, a non-ASCII letter) accepted when a later op removed or renamed the item: the raw id stayed in the records and reached the reports' code spans (a line break there forged a section, security gate R5.4 round 2) refused at the op, the check the final document applies anyway (test ids_and_field_segments_that_could_forge_report_structure_are_refused)
a label, id or path holding a code point XML 1.0 refuses, or a carriage return, in a review drawing written (a non-well-formed file; a raw CR read back as a line feed) refused: the drawing is not written

The drawing comparison hides nothing (security gate, MEDIUM): the rule fallback of --check requires the committed file to rebuild byte for byte from its tree (so no comment, processing instruction, encoding or entity form can escape the comparison), the rule to change that tree, and the rebuilt text after the rule to equal the produced one byte for byte; declared: is printed only then (test the_rule_fallback_refuses_what_the_tree_does_not_carry: a stylesheet processing instruction, comments, a trailing comment and another declared encoding refused). The committed drawing is read by the core's reader before any other parse, so its depth cap holds (a 100,000-level file is refused, never a stack overflow). The overlay prints a coordinate that overflowed as Infinity, as String(number) did. The renderers are indexed (citation counts in one walk, previous markers and kept ids hashed, subjects grouped per change).

Tests: cargo test -p faunosteo-core --features curation (review 12, Markdown 2, draft 18, importer 5, binary 3, formatting 7, plus the crate's suites); anatomy 144 (two generators added).

11.15 Checkpoint R5.4

Graphic differences for the owner's validation: none in shapes, colours, positions or frames; one text difference in app-main.svg (the trigger's English name and tooltip), already decided at R3 and identical to the editor canvas.

Residual risks: the reports admit an allowlist of characters and forms and refuse the rest, including text Prettier would have kept (links, HTML, character references, symbols, combining marks, non-ASCII spaces, most uses of * and _): a future changeset using them stops the pipeline, visibly, until the allowlist is widened from new TypeScript probes or the port grows a Markdown printer; the allowlist is proven by probes, not by a model of Prettier: each gate round of R5.4 found a family the previous rules missed (Markdown syntax, constructs, strong pairs and URLs, then non-terminated references, image references and nested padded wiki links, then authored code spans and underscores paired across code spans, then wiki links opened in one field and closed in another and field segments closing an author's bracket from a code span), each now ruled and frozen in the sweep, so a combination of admitted characters no probe covers could still differ; the comparison of the application's drawings accepts exactly the trigger-name rule, byte for byte; the frozen horse.svg is read, never regenerated, so a future change of the drawing needs its own decision; the record that passes the bound has been built before it is refused (one item copy and one clone of the op's value, at most twice the 16 MiB read cap), and a subtree set writes its value into each item before recording it, so the document holds at most as many copies as the records bound admits; the comparison of --check looks up each trigger's view linearly (views × triggers, the views bounded through the drawings bound); parsing changes.json (R5.3 code) holds about 65 times the file in memory (about 1 GB at the 16 MiB read cap, security gate R5.4 round 9), before any bound of the applier applies, and references.json goes through the same parser (the same order, not measured); two scans are quadratic but out of reach or bounded (security gate R5.4 round 12): report_guard::underscore_pairs_later on a line of many code spans and plain underscores (53.7 s on a synthetic 900 KB line; the generator writes at most two plain parts that can carry an authored _ per line, so it stays linear), and pipeline::review_drawings_bytes walking views × annotations before its bound applies (about 2 s at the 200,000-value document bound); and the allowlist admits the invisible Hangul fillers (U+3164, U+115F, U+1160, U+FFA0, letters Prettier keeps, no structure); the residual risks of §11.13 stand.

Conditions for R5.5: the owner's validation of this checkpoint; the upload tool (ureq, the service key from the environment, bucket anatomical-sheet-assets, key <sha256>.svg, upsert: false, bytes verified against assets.json, RPC confirm_sheet_asset_upload) run against the local stack only, with its runbook.

11.16 R5.5: the sheet-asset upload tool, the R5.4 closing adjustments (2026-10-23)

Contract .claude/tasks/contracts/2026-10-23-rust-r5-upload.md. Owner brief « Validation R5.4 et autorisation conditionnelle R5.5 ».

Tool. upload-sheet-assets (crates/core, feature upload = curation + ureq, the version the worker already uses; pnpm assets:upload [--check] <seed folder>). The rules are the core's (curation::upload: manifest, destination, bytes through the one SVG reader, plan from the observed state, closed error kinds); the binary owns the file system, the environment and the network, split in main.rs (flow, files) and storage.rs (HTTP). It replaces packages/supabase/scripts/ upload-sheet-assets.ts, kept as assets:upload:legacy until the R5.7 census. Behaviour and runbook: SUPABASE.md §3.1. Differences from the TypeScript tool, all refusals added: no default destination (a local address with an explicit port is required); an existing object is hashed, not trusted by its name; a missing or foreign asset row stops the run instead of failing after the upload; the whole run is planned before the first write; the file must pass the SVG reader with nothing removed; sizes and entry counts are capped; nothing is overwritten, deleted or made public, ever (x-upsert: false, no DELETE, no bucket call but the read).

Destination rule. http, explicit port, no credentials, path, query or fragment; host localhost, a loopback address, or the private IPv4 address equal to FAUNOSTEO_DEV_HOST. A name other than localhost is never accepted (it cannot be proven local without resolving it). The handshake then checks the private bucket and the key before any object is read or written. The DEV address counts only if a socket can be bound to it (an address of this machine). A local port held by something else would receive the key: accepted on a single-user machine, the same stance as the worker's SUPABASE_URL.

Tests. curation_upload (7: manifest family, bytes, 15 destination refusals + DEV host rule, plan), upload_tool (12, the binary against a loopback stub with a made-up key: --check writes nothing, run then rerun, different bytes never overwritten, missing and foreign row stop before any write, 401/403, resume after a failed confirmation, unreachable port, refused destinations, folder outside the seed, usage, an oversized object refused once as State, a DEV address that is not this machine), curation_caps (4). Not run by the assistant: the session against the real local stack (pnpm e2e:sheet-assets: upload, rerun, anon key, wrong key, refused destinations, unreachable port); the assistant's own run of the tool with the service key was refused by the permission layer (CLAUDE.md: no transfer tool run by Claude) and was not retried by another route. The owner runs it.

Read caps (owner §3). changes.json and references.json are refused above 4 MiB, by name, in the core (MAX_CURATION_FILE_BYTES, checked before the parse) and in the binary (bounded read, the bytes read are counted as well as the size seen). Measured: 221.5 KB and 17.3 KB committed (about 19 and 240 times under the cap); --check peaks at 18.5 MB resident; a synthetic changeset of 765 changes (3.98 MB, ids renumbered) parses at +39 MB over a 7 MB baseline, about 10 times the text. The 65 times of the R5.4 round-9 security gate (§11.15) is a worst-case shape of many tiny values; at the 4 MiB cap that is about 260 MB where the 16 MiB read cap allowed about 1 GB. Other budgets (document depth and values, records, drawings, the 16 MiB read cap for every other source) unchanged. 4 MiB leaves a wide margin; a future multi-species changeset is a business-contract question and is not decided here.

Owner decisions applied. Quadratic scans (§5): kept, debt recorded in §11.15, no rewrite without a measured problem. URLs in titles, questions and justifications (§4): kept verbatim in the data and in the Markdown reports, no active HTML produced; an interface shows them as untrusted text. Divergent refusals (§6): invalid field segments, ids outside the stable-id grammar, inputs over the budgets, each a controlled PipelineError::Source or Guard, none dropping authored data; the grammar is the sheet contract's ^[a-z0-9][a-z0-9_-]{0,63}$, species-neutral (curation_caps checks ids of other species). Markdown stays an allowlist: an unreproduced form is a loud refusal, never a different file. FLOOR (§2): the clarification is in the R5.4 contract, with scripts/floor-clarification-check.sh.

Serde tolerance of the R2 contracts (owner §7), characterisation only; nothing changed. Structures: every serde-derived contract of domain/{sheet,report,archive}, read by the gated readers (report/read.rs: Report::deserialize for v3, ReportV2::deserialize for v2; archive/read.rs; the PDF import path). Two tolerances: a struct is read from a positional array, and a unit enum variant from a one-key map. Probed on Report v3 (test characterisation_serde_tolerance, which pins today's verdict):

Input (minimal change of report-v3.demo.json) Rust now Historical Zod contract
"sheet": [sheetId, null, documentSha256] accepted refused
"practitioner": [name, cabinet, contact, siret] accepted refused
observations[0].severity = {"mild": null} accepted refused
a zone written as an array (probe, not pinned by the test) accepted when the types of the positions fit the fields, whatever they mean; refused in the probe because a label landed on laterality refused
"extra": 1 (unknown field) accepted accepted (non-strict objects)

Consequence of accepting: a hand-built or foreign attachment imports; the report is re-serialised in the canonical object form, so nothing stored is non-canonical, but a positional array read in the wrong order assigns values to the wrong fields without an error when the types agree (an integrity risk for crafted files, not a memory or code-execution one). Consequence of refusing: only files the application never produced are turned away. Risk for R2, R3 and R4 archives: none either way, every archive the product wrote is in object form (the frozen envelopes round-trip, report_contract, and the N-1 suites), so a strict reading rejects no golden and no fixture. Proposal: the guard already used for the authored files (draft/shape.rs: compare the input with its typed reading serialised back) at the three reader entries, per-file go of the owner, decided before R5.6 since the membership test touches the same readers there; until then the gated readers are unchanged.

Open points carried: debt list of §11.12 and §11.13 stands (migration map cascade replay, clippy.toml I/O list); the upload tool is not run against the real stack by the assistant.

Gate round 1 (2c44506 + a481af5): pnpm check:all green 21:21:38; security PASS (1 MEDIUM, 9 LOW, .claude/audits/2026-10-23-rust-r5-upload-security.md); fresh verifier ECARTS(4) (.claude/audits/2026-10-23-rust-r5-upload-verify.md): an object over the size cap was classified Network and retried (now a final State, test), "retried three times" meant three attempts (now four, one try and three retries), the runbook's exit codes (fixed), the FLOOR script could not print OK while the declared evals.md:205 line stands (it is now listed as declared, still not requalified). Security fixes taken: keys off every argv in sheet-assets-e2e.sh (M1); the tool is compiled without the key in the environment, then run (L1); the DEV address must be one of this machine's (L2); a malformed request is final, not retried (L3); CLAUDE.md names the three files allowed std::fs (L7). Kept and declared: the cleartext key on plain http to a local port (L2), the file-read race mitigated by the hash (L5), the pre-existing confirm_sheet_asset_upload that does not re-check the hash (L6, SQL outside R5.5), the waived fixture lines (L8), the serde tolerance (L9, owner decision). Outside the diff, reported by the audit and not verified: supabase/config.toml sets no JWT secret, so the local stack likely uses the CLI's public default keys while port 54321 is open to the LAN.

Gate round 2 (fad85c0): pnpm check:all green 21:47:11; targeted fresh verifier: C1 to C13 MET, C14 open only on these two gates, now run; security PASS, 5 LOW kept and declared (.claude/audits/2026-10-23-rust-r5-upload-security-2.md): Protocol errors (also a key with non-ASCII bytes) are retried and end Network; the DEV-address bind accepts the subnet broadcast (the kernel then refuses the connection, the key is never sent, the run ends Network); the launchers run target/release/… and ignore CARGO_TARGET_DIR; the FLOOR declared line is pinned by line number; the non-local DEV-address test assumes 10.255.255.254 is not local (false on WSL2).

11.17 Checkpoint R5.5

Done: the upload tool in Rust with its runbook, the R5.4 closing adjustments (4 MiB curation cap, FLOOR clarification, serde characterisation). Not done by the assistant: the run against the real local stack (pnpm e2e:sheet-assets, by hand). Open for the owner: the STUB line evals.md:205 (FLOOR, declared), the serde tolerance decision before R5.6, the local stack's likely default keys with 54321 on the LAN.

Prerequisites of R5.6: the owner's go; the convention sha256-rfc8785-validated-v1 (D-R5 B, BDR-068) with its RFC 8785 vectors and the independent differential; the aliases of the historical fingerprints taken from trusted frozen documents only (the census .claude/audits/R5_DOCUMENT_SHA256_CENSUS.md: the one stored historical fingerprint is 27c7383c…2660; its other digests, 91e459f4…14c2 of legacy-import/document.json and eaf891f4…5d54 of the draft's jsonb::text, are stored nowhere and are not aliases), never from an archive or a bundle; the per-file go for the membership test in the gated readers (report/rebase.rs, archive/read.rs, pdf/import.rs), together with the serde decision above; the seed regenerated once by the Rust tool and the assets re-uploaded only if their bytes change (they do not: horse.svg is frozen); .prettierignore on the Rust-written paths; the migration-map cascade debt (§11.12) fixed before any changeset renames a view, zone, region, category or cited reference.

11.18 R5.5 closed; targeted corrections before R5.6 (2026-10-24)

Owner brief « Clôture R5.5, corrections ciblées et préparation R5.6 ». Contract .claude/tasks/contracts/2026-10-24-rust-r5-5-closing.md.

Real local stack: PASS, run by the owner by hand (pnpm e2e:sheet-assets, 11 checks, verdict e2e:sheet-assets OK). This result is the owner's, distinct from the assistant's simulated-server suite (upload_tool); the assistant did not rerun it. R5.5 is closed. FLOOR clarification and the 4 MiB cap accepted; evals.md:205 stays declared, not requalified.

Two LOW corrections. Protocol errors (a malformed HTTP answer, a key a header refuses) are final, no longer retried (test a_malformed_answer_is_final_and_not_retried: one request, exit 1). The DEV address must be an own unicast address: bound, then connected to itself (no packet) with that address kept as the local end; a subnet broadcast binds but refuses the connect (binary test over the host's inet and brd addresses). The other LOW reserves of §11.16 stay tracked.

Serde hardening of three v3 shapes (owner go). report::read::check_v3_shape refuses on the raw value, before the typed read, sheet or practitioner not an object and an observation severity not a string (ReadFailure::Invalid with the field named at read_report_document; a serde_json::Error at parse_envelope, whose caller drops the copy as before). The report, each observation and the envelope must be objects themselves, or a positional parent would carry those fields past the check (found by the closing gates, test a_positional_parent_does_not_carry_a_refused_shape_past_the_check). Called at the two entries that read a v3 report from outside: read_report_document (v3 branch: PDF import, bare archives, draft restore) and parse_envelope (the session's archive copy). Nothing else narrowed: an unknown field and an absent severity are read as before; null severity was and stays refused (optional, never nullable). Test characterisation_serde_tolerance turned around (6 cases, the envelope entry and positional parents included). Every R2-R4 suite, the PDF import suites, the envelope goldens and the N-1 reader pass unchanged; no authentic archive was rejected. Not covered by the go, left as is: the same derives on Report v2 and on the other contracts.

confirm_sheet_asset_upload, characterised (no SQL change). EXECUTE revoked from public, anon, authenticated, granted to service_role only (migration 20261009100000; pgTAP 006: an editor gets 42501, the service role confirms, twice is idempotent; anon is covered by the grant, not by its own assertion). The function sets uploaded_at for the row id without checking that <sha256>.svg exists in storage.objects or that its bytes match: a service-role caller can confirm a row with no object or with other bytes under the key. Not exploitable from an API role: no INSERT, UPDATE or DELETE policy exists on the bucket, so only the service role can place bytes, and the service role already bypasses RLS. In the tool, the row is confirmed only after the object is read back and hashed. Debt before any public exposure: check the object's existence (and size) in the function. On DEV, see the next point: the service role is reachable from the LAN today.

DEV stack (owner §5). Measured without printing a secret: the stack uses the Supabase CLI's public default JWT secret, the service key is the public demo key (iss: supabase-demo), and 54321 is open to the LAN by design, so a device of the network can act as service_role on DEV. The checks to run for 54321 (listener, UFW, rootless or rootful Docker, a probe from another device) and the two remedies are in ENVIRONMENTS.md §3.6. No firewall or configuration was changed.

R5.6 prepared, not started. Plan .claude/tasks/plans/2026-10-24-rust-r5-6-fingerprint-switch.md.

Closing gates round 1 (257a29b): pnpm check:all green 03:39:24; security PASS (2 MEDIUM, 6 LOW, .claude/audits/2026-10-24-rust-r5-5-closing-security.md); fresh verifier ECARTS(2): the shape check was blind under a positional observation or envelope (fixed, as above), and a stale "or null" message (fixed). Also fixed: a multicast address no longer counts as an own address (it binds and connects on Linux; the private-range rule masked it end to end). Kept: the binary's own-address test checks nothing more than loopback where ip is absent; the internal typed re-reads (pdf/write/export.rs, ops.rs, the export input of facade.rs) read values the core itself built or the page's own state and skip the raw shape check; the other nested v3 fields and v2 keep serde's leniency (outside the go).

Closing gates round 2 (1ec9e1b): pnpm check:all green 03:51:55; targeted fresh verifier K3 MET, K4 met in behaviour (23 bypass probes refused, a census of 157 repository JSON files finds no authentic shape refused, --features cli 261 passed), ECARTS(2) formal: the parse_envelope error type and an audit-prose FLOOR line, both settled by a contract Clarification submitted to the owner.

11.19 R5.6 prepared: the fingerprint convention and its registry, not active (2026-10-24)

Owner brief « Validation R5.5, arbitrage D-R5.6 et préparation de la bascule ». Convention sha256-rfc8785-validated-v1 confirmed; the core's compiled registry is the only alias authority; five consumers approved (report/rebase.rs, archive/read.rs, session.rs, pdf/write/input.rs, pdf/compare/lines.rs); Rust becomes the only generator at the switch. Nothing is active: no reader, writer or generated file uses the new module; pnpm r5:import-equine --check gives 0 differences and documentSha256 stays 27c7383c…2660.

Committed (inert). domain/sheet/fingerprint.rs: canonical_json (RFC 8785: UTF-16 member order, js_number, the JSON.stringify escape set, no normalisation, I-JSON numbers only), sheet_fingerprint (feature fingerprint: strict parse, R2 shape, zero integrity issue, JCS of the typed reading, SHA-256), TRUSTED_ALIASES (one entry: sheet 503dc301-…, canonical 12d788727c1e532641bd5b3a7ecf39dbdd25e70350f8a76be5ca917b262874e2, alias 27c7383c445c73dc2001ebf4794a3ea63d416910bbbaa0d7848dd720de7c2660, convention of the alias sha256-prettier-file-bytes-v0), equivalence (Identical, TrustedAlias, Different; the pair must belong to the same sheet, either way round; raw values stay with the caller) and check_declared (a sheet-ref.json block must name v1 and list only registered aliases of that sheet and canonical value). Tests sheet_fingerprint (9): the RFC vectors, the 44,322-row V8 number oracle, the independent Node reference (scripts/r5-fingerprint-differential.mjs, own canonicaliser, frozen once into oracles/r5/fingerprint-differential.json, 7 cases: ES number edges, UTF-16 key order, escapes, nesting, repeated keys), the draft's value recomputed equal to the frozen b_rfc8785_validated, invalid and malformed documents refused, the registry contract, and the census of the historical archives (147 PDF attachments and the JSON fixtures: 124 sheet stamps, 123 are the alias and open as the same document, the one other stays different).

Prepared, not applied: .claude/tasks/plans/r5-6-switch.patch (applies cleanly on this commit). The five consumers through equivalence (rebase skipped on the registered pair of the same sheet, the stamp kept; archive snapshot pair; export sheet match; report-compare prints both raw values for an alias match; session.rs needs no own change, it goes through the rebase), the generator stamping sheet_fingerprint and writing the descriptive block, the sheet load refusing a block that contradicts the registry (loaded.rs, facade.rs: invalid_sheet), .prettierignore on legacy-import/ and draft/, and the rehearsal suite fingerprint_consumers (3: alias not rebased and stamp kept, real change and forged value rebased, archive pair kept and forged pair rejected). Rehearsal, corrected by the fresh verifier: pnpm rust:check and pnpm check:all (14:32:05) were green with the five consumers wired only, before the generator, load and report-compare parts were added. With the whole patch on the current seed: the cli, fingerprint and default suites are green, 4 tests of curation fail (below). With the seed switched as well (verifier's simulation in a scratch copy), 3 more fail: the 2 fingerprint_consumers cases whose precondition reads the seed as 27c7…, and pdf_import o7_locate_and_read_match_the_typescript, whose frozen R4 oracle records the stamp of migrated v2 reports (scan.report-v2-{full,minimal}.pdf), which follows the migration map to 12d7…. Neither suite has run end to end on a switched seed yet.

Seed at the switch (measured with the patch, written to a scratch folder, never to the seed):

File Before After Why Check Rollback
draft/sheet-ref.json sha256 2c0716f1…b285, document_sha256 27c7…2660 sha256 03e7f6ab…623b, document_sha256 12d7…74e2 + block fingerprint {convention, aliases: [27c7…2660]} the convention --check byte-exact against the regenerated folder; the load check git revert
draft/report-migration-map.json sha256 4139c51d…fce9, sheet.documentSha256 27c7… sha256 0e991bc2…2db, 12d7… a migrated v2 report is stamped with the current value same git revert
the 16 other files unchanged unchanged (document.json, horse.svg, equine_draft.sql compared byte for byte) no content change --check n/a

To settle in the switch: four tests in two suites fail with the generator switched. Two expect it (curation_draft: the draft files byte for byte against the TypeScript ledger, and the historical fingerprint test): at the switch they compare the two files under a declared rule (the fingerprint field and block only), the oracles untouched. Two in curation_review: review_drawings_past_their_bound_are_refused_before_rendering needs the fingerprint after the drawings bound (order); the_drawings_projection_bounds_what_is_written builds a draft with every annotation removed, an invalid document that now has no fingerprint, so its fixture has to stay valid (reordering does not fix it). The O7 oracle and the switched-seed preconditions take a declared rule too.

Gates on 3b9a395: pnpm check:all green 14:41:00; security PASS, 2 MEDIUM, 9 LOW (.claude/audits/2026-10-24-rust-r5-6-prep-security.md); fresh verifier ECARTS(2) (.claude/audits/2026-10-24-rust-r5-6-prep-verify.md): the patch broke the report-compare build (fixed in the patch) and these docs claimed a green rehearsal (corrected above). Fixed after: the declared block is strict (unknown keys refused), and v1 refuses a value that is not 64 lowercase hex or that is itself a registered alias (AliasRefusal::NotCanonical, test). Open for the owner, MEDIUM M1: on the alias path the report keeps 27c7… while a new export's snapshot takes 12d7… from the loaded sheet; the frozen N-1 reader, a rollback build and any pre-switch build compare the two strictly and would drop that envelope's snapshot (sheet_mismatch; the report is kept, the archived labels lost), and the registry entry could then never be removed. Remedies: the export writes the snapshot reference with the report's own stamp on an alias match (recommended: every reader then sees one value, nothing rewritten), or the report is re-stamped at the rebase, or accepted with an N-1 test. Open, M2 remainder: a sheet-ref.json without a block still loads unchecked (pre-switch bundles and the test sheets carry none); refusing it at the switch means giving every test sheet a block. Also: the census asserts floors (over 50 attachments, over 30 alias stamps), not the exact 147/124/123; 11 of the RFC's 24 appendix numbers are not in the V8 oracle (they print right in a probe, unpinned); the report-compare alias line drops the draft/published status the plain line shows.

11.20 R5.6 rehearsed in isolation on the switched seed (2026-10-25)

Owner brief « Validation de la préparation R5.6 et corrections préalables à la bascule ». Contract .claude/tasks/contracts/2026-10-25-rust-r5-6-rehearsal.md. The final patch .claude/tasks/plans/r5-6-switch.patch (28 files) was applied, with the seed switched, in a detached worktree of 943a25a under the session scratchpad; the branch's own state stays inactive (seed 27c7…, nothing active).

M1, option 1. pdf/write/input.rs keep_the_report_stamp: after assert_exportable, an old report on the registered historical value of the same sheet, exported against the canonical value, archives a snapshot carrying the report's own stamp; a new report keeps the canonical value. The equivalence is one way (equivalence(sheet, stamped, current): an old stamp against the canonical value, never the reverse). The rebase and report-compare also need the loaded sheet's fingerprint_verified (set only when a v1 block was checked against the registry and its value recomputed from the document at load, loaded.rs check_reference; hashing is no longer feature-gated, the wasm module carries sha2). The export does NOT: input.rs sees only the snapshot, so it grants the pair on the snapshot's claimed value (gate finding below). archive/read.rs stays strictly equal: the M1 envelope holds one value, so no archive check is loosened.

v0 and v1. No block: a historical reference, loaded as before, unverified, no alias privilege, never v1 (even with the canonical value: an old stamp then rebases). A block: known keys only, v1, 64 lowercase hex, never an alias value, aliases only from the registry for that sheet and value, value recomputed from the document; any contradiction is invalid_sheet.

Original contexts kept, new behaviour tested apart. The pre-switch sheet-ref.json and migration map are frozen under crates/core/tests/fixtures/r5-6/pre-switch and proven the TypeScript's files against the R5.1 ledger. O7 (pdf_import), O10 (pdf_compare), the R2 Zod oracle (r2-oracles), the R5.1 ledger (r5.pipeline-oracles), the TypeScript golden (seed.golden) and the app goldens (v2 reports taken as migrated before the switch) run in that context, unchanged. Declared rule R5.6-fingerprint-v1: in the two files only the fingerprint moves from alias to canonical value and sheet-ref.json gains the block (curation_draft, byte-exact through the generator's formatter); report-compare prints the alias line, status kept, both raw values, only for a report read as is (77 O10 rows; a migrated v2 report carries the canonical value and keeps the plain line); a report on another document still prints !!.

Results on the switched state. pnpm rust:check green; pnpm check:all green 00:56:22; --check 0 differences on 18 files. Suites: r5_6_switch 8 (the owner's nine scenarios: old PDF import, no rebase, coherent re-export, current reader, pre-switch bundle, labels/views/annotations/branding kept, new report canonical, forged and case-changed stamps, mixed envelope still rejected, real content change rebases, load refusals), sheet_fingerprint 10 (census pinned: 147 attachments, 124 stamps, 123 alias), vitest r5-6.n-1 (the frozen N-1 scanner and Zod readers keep the re-exported snapshot and its content) and app r5-6.switch (2). The app goldens and R4 digests are reproduced byte for byte by re-exporting the historical reports on the switched sheet. Rollback: the pre-switch build's own report-compare (this branch, unpatched) reads the re-exported PDF with the snapshot kept, matching the bundled sheet. Generators: the Rust --out gives exactly the two switched files; the TypeScript generator (import:equine:legacy) still writes the pre-switch files (seed.golden).

Not done: the patch is not applied to the branch; pnpm format must never run over .claude/ (it rewrote the append-only audits in the worktree, reverted there).

Gates on the rehearsal (patch at 82e2e43): security PASS, 1 MEDIUM, 6 LOW (.claude/audits/2026-10-25-rust-r5-6-rehearsal-security.md); fresh verifier ECARTS(3) (.claude/audits/2026-10-25-rust-r5-6-rehearsal-verify.md), one root cause: the export path has no loaded sheet, so assert_exportable and keep_the_report_stamp grant the registered pair on the snapshot's claimed value. Probe: a v0 sheet (no block, unverified) with the canonical value, the old demo report and the core's own build_sheet_snapshot export with 27c7/27c7 where the pre-patch code answered sheet_mismatch. The application cannot reach it (every stored report is rebased first, and the rebase checks the flag), the core's export API can. The fix needs the snapshot builder, outside the approved files: decide the stamp in domain/archive/snapshot_rules.rs build_sheet_snapshot (it holds the loaded sheet and its flag; called by ops.rs archive.snapshot) and put assert_exportable back to strict equality, so the export never grants an alias. Not applied: awaiting the owner. LOW kept: "fingerprint": null and a misspelt block read as v0 (no privilege), public mutable reference/fingerprint_verified fields, a draft-allowed validation warning would make a v1 bundle unloadable, canonical_json recursion unbounded (trusted input today), stale comments on pnpm import:equine in scripts/import-equine.sh and CLAUDE.md.

11.21 R5.6 M1 corrected, full rehearsal repeated (2026-10-25)

Owner brief « R5.6 : autorisation de correction M1, nouvelle répétition obligatoire ». Supersedes the M1 mechanism of §11.20: input.rs keep_the_report_stamp is gone and pdf/write/input.rs is unchanged from 943a25a (strict equality). Final patch .claude/tasks/plans/r5-6-switch.patch (30 files, baff882), rehearsed in a fresh detached worktree of 8e77e37.

Cause of the defect. The export only sees the snapshot (ExportInput), never the loaded sheet, so it could not know whether the sheet's v1 value had been verified; it granted the registered pair on the value the snapshot claimed (verifier probe: a v0 sheet carrying the canonical value exported an old report).

Fix. The decision is taken where the loaded sheet is known: domain/archive/snapshot_rules.rs build_sheet_snapshot (behind archive.snapshot) keeps the report's historical stamp only when LoadedSheet::recognises_historical_stamp holds: the loader verified a v1 block (private verified_fingerprint, set only by from_bundle), that value still equals the reference, the registry binds the stamp to it for this sheet id (one direction), and the current document recomputes to it at the moment of the decision (so a mutated pub document or reference loses the privilege). The rebase and report-compare use the same predicate; the export refuses any report whose stamp differs from the snapshot's. "fingerprint": null and malformed blocks are refused (present_block); a v1 fingerprint refuses integrity errors and accepts draft warnings (is_publishable: the two warning rules are allowed in a draft and never block publication; a warnings-only v1 sheet loads); canonical_json is bounded at 128 levels (CanonicalError::TooDeep, serde_json's parse limit). Public API: the patch's own pub field fingerprint_verified becomes the method is_fingerprint_verified(); no released or wasm API changes.

Gates on the exact final state. pnpm rust:check green; pnpm check:all green 01:53:59; --check 0 differences; the Rust --out equals the switched seed for sheet-ref.json and report-migration-map.json and leaves document.json, horse.svg and equine_draft.sql byte-identical. r5_6_switch 14 (direct export API: unverified v0 refused, mutated document or reference refused, another sheet id refused, contradicting v1 content refused at load, null and malformed blocks refused, warnings-only v1 loads, the earlier scenarios), sheet_fingerprint 11 (depth 128/129), vitest r5-6.n-1 2 (snapshot from the core's archive.snapshot; the v0 counterpart refused), app goldens and R4 digests byte for byte. Security PASS, LOW only (.claude/audits/2026-10-25-rust-r5-6-final-security.md); fresh verifier CONFORME 8/8 with its own direct-API probe (.claude/audits/2026-10-25-rust-r5-6-final-verify.md). Wasm: 1,532,324 B raw / 518,018 B gzip before, 1,575,574 / 531,715 after (+43 KB raw, +13.7 KB gzip: sha2, the canonicaliser, the load check); no wasm size budget is defined in the repository.

Residual, not changed after the last gate: equivalence is public and grants from the registry alone (its only caller is the proof predicate; make it crate-private at activation); stale comments in fingerprint.rs (lines 6, 15, 246-247: "zero integrity issue", "will declare"); a page script can still hand the export a self-consistent report and snapshot (no equivalence results, every reader decides again); the rebase's exact-equality branch has no sheet-id check (since R2); r5_6_switch writes its re-export under <repo>/target/tmp regardless of CARGO_TARGET_DIR.

11.22 R5.6 active: the fingerprint convention sha256-rfc8785-validated-v1 (2026-10-25)

Owner brief « Autorisation officielle de la bascule R5.6 ». Switch commit 9e87016 on feature/rust-r5-pipeline-core (the verified final patch, plus the owner's adjustments: equivalence crate-private, its test moved inside fingerprint.rs; stale comments fixed; the trust boundary documented in fingerprint.rs; two lines of ANATOMICAL_SHEET_MODEL.md; the new-report rollback file written by r5_6_switch). Decision BDR-070.

Fingerprints. The equine draft sheet 503dc301-a8b1-50d4-9e44-0919b2fc2916: canonical v1 value 12d788727c1e532641bd5b3a7ecf39dbdd25e70350f8a76be5ca917b262874e2; historical value (SHA-256 of the Prettier document.json bytes, convention sha256-prettier-file-bytes-v0) 27c7383c445c73dc2001ebf4794a3ea63d416910bbbaa0d7848dd720de7c2660, the one entry of TRUSTED_ALIASES, honoured only through LoadedSheet::recognises_historical_stamp. Report v3 sheet.documentSha256 keeps 64 hex.

Seed. Regenerated once by the Rust tool into a fresh temporary folder, compared file by file, the two authorised files copied: draft/sheet-ref.json 2c0716f1…b285 → 03e7f6ab7ffba62007afa2bd39506c72b7034b07b54367d35adf7f7cc670623b (value + fingerprint block) and draft/report-migration-map.json 4139c51d…fce9 → 0e991bc2b1e54668797706aa8b21670ff420926fad133b2077bfbae61ba6e2db. document.json (27c7…), assets/horse.svg (0ea5202f…), equine_draft.sql (c5a24312…) and every other file byte-identical; the fresh output's review/app-main.svg differs from the committed one only under the R3 trigger-name rule declared since R5.4 (not copied). pnpm r5:import-equine --check: 0 differences. pnpm import:equine is the Rust pipeline; pnpm import:equine:legacy the TypeScript one until R5.7. The SQL seed's own header still names packages/anatomy (frozen bytes, kept).

Trust boundary. Equal fingerprints keep their historical meaning (the same reference string), which is no proof of content: an API taking caller-built data (an export input, a hand-made bundle, a mutated pub reference) is trusted for what it declares, as before R5.6. An alias, never: it needs the loader-verified v1 value and the document recomputed at the decision.

N-1 and rollback (measured). An old report (27c7) on the active sheet: opens with no rebase, re-exports with one stamp, read with the snapshot kept by the current reader, the frozen N-1 readers and the pre-switch build (59521dc: report-compare "matches the bundled sheet", import rebased=false). A NEW report (12d7) read by the pre-switch build: the archive is kept, report-compare says "written on another sheet document", and the import rebases (0 unresolved zones and findings, the stamp set back to 27c7): nothing is lost, but the application shows its rebase notice for what is the same content. The rollback is not transparent for reports written after the switch: accepted while R5 stays on the branch; to be settled before any release to users (keep the switch with the release, or ship the registry to the build that could be rolled back to).

Gates on 9e87016. pnpm rust:check green, pnpm check:all green 02:10:52, --check 0 differences; r5_6_switch 14, sheet_fingerprint 11 + the lib unit test, pdf_import 4, pdf_compare 16, curation_draft 20, curation_review 12, archive_rules 38; vitest N-1 2, app switch 2, goldens 13 + envelopes 3, R2 oracles 7, anatomy 15. Security PASS, LOW only (.claude/audits/2026-10-25-rust-r5-6-active-security.md); fresh verifier: 8 contract clauses and 5 activation criteria met, ECARTS(1) = S7 (isolation) written before the activation was authorised, settled by the contract Clarification of 2026-10-25 (.claude/audits/2026-10-25-rust-r5-6-active-verify.md). Wasm 531,715 B gzip (518,018 before the switch, +13.7 KB), under the earlier 600 KB reference mark; no budget added.