Files
faunosteo/docs/development/RUST.md
T
bchanot bbab0e61cb feat(domain): sheet.empty free op for a new sheet's document (V1-2.5 C)
Wraps create_empty_sheet_document; refusals invalid_shape / invalid_json; ts-rs SheetEmptyInput, core-wasm proof, app wrapper emptySheetDocument.
2026-11-02 16:19:49 +01:00

4609 lines
362 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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.
```bash
# 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):
```bash
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, `.dockerignore`d) 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
```text
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` (= `pnpm db:sandbox avatar-e2e`), on the throwaway stack only
since V1-2.3 (`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:
```bash
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
```bash
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). Closed at V1-2.2 (§12.7): a reference must name an id its
drawing defines, and the canvas scopes ids per view.
- 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).
### 11.8 Recommended slicing (nothing started)
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:equine` holds 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.
### 11.23 R5.7: consumer census, `packages/anatomy` and `packages/domain` deleted (2026-10-25)
Owner brief « Validation R5.6 et autorisation R5.7 ». Plan `.claude/tasks/plans/2026-10-25-rust-r5-7-cleanup.md`,
contract `.claude/tasks/contracts/2026-10-25-rust-r5-7-cleanup.md`. Base 756b7ef (R5.6 active).
**Census (before any deletion).** Outside the two packages: `packages/anatomy` was reached by the root script
`import:equine:legacy`, the Dockerfile (`COPY packages/anatomy/package.json`), the workspace (`pnpm -r test:run` ran its 144
cases inside `pnpm check`), `r4.census.test.ts` (xmldom pinned under it), the SQL seed header (text) and docs and Rust module
comments (text). `packages/domain` was reached by `packages/anatomy` (5 runtime symbols), the Dockerfile, the Rust suites
`report_rules` and `archive_rules` (they read `packages/domain/tests/fixtures/report-v2.{full,minimal}.json` from disk), the
app ESLint ban (a closed door), docs and three SQL migration comments (applied migrations, never edited). No application,
glue or Supabase-package source imported either (grep + `r4.census`). `packages/domain/src` is byte-identical to the frozen
N-1 copy `packages/core-wasm/tests/n-1/domain` (`diff -r`), which stays. `packages/supabase/scripts/upload-sheet-assets.ts`
(`assets:upload:legacy`) was the TS upload tool replaced at R5.5.
**Matrices.** `crates/core/tests/curation/FILES.tsv`: the 112 tracked files that left (110 deleted, the 2 fixtures moved),
each with its Rust counterpart (55 ported, 48 replaced, 9 package tooling or test helpers deleted). `crates/core/tests/curation/LEDGER.tsv`:
one row per TS case at 756b7ef (anatomy 144 in 22 files, domain 263 in 13), with its contract, status, target, oracle and
note: 256 ported, 149 replaced (frozen oracle, byte-exact committed seed, golden), 2 deleted (`never mutates its inputs`: the
Rust applier takes `&Value`, no aliasing hazard; `r2-horse-slice`: it wrote the JSON fixture from the `.ts` one, the JSON is
the source now), 0 uncovered. The 64 domain rows of `archive.branding-labels` re-registered by two other files are listed
as such. Mapping by two read-only analyses, every target checked against `cargo test -- --list` (154 cargo targets, 0
missing) and by `apps/app/tests/unit/r5.census.test.ts` on every run.
**Contracts ported first** (the mapping found 15 anatomy cases whose contract only the TypeScript checked, and one partial
domain oracle): `curation_leaves.rs` (new, 8 tests: the 612 leaves 442/141/29, leaves land on leaves, FR and EN snapshots and
the vet flag per finding, the 29 removed with their legacy path, the 141 moves split 134/7 inside their zone, v3 re-read
stable, the 26 observable legacy ids on the right view with their names, C7 kept on a defined region); `curation_draft` (+7:
a cite of a reference the same change added, the view box read and `1 2 3` refused, the map following a move through a
just-renamed path, `CHG-000` reserved, the dollar-quote tag refused, the 16 rows of the R5.1 ledger equal to the committed
files with the pre-switch substitution, the two generated folders holding exactly the ledger's files plus the byte copies);
`curation_format` (+1: `inferRegionCode`, the 12 rows of `js-semantics.json` no Rust test read, and the TS cases);
`curation_review` (+1: an annotation dropped by a change drawn `removed`); `anatomy_compose` (+1: the halo filter never
duplicated on a root that holds it); `report_contract` (+1: `migration-map.draft.json` read entry by entry as Zod read it,
27 annotations, 792 paths, 34 nulls, the committed map differing only by its fingerprint). Partial points kept as notes in
the ledger (no business contract lost): the empty document's `view_box: null` literal, two relabel assertions, the
`snapshotIndexSource` and `buildSheetIndex` TS-only adapters, JS identity probes.
**Fixtures.** `report-v2.full.json` (`e96b0882…729c`) and `report-v2.minimal.json` (`ba79698c…fde7`) moved by `git mv` to
`crates/core/tests/fixtures/`, sha256 equal before and after (also asserted by `r5.census`); identical to the app's copies
under `apps/app/tests/fixtures/`, which stay. Kept untouched: the R2 oracles (`oracles/*.json`, `characterisation.json`,
`verdicts.json`), R3 (`oracles/r3`), R4 (`oracles/r4`, `pdf/LEDGER.tsv`, the app goldens and `goldens/r4` digests), R5
(`oracles/r5`, 13 files), the pre-switch seed copies (`fixtures/r5-6/pre-switch`), `fixtures/horse-slice.json`, the
conformance fixtures, every reference PDF, the migration data, the N-1 readers. The generators that wrote them left with the
packages; an oracle is never regenerated.
**Deleted.** `packages/anatomy`, `packages/domain`, `packages/supabase/scripts/upload-sheet-assets.ts`, the scripts
`import:equine:legacy` and `assets:upload:legacy`, the two Dockerfile `COPY` lines. Lockfile through `pnpm install --offline`
then `--fix-lockfile`: 69 lines removed, `@xmldom/xmldom` 0.9.12 gone, the two importers gone; `tsx` 4.23.15 is declared by
no package and stays resolved only as vite's optional peer, marked `optional: true` (`pnpm dedupe --check` clean: removing
it would take a hand edit); no other version moved; `--frozen-lockfile` installs. Root Prettier stays (`pnpm format`,
`db:types`, `db:types:check`). Left on disk, git-ignored: `packages/{anatomy,domain}/node_modules` (pnpm symlinks; the
recursive delete was refused to Claude by the permission layer, owner action as for `packages/pdf`).
**Census tests.** `r4.census.test.ts`: xmldom, the TS domain and the pipeline package banned from the app and glue sources
and manifests; the lockfile holds no `@xmldom/xmldom` and no `packages/{anatomy,domain}` importer, with a non-vacuity check
(the importer split finds `.`, `apps/app`, `packages/core-wasm`). `r5.census.test.ts` (10 cases): the packages and the TS
upload script absent; no manifest declares them, xmldom or tsx, no `:legacy` script, `import:equine` and `assets:upload` run
the Rust binaries; the lockfile importers equal the manifests on disk (non-vacuity) and resolve none of them; no app, Vite,
glue or Supabase-package source imports them (non-vacuity: `@faunosteo/core-wasm` is found); the Dockerfile copies only
existing manifests; the ESLint ban names `@faunosteo/domain`, `@faunosteo/anatomy`, `@xmldom/xmldom`; every `FILES.tsv` row
absent with its counterpart present; every `LEDGER.tsv` row absent, 407 = 144 + 263, valid status, each cargo target a
`#[test]` function of its test file and never an `#[ignore]` one, each oracle file present; the moved fixtures' sha256; the oracles, pre-switch copies and N-1 readers present.
**Test counts.** Before (756b7ef, vitest JSON): TypeScript 943 (app 436, core-wasm 60, supabase 40, anatomy 144, domain 263);
Rust core 364 (features `cli,upload`) + worker 33. After: TypeScript 546 (app 446 = 436 + the 10 R5 census cases, core-wasm 60,
supabase 40); Rust core 383 (+19 ports) + worker 33. The 407 deleted cases are covered as the ledger says.
**Historical reproducibility (rehearsed 2026-10-25, detached worktree under the session scratchpad).**
| | |
|---|---|
| Last commit where the TypeScript pipeline was the official seed writer | `59521dc1953e6005045ca5b39434de6377033237` (`pnpm import:equine` = TS) |
| Last commit holding the TypeScript pipeline | `756b7ef34d9cac9cfcb8288fecbf07599837a5ba` (`pnpm import:equine:legacy`) |
| Tooling | Node 24 (rehearsed on v24.21.0), pnpm 10.13.1 (corepack), lockfile sha256 `a8611f22…1334` (same at both commits) |
| Dependencies resolved | zod 3.25.76, @xmldom/xmldom 0.9.12, prettier 3.8.3, tsx 4.23.15, typescript 5.9.3, vitest 3.2.7, eslint 9.39.4, @types/node 20.19.41 |
```bash
git worktree add --detach <empty scratch dir> 59521dc
cd <that dir> && corepack pnpm install --frozen-lockfile --offline # or without --offline
corepack pnpm import:equine # TS writer: rewrites the two seed folders of this worktree only
git status --porcelain # empty: the TS reproduces the committed seed byte for byte
corepack pnpm --filter @faunosteo/anatomy --filter @faunosteo/domain test:run # 144 + 262 green
# at 756b7ef: corepack pnpm import:equine:legacy → exactly draft/sheet-ref.json and draft/report-migration-map.json
# differ (pre-switch values, equal to crates/core/tests/fixtures/r5-6/pre-switch); run the suites on a clean tree
# (they read the committed seed): 144 + 263 green
```
Rehearsal results: at 59521dc `git status` empty after the run, 144 + 262 green; at 756b7ef the two files only, at
`2c0716f1…b285` and `4139c51d…fce9`, and 144 + 263 green on the clean tree (one run of the suites over the tree the generator
had just rewritten failed `r2-oracles` "committed migration map after R5.6", as it should).
Expected sha256 of the TypeScript output (the committed seed except the two R5.6 files; the 16 text rows are also
`oracles/r5/pipeline.json` `artifacts`, asserted by `curation_draft`):
| File (under `supabase/seed/anatomical-sheets/equine/`) | sha256 |
|---|---|
| `draft/assets/horse.svg` | `0ea5202fa3b95bac167b87c12ee969ab0272e085b60c2d34dbca6202c5f08541` |
| `draft/assets.json` | `c490dc758b330f372548a595826e2d4de73dcb935af1e39cb4883d5b31927cf5` |
| `draft/CHANGELOG.md` | `48c010c8c8010f81d201005b485ecfe01e0b8c8ea76b944d220bcf2174d8b6c7` |
| `draft/document.json` | `27c7383c445c73dc2001ebf4794a3ea63d416910bbbaa0d7848dd720de7c2660` |
| `draft/equine_draft.sql` | `c5a24312c6a77cdd7e545dc34ebee377abd1ef9f9868fbffedbd6c21f53bed1e` |
| `draft/report-migration-map.json` | `4139c51d3acd69ba9ca0ee6bb7bd7ebe7be4eb818e330ff278b37e1d04b7fce9` |
| `draft/review/annotations-head.svg` | `2d6858a1891cdae36ffd364b30bc7586bcfcc1ea76a79ac0cda99497a21672e6` |
| `draft/review/annotations-main.svg` | `1fd2e385468b1013ccd34f03ddf2ad80a7755f8d6b9071514e48aafa0e7bd4e4` |
| `draft/review/app-head.svg` | `8d33077cdc87d2b979a58d75e271102fb9b18fcc2fa93ebd97758672f5eb3e80` |
| `draft/review/app-main.svg` | `985a043aa1871b58ceec1f96e4fc4c6edd02e05bdb82694787a5c4ea5d6f81d5` |
| `draft/REVIEW-REPORT.md` | `fbdaa58db0dbc092b7a0cd039804e1879f1351669abf7c6d0a0cf1189f0c8bfb` |
| `draft/sheet-ref.json` | `2c0716f1536e4182cde9ffb0f183c7255d1ad6a1fc754d72011ff8090304b285` |
| `legacy-import/assets/Horse_head.svg` | `9c03b98c0e55e3f684ce314b88dab2a0e11f488af6cc9140d61e1b2d5f9cb94c` |
| `legacy-import/assets/Horse.svg` | `5fe3819c8bf07f18fcc51f40f3d06b1bc82e6202a62afa003e8639867b5b212d` |
| `legacy-import/assets.json` | `109b0e7b8a03d398ea89ef278021f73d4f387992bbfdb2196c9cb7bec4232f2f` |
| `legacy-import/document.json` | `91e459f4c0ac8043831242c9fccde01f75f1023464db909f1c29571aa8a414c2` |
| `legacy-import/IMPORT-REPORT.md` | `7233bca100c8c1acc6e16310acd9e3e241e6760ab73855dcbf3a2bb92282d240` |
| `legacy-import/legacy-id-map.json` | `4ec2b4e3a0ee7d901145ce45f9cc240d28e30997155a51c6d53ea1c1a36667b7` |
The old engine is not reintroduced in the tree; no third engine is kept.
**Seed SQL header.** `equine_draft.sql` line 2 still reads "Generated by `pnpm import:equine` (packages/anatomy)". Changing it
would change the frozen seed bytes (`c5a24312…ed1e`, ledger row): kept, explained in `curation/draft/seed.rs` beside the
emitted text and here. The generator is the Rust module since R5.6.
**Rust pipeline parity.** `pnpm import:equine --check`: legacy-import 6 files, draft 12 files, 0 differences (app-main under
the declared R3 trigger-name rule).
**Checks on the final state.** `pnpm install --frozen-lockfile` ok; `pnpm rust:check` green; `pnpm check:all` green 03:58:13
(advisories ok, wasm, `pnpm check`, app image, worker sandbox tests and runtime image); RFC 8785 and alias (`sheet_fingerprint`
11, `r5_6_switch` 14), archives (`archive_rules` 38, `report_rules` 17 on the moved fixtures), PDF (`pdf_*`, `pdf_compare` 16),
the N-1 suites (`n-1.reader`, `r5-6.n-1`, `n-1.scanner`), seed and sheet integrity (`curation_*`, `sheet_rules`,
`sheet_conformance`), the census suites.
**Owner validation and pre-merge checks (2026-10-25, brief « Validation R5.7 et dernière vérification pré-fusion »).**
R5.7 is validated. Decision C6: `tsx` may stay named in the lockfile as long as it is only the optional peer of vite
(`pnpm why tsx -r`: `tsx` 4.23.15 reached only as `vite` 7.3.6's peer, `peerDependenciesMeta.tsx.optional: true`, through the
devDependencies of the app, `core-wasm` and `supabase`; no importer lists it, no root `node_modules/.bin/tsx`; pnpm links the peer's bin under the three packages' own
`node_modules/.bin`, which no script calls); no lockfile hand edit,
no override; the contract records the clarification and the census still fails on a declared `tsx`, a manifest script naming it or an
importer listing it. The 149 `replaced` rows were checked active: every cargo target runs in `cargo test` (none `#[ignore]`d,
now asserted by the census), the two vitest targets name existing cases, and every cited oracle is read by a test (the 26
conformance cases through `read_dir`, the R3 canvas goldens through their view name). The checks were rerun on the state meant
for the merge after the two changes that followed the first `check:all` (the C8 digest typo, the census `#[test]` rule); their
results, the fresh verifier and the security audit are recorded in `.claude/audits/2026-10-25-rust-r5-7-premerge.md`.
**Follow-ups kept (brief §10, unchanged by R5.7).** The rollback limit of reports written after R5.6 (a build that can roll
back must recognise both conventions before any public exposure; tested by `r5_6_switch`); DEV Supabase hardening
(ENVIRONMENTS.md §3.6); the migration-map cascade debt (§11.12); the direct export API trust boundary (§11.22); the SQL
checks before public exposure (`confirm_sheet_asset_upload`); the accepted LOW items of §11.16 to §11.22. Once the generators
are gone, a change of `curation/changes.json` cannot re-freeze `pipeline.json` or the synthetic oracles: the Rust tests that
pin the real draft (46 changes, 825 records, the 612 fates, the fingerprints) then need an owner decision on a new baseline.
## 12. V1-2.2: the sheet authoring core (2026-10-29)
Owner brief « Autorisation de démarrer V1-2.2 » (V1-2.1 VERIFIED at ac71c5b), contract
`docs/development/V1-2_ANATOMICAL_SHEETS.md` §16.3. No SQL, no screen, no DEV operation. Owner answers taken before the
code (2026-10-29): the editors' exports come from the owner (cairo and ImageMagick exports committed meanwhile); a
document that does not read strictly fails as `verification.integrity.document` (§6.5); a draft preview reports caps and
missing drawings, a published or deprecated one refuses them.
### 12.1 What runs in Rust, and who calls it
| Module (`crates/core/src`) | What | Consumer |
|---|---|---|
| `domain/sheet/size.rs` | the server's document measure, `octet_length(content::text)`: `jsonb` text form (`": "`, `", "`, PostgreSQL's string escapes, numbers as `numeric` prints them, never an exponent), lengths summed in one walk | the verdict, `preview.state` (the validation panel's « taille ») |
| `domain/sheet/keys.rs` | `ElementKey` (sheet, reference, region, annotation category, view, annotation, zone, finding path), the marked elements in document order | edit commands, change list, groups |
| `domain/sheet/caps.rs` | `CapsReport`: every `SnapshotCaps` limit plus the 2 MiB document cap, the exceeded names | verdict, preview |
| `domain/sheet/review.rs` | completeness (markings, vet referrals, uncited categories and nodes), review groups (`general`, `view:<id>`, `zone:<id>`, removal groups) with digests and `coverable`, the change list against a base | verdict, preview |
| `domain/sheet/report.rs` | `SheetReport`: measure, issues (the 21 rules plus `annotation.geometry.missing`), caps, completeness, groups | verdict, preview |
| `domain/sheet/verdict.rs` | `compute_verdict`: pure, bound to sheet, version, revision and review; closed codes; the shape the M5 SQL reads | the worker's keyless child (V1-2.3); not exported to the browser (O15) |
| `domain/sheet/preview.rs` | `PreviewSheet`: drawings hashed against their rows and read once per sha256, draft / published / deprecated, `replace_document`, `add_drawing`, `state` | wasm `PreviewBuilder` → `PreviewSheet` (V1-2.5 catalogue, V1-2.6 editor) |
| `domain/sheet/edit.rs` | `apply_edit` (insert, update, remove, move, set_status, mark_reviewed) with the §6.6 marking rules; `dependents` | free ops `sheet.edit`, `sheet.dependents` |
| `anatomy/svg/clean.rs`, `sanitize.rs` | `clean_svg(bytes)`: clean / cleanable / rejected; the sanitiser's walk also names the removals that carried active or external content (`active`) | wasm `clean_svg` (V1-2.6 upload) |
**Digests.** SHA-256 of the RFC 8785 text of `{"group": <key>, …content}` read from the typed document (an omitted
marking is written `inherited`): `general` is the document without `views`, `annotations`, `finding_zones`; `view:<id>` is
`{views: [the views of that id], annotations: [those drawn in it, document order]}`; `zone:<id>` is
`{finding_zones: [the zones of that id]}`; a removal group is `{removed: true}`. A group is coverable when it holds no
`to_confirm` and no `inherited` element; a removal group always is. A core change of these rules is a « core change » of
§6.4 (rounds withdrawn).
**Verdict codes,** first one recorded as the round's `failure_code`: `verification.integrity.document`, `.base`,
`verification.validation.rules`, `.no_geometry`, `.caps`, `verification.integrity.drawing_missing`, `.size_mismatch`,
`.object_conflict` (bytes not hashing to the row, which is the object key), `.svg_rejected`, `.svg_removal`,
`.svg_not_canonical` (§12.7), `.fingerprint`. Drawing results: `ok`, `missing`, `size_mismatch`, `hash_mismatch`,
`svg_rejected`, `svg_removal`, `svg_not_canonical`.
### 12.2 Facade
Free (`call`): `sheet.edit` `{document, command}` → `{document}`, failures `unknown_key`, `duplicate_key`,
`invalid_target`, `id_changed`, `invalid_position`, `too_deep`, `has_dependents` (§12.7), `too_large` (input over 8 MiB + 2 MiB or the OD-3 value
budget); `sheet.dependents` `{document, key}` → `{dependents: [{element, relation}]}`; `sheet.empty` (V1-2.5)
`{species_id, name: {fr, en}}` → the empty document (`create_empty_sheet_document`, no slug), failure `invalid_shape`. Wasm classes: `PreviewBuilder`
(`add_drawing(assetId, sha256, bytes)`, `build(PreviewInput JSON)` throwing `<kind>: <detail>`: `invalid_document`,
`drawing_missing`, `drawing_hash_mismatch`, `fingerprint_mismatch`, `caps`), `PreviewSheet` (`call`: `preview.state`,
`view.canvas`; `replace_document`, `add_drawing`: `{"ok":true,"value":null}` or `invalid_document`,
`drawing_hash_mismatch`, `caps`, `read_only`); a preview holds at most 16 drawings of at most 2 MiB each
(`MAX_HELD_DRAWINGS`; the builder's `add_drawing` answers `false` past them and its build throws `caps: drawings`); the function `clean_svg(bytes)` (`SvgCleaning`). `view.canvas` is one composition for `LoadedSheet` and
`PreviewSheet` (`ops::canvas_of`). The runtime (`CoreRuntime`) does not manage preview handles yet: their poison and
recovery come with their first page (V1-2.5). ts-rs: 31 new type files, `types/index.ts` 126 entries. The app's
trapping test stub (`apps/app/tests/helpers/core.ts`) lists the two new glue members, as it lists every member of
`GlueModule`.
### 12.3 Behaviour (declared)
1. The sanitiser keeps, removes and refuses exactly as before (R3 oracles O4/O5 green; the declared changes of §12.7 apart); its walk also lists, in
`active`, each removal that carried a script, an embedded document or image (`image`, `feImage`, `foreignObject`,
`iframe`, `object`, `embed`, media, and the HTML fetchers `img`, `input`, `source`, `frame`, `form`, `meta`, `link`,
`base`…), any element of the XHTML namespace, animation, a link (`a`), an event handler (`on*`), a fetching attribute
(`src`, `srcset`, `action`, `data`, `poster`, `http-equiv`…), a reference outside the document (`href`, `url(…)`),
`@import`, `javascript:`, `expression(`, `image-set(`, `behavior:`, or a backslash. A `<style>` element is active
when its text holds such a value, cleanable otherwise. A processing instruction other than the XML declaration
(`<?xml-stylesheet …?>`), which the tree never reads but the stored bytes would keep, refuses the file in the
cleaning (`svg_active_content`, named `?<target>`) and in the verdict (`svg_rejected`, `processing_instruction`);
the hostile file `comments-pi-cdata.svg` moved from clean to refused.
2. The cleaning reads a picked file with one difference from the stored-drawing reader: an oversized `title` or `desc`
(over 4 KiB) is a removal (the cleaned text drops it) where the stored reader refuses the file (`too_complex`); its
subtree is still classified, so active content inside it refuses the file.
3. `clean_svg` answers `cleaning_unstable` if the stored text (§12.7) did not read back with no removal and give
itself again (what the admin confirms is what every reader draws); the property test proves
it never happens on the corpus and 3 000 generated drawings, and the check stays so no upload rests on the test.
4. The document measure is exact for texts written as JavaScript writes numbers (every core output); a page that sends
another spelling (`1.50`, `1E2`) is stored as written and may measure a few bytes differently.
5. `EditCommand` and `NewElement` keep serde's tagged wire forms but are read through `serde_json::Value`, and
`read_document` reads from `&Value`: serde's tagged readers and the owned-`Value` reader each compiled a second copy of
the schema's reader into the module (measured: 635.7 KB gzip before, 582.7 KB after).
### 12.4 Proofs and tests
- `sheet_size` (6): 17 PostgreSQL vectors (`oracles/v1-2-2/size.json`, measured by PGlite 17.5 from
`oracles/v1-2-2/size.mjs`), the equine seed at 184 105 bytes (the real image's value, contract §12.3), the pgTAP 017
vectors (cap − 1, cap, cap + 1 in 1-, 3- and 4-byte characters, dense, `1e21`), 600 000 numbers in linear time.
- `sheet_review` (9): the equine counts of the contract (188 / 31 / 620 over 839 elements, 30 groups), digests stable
and local to their group, an omitted marking digesting as `inherited`, coverage, a derived version deleting a zone
with its removal group and change list, removal digests bound to their key, an inherited element alone keeping its
group uncoverable, added / changed / status-changed / removed-plus-added, a reorder changing the digest only.
- `sheet_verdict` (15, the stored form included, §12.7): a clean sheet and the equine draft pass (fingerprint `12d78872…`, 30 groups, 184 105 bytes); the
shape the SQL reads; each rule and drawing fault alone; caps at cap − 1 / cap / cap + 1 (annotations, labels in
astral characters, depth, nodes, document bytes; views, drawings, drawing bytes and total bytes through
`caps_report`); code order; determinism; base and removal groups; a
document at every cap (64 views, 1 024 annotations, 8 192 nodes, depth 8) verified.
- `sheet_preview` (11, the stored form included): the equine draft previews with the bundle's index tables and canvases and its fingerprint; hash
mismatch refused in every mode; fingerprint, missing drawing and caps refused for published and deprecated, reported
for drafts; an invalid draft draws with its issues; five replacements, one drawing read; read-only published; no
report operation on a preview; at most 16 drawings of at most 2 MiB.
- `sheet_edit` (12, removals refused while named, §12.7): each marking rule of §6.6, the refusals, `dependents`, the facade, and 400 random commands on the
small sheet and on the equine draft, view crops and drawings, references, zones included (strict re-read;
on the marked elements, annotations, categories and nodes: every key kept by every command but `remove`, which
takes only its key and descendants, the rule of insert, update, move, set_status and `mark_reviewed`; nothing
turned `inherited`). The keys of views, references, regions and annotation categories and the redraw rule are held
by the case tests, not by the property test.
- `svg_clean` (14 since §12.7, 17 since §12.8): the 42 hostile files, each on the §9.2 line it belongs to; the security audit's 13 probes
(stylesheet PIs, active content under a long title, HTML fetchers, XHTML elements) refused; a stored PI refused by the
verdict; active names; a plain `<style>` cleaned and
named, four hostile ones refused; the product drawing clean with its sha256; the committed exports (four, three
Inkscape ones since §12.7); the owner's folder (the two Figma exports since §12.8, fixed expectations in their own test); the fixpoint on the corpus and on 3 000 generated
drawings (138 clean, 2 434 cleanable, 428 refused: 256 dangling references, 172 reference cycles; before §12.7:
123 / 2 697 / 180 cycles).
- Mutation run (10 mutants, each against its suite; `.claude/audits/2026-10-29-v1-2-2-mutations.py`): caps off by one, digest without its key, no active class, hash
unchecked, an update keeping `reviewed`, fingerprint unchecked, `inherited` counted as read, redrawn views ignored,
numeric scale ignored, removal groups never made: 10 killed (the `inherited` one survived the first run; the test
that kills it was added).
- `packages/core-wasm/tests/preview.test.ts` (5) on the shipped module: the equine preview equals the `SheetHandle`'s index
and canvases, the closed refusals, a replacement redrawn, `sheet.edit` and `sheet.dependents`, `clean_svg` on 45 hostile
inputs and floods with no trap (slowest 0.4 ms).
### 12.5 Measurements
| Measure | Value |
|---|---|
| shipped module | 1 513 522 B raw, 559 360 B gzip -9 (script), 569 181 B by Node's gzip in `size.test.ts` (final, finalisation §12.8; 568 696 B at f1ef6a4, the debug `name` section dropped since §12.7); budget 600 000 (D-R13); 596 671 B at ca31b78, 531 715 B before V1-2.2 (RUST.md §11.22) |
| verdict at every cap, native | 107 ms release, 493 ms debug (document 1 165 850 bytes) |
| `clean_svg`, shipped module | 45 hostile inputs and floods, slowest 0.4 ms |
Security audit (fresh, on 741c25c): PASS, two MEDIUM and two LOW fixed in the same step. Fresh verifier (same
commit): ECARTS(6), all closed in the same step (the long-title MEDIUM, the property test's insert and
`mark_reviewed` checks, the cap − 1 fixtures of views, drawings and bytes, a floor false positive, record wordings) (processing instructions
kept in uploaded bytes; active content classed cleanable under a long title or as HTML fetchers; review groups built
in quadratic time, now one indexed pass; the runtime fixpoint check now compares the serialisation too).
Second round (fresh, on 8294d54): verifier ECARTS(3) (A6 waits on the owner's exports; A12 outside its permitted
commands, covered by `check:all`; the app test stub, now recorded in §12.2) and security PASS with findings fixed in
the same step: one indexed walk per view chain in `sheet.edit` (2 000 chained views were cubic, 5 s per edit; now a
test bound of 1 s debug), a set for the referenced drawings, a replaced asset releases its parse, `xml:base` and the
CSS loaders `src(`, `image(`, `cross-fade(` refused as active, the PI scan fail-closed (`?unreadable`), a drawing
with a PI shown `rejected` by the preview as the verdict refuses it.
### 12.6 Residual risks and points for V1-2.3
- The module's margin under its budget is about 30.8 KB by the test's measure since §12.8 (31.3 KB at §12.7) (3.3 KB before): the V1-2.5 and V1-2.6 pages must not grow the
core's browser surface without measuring.
- cairo colours: closed at the checkpoint (§12.7), strict numeric `rgb()` / `rgba()` kept.
- Editor exports: Inkscape 1.4.3 covered at the checkpoint (§12.7), Figma at the finalisation (§12.8); A6's final
perimeter (owner, 2026-10-30, §12.10) is Figma, Inkscape, cairo and ImageMagick; Adobe Illustrator and Affinity are
optional and untested, never claimed without a real export. Figma's text
handling is untested: neither owner file carries the source's live text.
- A verdict whose document does not read strictly carries no group and no drawing: M6's structure check
(`complete_sheet_verification`) must accept a failed verdict without them, or the round would wait for its attempt limit.
- `PreviewSheet` handles are not yet under `CoreRuntime`'s poison and recovery (§8.3): the first page that holds one adds
it.
- Dangling `#id` references and original bytes uploaded as they are: both closed at the checkpoint (§12.7).
- `validate_sheet_document`'s `view.parent.cycle` rule (R2 code) walks each view's parent chain: quadratic on a long
chain (8 000 chained views, 2.4 s per `preview.state` in the module; the server cap of 2 MiB allows that order).
Left as it was in this step; memoising the chain is the fix, with the conformance fixtures as its oracle.
- The glue copies a drawing's bytes into linear memory before the 2 MiB check (transient, bounded by the bucket).
### 12.7 Owner arbitrations at the checkpoint (2026-10-29)
Brief « V1-2.2 : arbitrages du propriétaire et finalisation » on `17d9199`; the owner chose, for each open point, the
option recorded in contract §17.4. All of it is in the core and the facade; no SQL, no screen, no DEV operation.
| Point | Built | Where |
|---|---|---|
| Dangling references | `SvgRejection::DanglingReference` (`dangling_reference`): `refs::check_targets` after the reference graph, in `read_svg` (stored drawings, verdict, preview, PDF snapshot gate) and in `clean_svg` after active content is classified | `anatomy/svg/{refs,mod,clean,tree}.rs` |
| Views isolated | `compose_canvas` scopes the drawing's ids and local references (`fv.<view>.`, `compose::id_scope`, `sanitize::scope_url_targets` rewrites exactly the targets `url_targets` reads); `compose_highlight` (PDF) unchanged | `anatomy/compose.rs` |
| Stored form | `serialize::stored_form` = `<?xml version="1.0" encoding="UTF-8"?>` + LF + `serialize`; `SvgCleaning.cleaned` renamed `stored`, filled for clean and cleanable; verdict `DrawingResult::SvgNotCanonical` → `verification.integrity.svg_not_canonical`; preview `rejected` `not_canonical`; upload tool `verify_asset` refuses another form | `anatomy/svg/{serialize,clean}.rs`, `domain/sheet/{verdict,preview}.rs`, `curation/upload.rs` |
| Colours | `sanitize::without_colour_functions`: lowercase `rgb(` 3 / `rgba(` 4 components, all bare ≤ 255 or all `%` ≤ 100, alpha ≤ 1 or ≤ 100 %, nothing glued before; applied inside `calls_only_local_url` only, so active values are classified as before | `anatomy/svg/sanitize.rs` |
| Removals | `EditError::HasDependents` (`has_dependents`) when `dependents(key)` holds anything but descendants | `domain/sheet/edit.rs` |
| Module size | `scripts/wasm-build.sh` passes `--remove-name-section` to wasm-bindgen | `scripts/wasm-build.sh` |
Declared oracle changes (frozen files untouched, the change applied in the test): `oracles/r3/sanitiser.json`
`dangling-references.svg` → `dangling_reference`, `css.svg` keeps `fill:rgb(1,2,3)` (5 removals instead of 6); the R3
canvas goldens (`canvas.{main,head}.json`) get their ids scoped (`with_ids_scoped_per_view` in Rust,
`withIdsScopedPerView` in the app's `canvas.trees.test.tsx`). The equine drawing is already in the stored form: its
sha256 `0ea5202f…`, the fingerprint and every R4 digest are unchanged.
Tests: `svg_scope` (7: valid reference, absent reference refused by reader, cleaning, preview and verdict, two views with
the same ids resolving each in its own view when both canvases are inlined, a cross-view attempt, three references to
one id, deterministic and repeated composition, a browser model over composed canvases); `svg_clean` (14: cairo export clean with its five colours, shapes and
references; seven dangerous constructs next to a colour refused as active, five other functions removed; the three
Inkscape exports; clean files uploaded in the stored form; generated drawings now also refused for dangling references);
`sheet_verdict` and `sheet_preview` (a drawing outside the stored form fails / shows rejected); `sheet_edit` (removal
refused while named, through the facade too; the property test checks that a removal never adds a referential issue and
that `has_dependents` is answered only when something names the element); `sheet_review` (zones removed after their
annotations are unlinked); `curation_upload`; `packages/core-wasm/tests/preview.test.ts` on the shipped module.
Inkscape: not installed and inkscape.org unreachable that day (504, then a timeout); the Ubuntu archive package
`inkscape_1.4.3-0ubuntu2_amd64.deb` (sha256 equal to the signed archive index) and 22 library packages were fetched with
`apt-get download`, unpacked with `dpkg-deb -x` into the session scratch folder and run from there (no install, no sudo).
`crates/core/tests/fixtures/svg/exports/generate-inkscape.sh` writes the three exports from `inkscape-source.svg`.
Security review of this round (fresh, 2026-10-29, BLOCK(1) HIGH, fixed in the same step): the sanitiser kept `url(#`
followed by any character, while the dangling check and the scoping read an id only from an id character, so
`url(#%61)` (and, in Chromium, `url('#<TAB>a')`) passed both and resolved in browsers, which percent-decode the fragment;
the expansion budget was walked around the same way (pre-existing since R3). Now `sanitize::local_url_target` is the one
reading of a `url(`: CSS whitespace, an optional quote, `#`, an id in the reference grammar, the same quote, CSS
whitespace, `)`; any other spelling is active content and refuses the file. A `url(` or `rgb(` glued to a longer name
(`xurl(`, `érgb(`, a non-ASCII letter included) is another function; a colour must end its value or list item. The
composer checks, fail-closed, that every reference of a canvas carries its view's scope and that each value holds
no more `url(` than local references (`unscoped_reference`), a coarse count that shares no parser with the reader. Tests
written apart from the reader: 14 refused spellings, 5 removed glued names, a 25 000-reference flood in `%61`, and a
browser model (percent-decoding, tab and newline stripping) over composed canvases (`svg_scope`). The R3 sanitiser
oracles needed no new declared change.
Residual (MEDIUM, security review): the scope is the view id, unique in one document only. A page that inlines canvases
of two documents at once (two versions side by side, two sheets) would share `fv.main.` and resolve in the first one in
tree order; any such page (a V1-2.5 catalogue grid, a V1-2.6 preview beside the editor, a V1-2.7 comparison; the
side-by-side diff itself is level 2, contract §8.3) must add a per-document prefix before it ships. The detail modal of the report editor draws another view of the same document, so its scope
differs.
Size (V1-2.2 final, by Node's gzip in `size.test.ts`): see §12.5. Contributors measured on a build keeping the name
section: code 1 283 513 B in 1 808 functions (gzip ≈ 462 KB) and data 219 920 B (gzip ≈ 90 KB); by crate, raw code:
`faunosteo_core` 46 % (`domain::sheet` 204 KB, of which `schema` 68 KB and `edit` 42 KB; `pdf::write` 91 KB;
`domain::report` 51 KB; `domain::archive` 41 KB; `anatomy::svg` 39 KB), `core` (fmt, float printing, slices) 18 %,
`serde_json` 12 %, `roxmltree` 3.6 %, `url` + `idna` 4.7 % (Zod's `.url()` check, `js::is_url`), `serde` 3 %,
`miniz_oxide` 2.7 % (PDF import). Options for later steps, none applied: `opt-level = "z"` for every crate (measured:
−1.6 KB gzip, not worth the speed), a lighter URL check than the WHATWG parser (`url` + `idna`: 61 KB raw, about 23 KB
gzip, but `is_url` must keep matching `new URL()`), the PDF writer, reader and inflater in a second lazily loaded module
(about 55 to 60 KB gzip by the attribution above, estimated; the editor pages never export), `wasm-opt -Oz` in the build
(not installed here; to be measured). No security check, validation or feature is removed for size.
### 12.8 Finalisation (owner, 2026-10-30)
Brief « V1-2.2 : finalisation et intégration A6 Figma » on `98060d7`, after the final independent review of `05de816`
(verifier ECARTS(3): A6 open, a LOW in `f1ef6a4`, a floor false positive; security PASS). Decisions in contract §17.5.
| Point | Built | Where |
|---|---|---|
| Glued `url(` | `sanitize::urls_unglued`: a value keeps every case-insensitive `url(` only when `url_openings` reads each one, so no attribute keeps `xurl(#a)` (or `url(` after a no-break space); before, `class`, `result`, `values` kept it, the verdict passed and only the canvas refused it (`unscoped_reference`) while the PDF drew it. Same helper as the reader, no second parser; the composer's count now holds on every read drawing | `anatomy/svg/sanitize.rs`, `anatomy/compose.rs` (comment) |
| Mask and clip units | `maskUnits`, `maskContentUnits`, `clipPathUnits` allowed, values `userSpaceOnUse` / `objectBoundingBox` only | `anatomy/svg/sanitize.rs` |
| Figma | the owner's two raw exports committed under `fixtures/svg/exports/owner/`: `default` clean, `ids` cleanable (`g@id`); stored forms pixel-identical to the raw files in Chromium 156 (208 pixels at × 8 differed before the units were allowed) | `tests/svg_clean.rs`, exports README |
Tests: `svg_clean` (`every_attribute_reads_url_with_the_one_grammar`: six attributes × nine glued spellings removed,
five non-strict or escaped spellings refused, an absent target refused, six values kept;
`mask_and_clip_units_keep_their_keywords_only`; `the_figma_exports_keep_their_mask_gradient_and_shapes`); `svg_scope`
(`the_canvas_the_preview_and_the_pdf_draw_every_drawing_the_reader_keeps`, `the_composer_refuses_a_reference_it_does_not_scope`,
which reaches the fail-closed branch on a tree built outside the reader). Mutations: dropping `urls_unglued`, the
keyword check or the `maskUnits` entry each fails the new tests. No frozen oracle, N-1 copy, protected reader or equine
file changed.
### 12.9 Reserved ids (owner, 2026-10-30)
Brief « V1-2.2 : correction de sécurité PDF et poursuite A6 » on `2f1f076`, after the MEDIUM of the final security
review: the PDF view keeps the drawing's ids and `compose_highlight` writes its halo filter `osteo-halo` next to them.
A drawing defining `filter#osteo-halo` replaced the engine's filter (the composer skipped its own when one existed: a
filter of transparent pixels erased the marker, 0 highlight pixels in Chromium 156 against 1602 for the plain drawing);
a non-filter element holding the id before the first `<defs>` won its resolution (the halo was lost, 825 pixels).
| Point | Built | Where |
|---|---|---|
| Reserved set | `refs::RESERVED_IDS` = [`HALO_FILTER_ID`] (`osteo-halo`), compared without ASCII case (the reader keeps ASCII ids only, `is_reference_name`); exact names, never a prefix: the historical drawings, the DEV equine object included, carry `osteo-overlays` | `anatomy/svg/refs.rs` |
| Reader | `SvgRejection::ReservedId` (`reserved_id`): `refs::check_reserved_ids` in `read_svg` after the targets, so the verdict (`svg_rejected`), the preview (`rejected`), the loaded sheet, the upload tool and the PDF snapshot gate (`snapshot_invalid`, `asset reserved_id`) answer it; `clean_svg` checks it after active content and the targets | `anatomy/svg/{refs,mod,clean,tree}.rs` |
| Composers | `compose_highlight` and `compose_canvas` refuse a tree holding a reserved id (`ComposeError::ReservedId`, `svg_rejected` / `reserved_id` in `view.canvas`); the highlight always writes its own filter (`has_halo_filter` removed) | `anatomy/compose.rs`, `ops.rs` |
Audit of the other ids the composition writes: none. The canvas scopes every drawing id (`fv.<view>.`) and no page id
starts with `fv.`; the annotation layer writes no `id` (its `data-*` cannot be forged: the reader removes `data-*`); the
filter's `result` names (`haloWide`, `haloTight`) resolve inside their own filter only. Spellings: character references
are decoded by the XML parser and refused; spaces, look-alikes outside ASCII, invisible characters, `xml:id`, prefixed
attributes or SVG elements are removed by the existing rules, so no tree reaching a composer holds the id; a CSS escape
or a percent-encoded `url(` target is active content.
Declared changes: `oracles/r3/sanitiser.json` `osteo-halo-id.svg` → `reserved_id` (the test applies it, the file stays
frozen); `svg_clean` corpus line `osteo-halo-id.svg` rejected; the R5.7 test "never duplicates the filter" now checks one
filter per composition and the refusal of a composed root given back. The R3 highlight oracle, the R4 digests, the equine
sha256 `0ea5202f…` and every committed drawing but that fixture are unchanged (`the_historical_drawings_read_as_before`
reads all of them). Module: 559 360 → 560 015 B gzip -9 (+655 B).
Tests: `svg_reserved_ids` (9: the set, a valid drawing with the engine's halo once, a filter of its own, the id on 23
element forms and the root, 11 reference spellings dangling alone and refused with the id defined, adversarial spellings,
512 letter cases + 30 character references refused and 90 look-alikes removed, both composers fail-closed, the equine
drawing and every committed SVG); `pdf_session` (`the_pdf_refuses_a_reserved_id_and_keeps_its_own_halo`: three hostile
snapshots refused at the gate, the demo export's halo is the engine's filter byte for byte and every marker names it);
`packages/core-wasm/tests/preview.test.ts` (three spellings on the shipped module). Mutations
(`.claude/audits/2026-10-30-v1-2-2-mutations-reserved-ids.py`): 11 killed of 11.
### 12.10 Root visibility and the final A6 perimeter (owner, 2026-10-30)
Brief « V1-2.2 : arbitrage définitif A6 et correction visibility » on `81f7639`, after the MEDIUM of the security review
of §12.9: both composers append the marker layer as the root's last child (the PDF view keeps the drawing's root, the
canvas copies its attributes), so the layer inherits the root's `visibility`, which no marker sets. A drawing
`<svg visibility="hidden">` whose children set `visible` back read clean (no removal) and drew without a marker.
| Point | Built | Where |
|---|---|---|
| Reader | `SvgRejection::RootVisibility` (`root_visibility`): `sanitize::check_root_visibility` accepts no `visibility` on the root or `visible` (CSS whitespace and letter case aside); `hidden`, `collapse`, CSS-wide keywords and any other value are refused. In `read_svg` after the reserved ids, so the verdict (`svg_rejected`), the preview (`rejected`), the loaded sheet, the upload tool and the PDF snapshot gate (`asset root_visibility`) answer it; `clean_svg` after active content, the targets and the reserved ids | `anatomy/svg/{sanitize,mod,clean,tree}.rs` |
| Composers | `compose_canvas` and `compose_highlight` refuse such a root (`ComposeError::RootVisibility`, `svg_rejected` / `root_visibility` in `view.canvas`) | `anatomy/compose.rs`, `ops.rs` |
| A6 | final perimeter Figma, Inkscape, cairo, ImageMagick; Illustrator and Affinity optional, never claimed without a real export; `owner/` and its procedure kept | contract core E1, V1-2 contract §17.6, export READMEs |
Why the root attribute only: the root's `class`, `style`, `transform`, `filter`, `mask` and `clip-path` were already
removed by the reader (so `style="visibility:hidden"` on the root is a removal and the cleaned drawing shows its
markers), `<style>` elements are removed, and a descendant's `visibility` stays in the drawing, never on the layer's
ancestors. Root `opacity` and `display` act on the drawing and the markers alike; `fill`, `fill-opacity` and the
stroke colour are set on every marker, so the root's never reach them.
Open after the independent security review of this step (pre-existing, owner decision, not built): the same
inheritance through properties no marker sets, and the view's frame. (1) Root `stroke-opacity="0"` (or
`stroke-dasharray="0.001 100000"`) with the drawing's groups setting it back removes every marker outline in the canvas;
the detail trigger, filled at 0.06, then shows 0 pixels in Chromium, Firefox and WebKit; the PDF highlight keeps its
0.85 fill. (2) Root `stroke-width="100000"` reaches the point hitboxes (`pointer-events="all"`, no stroke set): in
Chromium and WebKit 13 of the 19 equine markers send their click to the last hitbox. (3) A view without `view_box`
(the equine main view) is framed by the drawing's root `viewBox`: shifting it and translating the drawing back leaves
the horse pixel-identical and every marker outside the frame. The class fix for (1) and (2) is the engine's: the layer
`<g>` resets the inherited properties (`visibility`, `stroke-opacity`, `stroke-dasharray`, …) and the hitbox gets
`stroke="none"`; it changes the R3 highlight oracle and the R4 digests (corrected in §12.12, 2026-11-01: the R4 PDF
digests do not change; the R3 highlight oracle and canvas goldens compare under a declared transform, and only the R4.1
real-raster manifest's call-1 `svgSha256` is edited). (3) needs a document rule (annotations inside
their view's frame, in the verdict and the preview) or the document owning the main view's frame.
Browser proof (equine main view, `hip` selected, halo on; pixels that differ from the same SVG without its layer, so 0
means no marker shows; composed by the core at `81f7639`, then by the fix):
| Root | Chromium 156 PDF / canvas | Firefox 157 PDF / canvas | WebKit 27.2 PDF / canvas | Fix |
|---|---|---|---|---|
| none (equine) | 3 920 / 43 685 | 3 918 / 43 779 | 3 930 / 43 687 | unchanged, SVG byte-identical |
| `visibility="hidden"`, children `visible` | **0 / 0**, drawing drawn | **0 / 0**, drawing drawn | 0 / 0, nothing drawn | `root_visibility` |
| `visibility="collapse"`, children `visible` | 0 / 0, drawing drawn | 0 / 0, drawing drawn | 0 / 0, nothing drawn | `root_visibility` |
| `style="visibility:hidden"` | removed by the reader: 3 920 / 43 685 | 3 918 / 43 779 | 3 930 / 43 687 | unchanged (cleanable) |
| `opacity="0"` | 0 / 0, nothing drawn | 0 / 0, nothing drawn | 0 / 0, nothing drawn | kept: whole view |
| `display="none"` | 3 920 / 0 (nothing drawn) | 0 / 0 (nothing drawn) | 3 930 / 0 (nothing drawn) | kept: whole view |
| `stroke`, `stroke-width="40"` | 5 052 / 64 175 | 5 065 / 64 332 | 5 055 / 64 351 | kept: markers drawn |
No frozen oracle, R3/R4 digest, step6 golden, N-1 copy, historical drawing or equine fingerprint changed: no committed
SVG carries a root `visibility`, `opacity`, `display` or `stroke`.
Tests: `svg_root_visibility` (6: visible and absent roots read, clean, verified, previewed and composed with the layer
showing; 16 values × 4 bodies refused by the reader, the cleaning, the preview, the canvas and the verdict; both
composers fail-closed; root `style` / `class` and `<style>` forms removed, their stored forms fixpoints, descendants
harmless; other root properties removed or whole-view; the equine drawing); `pdf_session`
(`the_pdf_refuses_a_drawing_whose_root_hides_the_markers`); core-wasm `preview.test.ts` (three values on the shipped
module). The reader suites share `tests/common/sheet_readers.rs`. Red first: with the error names added and no check
wired, the reader, composer and PDF tests failed (3 of 14), then passed with the check. Mutations: V1 to V9 killed, and
K1 to K11 of §12.9 rerun, all killed (20 of 20).
Module: 560 015 → 560 377 B gzip -9 (+362 B), 1 513 968 → 1 515 246 B raw; Node's gzip 569 817 B (budget 600 000).
### 12.11 The frame of a view (owner, 2026-10-30, defect 3)
Brief « V1-2.2 : arbitrages propriétaire sur les trois MEDIUM » on `958228a`, point 3 (open item (3) of §12.10): a
geometric rule in the core, the source document never rewritten.
| Point | Built | Where |
|---|---|---|
| Frame | `view_frame(view, drawing)`: the view's `view_box`, else the drawing root's `viewBox` read with the SVG grammar (`path::number_list`: four finite numbers separated by comma-wsp, width and height positive); `None` otherwise. One definition for both composers, the verdict and the preview | `anatomy/frame.rs`, `anatomy/path.rs` |
| Composers | both frame the view on it (`Frame::view_box`, JavaScript number printing; the canvas falls back to `0 0 100 100`, the PDF view drops an unusable `viewBox`) and remove the drawing's `preserveAspectRatio`, so the default `xMidYMid meet` shows the whole frame in the canvas box and in the clamped PDF raster | `anatomy/compose.rs` |
| Bounds | circle `cx ± r`, polygon points, path data read strictly (moveto, lines, cubic and quadratic curves with their `S`/`T` reflections, arcs in centre parameterisation with the radii scaled up as SVG 1.1 F.6 says); curves and arcs measured at their extremes, not their control points; a path a browser would not read whole (missing number, bad flag, unknown command, trailing comma, number out of range, no initial moveto) is `Unreadable` | `anatomy/path.rs`, `anatomy/frame.rs` |
| Rule | an annotation is in frame when its bounds are inside the frame, edges included (slack 1e-9 of the span); otherwise `annotation.geometry.out_of_frame` at `annotations[i].geometry`; a view drawn on a clean drawing with no frame is `view.frame.unknown` at `views[i]`; a view whose drawing is missing or refused is not measured (its own failure names it); a repeated view id is measured once, as the composers find it | `frame_faults`, `report::frame_issues` |
| Verdict | the issues join `issues`, the failure `verification.validation.out_of_frame` follows the drawing faults; never a `rules` failure | `domain/sheet/verdict.rs` |
| Preview | the same issues in `state().report.issues`, on the drawings held (draft, published, deprecated alike) | `domain/sheet/preview.rs` |
Not covered by the rule: a view whose `view_box` is inside the drawing's area while the drawing moved elsewhere (the
annotations are in frame over an empty area); the rule proves the markers are visible, the review proves they sit on the
anatomy. Transforms inside the drawing move the drawing only; the reader removes the root's own `transform`.
Tests: `sheet_frame` (12; on `958228a` 9 fail and the 3 that only accept pass): the equine draft
in frame; the reported drawing (the horse's `viewBox` moved by 10 000, its content translated back, pixel-identical,
read clean) refused with its 19 main-view annotations and the `out_of_frame` code alone, the head view untouched, the
document text unchanged; edges accepted; past an edge by 0.001 refused; curves inside although their control points are
out, arcs and rotated arcs out although their endpoints are in; unreadable path data; secondary views on their crop and
on their own drawing; a document `view_box` over the drawing's; `viewBox` spellings a browser reads and those it does
not (absent, zero or negative size, three or five numbers, `0x0`, `px`, `1e999`, empty); legitimate transforms (scaled
content, frame moved with its annotations); a missing drawing not measured; both composers on the measured frame without
the drawing's `preserveAspectRatio`. Unit tests of `path.rs`: 500 random cubics and 500 random arcs against 20 001
samples each (bounds hold every sample and are no larger), the path and number grammars. Verdict and preview agree on
every case (`judged`).
Mutations (`.claude/audits/2026-10-30-v1-2-2-mutations-three-medium.py`, F1 to F16): 17 of 17 killed (F16 « frame
faults also a rules failure » survived the first run; the reported-drawing test now pins the failure list).
Oracles: none changed by this rule; the R3 canvas and highlight trees, the R4 digests and the step6 goldens pass as
frozen (no committed drawing carries a `preserveAspectRatio` or a `viewBox` in another spelling).
Module: 560 377 → 572 993 B gzip -9 (+12 616 B, the curve and arc measure), 1 515 246 → 1 544 834 B raw; Node's gzip
582 919 B (budget 600 000).
### 12.12 Marker isolation and the hitbox capture (owner, 2026-10-30, defects 1 and 2)
Brief « V1-2.2 : arbitrages propriétaire sur les trois MEDIUM », points 1 and 2 (open items (1) and (2) of §12.10). A
structural fix in the composition, common to both forms, not a list of refused attributes.
| Point | Built | Where |
|---|---|---|
| Composition root | the engine's own `<svg>`: `xmlns`, `xmlns:xlink`, the frame (§12.11). The drawing's root becomes a `<g>` holding its other attributes (`viewBox`, `preserveAspectRatio`, `version`, `width`, `height`, `x`, `y` dropped) and its children; the marker layer, and in the PDF view an engine `<defs>` holding the halo filter, are that group's siblings | `anatomy/compose.rs` (`isolated`) |
| Layer | the composers draw `render_composed_layer`: the R3 tree with each point hitbox declaring `stroke="none"` and `pointer-events="visibleFill"` (its clickable area is its circle: under `all` a stroke widens the hit area even unpainted); the zones and the trigger already declare their stroke width; the R3 `render_layer` stays for the seed review drawings, unchanged | `anatomy/layer.rs` |
| Kept | the reader rules of §12.9 and §12.10 (`reserved_id`, `root_visibility`) and both composers' fail-closed checks | |
What reached a marker before, and why the structure ends it: inherited properties (`stroke`, `stroke-width`,
`stroke-opacity`, `stroke-dasharray`, `stroke-dashoffset`, `stroke-linecap`, `stroke-linejoin`, `stroke-miterlimit`,
`fill`, `fill-opacity`, `fill-rule`, `visibility`, `color`, `clip-rule`, `color-interpolation-filters`, the font
properties) pass from an ancestor to a child, which a child's own attribute overrides only for the properties it sets;
`opacity`, `display` and the conditional `systemLanguage` act on the element and its whole subtree, which no child can
undo. The reader already removes the root's `class`, `style`, `transform`, `filter`, `mask` and `clip-path`, refuses a
root `visibility` other than `visible`, keeps no `pointer-events` or `cursor` attribute and no `<style>` (a descendant's
`style` may still set them, or any CSS property without a function call: it acts on the drawing only). With the layer a
sibling of the drawing, its only ancestor is the engine's root (and, in the canvas, the page, whose stylesheet is the
application's). Consequence for drawings: a root `opacity="0"` or `display="none"` now hides the drawing alone, in every
engine and both forms (before: the whole view, or nothing, depending on the engine and the form).
Proofs: `svg_marker_isolation` (5 at lot B, all red on `958228a`; 7 since, with the census and the canvas passes): 22 root properties one by one and all at once never on the
layer's ancestors, the drawing keeping them on its group, in both forms; the equine drawing; the halo outside the
drawing; every interactive surface declaring its stroke and capture. Browser pixels (Chromium 156, Firefox 157,
WebKit 27.2; PDF raster as `browserRasterizer`, canvas inline): the equine views identical before and after (0 px), the
markers under nine hostile roots identical to the plain markers (0 px) where `958228a` drew them altered (4 700 to
196 000 px) or not at all (`opacity`, `display`). Real PDF exports (demo, v2full, v2unresolved, Chromium rasters): byte-
identical to `958228a`. Clicks (`e2e/ui/canvas-clicks.spec.ts`): 67 pass on Chromium desktop and phone, Firefox, WebKit
desktop and phone; on `958228a` 45 fail. Mutations I1 to I7 killed, K1, K7, K8, K10, V1, V6, V7 rerun killed.
Census and browser probe (owner brief 2026-11-01, « Lot B : approuvé »): `svg_marker_isolation::
nothing_the_reader_keeps_changes_the_layer_or_the_halo` sets each of the reader's 77 allowed attributes (`sanitize::
ALLOWED_ATTRIBUTES`, structural ones aside) on the root and on a descendant group, and 17 descendant `style` values,
including CSS that acts outside its subtree in an HTML page (`z-index` with `position`, `position:fixed`, `mix-blend-mode`
with `isolation`, `view-transition-name`, a 4 000 px `outline`, `contain`, `translate` in depth, anchor positioning,
`pointer-events`); the layer and the halo serialise byte for byte as with a plain drawing, the root carries only
namespaces and the frame. In the browser (Chromium 156, Firefox 157, WebKit 27.2, canvas inline and PDF raster), an opaque
magenta rectangle covering the whole frame, last child of the equine drawing, carrying 21 candidate styles (15 kept by the reader; 6 with a function call,
`transform:translateZ(…)`, `scale(…)`, `filter:drop-shadow(…)`, `backdrop-filter`, `clip-path:inset(…)`, `mask-image`,
removed by it): the magenta pixel
count equals the unstyled rectangle's inside the frame (the huge stroke and the outline only cover the anti-aliased edge
rows) and the 13 points keep their click; the positive control (the same rectangle placed after the layer) covers every
pixel and takes 0 of 13 clicks. Tools: `.claude/audits/2026-11-01-v1-2-2-decisions-tools/`.
References (owner brief 2026-11-01, « Références historiques : modification contrôlée autorisée »). The frozen files are
not edited; the tests apply the declared transform to their frozen side and compare strictly:
| Reference | Transform | Where |
|---|---|---|
| R3 highlight oracle `crates/core/tests/oracles/r3/highlight.json` (36 cases) | `with_isolated_layer`: the root keeps `xmlns`, `xmlns:xlink`, `viewBox`; its other attributes and every child before the layer go into a `<g>`; `filter#osteo-halo` leaves the drawing for an engine `<defs>` placed before the layer; each point hitbox (circle, `pointer-events="all"`, no `stroke`) gets `stroke="none"` and `pointer-events="visibleFill"` | `tests/common/svg_tree.rs`, `anatomy_compose.rs` (the R3 canvas goldens there and in `anatomy_canvas_op.rs` also take `with_canvas_passes`, §12.13) |
| R3 canvas goldens `apps/app/tests/fixtures/goldens/r3/canvas.{main,head}.json` | `withIsolatedLayer`, the same rules on the mounted canvas tree | `tests/helpers/svgTree.ts`, `canvas.trees.test.tsx` |
| R3 layer goldens `canvas.{main,head}.layers.json` | `withDeclaredHitboxes`, then `withCanvasPasses` (§12.13) | same |
| R4.1 real-raster manifest `apps/app/tests/fixtures/pdf/r3/real/manifest.json`, call 1 `svgSha256` | edited, the one byte digest no transform can map: `a9a3155c…2c11` → `45fd4aaf…fc7f`; call 2 unchanged; `pdf-export.session.test.ts` green on all calls | the manifest (original in Git history, `87b8873`) |
Unchanged and still compared as frozen: R3 `layer.json` and `sanitiser.json`, the R4 PDF digests, the step6 goldens, the
N-1 copies, the seed review drawings (R3 layer kept for them), the equine drawing (sha256 `0ea5202f…`) and its fingerprint.
The equine renders identically before and after (0 px, three engines, canvas and PDF), and the real PDF exports are
byte-identical to `958228a`. Correction to §12.10: the class fix does not change the R4 digests; only the R4.1 call-1
`svgSha256` changes.
Junction points (open here until 2026-11-01): the vertebral junction points sat on the edge of zones painted and hit
after them; 28 to 49 % of `c7-t1`, `l6-s1` and `t18-l1`'s visible disc recorded the zone, 8 % of the fore fetlock's the
fore sesamoids. Closed by the canvas passes of §12.13.
### 12.13 Owner decisions of 2026-11-01
Brief « V1-2.2 : décisions et poursuite des corrections » on `f1bb19b`: lot B approved and committed (`4f52f5e`), the R3
transforms and the R4.1 call-1 `svgSha256` authorised (`e677150`, §12.12).
**Junctions, « the visible wins », the editor canvas only** (owner answer 2026-11-01: the PDF view is not interactive and
keeps the document order, its bytes, the R4 digests and the step6 goldens). `layer::render_canvas_layer`, drawn by
`compose_canvas`: every point hitbox, then every zone and trigger, then every visible twin, each pass in document order;
the twin captures on `visiblePainted` (its declared fill and its 1.5 stroke). `render_composed_layer` (PDF) and
`render_layer` (R3, review drawings) unchanged. Declared transform on the frozen canvas side: `with_canvas_passes`
(`tests/common/svg_tree.rs`, after `with_isolated_layer`) and `withCanvasPasses` (`tests/helpers/svgTree.ts`, inside
`withIsolatedLayer` and on each `canvas.*.layers.json` layer); the R3 highlight oracle keeps `with_isolated_layer` alone.
Visible consequence, declared: a selected point's hitbox, filled by the canvas stylesheet, sits under a neighbouring zone,
which tints the part it covers at 30 %.
| Proof | Result |
|---|---|
| `svg_marker_isolation::the_canvas_paints_hitboxes_then_shapes_then_twins_and_the_pdf_keeps_document_order` | passes sorted in both views, document order inside each pass, one twin per hitbox; the PDF view interleaved, twins `pointer-events="none"` |
| `canvas-clicks.spec.ts`, 6 projects (Chromium 1280, 375 and 320 touch, Firefox 1280, WebKit 1280 and 375 touch) | 99 passed, 0 fixme. On `e677150` (lot B alone) the junction test and the disc test fail in all 6 projects (12), the rest pass |
| junction test | `c7-t1`, `l6-s1`, `t18-l1`, fore fetlock: the centre and four points towards the disc edge (80 % of the radius, at most the radius less 1.5 px) record the point, real clicks or taps |
| disc test | every twin of the main and head views, sampled every 2 units inside 95 % of its radius: 100 % record the topmost disc, through the browser's hit test |
| zone test | every zone and the trigger, sampled every 4 units, 2 px inside their fill, away from any disc and any later shape: 100 % record the shape |
| close fetlocks | each centre records itself; the gap between their discs, inside both hitboxes, records the later hitbox (a real click where the margin is 1.5 px or more, the hit test below) |
The five `fixme` of the previous checkpoint were one test, « a click on a vertebral junction records the junction », in
each of the five projects of the time: it now runs unmarked in the six. Module: 574 234 B gzip -9 (lot B 573 134).
**The scale bypass, closed by the visible size** (owner decision 2026-11-01: the projected visibility of the markers,
not a cap on the `viewBox`; threshold 4 CSS px on the smallest supported preview, the 6 px starting point refusing the
validated equine). The security review's reproduction: the horse's `viewBox` × 1 000 with the content scaled back draws
the same horse, every marker in frame and below a pixel, accepted. One definition in `anatomy::frame`, measured by the
verdict and the preview after the frame (`frame_faults`), the composers framing on the same `view_frame`:
| Rule | Value and why | Where |
|---|---|---|
| Smallest preview | the editor at 320 × 568 CSS px (the narrowest width the V1-2 contract §8.4 tests), measured in Chromium on 2026-11-01: the main view's canvas box 286 px wide, growing to 310 px tall (a tall frame reaches 310.4); a detail view in the dialog's 4:3 box, 254.9 × 191.1. `MAIN_PREVIEW_PX` 286 × 310, `DETAIL_PREVIEW_PX` 254 × 191, scale `min(w / width, h / height)` (`xMidYMid meet`) | `frame::Frame::preview_scale` |
| Visible size | what the layer paints, never the click surface: a point's (or a circle zone's) visible disc `2 × max(2, r − 12)` (`layer::twin_radius`, the one formula the layer draws with), a trigger circle's diameter, a polygon's or a path's smaller side, curves and arcs on their shape (`path_bounds`) | `frame::visible_size` |
| Threshold | `MIN_VISIBLE_PX` 4. Measured equine at 320 × 568: junctions 4.97 px (`c7-t1`, `l6-s1`, `t18-l1`, r 30), the other main points 6.07, the head points 15.1, the smallest zone side 13.1 (sacral). 6 px would refuse the junctions at 320, 360 (5.66) and 375 px (5.92) | |
| Refusal | issue `annotation.geometry.too_small` (path `annotations[i].geometry`), verdict `verification.validation.marker_too_small` after `out_of_frame`; the document never rewritten | `report.rs`, `verdict.rs`, `preview.rs` (through `frame_issues`) |
| Frame range (`f32`) | a frame is usable only if finite and: every edge within `2²⁰` (`f32` keeps a sixteenth of a unit there), each span at least 1 unit (painted pixels, below: WebKit 27.2 paints nothing from `2⁻⁷`, Chromium 156 drifts at `2⁻¹⁴`; below one unit the layer's fixed sizes exceed the frame), aspect at most 100 (beyond, the frame is 2.9 px tall on the phone box), farthest edge at most 256 smaller spans (a coordinate's `f32` error, about `|v| × 2⁻²⁴`, stays below `2⁻¹⁶` of the span: 0.15 px on a frame shown 10 000 px wide). Equine: edges 2 073.4, ratio 1.27 (main) and 1.47 (head). Otherwise no usable frame (`view.frame.unknown`, `out_of_frame`); the canvas falls back to `0 0 100 100`, the PDF view to no `viewBox` | `frame::Frame::from_numbers` |
The values and transforms the rule bounds: the markers' only transform is the frame's mapping onto the box (they sit
in the engine's root, §12.12), bounded by the frame range; their coordinates are inside the frame, so within it. The
drawing's own transforms move the drawing alone and change no measure (`transforms_inside_the_drawing_never_change_the_measure`);
a drawing scaled to nothing is the preview's and the reviewers' to see, as any drawing content.
Rust and the browsers on the limits (tools `.claude/audits/2026-11-01-v1-2-2-decisions-tools/`: `frame-probe.mjs` on
the cases of `frame_probe_generator.rs.txt`, `span-pixels.mjs`; Chromium 156, Firefox 157, WebKit 27.2). Each case is the
core's composed canvas in the preview box with the AnatomyCanvas CSS; the core's f64 expectation of each hitbox (stroke
none: Firefox counts a stroke in an element's client rect, the others do not) against the browser's layout:
| Case | Core | Chromium / WebKit: size gap, centre gap | Firefox |
|---|---|---|---|
| equine main, × 1.24, × 1.25, × 100, head on the detail box | accepted, accepted (junction disc 4.005 px), `too_small` (3.973), `too_small` (0.050), accepted (15.08) | ≤ 8.2e-5 relative, ≤ 0.014 px | ≤ 0.4 % relative (client rects in 1/60 px app units: 24 % of the 0.067 px hitbox at × 100), ≤ 0.012 px |
| thresholds on a 1 000-unit frame, discs 4.576 and 3.432 px | accepted, `too_small` | ≤ 1e-6 relative, ≤ 4.2e-7 px | ≤ 0.2 %, 0.0035 px |
| far edge at `2²⁰` (span 8 192); far edge at 256 spans (span 10) | accepted, accepted | 0, ≤ 0.0034 px | ≤ 0.84 %, ≤ 0.2 px |
| far edge at 10⁵ and 10⁶ spans (refused, drawn raw) | `no_frame` | centre gap 0.14 px, then 11 px: the `f32` error the ratio rule keeps out | 0.44 px, 9.6 px |
| span 1 unit to `2⁻²⁰`, disc a quarter of the frame, painted pixels | accepted from 1 unit (`no_frame` below) | Chromium exact to `2⁻¹⁰`, 0.46 px at `2⁻¹⁴`, nothing painted at `2⁻²⁰`; WebKit exact to `2⁻⁵`, nothing painted from `2⁻⁷` | exact at every span (its client rects drift from 286 px per unit: 3.3 % at a span of 1, rendering unaffected) |
Path numbers (fresh security review and verifier on `96b9978`, MEDIUM): every number of a path's `d` and of a `viewBox`
is read within `±2²⁰` (`path::Cursor::number`), else the path is unreadable (`out_of_frame`). Browsers read path data
in `f32` and draw nothing for an arc radius or rotation past `f32::MAX` (Chromium, WebKit; WebKit from `1e30`), while the
endpoints kept the bounds in frame and the verdict passed. `path_numbers_past_the_frame_magnitude_are_refused` (red
before the bound). Residual: a rotation below `2²⁰` degrees is reduced in `f32` by the browser (ulp 0.0625° at `10⁶`).
Mutations on `96b9978` (`.claude/audits/2026-11-01-v1-2-2-mutations-decisions.py` and the 2026-10-30 script): 55 killed,
F5 (zero span accepted) survives as equivalent, the aspect rule refusing a zero or negative span; six 2026-10-30 anchors
moved with the code, re-anchored and killed in the new script. N8 (the path number bound) added after the review.
Declared limit: a thin shape drawn on a diagonal is measured on its bounds, so it can pass while showing a line; the
rule is a scale floor against the bypass, never a review of shapes (the zones keep their declared 2-unit stroke). The
security review measured its consequence (MEDIUM, open, owner decision): a zone path whose interior has zero winding
(an outline traced twice in opposite directions) or a near-collinear polygon passes the 4 px rule, paints no interior
and is hit only on its 2-unit stroke (0.28 CSS px on the equine phone scale), in the three engines. Closing it needs a
filled-area measure (nonzero rule) or a « zone without interior » issue. Closed by the interior rule (owner brief of
2026-11-01, §12.14).
### 12.14 The last MEDIUM: zone without interior (owner, 2026-11-01)
Brief « V1-2.2 : fermeture du dernier MEDIUM » on `de2dfb3`: the decisions of §12.13 confirmed (threshold, frame rule,
bounds, codes `too_small` / `marker_too_small`, isolation, canvas passes, PDF order and bytes, R3 transforms, R4.1
manifest, the five former `fixme`); a zone without a usable filled interior refused by the verifier, in the core.
Closure (owner brief « Validation définitive V1-2.2 », 2026-11-01, BDR-092): V1-2.2 VERIFIED on `c73415a`, the rule and
both codes approved, the equine accepted unchanged; the LOWs below accepted for the closure and still tracked, never
declared fixed (V1-2 contract §17.7).
**Rule** (`anatomy::interior`, called by `frame::annotation_placement` after the bounds rule, so by the verdict and the
preview): a polygon or a path annotation (zone or trigger) must fill a disc of `MIN_VISIBLE_PX` 4 CSS px across on the
smallest preview (§12.13: main 286 × 310, detail 254 × 191, `xMidYMid meet`). Circles keep their exact disc measure.
| Part | What and why | Where |
|---|---|---|
| Fill rule | `nonzero` (`LAYER_FILL_RULE`): the layer writes no `fill-rule`, the composition root carries none, the drawing's sits in its own group (§12.12). The measure takes either rule; `evenodd` is tested, never used by the layer | `interior::FillRule` |
| Stroke | never counted: the measure reads the fill alone, whatever the shape's `pointer-events` (`all` on zones and triggers, its 2-unit stroke taken by the browser too) | |
| Outline | a polygon's points; a path read by the one SVG path reader (`path::path_outline`, same grammar and `±2²⁰` bound as `path_bounds`), each subpath closed by the fill, a lone moveto adding nothing; cubics, quadratics and arcs cut into chords: over a parameter step `h` a chord departs from its curve by at most `K h² / 8`, `K` bounding the second derivative (cubic `6 max‖Δ²‖`, quadratic `2‖Δ²‖`, arc `max(rx, ry) × sweep²`, the radii as scaled to reach the endpoint); chords asked within 0.05 px (`INTERIOR_TOLERANCE_PX`), at most `MAX_CURVE_CHORDS` 64 per curve, the largest deviation recorded | `path::Outline` |
| Measure | the widest disc whose centre the rule puts inside and every edge (closing edges included) at least the radius away: the disc crosses no edge, so all of it has the centre's winding number; the deviation taken off the radius. Conservative: a nonzero fill running on past an inner edge is not counted (pentagram: 3.09 measured, 3.82 filled) | `interior::widest_disc` |
| Search | polylabel's subdivision: square cells from one covering the outline, a cell's best centre at most its centre's radius plus its half diagonal, the most promising cell cut first (a max-heap ordered by `total_cmp`), cells below 0.05 px never cut; deterministic. Refuses in doubt: measured, the first L accepted at its elbow holds 4.026 px | |
| Caps | 4 096 outline vertices (`MAX_OUTLINE_VERTICES`), 4 096 cells per shape, one budget of `2²⁵` edge distances per sheet (`MAX_INTERIOR_WORK`, 0.35 s natively at 8 192 edges × 4 096 cells; the equine takes about 10⁵): a shape over them is refused, never accepted | `interior::Budget` |
| Refusal | issue `annotation.geometry.interior_too_small` (« fills no interior wide enough to tap », or « too complex for the interior measure »), verdict `verification.validation.marker_interior_too_small` after `marker_too_small`, never a rules failure; the document never rewritten | `report.rs`, `verdict.rs` |
Threshold, measured before freezing (equine draft, 320 × 568, widest disc across): caudal 4.951 px, sacral 11.30,
thoracic 11.47, cervical 12.17, lumbar 14.15, head trigger 29.13. 4 px keeps the approved threshold of the points (a point
shows a 4 px disc, a zone must hold one) and refuses no equine shape; the caudal zone now falls first when the horse is
scaled, past × 1.2378 (4.951 / 4), before the junctions (× 1.2414). Above 4.95 px the threshold would refuse the
validated equine; below, a tap target smaller than the points'.
| Proof | Result |
|---|---|
| `sheet_marker_visibility::shapes_without_a_usable_interior_are_refused` | each accepted before this rule (bounds pass): a path forth and back, a triangle traced back on itself, the same square twice in opposite directions, a 1 px diagonal sliver, a cubic and an arc travelled there and back, a 2 px ellipse turned 45°, an L of 3.3 px arms (3.87 px): `interior_too_small`, `marker_interior_too_small` |
| `small_shapes_that_fill_are_accepted` | a 4.5 px tall triangle, a 6 px disc of two arcs, a cubic lens, an L of 3.6 px arms (4.22 px), a pentagram of winding 2 (6.18 px; 3.26 under evenodd) |
| `the_interior_threshold_holds_at_its_edge` | L at 4.030 px accepted, 4.019 (doubt band) and 3.995 refused |
| `the_interior_follows_the_projection` | the same L at ten units per px, at the offset limit (256 spans), in a one-unit frame (286 px per unit) |
| `drawing_transforms_never_change_the_interior`, `a_shape_too_complex_to_measure_is_refused` | a drawing scaled × 1 000 changes nothing; 4 096 vertices measured, 4 097 refused (polygon and path) |
| equine | `the_equine_draft_shows_every_marker_on_the_phone_preview` passes; `the_equine_threshold_falls_on_the_caudal_zone_then_the_junctions`: × 1.235 accepted, × 1.24 the caudal zone alone (failures `[marker_interior_too_small]`), × 1.25 with the three junctions |
| `interior` unit tests | square, pentagram under both rules, forth and back, two opposite loops, deviation taken off, stop and floor, budget shared and spent, 60 random polygons (self-intersecting included) under both rules: never wider than a dense grid, every rim point filled |
| `path` unit tests | 300 random cubics, quadratics and arcs: every curve point within the recorded deviation of its chords, the deviation within 0.05 unless capped (arcs whose radii the endpoints scale up); closepath restarts at the subpath start; vertex cap |
Browsers (`apps/app/e2e/ui/interior-clicks.spec.ts`, the six click projects: Chromium 1280, 375 and 320 touch, Firefox
1280, WebKit 1280 and 375 touch; 102 passed, and `canvas-clicks.spec.ts` 99 unchanged). The probe
(`e2e/fixtures/interior-probe.json`, written and drift-checked by `tests/interior_probe.rs`) gives 16 shapes in the
preview's 286 × 310 box (one unit per CSS px) with the core's verdict and widest disc. For each, the browser's own fill
(`pointer-events="fill"`, stroke out) is sampled every 0.25 px and its widest disc taken by an exact distance transform:
the core never claims more than the browser fills (at most 0.5 px under it); the 10 refused fill no 4 px disc in any
engine (an arc radius of `1e-49` and an arc between endpoints one `f32` point apart fill nothing at all); the 6 accepted take a real click or tap at the core's centre and the hit test at 32 points of 90 % of its radius,
fill only and as shipped. A drawing root `fill-rule="evenodd"` leaves the pentagram filled at its centre (isolation).
Then the equine shapes in the canvas: the core's disc hit test-clear (samples under a point's disc aside, at most a
quarter), and a real press where the fill lies farthest from every disc records the zone.
Chromium's touch adjustment, measured (tool `.claude/audits/2026-11-01-v1-2-2-interior-tools/`, taps every 2 px of each
equine zone's own hit area, 400 ms apart): a tap up to about 10 px around a point's disc goes to the point on
`chromium-320` and `chromium-375`, not on `webkit-375`. Taps recorded as the zone at 320 px: caudal 18/21, sacral 51/67,
lumbar 87/104, thoracic 72/97, cervical 195/195, trigger 278/284 (the rest to the neighbouring junctions and points, or to
nothing at the edges); WebKit 375: 91 to 99 %. Every equine zone keeps a tappable interior; near a point, Chromium's
targeting goes to the point, a browser behaviour the measure does not model (no selection redesign in V1-2.2).
Known limitation (owner, 2026-11-01, LOW accepted): a visible disc covering another marker entirely, or the only
interior of a zone, takes its taps; no rule refuses it. The human review identifies overlapping markers before a sheet
is published; no proof here claims that every marker is individually selectable when two overlap entirely. The arc
rotation reduced in `f32` by browsers (sub-pixel, §12.13) stays bounded by the `2²⁰` number bound, its tests kept.
Fresh reviews on `8dd2d78`. Security PASS with one MEDIUM, fixed: an arc radius below `f32` precision (`1e-49`) was read by
the core as the half disc its endpoints scale it to, while browsers read it as zero (a straight line) or, below about
`1e-19`, square it to nothing; the core accepted a shape the browser never fills. An arc radius other than zero is now at
least `path::MIN_ARC_RADIUS` `2⁻²⁰` (the scaled radii stay finite in `f32`), else the path is unreadable
(`out_of_frame`): `a_tiny_arc_radius_is_not_read`, `path_numbers_past_the_frame_magnitude_are_refused`, probe
`arc-radius-1e-49`. Its LOWs, fixed: an arc adds its scaled radius × `2⁻²³` to the deviation (the browser's `f32` arc
arithmetic, a bound, not a measure: `a_large_arc_radius_adds_its_f32_drift`); the flattening stops tracing once over the
vertex cap; a path without an outline is refused, not accepted (unreachable, the bounds and the outline sharing one
reader). Informational: verdict and preview may differ by a libm ulp between native and wasm on a shape tuned to the
threshold; the verdict has no production caller yet (V1-2.3). Verifier ECARTS(3), all documentation: this section's
pointer from §12.13, the × 1.235 assertion, the audit tools committed.
Second security review, on `03be75b`: PASS, the radius MEDIUM closed, two siblings of the same `f32` class, fixed. Browsers
store path points in `f32`: an arc whose endpoints are one `f32` point (`A20 20 0 1 1 40.000001 50` from `40 50`) draws
nothing there, while `f64` drew a full circle; the core now compares the endpoints as stored and draws no arc either
(`an_arc_between_endpoints_equal_in_f32_draws_nothing`, probe `arc-endpoints-equal-in-f32`). An ill-conditioned arc (a
flat ellipse along its chord) moves far for one ulp of an endpoint: the core draws the same arc with an endpoint or a
radius moved by one `f32` ulp (six variants), adds the largest distance between them at 33 parameters to the deviation,
and adds the variants' extremes to the bounds (`an_ill_conditioned_arc_carries_its_f32_spread`: the reported needle,
18 units past the chord, inside the bounds; a semicircle of radius 1 000 keeps 0.84 units, its centre moving as the square
root of an ulp, as in the browsers). An estimate of the browser's input rounding, compared point to point; the arc
arithmetic drift raised to `4 × 2⁻²³` of the radius. Bounds of every arc grow by a few ulps (an arc flush with the frame's
edge counts them). LOW kept, pre-existing, outside the diff: relative commands accumulate in the browser's `f32` current
point; the worst aligned case (4 096 segments at the 256-span offset limit) drifts 6 % of the span, contrived.
Third security review, on `86dce16`: PASS, no MEDIUM. Both siblings refuse or match (an f32 browser model on ~300 000
random arcs: no counterexample at 0.5 CSS px; worst under-cover 0.13 units on generic arcs, about 0.1 px of disc radius).
LOWs: the spread's sampling ran for bounds alone and past the vertex cap, now skipped there (`86dce16` → the next commit;
the variants' extremes still join the bounds); open, declared: a semicircle exactly tangent to a frame edge counts the
spread of its variants (a few thousandths of a unit), so a detail `view_box` cropped exactly to an arc's extreme is
refused as out of frame; the spread is an estimate (one ulp, one axis at a time, rotation not moved); a zero-width needle of
a refused flat arc may run past the frame as a hairline nothing fills; arcs cost about 6 µs each natively, bounded by
the 2 MiB document only (≈ 1.8 s for a document of nothing but arcs, in the author's own preview).
Mutations (`.claude/audits/2026-11-01-v1-2-2-mutations-interior.py`), rerun on the final code `c73415a`: 29 killed, 2
equivalent: Z22 (the floor prune removed; a cell that cannot reach the floor never holds an accepted disc) and Z25 (a path
without an outline accepted; unreachable). Z7, Z19 and Z24 re-anchored on the final code (their first anchors left with
`03be75b` and `86dce16`, found by the closing verifier); Z23 (tiny radius read) is killed by the unit suite only, the `f32`
spread of `86dce16` refusing the same arcs on its own in `sheet_marker_visibility`. S1, S8 and F16 of the previous scripts,
whose anchors moved, re-anchored and killed. Module 580 428 B gzip -9 (native build; +6 195 B, budget 600 000, margin
19 572 B), 580 522 B in the app image (margin 19 478 B).
Ignored cargo tests: the three are one test, `pdf_serialize::l_report_with_real_rasters_costs_what_it_costs`, counted
once per cargo run whose features build `pdf_serialize` (workspace, `cli`, `ts,pdf-read,pdf-write`). A timing print for
§10.7, 40 s in debug; run on request in release (2026-11-01: passed, 120 views, 46.5 MB, 5.2 s). The L report's export
itself is covered unignored (`pdf_budget`); it masks no required scenario.
## 13. V1-2.3: the server verdict in the worker (2026-11-01)
Owner brief « Validation définitive V1-2.2 » (V1-2.2 VERIFIED at `c73415a`): V1-2.3 along the V1-2 contract §16.4.
Contract `.claude/tasks/contracts/2026-11-01-v1-2-3-worker-verification.md`, plan
`.claude/tasks/plans/2026-11-01-v1-2-3-worker.md`. Sandbox only; DEV untouched.
| Part | What | Where |
|---|---|---|
| M6 | `claim_sheet_verifications`, `get_sheet_verification_input`, `complete_sheet_verification`, `fail_sheet_verification`, service role only (claims checked too); the verdict checked for its binding (stale) and its structure (malformed), nothing written otherwise | `supabase/migrations/20261101100000_sheet_verification_jobs.sql`, pgTAP `021` (51) |
| Link | the worker links `faunosteo-core` (default features: no PDF, no curation); `version` prints the core version | `crates/worker/Cargo.toml` |
| Child | `verify`: framed stdin (`[u32 LE header length][header JSON][document][base][drawings]`), `compute_verdict`, verdict JSON out; same sandbox as `decode`, its own limits (12 MiB in, 3 MiB out under the 4 MiB SQL cap, 1 GiB, 60 s CPU, 90 s; container `mem_limit` 1 280 MiB so the child limit binds first); a frame the child cannot read is a broken parent (`frame_invalid`), never content | `verify_frame.rs`, `verify.rs`, `limits.rs` |
| Spawner | per command: `Spawner::for_decode` (unchanged values), `Spawner::for_verify`; a verify output counts only when it parses as a JSON object | `spawn.rs` |
| Mode | `run --jobs sheet-verify`: no sweep; drawings fetched under the archive caps, anything else passed without bytes for the core to name; §6.5 rows mapped to closed worker codes; watchdog stage `VERIFY` 95 s | `run.rs`, `verify_job.rs`, `backend.rs`, `http.rs` |
| Compose | service `worker-verify`, profile `worker`, same hardening as `worker` | `docker-compose.yml` |
Seccomp: the verify child at the caps was killed by SIGSYS in the Alpine stage; the derivation
(`derive-seccomp.sh`, extended to trace `verify --no-seccomp` on the clean and at-caps frames) traced `brk`
(musl mallocng growing the heap for the core's many small allocations) and nothing else new. `brk` was added to the
allowlist shared by both children; it only moves the program break, bounded by `RLIMIT_AS`. A filter per command
would keep `decode` without it, for more code: not done, listed for the owner.
Proofs (2026-11-01):
- `pnpm worker:test`: unit 28, `job_loop` 11 (unchanged), `verify_loop` 15, sandbox 23 under the full filter
(clean sheet passed, at-caps sheet within the limits, empty environment, over-cap input, malformed frame,
violation killed), derivation « allowlist covers the trace ». `pnpm worker:image` ok. `pnpm rust:check` green.
- `pnpm db:sandbox verify-e2e` (real worker container, gateway on the sandbox network, no host port): 7 tests,
cases a to h of the contract: clean equine draft opened (about 60 ms in the worker); `svg_not_canonical` and
`drawing_missing` with their exits; `no_geometry` and `out_of_frame`; no decision or publication without a current
passed verdict, then approval and publication after it; stale and malformed completions leave the round
byte-identical; avatar and purge rows untouched by the verification mode; the working copy verified in place on
the shared drawing object; the at-caps document (1 059 150 bytes of text, 129 groups) verified in 185 ms by the
worker, 842 ms from submission (budget 120 s), on a 10 × 10 drawing (on the horse frame its markers fail
`marker_too_small`, the rule working).
- Upgrade rehearsals on the sandbox: from the state before M6, and from the state before M4 (the DEV state, M4 to
M6 in one `migration up`): pgTAP 1 859 PASS, `verify-e2e` 7/7, `types --check` equal.
- Not measured: the largest input the policy allows (a 2 MiB document, its 2 MiB base and four drawings, 6 MiB).
- Hostile corpus: the 42 SVG files of `crates/core/tests/fixtures/svg/hostile` as the drawing of a submitted sheet,
each through the real `verify` child under the full filter (`the_hostile_svg_corpus_fails_verification_inside_the_sandbox`,
added after the verifier's review): every one a `failed` verdict with a `verification.integrity.svg_*` code, no
signal, no crash. `pnpm worker:test` then 24 sandbox tests.
Reviews (fresh, 2026-11-01, on `7043d39`):
- Security: PASS, semgrep 0 on the pinned rulesets. MEDIUM pre-existing hygiene (the throwaway sandbox account's
password literal in `scripts/db-sandbox.sh`). LOWs fixed: the verdict cap measured twice (child output now
3 MiB, under the 4 MiB SQL measure of `jsonb::text`); the child's 1 GiB address space above the container's
512 MiB (`worker-verify` and the sandbox worker now 1 280 MiB, so the child's limit binds first). LOWs open: no
backoff between attempts (closed afterwards by the owner decision of 2026-11-01: SQL delay of 2, 5, 10, 20 s, V1-2 contract §6.4; the finding as written on `7043d39` is left); a document naming several hundred
registered drawings overflows the 64 KiB frame header and is reported `resource_limit` instead of the core's
`caps` (wrong exit message, no security effect); SQL interpolation of generated ids in the sandbox test only.
- Verifier: ECARTS(2). W1-W5, W7 met. W6: the hostile corpus through the child was missing (added, above); `pnpm
e2e:avatar` « unchanged » not run: the script starts a worker against the DEV stack, which §16.4 (« no worker started on DEV ») and §16.11 forbid
without the owner, so it stays the owner's decision (the avatar loop is unchanged: `job_loop` 11 tests, and the
verification mode leaves avatar and purge rows untouched, e2e case f). W8: gates recorded below.
Gates on the final HEAD: see the closing line of this section.
Choices for the owner: worker codes, attempt limit five, lease 10 minutes, verdict caps (4 MiB in SQL, 3 MiB at the
child), service name
`worker-verify`, the shared `brk`, and that an object larger than the policy is passed without bytes (named
`drawing_missing` by the core, not `size_mismatch`).
Gates on the final code `6aa85fe` (2026-11-01): `pnpm check:all` passed (cargo 0 failed, 3 ignored: the one timing test
of §12.14 × 3 feature runs; e2e:ui passed; app image, `worker:test` 24 sandbox tests and the derivation, `worker:image`;
WASM 580 522 B gzip in the app image, unchanged by V1-2.3); `pnpm e2e:shell` 86 passed on the isolated sandbox;
`pnpm db:sandbox verify-e2e` 7/7. DEV untouched (the start times of its containers unchanged).
Second reviews on `6aa85fe`: verifier ECARTS(1), the one item owner-gated (`pnpm e2e:avatar`, a worker on DEV), the
hostile corpus met; security PASS (MEDIUM pre-existing sandbox password literal; LOWs: the 3 MiB / 4 MiB relation is
empirical, a refused verdict ending fail-closed `verdict_refused`; DEPLOY.md memory note, fixed).
### 13.1 Reserves Q3 and Q4: inputs at the caps, `brk` bounded (2026-11-01)
Contract `.claude/tasks/contracts/2026-11-01-v1-2-3-reserves.md`. Fixtures (`fixtures.rs`, `test-hooks`): `verify_max_frame()`,
also `fixture verify-max`: document and base of exactly 2 097 152 bytes (the `jsonb::text` spelling, `": "` and `", "`,
filler in `attribution.notes`; the core measures `document_bytes` 2 097 152), four drawings of 2 097 152, 2 097 152,
1 048 576 and 1 048 576 bytes (6 291 456 in all), a frame of 10 486 658 bytes. A drawing is the stored prolog, a 10 × 10
root, 10 000 `<path d="M0 0L5 5"/>` and a last path whose `d` ends in as many spaces as the size needs. Unit tests run the
core on each fixture: the maximum is `passed`; four drawings of 2 MiB (no base), five drawings, one drawing of 2 097 153
bytes and a document of 2 097 153 bytes are `failed` with `verification.validation.caps` (content, exit 0).
Through the full sandbox (`tests/sandbox.rs`, now 31 tests): `the_maximum_input_is_verified_within_the_limits` (`passed`,
verdict 2 531 bytes, under the 3 MiB cap and the 90 s deadline), `inputs_just_beyond_the_caps_fail_as_caps_through_the_sandbox`,
`the_verify_input_cap_is_exact` (a frame of exactly 12 MiB is read, here refused by the frame check; one byte more is refused
unread by the existing test). Measured on the development host, release build, glibc, sandbox applied: the maximum 104 ms,
the sheet at every other cap (2 118 765 bytes in, 24 689 out) 142 ms. The Docker `test` stage passes the same tests; its
log does not print the timings (captured output).
`brk` in the verify child (`tests/sandbox.rs`, 1 GiB address space): `--alloc-gib 2` and the new hook
`--alloc-small-gib <n>` (4 KiB chunks kept alive, the small-allocation path) both end in SIGABRT and the survival
message never appears; `--mmap-exec` and `--signal-parent` die with SIGSYS; `--violate` was already covered. The CPU and
deadline hooks stay on the decode child. No syscall added to `ALLOWED_SYSCALLS`.
Derivation: `derive-seccomp.sh` also traces `fixture verify-max` through `verify --no-seccomp`; the traced set is
unchanged (`brk exit_group getrandom mmap mremap munmap read write`), the allowlist covers it.
The two misclassifications stay tracked, not fixed (`tests/verify_loop.rs`): a frame header over 64 KiB is reported
`resource_limit`; an object over the policy is passed without bytes and the verdict lists `caps` then `drawing_missing`
(its declared size already exceeds the cap), never `size_mismatch`.
Reserves Q1, Q2, Q5 and the gates (2026-11-01). The avatar suite runs on the throwaway stack through
`pnpm db:sandbox avatar-e2e` (the real worker in its default mode, 5 tests), never on DEV; the sandbox's throwaway
accounts get random passwords per run. M6 amended in place (applied nowhere but the sandbox): a technical failure is
claimable again after 2, 5, 10 then 20 s (`not_before`, hidden from `authenticated`), the worker never sleeps; sandbox
case `i` measured the real worker taking the round 10.8 s after a failure at attempt 3 while it opened another round
meanwhile; cases `j` and `k` take the caps through the real worker (document 2 097 152 bytes and a 2 MiB base with
6 291 456 bytes of drawings: passed, worker 156 ms and 191 ms; one byte beyond refused at save, registration and bucket;
over the total or the count: `caps`). Security review PASS; its MEDIUM (a null lease token matched an unleased round
through `is distinct from`, service role only) fixed in the three round RPCs, pgTAP 021 at 72. On the final M6:
sandbox `test-db` 1 880 PASS, `types --check` equal and `verify-e2e` 10/10 on a fresh stack and on the upgrades from
before M6 and from before M4 (the DEV path); `avatar-e2e` 5/5; `test` 87 and `e2e:shell` 86 (rerun on the final M6
after the verifier's ECARTS(2): the earlier run predated the fix); DEV untouched.
Retry by effective cause (owner brief 2026-11-01, closure C1). SQL holds the code policy
(`private.sheet_worker_final_codes`: `resource_limit`, `verdict_refused` close the round at the first
occurrence, `closed_by` `definitive` in the audit; the others retry 2, 5, 10, 20 s up to five attempts,
`closed_by` `attempt_limit`); the worker maps the cause to the code (`verify_job::classify_child`,
`signal_code`), as implemented:
| Child end | Code | Policy |
|---|---|---|
| frame refused by the parent (header over 64 KiB) | `resource_limit` | definitive |
| `Rejected` (input over the child cap) | `resource_limit` | definitive |
| `OutputOverflow` | `resource_limit` | definitive |
| SIGXCPU (CPU budget; the hard limit is two seconds after the soft one, so the budget shows as SIGXCPU) | `resource_limit` | definitive |
| SIGABRT (memory budget, abort) | `resource_limit` | definitive |
| SIGSYS (seccomp filter) | `resource_limit` | definitive |
| SIGKILL or any other signal (OOM killer, stop: from outside; the parent's own kills are `Timeout` and `OutputOverflow`) | `unavailable` | transient |
| `Timeout` (wall clock) | `timeout` | transient |
| transport, Storage | `unavailable` | transient |
| `Broken`, `Failed` | `unavailable`, then the worker stops | transient |
| verdict answered `malformed` | `verdict_refused` | definitive |
| dead lease | `lease_expired` (set by the claim) | transient, immediate |
What changes for the codes: a SIGKILL is now reported `unavailable` (it was `resource_limit`); the
outcome (`unavailable`) and the code list are otherwise unchanged. A definitive round closes after one
child run instead of five identical ones. Still tracked and open: the header over 64 KiB is reported
`resource_limit` where `caps` would name it (test `tracked_a_header_over_64_kib_is_reported_resource_limit`).
Closure adjustments (owner brief « Validation V1-2.3 (M6) et derniers ajustements », 2026-11-01). `pnpm e2e:avatar` is
the alias of `pnpm db:sandbox avatar-e2e` and `scripts/avatar-e2e.sh` is removed: the suite throws at load unless its
URL is `http://127.0.0.1:57800`, its database container `faunosteo_dbsandbox_db` and both keys carry the sandbox's
issuer `db-sandbox`; an occupied port 57800 stops the run before anything starts. The sandbox gives its seeded
accounts a per-session secret after seeding (GoTrue, body on stdin), so no sandbox test uses the DEV seed password.
`fail_sheet_verification` refuses `lease_expired` (the claim's own record). Targeted review (retry policy, command
isolation): PASS; accepted and open: a document needing about 60 s CPU under host contention can reach the 90 s wall
deadline first and be retried as `timeout` (at most five runs, no publication effect); SIGABRT also covers a child
panic and a host ENOMEM, both closed `resource_limit`; a verdict bound to another round with a valid token answers
`stale` and waits for the lease. Gates on `3c141c9`: `check:all`, sandbox `test-db` 1 898 PASS, `types --check`,
`test` 87, `verify-e2e` 10/10, `e2e:avatar` 5/5, `e2e:shell` 86; DEV untouched.