fix: guard runtime mutation across parked refresh stages
Verify Tessera GUI / verify (push) Failing after 9m6s

This commit is contained in:
2026-10-23 01:22:03 +08:00
parent ba26e74bea
commit 6c4be694f7
4 changed files with 75 additions and 0 deletions
+3
View File
@@ -512,3 +512,6 @@ ReplSession now owns a resumable RefreshWork containing window traversal, pendin
Viewport refresh now advances through ReplSession's saved refresh state on worker idle turns. A turn advances one traversal stage or a 256-instruction layout quantum; a pending job shortens the next worker wait to 1 ms. Tasks/window commands and document publication wait for complete refresh. ui.stats().refreshYields reports cooperative idle returns. Mutating requests first drain the existing job, so they cannot run inside its read-only scope. This is serialized input, not live cancellation/rollback or latest-input coalescing. Initial loads, explicit REPL/event refresh and task callbacks still drain synchronously; native Rust measurement/paint calls remain atomic.
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.
+3
View File
@@ -164,3 +164,6 @@ ReplSession now owns a resumable RefreshWork containing window traversal, pendin
Viewport refresh now advances through ReplSession's saved refresh state on worker idle turns. A turn advances one traversal stage or a 256-instruction layout quantum; a pending job shortens the next worker wait to 1 ms. Tasks/window commands and document publication wait for complete refresh. ui.stats().refreshYields reports cooperative idle returns. Mutating requests first drain the existing job, so they cannot run inside its read-only scope. This is serialized input, not live cancellation/rollback or latest-input coalescing. Initial loads, explicit REPL/event refresh and task callbacks still drain synchronously; native Rust measurement/paint calls remain atomic.
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.
+3
View File
@@ -1167,6 +1167,9 @@ UiBridge::begin_layout_frame/resume_layout_frame now expose PendingLayout around
Viewport refresh now advances through ReplSession's saved refresh state on worker idle turns. A turn advances one traversal stage or a 256-instruction layout quantum; a pending job shortens the next worker wait to 1 ms. Tasks/window commands and document publication wait for complete refresh. ui.stats().refreshYields reports cooperative idle returns. Mutating requests first drain the existing job, so they cannot run inside its read-only scope. This is serialized input, not live cancellation/rollback or latest-input coalescing. Initial loads, explicit REPL/event refresh and task callbacks still drain synchronously; native Rust measurement/paint calls remain atomic.
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.
## UI host object
Positional arguments only:
+66
View File
@@ -355,6 +355,7 @@ impl ReplSession {
})
}
pub fn execute(&mut self, source: &str, namespace: &str) -> Result<ReplResult> {
self.require_idle_refresh()?;
if self.faulted {
bail!(
"runtime stopped after a callback or rendering failure; reset the session or replace its program"
@@ -494,6 +495,14 @@ impl ReplSession {
self.refresh.is_some()
}
fn require_idle_refresh(&self) -> Result<()> {
anyhow::ensure!(
!self.has_pending_refresh(),
"finish pending refresh before mutating this runtime"
);
Ok(())
}
fn refresh_document(&mut self) -> Result<Option<RenderDocument>> {
loop {
match self.poll_refresh(false)? {
@@ -733,6 +742,9 @@ impl ReplSession {
/// Deliver ready work on the owning VM worker, never from the GUI or a
/// provider thread. A failed callback stops the same shared fault domain.
pub fn poll_tasks(&mut self) -> Result<Option<RenderDocument>> {
if self.has_pending_refresh() {
return Ok(None);
}
if self.faulted {
if self.bridge.cancel_tasks(&mut self.candidate.vm)? > 0 {
self.bridge
@@ -762,6 +774,7 @@ impl ReplSession {
}
pub fn take_window_commands(&self) -> Result<Vec<crate::window::Command>> {
self.require_idle_refresh()?;
self.bridge.take_window_commands(&self.candidate.vm)
}
@@ -769,6 +782,7 @@ impl ReplSession {
&mut self,
viewport: Option<crate::layout::Size>,
) -> Result<Option<RenderDocument>> {
self.require_idle_refresh()?;
if self.faulted {
bail!("runtime stopped after a callback or rendering failure");
}
@@ -786,6 +800,7 @@ impl ReplSession {
}
pub fn retire_window(&mut self, id: u64) -> Result<()> {
self.require_idle_refresh()?;
// This path is exclusively host cleanup after the domain has stopped.
// No language functions, layout, paint or lifecycle hooks may run here.
self.faulted = true;
@@ -809,6 +824,7 @@ impl ReplSession {
}
pub fn dispatch(&mut self, input: &crate::events::Input) -> Result<ReplResult> {
self.require_idle_refresh()?;
if self.faulted {
bail!("runtime stopped after a callback or rendering failure");
}
@@ -4015,6 +4031,56 @@ page.render(block)
);
}
#[test]
fn incremental_viewport_refresh_retains_published_documents_until_complete() {
let (mut session, _) = ReplSession::load(
include_str!("../examples/flex-constraints.endor"),
"app.main",
271,
1,
)
.unwrap();
let old_version = session.documents[&crate::window::MAIN_WINDOW]
.frame
.layout_version;
let viewports = std::collections::BTreeMap::from([(
crate::window::MAIN_WINDOW,
crate::layout::Size {
width: 800.0,
height: 600.0,
},
)]);
assert!(
session
.resize_windows_incremental(&viewports, false)
.unwrap()
.is_none()
);
assert!(session.has_pending_refresh());
assert!(session.execute("blocked = 1", "app.main").is_err());
assert!(!session.is_faulted());
let mut completed = false;
for _ in 0..1000 {
if let Some(document) = session
.resize_windows_incremental(&viewports, false)
.unwrap()
{
assert!(document.frame.layout_version > old_version);
assert!(!session.has_pending_refresh());
completed = true;
break;
}
assert_eq!(
session.documents[&crate::window::MAIN_WINDOW]
.frame
.layout_version,
old_version
);
}
assert!(completed);
assert!(source_measure_stat(&mut session, "refreshYields") > 0);
}
#[test]
fn bridge_layout_can_return_pending_before_committing_a_complete_frame() {
let children = std::iter::repeat_n("item", 40)