feat(viewer,renderer): measurement and snapping over released geometry via readback (#10264, release off)

Merged
LO
9d ago
+1463-70

Stacked on #10876 → #10868. This is #10264 readback stage 3: measurement and snapping keep working after a (test-only) CPU-geometry release. Product release stays disabled.

Validation at 752dbb4b76 (main merged at 7870793c0e, 2026-11-20)

  • Queue head c88f1014b6 = 752dbb4b76 + main at 2d54af0de6 (#11038 entry ceiling). The 7 main commits since 7870793c0e touch no file this PR changes (export, backups, CI probe, tests). The validation above stands; the merge queue retests on current main. Revert oracle applies on c88f1014b6.
  • full viewer suite: 4 shards, 25,236 tests, 0 failed (362 skipped), on 752dbb4b76 (fleet request auto-f1292a0d). In the same job: root build, API surface and root typecheck exit 0, all pre-handoff gates exit 0 (revert oracle included), and renderer tests 2,925 with 0 failed.
  • Real-GPU release spec (geometry-backing-release, Pop RTX via Xvfb/Vulkan): 3/3 on 752dbb4b76 in two runs, and 3/3 on 742f09b330, 5a04392fa1 and 3b417758a5. One earlier run on 752dbb4b76 had AC20-FZK-Haus probe 14 return unavailable (fail-closed, no hit or snap) where resident hit entity 31470. It did not reproduce in four further runs. It is recorded as an intermittent refusal to investigate (follow-up); it is never a wrong answer.
  • Perf ratchet: entry 2,003,490 bytes against the old allowance of 2,002,098. It fits the reset ceiling in #11038 (allowed about 2,004,032).

What

  • Renderer (published, minor changeset and guide section): Renderer.setReadbackRaycastMeshes(meshes | null). The pieces join raycastScene / raycastSceneMagnetic candidates under the same hide/isolate and section-clip rules. The host places and owns them; null clears them. Callers that never set any see no change.
  • geometry-readback.ts is the shared, bounded access layer for every later consumer PR.
    • leaseEntityGeometry, leaseRegionGeometry, modelGeometry.
    • Resident meshes are answered from memory, unchanged.
    • Released meshes (emptied but still counting triangles) are answered only from a current, complete backing. Anything else is GeometryUnavailableError, never an empty or zero answer.
  • ReadbackRaycastFeeder:
    • GPU-picks the entity under the pointer (S1 batch pick, which works on released scenes).
    • Leases that entity plus the backed chunks within ±1 m of the hit. The hit is moved from the placed frame to the model-local frame using the scene's own placement.
    • Places the pieces through placeAppearanceSource and feeds only entities the scene draws. The store also holds type-filtered spaces, openings and class-2 templates; feeding those made the first GPU run hit the wrong entity.
    • Byte-capped. A newer pointer position cancels an older prefetch. Pieces are dropped when the model list or content version changes.
    • An instanced or unbacked front surface is refused (unavailable), never measured through to whatever is behind it.
  • Measure hover: unchanged while resident. Once the scene reports a release, it lazily loads the readback module, prepares, then runs the same magnetic raycast or point pick.
  • Test-only debug command snap-probe-for-test, used by the GPU spec.

Evidence (head 97ac1a02)

  • Node: feeder/readback 6/6, the backing set and existing measure suites: 44 viewer tests, 0 failures. Covered:
    • a resident scene is never fed
    • neighbourhood in the model frame, with drawn entities only
    • incomplete and stale backings are refused
    • cancellation
    • resident vs released readback rules
    • an instanced/unbacked front surface is refused
  • Renderer: raycast-engine + snap suites 32/32, including the new readback test: released scene → no hit; readback pieces give the identical hit point and snap kind; hidden and non-isolated pieces are excluded; null clears.
  • Real GPU (headed Chromium 1248, private Xvfb, NVIDIA Vulkan, ifc-gpu-check, untimed): 8/8, all five #10868 IndexedDB cases plus the release spec. Each public model: the tap is started before the stream with 64 KiB chunks (so readback leases a neighbourhood, not the model), sealed, test-only released and read back. A 20-point magnetic-snap grid is probed before release (resident) and after (readback):
FixtureMeshesChunksInstanced occurrencesGrid hitsAnswered from readbackIdentical hit + snap (≤1e-6)CPU-held bytes before → after
AC20-FZK-Haus317180888/8 (edge)1,790,292 → 0
duplex622260444/4 (edge)1,955,320 → 0
C20-Institute-Var-22,01025893555/5 (edge, vertex)1,963,660 → 110,732

Every flat mesh also reads back byte-identical (order-sensitive digest). These are untimed correctness checks; no timing or memory-saving claim.

Gaps (release blockers, next PRs)

  • Instanced occurrences under the pointer are refused after release, not measured. Instanced readback for tools needs occurrence materialization from backed shards; that comes in the exports/device-recovery stage.
  • Snaps to instanced neighbours of a flat hit are missing after release. The snap lands on real flat geometry, but its candidate set is smaller than when resident.
  • Only 17 of 60 grid points landed on geometry, because the models sit small in the default view. A denser real-model grid is the next evidence step.
  • Touch / tap-only measurement has no hover prefetch, so a released scene gives no hit there (not a wrong one).
  • Caps, plan cuts and drawings, exports, quantities and selection centre, device recovery, content-version reload and federation alignment are not covered here.
  • Rotated models read back as unavailable (fail-closed, r4644942407): only a model's translation is inverted from a scene hit to model-local sources. Follow-up: invert the full placement (yaw and pivot) for flat sources.
  • A placement whose view moved before its readback is dropped with a warning (fail-closed, r4645389426, fixed in 9a44b0973e): its (x, y) names a surface only under the view it was clicked in.
  • Follow-up (r4645389649, deferred under the review-round cap): an unavailable drag read leaves the earlier rubber-band endpoint, snap target and edge lock on screen. It is preview residue only; nothing is placed from it.
  • A placement whose hide or isolate changed before its readback is dropped too (r4646436353, fixed in 37bd1fe30d).
  • Follow-up (r4646578150): give hover the same click-time view fence, so a late hover read cannot restore a stale live point after the camera moved (preview only).
  • Follow-up (r4646578322): when the GPU pick has no world position, feed the neighbourhood around the hit entity's bounds; today only the hit entity is fed, so neighbouring snaps are missed (the measured point stays correct).
  • Follow-up for #10887 (r4646577967): modelGeometry with an empty resident list should read a current, complete backing and yield nothing otherwise. It is unreachable here: release keeps meshes in the list, and #10880 has no whole-model caller.
  • A failed load of the lazy measure-readback chunk is retried by the next action instead of being cached, and a placement that throws releases its leases (r4646675734, r4646675783; fixed in 5a04392fa1).
  • Follow-ups (CodeRabbit, deferred under the review-round cap): coalesce stale drag previews so only the latest reads (r4646675742); dispose the readback subscriptions with the renderer (r4646675754); charge the picked entity's bytes to the neighbourhood budget (r4646675768).
  • A placement whose model moved renderer-side before its readback is dropped too (r4646794153, fixed in 742f09b330).
  • A point that cannot be read back (refused, stale or failed) discards the measurement in progress, so a finish never records the other points with one missing (r4647261448, fixed in 752dbb4b76). A queued placement checks Point mode's full staleness key plus the canvas CSS size (1abd223c15, c2839be835).
  • Follow-ups (r4647383677, r4647384013): size the readback neighbourhood from the snap radius projected at the hit depth instead of a fixed metre (snap completeness when zoomed out); compare snap targets for no-hit grid points in the GPU spec. On a GPU miss just past an edge (r4648159014), feed the neighbourhood of the nearest pick within the snap radius so a magnetic snap to that edge matches resident.
  • Follow-ups from CodeRabbit's replies: extend the feeder's lease cleanup through swap(), which only throws if a host's mesh setter throws (not today's renderer); and give the gate chunk a browser-level recovery path (for example a reload prompt) for browsers that cache a failed module fetch. The app-level cached rejection is already cleared.
  • Known caveat, both paths (r4646675796, #10653): a merged piece is admitted by its own expressId, so triangles of a hidden entity in its per-vertex entityIds lane can be hit. The resident flat index behaves the same; the fix (per-triangle visibility or splitting merged pieces) belongs with #10653. Same class (r4647185634): a merged piece whose host entity is not drawn is skipped, so its still-drawn members cannot be measured through readback. That is a refusal, not a wrong answer.
  • The test-only measure snap probe raycasts only on an answered read, matching the hover path (r4645389854, r4646325207; fixed in 2d6eeadfbd).

Entry bundle (perf ratchet viewer-entry-js-bytes)

All readback logic is in lazy chunks: measureReadbackGate plus the feeder and backing reader it loads. The entry chunk carries only measureReadback.ts (a released-scene check and the click scope) and one call per handler. A resident scene loads nothing.

Numbers from local builds, which match CI to 2 bytes (f0be41de7d handlers: local 2,004,167, CI 2,004,169):

  • f0be41de7d: this layer +2,053 bytes over main.
  • 52a5be0f37: this layer +807 bytes over main.
  • Main itself, on the f0be41de7d merge ref, was ~2,002,116, already 18 bytes past the allowed 2,002,098 (ceiling 2,000,098 + 2,000). So the estimate for 52a5be0f37 is ~2,002,923, still +825 past tolerance. The ceiling has not been raised; the decision is open.

🤖 Generated with Claude Code

Main integration validation (c68445ef63)

Merged main 80408df7b9 after #10868 landed; retained this layer's existing browser configuration for both IndexedDB and GPU release specs. The merged head has no conflict with that main. Fleet request auto-6114af47df9f4b90b13690058d9fb772, PC job f8d6750d-2a67-45d9-9c34-3c2dd0210c8c, completed exit 0 with unchanged source and published evidence: root build, root typecheck (including test-source audit), API surface, and all 18 pre-handoff gates against main 80408df7b9. The earlier request auto-10f6b02e completed exit 1 because the API check was invoked without the full build prerequisite; its original evidence is retained. This integration run did not run the full viewer suite or GPU specs, so it is not merge acceptance. Product release remains disabled.

Validated base alignment

Ancestry alignment head cea16cf99f merges validated ingestion head 76d451f130. Its Git tree 8bf0f485cb3f9da750abcb444170522712522ec4 is identical to validated c68445ef63; no files changed. The build/typecheck/API/pre-handoff receipt above belongs to c68445ef63, not a new exact-head run. The aligned base removes unrelated main changes from the review diff. Full viewer/GPU acceptance is still pending. Product release remains disabled.

Summary by CodeRabbit

  • New Features
    • Measurement placement, dragging, and hover snapping now work with geometry released from memory when readback data is available.
    • Raycasting and snapping can use supplied readback geometry while respecting visibility settings.
  • Bug Fixes
    • Measurement previews and placements now wait for readback results when needed, helping avoid missed or outdated results during interactions.
  • Documentation
    • Added guidance on supplying and clearing readback geometry for snapping on released geometry.