From ed301b2eb4975be1678b36383748e34ee912fdf4 Mon Sep 17 00:00:00 2001 From: Codex Bot Date: Fri, 23 Oct 2026 01:34:55 +0800 Subject: [PATCH] feat: restore prepared mounts when cancelling unpublished layout work --- README.md | 3 ++ src/README.md | 3 ++ src/ui_bridge.rs | 83 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 69 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 1966c0e..a0737ec 100644 --- a/README.md +++ b/README.md @@ -515,3 +515,6 @@ Viewport refresh now advances through ReplSession's saved refresh state on worke Runtime mutation entry points reject direct calls while refresh work is pending, before executing source or changing metadata; task polling defers. The API worker drains the saved refresh before accepting those mutations, keeping the runtime usable. Incremental refresh keeps the prior complete document map until a stable pass, including across window traversal boundaries where no VM read-only frame is currently active. + + +Pending bridge layouts now retain a Mount checkpoint. cancel_layout_frame closes the VM continuation, restores the old Mount payloads/links/dictionary and marks the presentation dirty for a new solve; discarded lifecycle hooks do not run. Successful finalization releases checkpoint roots after callbacks. This restores speculative Mount preparation, not arbitrary application writes or already completed lifecycle callbacks. diff --git a/src/README.md b/src/README.md index 8d14812..9aa6b1a 100644 --- a/src/README.md +++ b/src/README.md @@ -170,3 +170,6 @@ Runtime mutation entry points reject direct calls while refresh work is pending, Mount preparation now has an explicit checkpoint that roots the previous dictionary, Mount payloads and metadata values. It can restore geometry/relations/registry after cancelling an unpublished layout, or release its roots after completion. Task cancellation moves from speculative preparation to immediately before the actual onUnmount callback, so cancelling preparation does not destroy the old occurrence's tasks. + + +Pending bridge layouts now retain a Mount checkpoint. cancel_layout_frame closes the VM continuation, restores the old Mount payloads/links/dictionary and marks the presentation dirty for a new solve; discarded lifecycle hooks do not run. Successful finalization releases checkpoint roots after callbacks. This restores speculative Mount preparation, not arbitrary application writes or already completed lifecycle callbacks. diff --git a/src/ui_bridge.rs b/src/ui_bridge.rs index 6a6f195..81a6a49 100644 --- a/src/ui_bridge.rs +++ b/src/ui_bridge.rs @@ -1716,6 +1716,7 @@ struct LayoutContext { desktop: ObjectRef, window: u64, hooks: Option, + checkpoint: crate::mount::Checkpoint, } pub struct PendingLayout { @@ -2564,15 +2565,23 @@ impl UiBridge { state.next_mount = state.next_mount.max(layout.identity_high_watermark()); frame.window = state.current; } - let (hooks, mounts) = { + let (hooks, mounts, checkpoint) = { let mut state = self .session .lock() .map_err(|_| anyhow::anyhow!("UI session poisoned"))?; - let hooks = state + let checkpoint = state.mounts.checkpoint(vm, desktop)?; + let hooks = match state .mounts - .synchronize(vm, desktop, page, nodes, &frame, true)?; - (hooks, state.mounts.ordered()) + .synchronize(vm, desktop, page, nodes, &frame, true) + { + Ok(hooks) => hooks, + Err(error) => { + checkpoint.restore(vm, desktop, &mut state.mounts)?; + return Err(error.into()); + } + }; + (hooks, state.mounts.ordered(), checkpoint) }; let context = LayoutContext { root: root.clone(), @@ -2581,6 +2590,7 @@ impl UiBridge { desktop, window: frame.window, hooks, + checkpoint, }; let draft = crate::source_layout::Draft { frame, @@ -2601,17 +2611,49 @@ impl UiBridge { Ok(()) } - // Abort is currently a fault-domain cleanup operation, not a live rollback - // of Mount preparation. The caller preserves the last published picture. - pub fn abort_layout_frame(&self, vm: &mut Vm, pending: PendingLayout) -> Result<()> { - let PendingLayout { work, context } = pending; - let cancelled = work.cancel(vm); - let released = context.hooks.map(|hooks| vm.release(hooks)).transpose(); - cancelled?; + fn discard_layout_context(&self, vm: &mut Vm, context: LayoutContext) -> Result<()> { + let LayoutContext { + desktop, + window, + hooks, + checkpoint, + .. + } = context; + let selected = self.select_window(window); + let restored = if selected.is_ok() { + match self.session.lock() { + Ok(mut state) => { + let result = checkpoint.restore(vm, desktop, &mut state.mounts); + state.force_frame = true; + result.map_err(anyhow::Error::from) + } + Err(_) => { + checkpoint.release(vm)?; + Err(anyhow::anyhow!("UI session poisoned")) + } + } + } else { + checkpoint.release(vm).map_err(anyhow::Error::from) + }; + let released = hooks.map(|hooks| vm.release(hooks)).transpose(); + selected?; + restored?; released?; Ok(()) } + pub fn cancel_layout_frame(&self, vm: &mut Vm, pending: PendingLayout) -> Result<()> { + let PendingLayout { work, context } = pending; + let cancelled = work.cancel(vm); + let restored = self.discard_layout_context(vm, context); + cancelled?; + restored + } + + pub fn abort_layout_frame(&self, vm: &mut Vm, pending: PendingLayout) -> Result<()> { + self.cancel_layout_frame(vm, pending) + } + pub fn resume_layout_frame( &self, vm: &mut Vm, @@ -2620,9 +2662,9 @@ impl UiBridge { let PendingLayout { work, context } = pending; if let Err(error) = self.select_window(context.window) { let cancelled = work.cancel(vm); - let released = context.hooks.map(|hooks| vm.release(hooks)).transpose(); + let restored = self.discard_layout_context(vm, context); cancelled?; - released?; + restored?; return Err(error); } let progress = work.resume(vm, 256); @@ -2646,9 +2688,7 @@ impl UiBridge { .finish_layout_frame(vm, context, draft) .map(|frame| LayoutProgress::Complete(Box::new(frame))), Err(error) => { - if let Some(hooks) = context.hooks { - vm.release(hooks)?; - } + self.discard_layout_context(vm, context)?; Err(error) } } @@ -2667,6 +2707,7 @@ impl UiBridge { desktop, window, hooks, + checkpoint, } = context; let crate::source_layout::Draft { mut frame, @@ -2725,10 +2766,12 @@ impl UiBridge { } Ok(frame) })(); - if let Some(hooks) = hooks { - vm.release(hooks)?; - } - result + let released_hooks = hooks.map(|hooks| vm.release(hooks)).transpose(); + let released_checkpoint = checkpoint.release(vm); + let frame = result?; + released_hooks?; + released_checkpoint?; + Ok(frame) } pub fn rendered(&self, vm: &Vm) -> Result>> {