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. 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. 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, desktop: ObjectRef,
window: u64, window: u64,
hooks: Option<ObjectRef>, hooks: Option<ObjectRef>,
checkpoint: crate::mount::Checkpoint,
} }
pub struct PendingLayout { pub struct PendingLayout {
@@ -2564,15 +2565,23 @@ impl UiBridge {
state.next_mount = state.next_mount.max(layout.identity_high_watermark()); state.next_mount = state.next_mount.max(layout.identity_high_watermark());
frame.window = state.current; frame.window = state.current;
} }
let (hooks, mounts) = { let (hooks, mounts, checkpoint) = {
let mut state = self let mut state = self
.session .session
.lock() .lock()
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?; .map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
let hooks = state let checkpoint = state.mounts.checkpoint(vm, desktop)?;
let hooks = match state
.mounts .mounts
.synchronize(vm, desktop, page, nodes, &frame, true)?; .synchronize(vm, desktop, page, nodes, &frame, true)
(hooks, state.mounts.ordered()) {
Ok(hooks) => hooks,
Err(error) => {
checkpoint.restore(vm, desktop, &mut state.mounts)?;
return Err(error.into());
}
};
(hooks, state.mounts.ordered(), checkpoint)
}; };
let context = LayoutContext { let context = LayoutContext {
root: root.clone(), root: root.clone(),
@@ -2581,6 +2590,7 @@ impl UiBridge {
desktop, desktop,
window: frame.window, window: frame.window,
hooks, hooks,
checkpoint,
}; };
let draft = crate::source_layout::Draft { let draft = crate::source_layout::Draft {
frame, frame,
@@ -2601,17 +2611,49 @@ impl UiBridge {
Ok(()) Ok(())
} }
// Abort is currently a fault-domain cleanup operation, not a live rollback fn discard_layout_context(&self, vm: &mut Vm, context: LayoutContext) -> Result<()> {
// of Mount preparation. The caller preserves the last published picture. let LayoutContext {
pub fn abort_layout_frame(&self, vm: &mut Vm, pending: PendingLayout) -> Result<()> { desktop,
let PendingLayout { work, context } = pending; window,
let cancelled = work.cancel(vm); hooks,
let released = context.hooks.map(|hooks| vm.release(hooks)).transpose(); checkpoint,
cancelled?; ..
} = 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?; released?;
Ok(()) 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( pub fn resume_layout_frame(
&self, &self,
vm: &mut Vm, vm: &mut Vm,
@@ -2620,9 +2662,9 @@ impl UiBridge {
let PendingLayout { work, context } = pending; let PendingLayout { work, context } = pending;
if let Err(error) = self.select_window(context.window) { if let Err(error) = self.select_window(context.window) {
let cancelled = work.cancel(vm); let cancelled = work.cancel(vm);
let released = context.hooks.map(|hooks| vm.release(hooks)).transpose(); let restored = self.discard_layout_context(vm, context);
cancelled?; cancelled?;
released?; restored?;
return Err(error); return Err(error);
} }
let progress = work.resume(vm, 256); let progress = work.resume(vm, 256);
@@ -2646,9 +2688,7 @@ impl UiBridge {
.finish_layout_frame(vm, context, draft) .finish_layout_frame(vm, context, draft)
.map(|frame| LayoutProgress::Complete(Box::new(frame))), .map(|frame| LayoutProgress::Complete(Box::new(frame))),
Err(error) => { Err(error) => {
if let Some(hooks) = context.hooks { self.discard_layout_context(vm, context)?;
vm.release(hooks)?;
}
Err(error) Err(error)
} }
} }
@@ -2667,6 +2707,7 @@ impl UiBridge {
desktop, desktop,
window, window,
hooks, hooks,
checkpoint,
} = context; } = context;
let crate::source_layout::Draft { let crate::source_layout::Draft {
mut frame, mut frame,
@@ -2725,10 +2766,12 @@ impl UiBridge {
} }
Ok(frame) Ok(frame)
})(); })();
if let Some(hooks) = hooks { let released_hooks = hooks.map(|hooks| vm.release(hooks)).transpose();
vm.release(hooks)?; let released_checkpoint = checkpoint.release(vm);
} let frame = result?;
result released_hooks?;
released_checkpoint?;
Ok(frame)
} }
pub fn rendered(&self, vm: &Vm) -> Result<Option<Arc<UiNode>>> { pub fn rendered(&self, vm: &Vm) -> Result<Option<Arc<UiNode>>> {