diff --git a/src/api.rs b/src/api.rs index 2f05978..bf07d4f 100644 --- a/src/api.rs +++ b/src/api.rs @@ -576,6 +576,7 @@ struct PendingInput { } enum PendingRequest { + BeforeInput, Input(Box), Candidate(Box), } @@ -724,7 +725,7 @@ impl Worker { &mut self, namespace: &Arc>, notify: &Notify, - drain: bool, + before_input: bool, ) { let (epoch, viewports) = match namespace.read() { Ok(current) => { @@ -748,16 +749,14 @@ impl Worker { runtime.poll_tasks()?; return Ok((None, Vec::new())); } - let resized = if drain { - runtime.resize_windows(&viewports)? - } else { - runtime.resize_windows_incremental(&viewports, false)? - }; + let resized = runtime.resize_windows_incremental(&viewports, false)?; if runtime.has_pending_refresh() { return Ok((None, Vec::new())); } - let completed = if drain { - runtime.poll_tasks()? + // An accepted foreground input waits only for the existing + // refresh; do not keep placing new callbacks ahead of it. + let completed = if before_input { + None } else { runtime.poll_tasks_incremental(&viewports)? }; @@ -831,9 +830,9 @@ impl Worker { if job.kind == RequestKind::Expression { return RequestProgress::Complete(build(job, namespace, notify)); } - // Mutating requests serialize behind a pending refresh. Idle polling - // parks between quanta, but input never interleaves heap mutation with - // an active read-only call or publishes a partly refreshed window set. + // Advance one existing refresh quantum, then park the HTTP request. + // No input statement executes inside the read-only scope; shutdown and + // newer viewport targets can be observed at every worker turn. self.refresh_viewport_mode(namespace, notify, true); let epoch = match namespace.read() { Ok(current) => current.submission, @@ -865,6 +864,13 @@ impl Worker { serde_json::json!({"ok":true,"execution":"repl-reset","persistent":true,"session_reset":true,"message":"Console memory cleared; displayed page preserved"}), )); } + if self + .repl + .as_ref() + .is_some_and(|(_, runtime)| runtime.has_pending_refresh()) + { + return RequestProgress::Pending(PendingRequest::BeforeInput); + } let event = if job.kind == RequestKind::Event { let input: crate::events::Input = match serde_json::from_str(&job.source) { Ok(input) => input, @@ -1083,6 +1089,7 @@ impl Worker { notify: &Notify, ) -> RequestProgress { match pending { + PendingRequest::BeforeInput => self.begin_request(job, namespace, notify), PendingRequest::Input(input) => self.resume_input(job, input, namespace, notify), PendingRequest::Candidate(runtime) => { self.resume_candidate(job, runtime, namespace, notify) @@ -1567,6 +1574,9 @@ Window is a host-provided managed resource: ui.window(), page.window(), page.ope Application exit now uses a private VM-worker control channel, independent of HTTP queue capacity. Main native close and a managed primary Window.close request asynchronous cleanup; duplicate requests coalesce and mutation requests are rejected with 503 while exiting. An unpublished candidate/input refresh is cancelled without replay. The current VM cancels all Task entries, closes managed windows, detaches occurrences child-before-parent per window, and invokes normal onUnmount hooks once. It does not run layout/paint during shutdown. All windows are closed before hooks run; new windows and tasks are forbidden. A stopped/faulted VM detaches without source hooks; reset/discarded pictures cannot revive an old VM. A hook error aborts remaining source hooks, releases prepared hook roots, drops the VM and reports failure before native exit. Completed shutdown is acknowledged to the GUI, which then ends the event loop. An OS exit bypassing CloseRequested uses a five-second bounded final fallback; non-cooperative native calls remain atomic and force-kill/crash cannot guarantee notifications. Native stderr records the window/mount/task-entry counts and whether source hooks were enabled, or the cleanup error. See examples/exit-lifecycle.endor. Cross-platform exit/drag validation remains broader follow-up work. +Foreground REPL/events now retain a BeforeInput request while an existing idle layout/paint refresh advances one stage/quantum per worker turn. They execute their source only after that refresh settles, so mutations never enter its read-only scope. New task callbacks are not delivered ahead of this accepted input. Shutdown can cancel the waiting request with 503, and superseded submissions still return 409. Reset cancels/discards the old VM instead of synchronously draining its unpublished refresh. Source parsing/compilation and ordinary synchronous source/native calls remain atomic boundaries; this change removes the worker's synchronous pre-input refresh drain. + + While a native tab drag is held over an overflow arrow area, the strip waits 350ms then reveals one hidden tab every 120ms, including in a compatible destination window. The preview scroll does not activate Pages or change business state. Drawing, hit testing and insertion gaps share the same transient visible range; release uses its full-order insertion index. Leaving the strip stops the timer; release, Escape, a new press or runtime generation change restores the normal active-tab-centered strip. A resize or changing tab count clamps the range. Native drag/mixed-DPI behavior still requires platform validation; application-exit cleanup is described below. @@ -1627,7 +1637,7 @@ source_layout::start now returns either Complete(Draft) or Pending(Work). The ho UiBridge::begin_layout_frame/resume_layout_frame now expose PendingLayout around the source job. This bridge-level continuation also owns its target window, page snapshot, tab projection, viewport restoration and retained lifecycle hook root. Only the Complete branch projects scroll/focus, captures dependency versions, merges derived caches, commits Mount geometry and runs deferred hooks. Resume restores the saved window context, and failure releases hook roots. ReplSession uses this protocol through its saved refresh state. Viewport refresh supports cross-worker-turn scheduling and prepared-Mount rollback; callers must not drop a pending bridge layout as a substitute for cancellation. -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. Mutating requests are serialized; newer viewport targets coalesce by cancelling unpublished layout. Initial source execution remains atomic; initial layout parks across worker turns. Explicit REPL/event refresh parks across worker turns. Idle tasks deliver at most one callback per turn and park subsequent layout; callbacks and individual native nodes remain atomic. Large intrinsic trees use the sliced driver; small intrinsic trees keep the fast path. +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 wait across worker turns for the existing job, so they cannot run inside its read-only scope. Mutating requests are serialized; newer viewport targets coalesce by cancelling unpublished layout. Initial source execution remains atomic; initial layout parks across worker turns. Explicit REPL/event refresh parks across worker turns. Idle tasks deliver at most one callback per turn and park subsequent layout; callbacks and individual native nodes remain atomic. Large intrinsic trees use the sliced driver; small intrinsic trees keep the fast path. 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. diff --git a/src/endor_host.rs b/src/endor_host.rs index eddaf24..1278339 100644 --- a/src/endor_host.rs +++ b/src/endor_host.rs @@ -795,6 +795,7 @@ impl ReplSession { Ok(Some(main)) } + #[cfg(test)] pub fn resize_windows( &mut self, viewports: &std::collections::BTreeMap,