From ac2a3bc41bcdd2cb54b286c4035b531eec41cf35 Mon Sep 17 00:00:00 2001 From: bchanot Date: Sun, 18 Oct 2026 04:42:53 +0200 Subject: [PATCH] chore(memory): R4 plan validated by the owner (BDR-057, LRN-059, LRN-060) --- .claude/memory/decisions.md | 7 +++++++ .claude/memory/learnings.md | 12 ++++++++++++ .claude/tasks/TODO.md | 2 +- .../plans/2026-10-17-rust-r4-pdf-core.md | 19 ++++++++++++++++++- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.claude/memory/decisions.md b/.claude/memory/decisions.md index 3bfa4c10..fc434640 100644 --- a/.claude/memory/decisions.md +++ b/.claude/memory/decisions.md @@ -436,3 +436,10 @@ Status: closed; R3 still awaiting owner LAN confirmation, not merged, R4 not sta Owner brief 2026-10-16 + AskUserQuestion: (1) Home import also takes JSON rescue copy: sniff first KiB (`%PDF-` → PDF; `{` / .json → copy), cap MAX_ATTACHMENT_BYTES 16 MiB before read, fatal UTF-8, pure `readRescueCopy` → core `draft.restore` (no JS parse), then existing hydrateImport branch; UNREADABLE_DRAFT_KINDS → `invalid_copy`. (2) `internal` reading draft → held `engine_failure` row (+ archive companion), `TrapMemory` keyed on (draft, archive) pair: no re-read by mount / New report / Import, only panel Retry (`retryTrapped`); any discard clears; `held_blocked_engine` alert. SUPERSEDES BDR-055 "never held" for `internal` only (`core_unavailable` etc. stay FAILED). (3) ReplaceSessionDialog (Annuler / Ouvrir le bilan en cours / Remplacer, copy when unsaved) on New report submit + Home pick when report in memory or draft slot; Home picker clicked synchronously. (4) `useUnsavedGuard` once in App. Commit 9bd9aca. Alt rejected: new store action openCopy (dup of hydrateImport, session change before validation); JS JSON.parse of copy (depth; core reads raw text); copy cap MAX_PDF_BYTES (50 MiB file cap, not JSON bound); trapped memory on draft text only (archive parsed in same call); fixing GC finalizer via glue internals. Status: closed; R3 awaiting owner LAN validation, not merged, no R4, release 0.2.0 untouched. + +## BDR-057 | 2026-10-18 | R4 plan validated: module workers, incremental export in main instance, JSON memory guard gated at R4.2 + +Context: R4.0 plan rev 2 (`.claude/tasks/plans/2026-10-17-rust-r4-pdf-core.md`: options §A.2, conditions §A.6), 3 challengers, owner approval 2026-10-18. +Decision: OD-1 module workers everywhere; import needs Firefox 114 (today it already needs DecompressionStream: Firefox 113, Safari 16.4); import support documented per browser apart from app support, from real checks. OD-2 incremental ExportSession in main instance: PDF + one decode ≈ 0.37 MB/view vs TS ≈ 3.8 MB/view (RGB planes held until save) vs two calls ≈ 0.91; offline export kept; cleanup on error/cancel. OD-3 JSON value budget in linear pre-scan + module `--max-memory`, thresholds from R4.2 reproducible measurements; not shown → stop before R4.3 import switch. OD-4 overwritten duplicate key holding lone surrogate refused, file untouched. OD-5 PDF crash/timeout `error_generic`, copy crash/timeout `error_core_unavailable`, kinds keep technical / resource / invalid apart. OD-6 J1 matrix exact, unrun device never reported validated. OD-7 ~5 MB fixtures, no real data in git. +Alt rejected: classic iife worker for Firefox 102-113 (dev/prod split for dead versions); two-call export (all PNGs in linear memory); disposable export worker (asset fetched at export breaks offline, protocol cost); throwaway main-thread instance (glue retains instances, LRN-060); own lossless JSON reader (R2 rejection holds). +Status: active. Order: plan merge → Safari download bugfix (owner validation) → feature/rust-r4-pdf-core → R4.1. diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md index ae4ed225..ac0d7a1d 100644 --- a/.claude/memory/learnings.md +++ b/.claude/memory/learnings.md @@ -454,3 +454,15 @@ Apply: R4 PDF worker failure states, Step 8 avatar upload errors, any capped ret - User text into i18n templates: `.replace(re, () => value)`; string replacement expands `$&`/`$'`. - Picker opened from a confirm dialog: call `input.click()` synchronously in the confirm handler (user activation, WebKit). Apply: any export/backup feature, R4 PDF reader worker failures, Step 13 uploads. + +## LRN-059 | 2026-10-17 | Rust `from_utf8_lossy` matches TextDecoder; serde_json differs from JSON.parse on overflow and surrogates + +- `String::from_utf8_lossy` after stripping one BOM = `new TextDecoder().decode()` (non-fatal): 200,015 random + edge byte strings (overlong, UTF-8 surrogates, truncated, double BOM), 0 diff. Parity holds on tested sequences, not proven in general. +- JSON.parse vs serde_json: `1e400` → JS Infinity (JSON.stringify writes `null`), serde_json "number out of range"; lone surrogate escape kept by JS, refused by serde_json; duplicate key last value at first position in both (preserve_order). A JS path that did parse → stringify has side effects (overflow → null, dropped duplicates): reproduce them or declare them. +Apply: Rust ports of JS readers of untrusted text (R4 PDF reader, Step 13 uploads, Step 15 server validation). + +## LRN-060 | 2026-10-17 | wasm-bindgen glue retains its instance until reload; only a terminated worker frees linear memory + +- `--target web` glue keeps the instance in module scope (`let wasm`, `__wbg_finalize_init`); ES module records are never unloaded, so each fresh glue import (`?instance=n`) keeps its old instance and memory (BLK-012: dead instances retained until reload). Linear memory never shrinks. +- Memory-heavy one-shot work: reuse the long-lived instance (high-water kept until reload) or run in a Worker terminated after (everything freed). A "disposable instance" on the main thread is a leak, not a release. +Apply: R4 import worker and export placement, any future in-browser wasm batch job. diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index 83191a9b..6269cea8 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -204,7 +204,7 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo - [x] R3 final checks 2026-10-17 (owner brief 2026-10-16): rescue copy importable from Home, trapping draft held (no reload loop), replace confirmation, guard app-wide → 9bd9aca (BDR-056, BLK-012); verifier CONFORME 10/10, security PASS, check:all green; residuals in BLK-012 - [ ] R3 follow-ups kept by the owner (2026-10-15): worker TLS exercised against a real HTTPS endpoint before the deployment that needs it; roxmltree limits + SVG prescan (pin the iterative release when published); Firefox/WebKit check; SVG references across drawings scoped per view before community uploads (Step 13); WASM size margin (396 of 600 KB) before R4; TypeScript PDF sanitiser still present until R4 - [ ] R4 pdf core: reader (Web Worker, BLK-009 browser measurements) + writer (`pdf-writer`, Std14 AFM, draw log; lines/rects/colours golden frozen with the TS engine first, D-R2) + `report-compare` tool; `packages/pdf` deleted; N-1 scanner reads R4 PDFs - - [x] R4.0 plan (owner go 2026-10-17, arbitrations A1-A13): `.claude/tasks/plans/2026-10-17-rust-r4-pdf-core.md` rev 2 after 3 challengers (correctness 6 major, robustness 10 major, simplicity 3 major; none fatal) on chore/rust-r4-plan; Playwright Firefox 157 installed + proven, WebKit 27.2 downloaded (owner: `sudo apt-get install libevent-2.1-7t64 libmanette-0.2-0`); awaiting owner validation + OD-1..OD-7; no code + - [x] R4.0 plan (owner go 2026-10-17, arbitrations A1-A13): `.claude/tasks/plans/2026-10-17-rust-r4-pdf-core.md` rev 2 after 3 challengers (correctness 6 major, robustness 10 major, simplicity 3 major; none fatal) on chore/rust-r4-plan; Playwright Firefox 157 installed + proven, WebKit 27.2 downloaded (owner: `sudo apt-get install libevent-2.1-7t64 libmanette-0.2-0`); validated by the owner 2026-10-18 with conditions (plan §A.6, BDR-057) - [ ] after validation: finish chore/rust-r4-plan into develop (owner signal), Safari PDF download fix (separate bugfix, owner go), then cut feature/rust-r4-pdf-core - [ ] R4.1 freeze (O1-O13, ledger, browser harness, TS baselines) - [ ] R4.2 reader (cargo + wasm, differential, OD-3 thresholds confirmed with owner before R4.3) diff --git a/.claude/tasks/plans/2026-10-17-rust-r4-pdf-core.md b/.claude/tasks/plans/2026-10-17-rust-r4-pdf-core.md index 514cc32a..508fb40f 100644 --- a/.claude/tasks/plans/2026-10-17-rust-r4-pdf-core.md +++ b/.claude/tasks/plans/2026-10-17-rust-r4-pdf-core.md @@ -3,7 +3,7 @@ - date: 2026-10-17 | rev 2 (after 3 plan challenges: correctness CONCERNS (6 major, 8 minor), robustness CONCERNS (10 major, 12 minor), simplicity CONCERNS (3 major, 9 minor); log in §B.12) | branch: `chore/rust-r4-plan` (plan only); code later on `feature/rust-r4-pdf-core`, one merge - spec: owner briefs 2026-10-17 "Préparation de R4" and "Autorisation de préparation R4.0" (arbitrations A1 to A13, §A.0); `docs/development/RUST_ARCHITECTURE_REVIEW.md` I.2, II.2 rows "pdf reader", "pdf writer", "report-compare", III.3, VI.1 to VI.4, D-R2, D-R3, D-R11, D-R12, D-R14; `RUST.md` §8.3, §8.7, §8.8, §9.4, §9.7; `PDF_IMPORT_HARDENING.md` §5; BLK-009, BLK-012; CLAUDE.md "PDF", "Schemas", archive-reader gate - facts: Annex (inventory, measurements and experiments of 2026-10-17) -- status: R4.0 only. No code and no fixture generated; R4.1 starts on the owner's explicit go. +- status: validated by the owner 2026-10-18 with conditions (§A.6). R4.1 may be prepared once the plan branch is merged, the Safari fix has merged and `feature/rust-r4-pdf-core` is cut from the updated develop. - not in scope: TTF fonts, `scope_disclaimer`, the planned collection caps, opening the import to external users (BDR-040 gate stays open), R5 (pipeline, `packages/anatomy`, `packages/domain`, `documentSha256`), the Safari download fix (separate bugfix), release 0.2.0, any deployment, any visible change on the documented browsers. # Part A. For the owner @@ -50,6 +50,23 @@ The application reads and writes archives with Rust only. An import, PDF or resc WebKit on this machine: `sudo apt-get install libevent-2.1-7t64 libmanette-0.2-0` (Firefox 157 and WebKit 27.2 for Playwright are downloaded; Firefox runs headless with workers and wasm). The go for the Safari download fix. Real PDFs, if any (§B.5.2). +## A.6 Owner validation (2026-10-18) + +OD-1 to OD-7 approved as recommended in A.2 (BDR-057), with these conditions, binding on the slices: +- OD-1: module workers, no second implementation for old versions. The import's support per browser is documented apart from the application's support, from real capability checks (P-W1, J1). +- OD-2: incremental export with bounded memory, cleanup on error and cancellation, offline export kept; release proven at R4.6 on success, error, cancellation and recovery. +- OD-3 (conditional): R4.2 sets the resource budgets from reproducible measurements covering upstream allocations (file buffer, inflation, decoded text, value tree), wasm linear memory, JavaScript objects (transfers, result parse), decoded images and the browser's peak (content-process RSS). If a budget cannot be shown or the preventive caps are insufficient: stop before R4.3 wires the import and present the results. A resource error never alters the original PDF, the bilan or the archives. +- OD-4: the overwritten-duplicate lone-surrogate case is refused; no JSON reader of our own; the source file stays intact, nothing is dropped silently. +- OD-5: messages as proposed; the outcome kinds keep technical errors, resource exhaustion and invalid files apart. +- OD-6: the J1 matrix of A.4 exactly; a device or browser not actually run is reported as not run, never as validated. +- OD-7: about 5 MB of fixtures; no real professional or confidential data in git (B.5.2). +- The A.3 differences stay under the oracles and are reported explicitly at each checkpoint; no other silent difference. +- The harness's 4 GiB RSS watchdog is not a guaranteed memory limit: every result that relies on it says so. +- Proofs owed in the slices, never assumed: png crate tolerance on historical files (R4.5, O6), loading the module in the worker per engine (R4.3), memory on hostile files (R4.2, R4.3, J1), incremental export without image accumulation (R4.6), v2/v3 compatibility (R4.2, R4.5), visual rendering (R4.5, final acceptance), import and export on the J1 browsers (J1, final acceptance), data kept when the engine fails (R4.3, R4.6). +- Goldens stay references, never regenerated to hide a regression; the TS engine is deleted only after parity is proven and every consumer has switched (R4.8). +- Checkpoint reports give concrete results, not plan repetition, and list the functional and graphical validations available. Manual priorities: FR and EN export, anatomical views and markers, a v3 import, real historical v2 PDFs, attachments and kept data, wrong and large files, the targeted browsers and phones. +- Order: R3 closed (checked 2026-10-18: merge 8df964b on develop, branch deleted locally and on origin); this plan merged; the Safari fix on a short branch, tested, merged after the owner's validation; `feature/rust-r4-pdf-core` from the updated develop. WebKit packages installed by the owner, then workers, wasm, imports, exports and memory protections checked on WebKit; WebKit results never replace a manual iPhone run. LAN DEV access kept. Excluded: R5, any deployment or production change, release 0.2.0, any graphical redesign. + # Part B. The plan ## B.1 Architecture and contracts