feat: restore prepared mounts when cancelling unpublished layout work

This commit is contained in:
2026-10-23 01:34:55 +08:00
parent cd07c958c1
commit ed301b2eb4
3 changed files with 69 additions and 20 deletions
+3
View File
@@ -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.
+3
View File
@@ -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.
+63 -20
View File
@@ -1716,6 +1716,7 @@ struct LayoutContext {
desktop: ObjectRef,
window: u64,
hooks: Option<ObjectRef>,
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<Option<Arc<UiNode>>> {