Skip to content

Plugin panels: atomic scene patches + retained projection cache (S03, api v29) - #3510

Merged
HakanSeven12 merged 1 commit into
HakanSeven12:mainfrom
schoeller:scene-ui-atomic-s03-patches-cache
Nov 23, 2026
Merged

HakanSeven12 merged 1 commit into
HakanSeven12:mainfrom
schoeller:scene-ui-atomic-s03-patches-cache

Conversation

@schoeller

Copy link
Copy Markdown
Contributor

Problem and minimal scope

Stage 3 of the atomic panel-surface train (#3460, merged): a plugin updates its published panel scene through bounded, revision-checked patches that apply atomically (all-or-nothing) against the stored head, and the host's canvas paints from a retained projection cache keyed by the actual render inputs — repaints are free; a patch costs exactly one re-projection.

Public API / wire changes and current API-major basis

Based on upstream main at 66c83e785 (API_VERSION = 29, declared by #3460). No new API major — this stage rides v29's tails:

  • PluginRequest::PanelSurfacePatch { panel_id, patch } — variant 64 (after publish 63).
  • PluginResponse::PanelSurfacePatchResult(Result<SceneRevision, SurfaceReject>) — variant 50 (after 49). Both pinned by panel_surface_patch_v29_wire_tail_is_pinned.
  • SceneOp { Add{parent,element} (None=root, Some=inside that group; only groups are containers), Replace{id,element} (same StableId required), Remove{id} (element + whole subtree) } and ScenePatch { base_revision, ops } with MAX_PATCH_OPS = 10_000 — in crate::scene (ungated: the pure store stays wasm-clean and shares the wire's vocabulary).
  • SceneError gains StaleBase / PatchTooLarge / UnknownParent / UnknownElement (internal, not wire-serialized; appended).
  • HostApi gains the paired panel_surface_patch / panel_surface_patch_for_plugin with the transport-era Unattached defaults; server dispatch + client override mirror the publish path.

Semantics

  • Atomic: apply_to stages a candidate, applies ops in order, advances the revision by exactly one, and re-validates the whole result. Any failure (stale base, unknown id/parent, duplicate id, budget) refuses with zero mutation — the publisher rebases; it never muddles through.
  • Stale base maps to the existing NonMonotonicRevision reject code with the stored head attached — no new reject codes, no speculative ack report (finding F1's economy).
  • Cache: PROJECTION_CACHE keys projected prims by (owner, panel, revision) — the actual render inputs; the theme applies at paint time and never invalidates. One bounded entry per thread; patched-away revisions are dead state. Lifecycle-safe: panel re-registration and the dead-plugin reap (retain_owners) now call forget_all_projections(), so a re-registered panel that restarts its revisions can never paint a dead scene's prims at a reused revision.
  • Proof test: five repaints of one revision cost zero re-projections; a one-subtree patch costs exactly one — repaints never rebuild.

Explicit non-goals and dependency

Depends on #3460 (merged — rebased onto its follow-up fixes at 66c83e785). Non-goals: semantic events/drag (S04, in preparation), widget surfaces (S05+), MCP (S08), any per-subtree incremental projection splicing (the revision-keyed cache is the demonstrated-need cache; finer granularity waits for a consumer).

Legacy compatibility

Existing variants untouched (appends only, tags pinned); DialogControl/DialogValue/HostNotification untouched; panels without scenes render their exact legacy trees. A v28 runner cannot decode tags 63/64 (manifest gate; v29 already declared by #3460).

Verification (exact commands, exit 0)

  • cargo test -p ocs_plugin_api --all-features → 208 passed, 0 failed, 1 ignored (includes patch atomicity, stale-base head report, unknown-id/parent refusals, budget, wire pins 64/50).
  • cargo test --lib -p OpenCADStudio -- panel_surfaces plugin_scene → 16 passed, 0 failed (store patch semantics + cache proofs).
  • cargo check --lib -p OpenCADStudio → clean; cargo check --locked --target wasm32-unknown-unknown -p OpenCADStudio -p ocs_web_worker → clean (recorded artifact).
  • Scoped rustfmt --check clean on touched files. Pre-existing upstream baseline failures (windows D3D12 trait errors — see the Plugin panels: publish declarative scene surfaces end to end (S02, api v29) #3460 discussion; fmt/clippy informational jobs) are inherited and untouched.

Live-test evidence

Not run — honestly. The patch path is exercised at the store/wire/semantics level above; the live host acceptance run remains recorded as pending tooling availability (same note as #3460).

Adaptation to upstream movement

Rebased onto 66c83e785 on top of this morning's panel-scene lifecycle fixes (95cdba06e): the projection cache now invalidates at the same lifecycle points the store forgets scenes (re-registration + reap), and paint_prim follows the upstream signature (bounds parameter removed).

… api v29)

Stage 3 of the atomic scene-ui train: a plugin updates its published
panel scene through bounded, revision-checked patches that apply
atomically (all-or-nothing) against the stored head, and the host's
canvas paints from a retained projection cache keyed by the actual
render inputs — repaints are free; a patch costs exactly one
re-projection.

Scene model (crates/ocs_plugin_api/src/scene.rs, ungated so the pure
store stays wasm-clean):
- SceneOp { Add { parent, element } (None = root append, Some = inside
  that group; only groups are containers), Replace { id, element }
  (replacement must carry the same StableId), Remove { id } (element
  plus its whole subtree) } — appended op vocabulary, never renumbered.
- ScenePatch { base_revision, ops } with MAX_PATCH_OPS = 10_000 and
  atomic apply_to: stale base or ANY op failure (unknown id/parent,
  duplicate id, budget overflow) refuses with zero mutation; success
  advances the revision by exactly one and re-validates the whole
  result, so a stored scene is a validated scene by construction.
- SceneError gains StaleBase / PatchTooLarge / UnknownParent /
  UnknownElement (internal type, not wire-serialized; appends only).

Wire: PluginRequest::PanelSurfacePatch (variant 64, after publish 63)
and PluginResponse::PanelSurfacePatchResult (variant 50, after 49),
pinned by panel_surface_patch_v29_wire_tail_is_pinned; HostApi gains
the paired panel_surface_patch / panel_surface_patch_for_plugin with
the transport-era Unattached defaults; server dispatch + client
override mirror the publish path. StaleBase maps to the existing
NonMonotonicRevision reject code with the stored head attached, so the
publisher can rebase — no new reject codes, no speculative ack report.

Host: PanelSurfaceStore::patch (attachment + ownership re-checks, then
the pure apply) and the session override; the dock seam is unchanged —
a patched scene simply renders at its new revision through the cache.

Retained cache: PROJECTION_CACHE keys the projected prim list by
(owner, panel, revision) — the actual render inputs; the theme applies
at paint time and never invalidates. One bounded entry per thread;
patched-away revisions are dead state. The proof test shows five
repaints cost zero re-projections and a one-subtree patch costs
exactly one — repaints never rebuild.

Verification: cargo test -p ocs_plugin_api --all-features 198 passed /
0 failed / 1 ignored; cargo test --lib -p OpenCADStudio -- panel_surfaces
plugin_scene 15 passed / 0 failed (new: atomicity, stale-base head
report, foreign-patch refusal, patch-without-store refusal, retained-
cache proof); wasm32 check green for OpenCADStudio + ocs_web_worker;
scoped rustfmt clean on touched files. Pre-existing upstream baseline
failures (fmt hunks, clippy -D warnings in entity_coverage/host/ipc/
process, non-blocking CI) inherited and untouched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants