test: cover paint cancellation, consistent publication and post-pause errors
Verify Tessera GUI / verify (push) Failing after 9m10s
Verify Tessera GUI / verify (push) Failing after 9m10s
This commit is contained in:
@@ -526,7 +526,7 @@ New viewport targets now coalesce pending refresh work. The runtime cancels only
|
||||
Cancellation checkpoints own explicit VM roots until restored or released. Initial presentations may have no mount dictionary; cancellation restores that absence too. Saved metadata values retain object-valued attributes. A pending refresh can restart while keeping already completed window drafts; no onMount/onUnmount callback is replayed merely because the viewport target changed. Mount-owned tasks are cancelled immediately before an actual onUnmount callback, never during abandoned preparation.
|
||||
|
||||
|
||||
Large intrinsic layout trees (more than 64 occurrences) now use the resumable per-occurrence driver too. Native measurement caches remain active, and a single native callback remains atomic; VM instruction boundaries between nodes allow the worker to yield and replace an obsolete viewport. Small intrinsic trees retain the allocation-free native fast path. Structural extraction, driver preparation, settling checks and final paint/projection still run atomically; this is not a wall-clock preemption guarantee.
|
||||
Large intrinsic layout trees (more than 64 occurrences) now use the resumable per-occurrence driver too. Native measurement caches remain active, and a single native callback remains atomic; VM instruction boundaries between nodes allow the worker to yield and replace an obsolete viewport. Small intrinsic trees retain the allocation-free native fast path. Structural extraction, driver preparation, settling checks and final command projection still run atomically; this is not a wall-clock preemption guarantee.
|
||||
|
||||
|
||||
Idle timer delivery now processes at most one ready callback (or one ineligible task cancellation) before starting an incremental refresh. No further task is delivered while that refresh is pending. Viewport changes can replace its unfinished layout without replaying the completed task callback. Task effects and native window commands publish only after settling; a previously completed resize may publish separately. Explicit input still drains pending work first. Synchronous host callers retain a maximum of 64 task deliveries per poll.
|
||||
@@ -538,7 +538,10 @@ REPL and event mutations now have incremental refresh entry points. They execute
|
||||
The API worker now owns a pending HTTP request plus its scalar result while REPL/event layout is parked. It advances the layout with current native viewport targets and responds only after the stable full-window publication and command extraction. Later mutation requests remain queued; GET /code can observe the last complete publication. A newer accepted PUT invalidates queued inputs but lets the already-running owner settle before candidate construction, so failed replacement can preserve its consistent heap. DELETE revokes that owner and prevents late publication. This queue ordering does not roll back already-executed source effects.
|
||||
|
||||
|
||||
Complete-source candidates now separate one-time compilation/source execution from initial layout. load_incremental owns the isolated VM while its first layout is pending; the current live VM stays separate. Cancellation uses the same Mount checkpoint/continuation cleanup as later refresh. Synchronous load helpers remain for host regression coverage. This does not yet slice parsing, compilation, source execution, structural preparation or paint.
|
||||
Complete-source candidates now separate one-time compilation/source execution from initial layout. load_incremental owns the isolated VM while its first layout is pending; the current live VM stays separate. Cancellation uses the same Mount checkpoint/continuation cleanup as later refresh. Synchronous load helpers remain for host regression coverage. This does not slice parsing, compilation, mutating source execution, structural preparation or final command projection.
|
||||
|
||||
|
||||
The API keeps the old runtime alongside a pending PUT candidate. Newer submissions cancel only the obsolete candidate; failures restore the published runtime's submission owner. Background epoch checks distinguish accepted replacements from DELETE revocation, so queued/superseded candidates do not destroy the previous live heap. Candidate resumption reads only the primary shell viewport, avoiding reuse of an old secondary window's dimensions for a new VM's resource with the same numeric ID. Success publishes the complete candidate document and commands together, then replaces the old runtime.
|
||||
|
||||
|
||||
Source paint now uses a resumable read-only VM call with the same 256-instruction quantum and a cumulative 1,000,000-instruction budget. The pending job owns the unpublished frame, visual snapshot, decoded command buffer and prepare root. The refresh worker resumes paint before advancing to another window and publishes only the full stable window set. New viewport targets cancel unfinished paint, discard partial commands and force that window to refresh. Already completed layout/Mount geometry and lifecycle callbacks remain committed; cancelling paint does not replay or undo them. Failure/discard explicitly closes the read-only continuation and releases its roots. paintSlices reports the most recently completed paint solve (1 when no override needs a pause); paintCancels counts viewport replacements that closed pending paint. Layout checkpoint rollback remains limited to unfinished layout preparation. Native callback bodies, driver preparation, command decoding/projection and rasterization remain atomic.
|
||||
|
||||
+4
-1
@@ -193,7 +193,10 @@ REPL and event mutations now have incremental refresh entry points. They execute
|
||||
The API worker now owns a pending HTTP request plus its scalar result while REPL/event layout is parked. It advances the layout with current native viewport targets and responds only after the stable full-window publication and command extraction. Later mutation requests remain queued; GET /code can observe the last complete publication. A newer accepted PUT invalidates queued inputs but lets the already-running owner settle before candidate construction, so failed replacement can preserve its consistent heap. DELETE revokes that owner and prevents late publication. This queue ordering does not roll back already-executed source effects.
|
||||
|
||||
|
||||
Complete-source candidates now separate one-time compilation/source execution from initial layout. load_incremental owns the isolated VM while its first layout is pending; the current live VM stays separate. Cancellation uses the same Mount checkpoint/continuation cleanup as later refresh. Synchronous load helpers remain for host regression coverage. This does not yet slice parsing, compilation, source execution, structural preparation or paint.
|
||||
Complete-source candidates now separate one-time compilation/source execution from initial layout. load_incremental owns the isolated VM while its first layout is pending; the current live VM stays separate. Cancellation uses the same Mount checkpoint/continuation cleanup as later refresh. Synchronous load helpers remain for host regression coverage. This does not slice parsing, compilation, mutating source execution, structural preparation or final command projection.
|
||||
|
||||
|
||||
The API keeps the old runtime alongside a pending PUT candidate. Newer submissions cancel only the obsolete candidate; failures restore the published runtime's submission owner. Background epoch checks distinguish accepted replacements from DELETE revocation, so queued/superseded candidates do not destroy the previous live heap. Candidate resumption reads only the primary shell viewport, avoiding reuse of an old secondary window's dimensions for a new VM's resource with the same numeric ID. Success publishes the complete candidate document and commands together, then replaces the old runtime.
|
||||
|
||||
|
||||
Source paint now uses a resumable read-only VM call with the same 256-instruction quantum and a cumulative 1,000,000-instruction budget. The pending job owns the unpublished frame, visual snapshot, decoded command buffer and prepare root. The refresh worker resumes paint before advancing to another window and publishes only the full stable window set. New viewport targets cancel unfinished paint, discard partial commands and force that window to refresh. Already completed layout/Mount geometry and lifecycle callbacks remain committed; cancelling paint does not replay or undo them. Failure/discard explicitly closes the read-only continuation and releases its roots. paintSlices reports the most recently completed paint solve (1 when no override needs a pause); paintCancels counts viewport replacements that closed pending paint. Layout checkpoint rollback remains limited to unfinished layout preparation. Native callback bodies, driver preparation, command decoding/projection and rasterization remain atomic.
|
||||
|
||||
+4
-2
@@ -1497,9 +1497,11 @@ New viewport targets now coalesce pending refresh work. The runtime cancels only
|
||||
|
||||
Cancellation checkpoints own explicit VM roots until restored or released. Initial presentations may have no mount dictionary; cancellation restores that absence too. Saved metadata values retain object-valued attributes. A pending refresh can restart while keeping already completed window drafts; no onMount/onUnmount callback is replayed merely because the viewport target changed. Mount-owned tasks are cancelled immediately before an actual onUnmount callback, never during abandoned preparation.
|
||||
|
||||
REPL/event requests retain their HTTP request and scalar result until the complete window set settles. The worker advances one stage/quantum per turn, takes current native viewport targets each time and keeps later mutations queued. GET /code keeps returning the last complete publication. Response metadata and native commands publish together after settling; no source/event callback is replayed. A running input can finish before a newer queued PUT, preserving a consistent old runtime if that candidate fails; DELETE revokes the owner and prevents its late publication. Source execution/callbacks and structural preparation/paint remain atomic.
|
||||
REPL/event requests retain their HTTP request and scalar result until the complete window set settles. The worker advances one stage/quantum per turn, takes current native viewport targets each time and keeps later mutations queued. GET /code keeps returning the last complete publication. Response metadata and native commands publish together after settling; no source/event callback is replayed. A running input can finish before a newer queued PUT, preserving a consistent old runtime if that candidate fails; DELETE revokes the owner and prevents its late publication. Source execution/callbacks and structural preparation and final command projection remain atomic; source paint execution can yield.
|
||||
|
||||
Complete-source PUT also parks an isolated candidate VM during initial layout. The worker retains its HTTP request and the prior live VM, advances one candidate stage/quantum per turn and commits only after its full window set settles. New PUT/DELETE submissions discard obsolete candidates and explicitly cancel their pending layout. Failure keeps the prior live owner; accepting a replacement alone does not revoke that owner. Candidate viewport updates use only the surviving primary shell; secondary native resource IDs and sizes still belong to the old VM until successful publication. Parsing, compilation, source execution, structural preparation and paint remain atomic.
|
||||
Complete-source PUT also parks an isolated candidate VM during initial layout. The worker retains its HTTP request and the prior live VM, advances one candidate stage/quantum per turn and commits only after its full window set settles. New PUT/DELETE submissions discard obsolete candidates and explicitly cancel their pending layout. Failure keeps the prior live owner; accepting a replacement alone does not revoke that owner. Candidate viewport updates use only the surviving primary shell; secondary native resource IDs and sizes still belong to the old VM until successful publication. Parsing, compilation, source execution, structural preparation and final command projection remain atomic; source paint execution can yield.
|
||||
|
||||
Source paint now uses a resumable read-only VM call with the same 256-instruction quantum and a cumulative 1,000,000-instruction budget. The pending job owns the unpublished frame, visual snapshot, decoded command buffer and prepare root. The refresh worker resumes paint before advancing to another window and publishes only the full stable window set. New viewport targets cancel unfinished paint, discard partial commands and force that window to refresh. Already completed layout/Mount geometry and lifecycle callbacks remain committed; cancelling paint does not replay or undo them. Failure/discard explicitly closes the read-only continuation and releases its roots. paintSlices reports the most recently completed paint solve (1 when no override needs a pause); paintCancels counts viewport replacements that closed pending paint. Layout checkpoint rollback remains limited to unfinished layout preparation. Native callback bodies, driver preparation, command decoding/projection and rasterization remain atomic.
|
||||
|
||||
## UI host object
|
||||
|
||||
|
||||
+130
-7
@@ -634,7 +634,11 @@ impl ReplSession {
|
||||
Err(error) => {
|
||||
self.faulted = true;
|
||||
if let Some(paint) = work.paint.take() {
|
||||
self.bridge.cancel_paint_frame(&mut self.candidate.vm, paint.window, *paint.work)?;
|
||||
self.bridge.cancel_paint_frame(
|
||||
&mut self.candidate.vm,
|
||||
paint.window,
|
||||
*paint.work,
|
||||
)?;
|
||||
}
|
||||
if let Some(pending) = work.pending.take() {
|
||||
self.bridge
|
||||
@@ -668,8 +672,14 @@ impl ReplSession {
|
||||
};
|
||||
self.bridge.select_window(id)?;
|
||||
if let Some(paint) = work.paint.take() {
|
||||
let PendingPaint { window, document, work: paint_work } = *paint;
|
||||
let progress = self.bridge.resume_paint_frame(&mut self.candidate.vm, *paint_work)?;
|
||||
let PendingPaint {
|
||||
window,
|
||||
document,
|
||||
work: paint_work,
|
||||
} = *paint;
|
||||
let progress = self
|
||||
.bridge
|
||||
.resume_paint_frame(&mut self.candidate.vm, *paint_work)?;
|
||||
return Self::accept_window_paint(work, window, document, progress);
|
||||
}
|
||||
let progress = if let Some(pending) = work.pending.take() {
|
||||
@@ -726,7 +736,11 @@ impl ReplSession {
|
||||
) -> Result<bool> {
|
||||
match progress {
|
||||
crate::source_paint::Progress::Pending(paint) => {
|
||||
work.paint = Some(Box::new(PendingPaint { window: id, document, work: paint }));
|
||||
work.paint = Some(Box::new(PendingPaint {
|
||||
window: id,
|
||||
document,
|
||||
work: paint,
|
||||
}));
|
||||
}
|
||||
crate::source_paint::Progress::Complete(draft) => {
|
||||
document.frame = draft.frame;
|
||||
@@ -794,7 +808,9 @@ impl ReplSession {
|
||||
let cancelled = work.pending.is_some();
|
||||
let cancelled_paint = work.paint.is_some();
|
||||
if let Some(paint) = work.paint.take()
|
||||
&& let Err(error) = self.bridge.cancel_paint_frame(&mut self.candidate.vm, paint.window, *paint.work)
|
||||
&& let Err(error) =
|
||||
self.bridge
|
||||
.cancel_paint_frame(&mut self.candidate.vm, paint.window, *paint.work)
|
||||
{
|
||||
self.faulted = true;
|
||||
return Err(error);
|
||||
@@ -1065,11 +1081,17 @@ impl Drop for ReplSession {
|
||||
fn drop(&mut self) {
|
||||
if let Some(mut work) = self.refresh.take() {
|
||||
if let Some(paint) = work.paint.take() {
|
||||
let _ = self.bridge.cancel_paint_frame(&mut self.candidate.vm, paint.window, *paint.work);
|
||||
let _ = self.bridge.cancel_paint_frame(
|
||||
&mut self.candidate.vm,
|
||||
paint.window,
|
||||
*paint.work,
|
||||
);
|
||||
}
|
||||
if let Some(pending) = work.pending.take() {
|
||||
// Close the read-only call/checkpoint before Candidate roots.
|
||||
let _ = self.bridge.cancel_layout_frame(&mut self.candidate.vm, *pending);
|
||||
let _ = self
|
||||
.bridge
|
||||
.cancel_layout_frame(&mut self.candidate.vm, *pending);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3189,6 +3211,107 @@ page.render(block)
|
||||
);
|
||||
}
|
||||
|
||||
fn resumable_paint_source(copies: usize, locals: usize) -> String {
|
||||
let children = std::iter::repeat_n("item", copies)
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let locals = "probe = 2\n".repeat(locals);
|
||||
format!(
|
||||
"class Painted: RectBlock {{\n tint: String\n mounted: Object\n function onMount(self: Painted, mount: Mount): Unit {{ self.mounted.increment() }}\n function paint(self: Painted, mount: Mount, geometry: Bounds): DisplayList {{\n{locals}drawing = RectBlock.paint(self,mount,geometry)\ndrawing.commands.at(0).color = self.tint\nreturn drawing\n}}\n}}\nmounted = ui.state(0)\nitem = Painted(2,20,0,\"#DDEEFF\",\"#ED6A5A\",mounted)\npage = Page()\npage.render(Row(0,0,{children}))"
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pending_paint_retargets_without_replaying_completed_mount_hooks() {
|
||||
let (mut session, initial) =
|
||||
ReplSession::load(&resumable_paint_source(80, 0), "app.main", 278, 1).unwrap();
|
||||
let viewports = std::collections::BTreeMap::new();
|
||||
session
|
||||
.execute_incremental("item.tint = \"#526AC7\"", "app.main", &viewports)
|
||||
.unwrap();
|
||||
for _ in 0..100 {
|
||||
session
|
||||
.resize_windows_incremental(&viewports, false)
|
||||
.unwrap();
|
||||
if session
|
||||
.refresh
|
||||
.as_ref()
|
||||
.is_some_and(|work| work.paint.is_some())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert!(
|
||||
session
|
||||
.refresh
|
||||
.as_ref()
|
||||
.is_some_and(|work| work.paint.is_some())
|
||||
);
|
||||
assert!(session.candidate.vm.has_suspended_call());
|
||||
assert_eq!(
|
||||
session.documents[&crate::window::MAIN_WINDOW]
|
||||
.frame
|
||||
.layout_version,
|
||||
initial.frame.layout_version
|
||||
);
|
||||
assert!(session.documents[&crate::window::MAIN_WINDOW].frame.commands.iter().all(|command| matches!(command, RenderCommand::RoundedRect { color, .. } if color == "#ED6A5A")));
|
||||
let latest = std::collections::BTreeMap::from([(
|
||||
crate::window::MAIN_WINDOW,
|
||||
crate::layout::Size {
|
||||
width: 900.0,
|
||||
height: 650.0,
|
||||
},
|
||||
)]);
|
||||
session.resize_windows_incremental(&latest, false).unwrap();
|
||||
assert!(!session.candidate.vm.has_suspended_call());
|
||||
let settled = session.resize_windows(&latest).unwrap().unwrap();
|
||||
assert_eq!(settled.frame.commands.len(), 80);
|
||||
assert!(settled.frame.commands.iter().all(|command| matches!(command, RenderCommand::RoundedRect { color, .. } if color == "#526AC7")));
|
||||
assert_eq!(
|
||||
session.execute("mounted.value", "app.main").unwrap().value,
|
||||
"80"
|
||||
);
|
||||
assert_eq!(source_measure_stat(&mut session, "paintCancels"), 1);
|
||||
assert!(source_measure_stat(&mut session, "paintSlices") > 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paint_error_after_pause_closes_read_only_scope_and_preserves_last_picture() {
|
||||
let (mut session, initial) =
|
||||
ReplSession::load(&resumable_paint_source(1, 300), "app.main", 279, 1).unwrap();
|
||||
let viewports = std::collections::BTreeMap::new();
|
||||
session
|
||||
.execute_incremental("item.tint = \"invalid-color\"", "app.main", &viewports)
|
||||
.unwrap();
|
||||
let mut paused = false;
|
||||
let mut failed = false;
|
||||
for _ in 0..100 {
|
||||
match session.resize_windows_incremental(&viewports, false) {
|
||||
Ok(_) => {
|
||||
paused |= session
|
||||
.refresh
|
||||
.as_ref()
|
||||
.is_some_and(|work| work.paint.is_some())
|
||||
}
|
||||
Err(_) => {
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(paused && failed);
|
||||
assert!(session.is_faulted());
|
||||
assert!(!session.candidate.vm.has_suspended_call());
|
||||
assert!(!session.candidate.vm.object_store().is_read_only());
|
||||
assert_eq!(
|
||||
session.documents[&crate::window::MAIN_WINDOW]
|
||||
.frame
|
||||
.layout_version,
|
||||
initial.frame.layout_version
|
||||
);
|
||||
assert!(session.documents[&crate::window::MAIN_WINDOW].frame.commands.iter().all(|command| matches!(command, RenderCommand::RoundedRect { color, .. } if color == "#ED6A5A")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_paint_can_rebind_old_plain_reference_to_new_result_without_mutating_it() {
|
||||
let source = r##"class ReboundRect: RectBlock {
|
||||
|
||||
+18
-5
@@ -1,5 +1,5 @@
|
||||
//! Source paint dispatch produces checked immutable commands. One read-only VM
|
||||
//! call sequences all overrides, sharing a single instruction/frame budget.
|
||||
//! resumable call sequences all overrides, sharing one instruction/frame budget.
|
||||
use crate::{
|
||||
document::{Frame, RenderCommand},
|
||||
layout::{self, Size},
|
||||
@@ -314,7 +314,9 @@ impl Work {
|
||||
progress: Result<endor_core::ExecutionProgress, VmError>,
|
||||
) -> Result<Progress> {
|
||||
match progress {
|
||||
Ok(endor_core::ExecutionProgress::Pending { .. }) => Ok(Progress::Pending(Box::new(self))),
|
||||
Ok(endor_core::ExecutionProgress::Pending { .. }) => {
|
||||
Ok(Progress::Pending(Box::new(self)))
|
||||
}
|
||||
Ok(endor_core::ExecutionProgress::Complete { value, reads, .. }) => {
|
||||
vm.release(self.prepare)?;
|
||||
vm.release_value(value)?;
|
||||
@@ -352,18 +354,29 @@ pub fn start(
|
||||
},
|
||||
vec![desktop],
|
||||
))?;
|
||||
let work = Work { desktop, prepare, output, root, frame, slices: 1 };
|
||||
let work = Work {
|
||||
desktop,
|
||||
prepare,
|
||||
output,
|
||||
root,
|
||||
frame,
|
||||
slices: 1,
|
||||
};
|
||||
let result = vm.start_read_only_call(
|
||||
prepare,
|
||||
&[],
|
||||
endor_core::ExecutionLimits { max_frames: 128, max_instructions: 1_000_000 },
|
||||
endor_core::ExecutionLimits {
|
||||
max_frames: 128,
|
||||
max_instructions: 1_000_000,
|
||||
},
|
||||
slice,
|
||||
);
|
||||
work.accept(vm, result)
|
||||
}
|
||||
|
||||
fn finish(vm: &mut Vm, mut work: Work, reads: Vec<ObjectRef>) -> Result<Progress> {
|
||||
let output = work.output
|
||||
let output = work
|
||||
.output
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("paint output poisoned"))?;
|
||||
if output.commands.is_empty() {
|
||||
|
||||
+20
-5
@@ -2500,10 +2500,16 @@ impl UiBridge {
|
||||
progress: crate::source_paint::Progress,
|
||||
) -> Result<crate::source_paint::Progress> {
|
||||
if let crate::source_paint::Progress::Complete(draft) = &progress {
|
||||
let reads = draft.reads.iter().copied()
|
||||
let reads = draft
|
||||
.reads
|
||||
.iter()
|
||||
.copied()
|
||||
.map(|object| vm.change_version(object).map(|version| (object, version)))
|
||||
.collect::<Result<std::collections::BTreeMap<_, _>, _>>()?;
|
||||
let mut state = self.session.lock().map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
|
||||
let mut state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
|
||||
state.paint_reads = reads;
|
||||
state.paint_slices = draft.slices;
|
||||
}
|
||||
@@ -2518,7 +2524,10 @@ impl UiBridge {
|
||||
) -> Result<()> {
|
||||
let cancelled = work.cancel(vm);
|
||||
let invalidated = self.select_window(window).and_then(|()| {
|
||||
self.session.lock().map_err(|_| anyhow::anyhow!("UI session poisoned"))?.force_frame = true;
|
||||
self.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?
|
||||
.force_frame = true;
|
||||
Ok(())
|
||||
});
|
||||
cancelled?;
|
||||
@@ -2651,7 +2660,11 @@ impl UiBridge {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn note_refresh_restart(&self, cancelled_layout: bool, cancelled_paint: bool) -> Result<()> {
|
||||
pub fn note_refresh_restart(
|
||||
&self,
|
||||
cancelled_layout: bool,
|
||||
cancelled_paint: bool,
|
||||
) -> Result<()> {
|
||||
let mut state = self
|
||||
.session
|
||||
.lock()
|
||||
@@ -2660,7 +2673,9 @@ impl UiBridge {
|
||||
state.layout_cancels = state
|
||||
.layout_cancels
|
||||
.saturating_add(usize::from(cancelled_layout));
|
||||
state.paint_cancels = state.paint_cancels.saturating_add(usize::from(cancelled_paint));
|
||||
state.paint_cancels = state
|
||||
.paint_cancels
|
||||
.saturating_add(usize::from(cancelled_paint));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user