From 0279953e9efda0780cb9aa4d1da791d1305e5acb Mon Sep 17 00:00:00 2001 From: bchanot Date: Thu, 15 Oct 2026 17:58:11 +0200 Subject: [PATCH] feat(editor): a clear final state once the engine spent its three recoveries (canvas and action alerts) --- .claude/memory/decisions.md | 6 ++++++ .claude/memory/journal.md | 1 + .claude/tasks/TODO.md | 1 + CHANGELOG.md | 2 +- apps/app/src/anatomy/drawing.ts | 9 ++++++--- apps/app/src/app/routes/EditorRoute.tsx | 9 +++++---- apps/app/src/app/routes/NewReportRoute.tsx | 3 ++- .../src/components/canvas/AnatomyCanvas.tsx | 11 +++++++--- .../observation/ObservationCard.tsx | 3 ++- .../observation/ObservationPickers.tsx | 3 ++- .../components/observation/VertebraPicker.tsx | 3 ++- apps/app/src/core/failure.ts | 11 ++++++++++ apps/app/src/core/runtime.ts | 5 +++++ apps/app/src/i18n/en.ts | 2 ++ apps/app/src/i18n/fr.ts | 2 ++ .../unit/components.AnatomyCanvas.test.tsx | 20 +++++++++++++++++++ docs/development/RUST.md | 6 +++++- packages/core-wasm/src/runtime.ts | 8 ++++++++ packages/core-wasm/tests/runtime.test.ts | 12 +++++++++++ 19 files changed, 101 insertions(+), 16 deletions(-) create mode 100644 apps/app/src/core/failure.ts diff --git a/.claude/memory/decisions.md b/.claude/memory/decisions.md index de3b100c..cdb45cc2 100644 --- a/.claude/memory/decisions.md +++ b/.claude/memory/decisions.md @@ -418,3 +418,9 @@ Status: closed (merged aab61c2). Plan rev 2 after 3 challengers (32 findings). Reader = prescan (markup state machine, caps before parse: 2 MiB, BOM, DOCTYPE, depth 64, 20k elements, attrs 256/100k, 16 xmlns, raw `<` 100k `=` 200k) → roxmltree 0.21.1 → own tree (qualified names as written, TS allowlist parity) → allowlist + declared extras (SVG ns only, comments dropped, text only title/desc ≤ 4 KiB, root without class/style/transform/filter/mask/clip-path, id grammar, href/url( local only after ASCII/CSS whitespace) → reference graph (cycles refused, expansion ≤ 50k) → serialiser (control whitespace as char refs, output ≤ 4 MiB). Product drawing with any removal refused at load (LRN-055). Facade: only `view.canvas {viewId}` (stateless, memoised per view; data-state still restyled in place). Highlight composition = core fn proven vs TS (O3), no facade op until R4 (snapshot-based call). Behaviour = code where ANNOTATION-RENDERING.md differed (doc rewritten first). Canvas failure → existing degraded notice + retry. Alt rejected: roxmltree alone with nodes_limit (recursion overflows wasm stack, measured); `svg.sanitize` / `view.highlighted` ops now (no consumer, wrong source for R4); states in the canvas op (dead: restyle runs after every build); dangling-ref removal (rendering change); duplicate-id refusal; property tests (no generator crate). Status: active; R3 awaiting owner validation, not merged. + +## BDR-054 | 2026-10-15 | R3 owner UX decisions: trigger names per language, three canvas failure states, retry policy + +Owner validated after R3 review: (1) unnamed trigger → `data-anno-name-fr`/`-en` + title take opened view name per language, empty language falls back to other; display only (not identifier, not persisted); frozen oracles untouched, tests apply declared change (`with_trigger_names_per_language` / `withTriggerNamesPerLanguage`, MAKE refused). (2) canvas failures distinct: engine (core_unavailable, internal) → `sheet.core_unavailable` + Réessayer (fresh instance may succeed); view (svg_rejected, no_asset, unknown_view, invalid_character, parse) → `canvas.view_unavailable`, no retry; detail in core outcome + DEV console only. (3) recovery cap 3 kept; after it `CoreRuntime.stopped` → `core.stopped` ("reload the page, report kept in tab") in canvas and in the 8 action alerts (`coreFailureMessage`), no retry. Wording of the three messages accepted. +Alt rejected: correcting the TS renderer too (engine/pipeline frozen until R4/R5; invisible in PDF: data-* dropped, title not rasterised); retry for deterministic view failures; editing goldens. +Status: closed (decisions); R3 still awaiting owner LAN confirmation, not merged. diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index 1bf7e535..27ece440 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -266,3 +266,4 @@ Owner brief: maintenance before R3. bugfix/r2-maintenance: rustls 0.23.46 (4 adv feature/rust-r3-anatomy-core: plan rev 2 after 3 challengers (32 findings; blocker = roxmltree recursion, measured overflow < 3,000 levels on 1 MiB → markup prescan before any parse). Freeze first: O1 canvas trees, O2 layer order, O3 36 highlights, O4/O5 36 hostile + 10 floods + 4 product SVGs, Chromium refs. Rust reader (prescan, tree, allowlist, reference graph, serialiser), layer, canvas/highlight compose, `view.canvas`; app canvas switched, denylist + anatomy dep deleted. All oracles green, mutation-checked; Chromium DOM = O1, 30/30 pixel-identical; module 396 KB gz (+56). check:all green. Gates dispatched; stop for owner validation, no merge, no R4. - Same day: gates. Verifier CONFORME 11/11. Security PASS + MEDIUM (prescan closer searched inside its opener, `` hid 5,000 levels → stack overflow) fixed; pass 2 PASS (4M differential docs) + LOW url( whitespace fixed; verifier re-run CONFORME. Final check:all green, Chromium 30/30 identical. BDR-052/053, LRN-056, EVAL-022. Stop: owner LAN validation. - 2026-10-15 owner UX decisions on R3: unnamed trigger names per language (contract doc first, Rust layer, declared change applied to frozen oracles, goldens untouched); canvas engine failure (retry) vs view failure (own message, no retry). check:all green, Chromium 30/30 identical + DOM = O1 (declared), verifier CONFORME 8/8, security PASS 0 findings. Owner LAN tests in progress; no merge, no R4. +- 2026-10-15 owner validated both UX fixes + retry on internal; asked 3-attempt cap then clear failure state: found canvas + 8 alerts would still offer retry after cap → `CoreRuntime.stopped` + `core.stopped` message, no retry. BDR-054. R3 not merged (LAN tests pending). diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index 5368e00e..ee42263c 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -199,6 +199,7 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo - [x] R3.6 gates: verifier CONFORME 11/11 ×2; security PASS ×3 (MEDIUM prescan closer desync + 3 LOW fixed: href/url( Unicode spaces, root painting attrs); check:all green 1 min 56 s; Chromium final 30/30 identical, DOM = O1 - [ ] R3 owner validation (LAN: TEST FONCTIONNEL + TEST GRAPHIQUE), then merge on the owner's go; R4 not started - [x] R3 owner decisions 2026-10-15: unnamed trigger names per language (6882c6d, contract d8e9bd3); canvas engine failure (retry) vs view failure (no retry) (c0a5c8c) + - [x] R3 owner follow-up 2026-10-15: retry kept for `internal`; after the 3 recoveries a clear final state (`core.stopped`) in the canvas and the action alerts, no retry (BDR-054) - [ ] 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 - [ ] R5 curation pipeline + importer + upload tool: seed golden regenerated once (new `documentSha256`, D-R5), `packages/anatomy` + `packages/domain` deleted, docs map; all before Step 13 diff --git a/CHANGELOG.md b/CHANGELOG.md index fcfaa659..80addde8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ Versions follow [Semantic Versioning](https://semver.org/). - **No visible change**, proven first with the TypeScript: canvas trees of both views and 28 selection states, layer trees with attribute order, 36 PDF highlight compositions, 36 hostile SVGs and 10 generated floods, the 4 product SVGs untouched; in Chromium 156 the live canvas trees equal the frozen ones and 30 screenshots (desktop and phone) are pixel-identical before and after. The Step 6 goldens are untouched. - Declared differences, none on a product drawing: elements outside the SVG namespace removed, comments dropped, no `class`/`style` on the inline root, stricter ids, text only in `title`/`desc` (4 KiB each), floods and reference cycles refused, a product drawing the allowlist would alter refused at load instead of silently cut, a canvas that cannot be composed shows the existing degraded notice with a retry (`docs/development/RUST.md` §9.4). - `docs/ANNOTATION-RENDERING.md` rewritten to describe the code exactly (no rendering change). Module 396 KB gzip (+56 KB, budget 600 KB). -- Owner decisions after the R3 review: a detail-view trigger without its own name now carries the opened view's name in each language (the English attribute and the tooltip title used to repeat the French name); the canvas tells an engine that did not load ("Réessayer") from a view whose drawing is refused or cannot be composed (its own message, no retry). +- Owner decisions after the R3 review: a detail-view trigger without its own name now carries the opened view's name in each language (the English attribute and the tooltip title used to repeat the French name); the canvas tells an engine that did not load ("Réessayer") from a view whose drawing is refused or cannot be composed (its own message, no retry); after its three recoveries the engine shows a clear final state (reload the page, the report is kept in the tab) in the canvas and in the action alerts, never a retry that cannot work. ### Security (maintenance after R2, 2026-10-14) diff --git a/apps/app/src/anatomy/drawing.ts b/apps/app/src/anatomy/drawing.ts index 6c68f57e..72786d1b 100644 --- a/apps/app/src/anatomy/drawing.ts +++ b/apps/app/src/anatomy/drawing.ts @@ -1,3 +1,4 @@ +import { coreStopped } from '@/core/runtime' import type { SheetIndex } from '@/services/sheetIndex' /** @@ -10,11 +11,12 @@ import type { SheetIndex } from '@/services/sheetIndex' export type ViewStates = ReadonlyMap /** - * Why a view cannot be drawn: the engine did not run (a retry may succeed), or the view + * Why a view cannot be drawn: the engine did not run (a retry may succeed), the engine + * stopped after its three recoveries (only a reload starts it again), or the view * itself cannot be drawn (a refused drawing, a view the core cannot compose: retrying * changes nothing). The technical kind stays in the core's outcome and the DEV console. */ -export type ViewFailure = 'engine' | 'view' +export type ViewFailure = 'engine' | 'engine_stopped' | 'view' export type ViewBuild = { ok: true; svg: SVGSVGElement } | { ok: false; failure: ViewFailure } @@ -28,7 +30,8 @@ function failed(failure: ViewFailure, kind: string, detail?: string): ViewBuild export function buildViewSvg(index: SheetIndex, viewId: string): ViewBuild { const text = index.canvasSvg(viewId) if (!text.ok) { - return failed(ENGINE_KINDS.has(text.kind) ? 'engine' : 'view', text.kind, text.detail) + const engine = coreStopped() ? 'engine_stopped' : 'engine' + return failed(ENGINE_KINDS.has(text.kind) ? engine : 'view', text.kind, text.detail) } const parsed = new DOMParser().parseFromString(text.value, 'image/svg+xml') const root = parsed.documentElement diff --git a/apps/app/src/app/routes/EditorRoute.tsx b/apps/app/src/app/routes/EditorRoute.tsx index 81b39d0e..4e70e053 100644 --- a/apps/app/src/app/routes/EditorRoute.tsx +++ b/apps/app/src/app/routes/EditorRoute.tsx @@ -36,6 +36,7 @@ import type { ExportWarning } from '@faunosteo/pdf' import type { RebaseOutcome } from '@faunosteo/core-wasm/types' import { useT } from '@/i18n/useT' import { DEFAULT_SPECIES_ID } from './NewReportRoute' +import { coreFailureMessage } from '@/core/failure' const DISCLAIMER_FLAG = 'osteo:disclaimer-shown' @@ -161,7 +162,7 @@ export default function EditorRoute() { const activeObs = activeIndex >= 0 ? report.observations[activeIndex] : undefined const outcome = sheet.index.ops.zoneClick(activeObs ?? null, annotationId) - if (!outcome.ok) return window.alert(t('core.action_failed')) + if (!outcome.ok) return window.alert(coreFailureMessage(t)) const click = outcome.value if (click.observation) store.updateObservation(activeIndex, click.observation) switch (click.kind) { @@ -189,7 +190,7 @@ export default function EditorRoute() { /** A store action the core ran: the practitioner hears about a failure. */ const guarded = useCallback( (result: ActionResult) => { - if (!result.ok) window.alert(t('core.action_failed')) + if (!result.ok) window.alert(coreFailureMessage(t)) }, [t], ) @@ -198,7 +199,7 @@ export default function EditorRoute() { function openVertebraPicker(index: SheetIndex, zoneIndex: number) { if (!activeObs) return const outcome = index.ops.vertebraInitial(activeObs, zoneIndex) - if (!outcome.ok) return window.alert(t('core.action_failed')) + if (!outcome.ok) return window.alert(coreFailureMessage(t)) setVertebraTarget({ zoneIndex, initial: outcome.value }) } @@ -207,7 +208,7 @@ export default function EditorRoute() { if (!obs) return const outcome = index.ops.removeZoneAt(obs, zoneIndex) if (outcome.ok) store.updateObservation(i, outcome.value) - else window.alert(t('core.action_failed')) + else window.alert(coreFailureMessage(t)) } function acknowledgeDisclaimer() { diff --git a/apps/app/src/app/routes/NewReportRoute.tsx b/apps/app/src/app/routes/NewReportRoute.tsx index 9f7b339b..c3cf55ea 100644 --- a/apps/app/src/app/routes/NewReportRoute.tsx +++ b/apps/app/src/app/routes/NewReportRoute.tsx @@ -15,6 +15,7 @@ import { import { useReportStore } from '@/state/reportStore' import { loadSheetIndex, useSheetAvailability } from '@/sheets/useSheet' import { useT } from '@/i18n/useT' +import { coreFailureMessage } from '@/core/failure' /** The one species this build ships a sheet for. */ export const DEFAULT_SPECIES_ID = 'equine' @@ -71,7 +72,7 @@ export default function NewReportRoute() { else if (created.reason === 'held') { window.alert(t('session.held_blocked')) navigate('/editor') - } else window.alert(t('core.action_failed')) + } else window.alert(coreFailureMessage(t)) } return ( diff --git a/apps/app/src/components/canvas/AnatomyCanvas.tsx b/apps/app/src/components/canvas/AnatomyCanvas.tsx index 0bdd17bd..527eed4c 100644 --- a/apps/app/src/components/canvas/AnatomyCanvas.tsx +++ b/apps/app/src/components/canvas/AnatomyCanvas.tsx @@ -17,6 +17,13 @@ export interface AnatomyCanvasProps { const ANNOTATED = '[data-anno-id]' +/** Only an engine that can still recover offers a retry. */ +const FAILURE_MESSAGE: Record = { + engine: 'sheet.core_unavailable', + engine_stopped: 'core.stopped', + view: 'canvas.view_unavailable', +} + function annotatedTarget(event: Event): Element | null { const target = event.target return target instanceof Element ? target.closest(ANNOTATED) : null @@ -133,9 +140,7 @@ export default function AnatomyCanvas({ {failure && (
- - {t(failure === 'engine' ? 'sheet.core_unavailable' : 'canvas.view_unavailable')} - + {t(FAILURE_MESSAGE[failure])} {failure === 'engine' && (