From aac3312bfbc644ddb1c50f7fa8d243eb886adc27 Mon Sep 17 00:00:00 2001 From: Brennan Stehling <277419+brennanMKE@users.noreply.github.com> Date: Mon, 9 Nov 2026 06:49:05 -0800 Subject: [PATCH] Perf: one frame stage record across egui's passes; the web keeps slow frames too (#9328) (#10103) * Perf: the web keeps slow frames too; its clock is performance.now() (#9328) now_ms() reads web_time::Instant, which is performance.now() on wasm, so the web build records slow frames, reports perf.slowFrames and logs them to the browser console. The stroke trace is off on the web for another reason: it has no environment, stderr or files to write to. Co-Authored-By: Claude Opus 5.5 (1M context) * Perf: one frame stage record across egui's passes (#9328) egui runs a frame's UI again when a pass asks for a discard (a sizing pass). The second pass opened a new stage record after the first pass closed its own, so a frame of two 30 ms passes was never slow and the stroke trace gained a 0-move row per extra pass. finish_frame now adds each pass's UI time to the record and leaves it open while ctx.will_discard() says egui will run the pass again; the last pass closes it. ui_start keeps the first pass's input time. Co-Authored-By: Claude Opus 5.5 (1M context) * Perf: a frame's stroke flag covers every pass Co-Authored-By: Claude Opus 5.5 (1M context) --------- Co-authored-by: Claude Opus 5.5 (1M context) --- crates/ui-egui/src/app/control.rs | 16 ++-- crates/ui-egui/src/app/frame.rs | 4 +- crates/ui-egui/src/control/tests.rs | 4 +- crates/ui-egui/src/frame_stages.rs | 93 ++++++++++++++++++++++- crates/ui-egui/src/stroke_timing_tests.rs | 2 +- crates/ui-egui/src/tools/stroke_trace.rs | 6 +- docs/control-protocol.md | 2 +- 7 files changed, 110 insertions(+), 17 deletions(-) diff --git a/crates/ui-egui/src/app/control.rs b/crates/ui-egui/src/app/control.rs index 1032873c56..ab20ffca36 100644 --- a/crates/ui-egui/src/app/control.rs +++ b/crates/ui-egui/src/app/control.rs @@ -8,13 +8,19 @@ impl PhotocraftApp { } /// Close this frame's stage record (`frame_stages`): keep it if it was slow, and hand it to - /// the stroke trace. `ui_ms` is the UI build's time. - pub(crate) fn finish_frame(&mut self, ui_ms: f64) { - let mut stages = std::mem::take(&mut self.perf.stage); - stages.ui_ms = ui_ms; + /// the stroke trace. `ui_ms` is this pass's UI build. A pass egui will run again + /// (`request_discard`, such as a sizing pass) leaves the record open, so a frame is one + /// record across all its passes. + pub(crate) fn finish_frame(&mut self, ctx: &egui::Context, ui_ms: f64) { + self.perf.stage.ui_ms += ui_ms; + self.perf.stage.stroking |= self.live_stroke.is_some(); + if ctx.will_discard() { + return; + } + let stages = std::mem::take(&mut self.perf.stage); let stages = self.slow_frames.finish(stages, gpu_canvas::now_ms(), self.perf.gpu, self.perf.gpu_ms); let info = &self.perf.gpu_info; - self.stroke_trace.frame(&stages, self.live_stroke.is_some(), || { + self.stroke_trace.frame(&stages, stages.stroking, || { let gpu = format!("{} {}", info.backend, info.adapter).trim().to_string(); if info.present.is_empty() { gpu } else { format!("{gpu}, {}", info.present) } }); diff --git a/crates/ui-egui/src/app/frame.rs b/crates/ui-egui/src/app/frame.rs index dafe8a25ef..c30d43be82 100644 --- a/crates/ui-egui/src/app/frame.rs +++ b/crates/ui-egui/src/app/frame.rs @@ -182,7 +182,7 @@ impl PhotocraftApp { // No editor was drawn this pass: end its IME context rather than keep a stale owner. type_tool::sync_ime(self, &ctx); // The frame's stage record was started with its input: close it here too. - self.finish_frame(0.0); + self.finish_frame(&ctx, 0.0); return; } let t0 = gpu_canvas::now_ms(); @@ -205,7 +205,7 @@ impl PhotocraftApp { self.perf.record_gpu(t); } self.perf.frame(ui_ms); - self.finish_frame(ui_ms); + self.finish_frame(&ctx, ui_ms); if !drawn { return; } diff --git a/crates/ui-egui/src/control/tests.rs b/crates/ui-egui/src/control/tests.rs index dfdbcacb10..1d66fdb651 100644 --- a/crates/ui-egui/src/control/tests.rs +++ b/crates/ui-egui/src/control/tests.rs @@ -138,7 +138,7 @@ fn perf_output_includes_slow_frames() { assert_eq!(call(&mut app, &ctx, "ui.inspect", json!({}))["result"]["perf"]["slowFrames"], json!([])); app.slow_frames.set_threshold_ms(0.0); app.run("file.new", json!({"width": 64, "height": 32})).unwrap(); - app.finish_frame(1.0); + app.finish_frame(&ctx, 1.0); let frames = call(&mut app, &ctx, "ui.inspect", json!({}))["result"]["perf"]["slowFrames"].clone(); let last = frames.as_array().and_then(|f| f.last()).expect("a slow frame").clone(); assert_eq!(last["command"], "file.new", "{last}"); @@ -156,7 +156,7 @@ fn perf_output_includes_slow_frames() { let played = app.run("actions.play", json!({"action": "Zoom"})).unwrap(); assert_eq!(played["ran"], 2, "{played}"); let outer_ms = app.perf.command_ms; - app.finish_frame(1.0); + app.finish_frame(&ctx, 1.0); let frames = call(&mut app, &ctx, "ui.inspect", json!({}))["result"]["perf"]["slowFrames"].clone(); let last = frames.as_array().and_then(|f| f.last()).expect("a slow frame").clone(); assert_eq!(last["command"], "actions.play", "{last}"); diff --git a/crates/ui-egui/src/frame_stages.rs b/crates/ui-egui/src/frame_stages.rs index c2b4fc5fb9..0bc1d6c416 100644 --- a/crates/ui-egui/src/frame_stages.rs +++ b/crates/ui-egui/src/frame_stages.rs @@ -3,12 +3,13 @@ //! [`FrameStages`] is one frame's record. Each stage has one writer: the raw input hook starts //! the frame, `App::run` adds commands, the GPU canvas path adds damage tracking and budgeting, //! [`crate::gpu_canvas::Perf::record`] adds composites and uploads, and the canvas adds stroke -//! rendering. `App::ui` closes it ([`SlowFrames::finish`]). A frame over [`SLOW_FRAME_MS`] goes +//! rendering. `App::ui` closes it on the frame's last egui pass ([`SlowFrames::finish`]). A frame over [`SLOW_FRAME_MS`] goes //! into [`SlowFrames`], the last [`SLOW_FRAMES`] of them, which the control channel's `perf` //! output lists as `slowFrames`; one `info` log line per second names them. The stroke trace //! (`stroke_trace`) reads the same record, so the app times a frame in one place. //! -//! On the web `now_ms()` is 0, so no frame is ever slow and the ring stays empty. +//! The web build does the same: `now_ms()` is `performance.now()` there, and the log line goes to +//! the browser console. use std::collections::VecDeque; @@ -51,12 +52,16 @@ pub struct FrameStages { pub refresh_px: u64, /// "gpu" or "cpu": who drew the canvas. pub path: &'static str, - /// Building the UI (`App::ui`), the canvas refresh included. + /// Building the UI (`App::ui`, every egui pass of the frame), the canvas refresh included. #[serde(skip)] pub ui_ms: f64, /// Rendering stroke points (the stroke trace's `stroke`). #[serde(skip)] pub stroke_ms: f64, + /// A stroke was live in some egui pass of the frame, even one a later pass cancelled (a tool + /// change) and whose dab rendered no stroke points. + #[serde(skip)] + pub stroking: bool, /// Pointer moves the frame delivered. #[serde(skip)] pub moves: usize, @@ -66,6 +71,9 @@ pub struct FrameStages { /// The raw input hook ran for this frame. #[serde(skip)] started: bool, + /// The UI build started (a later egui pass of the frame doesn't start it again). + #[serde(skip)] + ui_started: bool, } impl FrameStages { @@ -77,7 +85,12 @@ impl FrameStages { } /// The UI build starts at `now`; `cpu_prev` is eframe's CPU time for the previous frame, in s. + /// A later egui pass of the same frame keeps the first pass's input time. pub fn ui_start(&mut self, now: f64, cpu_prev: Option) { + if self.ui_started { + return; + } + self.ui_started = true; if !self.started { self.start(now, 0); } @@ -295,6 +308,80 @@ mod app_tests { use crate::PhotocraftApp; + /// One frame of `passes` egui passes of `pass_ms` each, through the app's hooks: the raw input + /// hook starts the record once, and each pass's UI build ends in `finish_frame`. Every pass but + /// the last asks egui for another, as a sizing pass does. `stroke`: each pass renders stroke + /// points for 1 ms. + fn frame(app: &mut PhotocraftApp, ctx: &egui::Context, passes: usize, pass_ms: u64, stroke: bool) { + app.perf.stage.start(crate::gpu_canvas::now_ms(), 1); + ctx.run_ui(egui::RawInput::default(), |ui| { + let ctx = ui.ctx().clone(); + let t0 = crate::gpu_canvas::now_ms(); + app.perf.stage.ui_start(t0, None); + std::thread::sleep(std::time::Duration::from_millis(pass_ms)); + if stroke { + app.perf.stage.stroke_ms += 1.0; + } + if ctx.current_pass_index() + 1 < passes { + ctx.request_discard("a sizing pass"); + } + app.finish_frame(&ctx, crate::gpu_canvas::now_ms() - t0); + }) + .drop_without_applying_deltas(); + } + + #[test] + fn two_30_ms_passes_of_one_frame_are_one_60_ms_slow_frame() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + let ctx = egui::Context::default(); + frame(&mut app, &ctx, 2, 30, false); + let frames: Vec<_> = app.slow_frames.frames().cloned().collect(); + assert_eq!(frames.len(), 1, "{frames:?}"); + let f = &frames[0]; + assert!(f.frame_ms >= 60.0 && f.ui_ms >= 60.0, "both passes: {f:?}"); + assert!(f.input_ms < 30.0, "the first pass isn't the second's input: {f:?}"); + assert_eq!(app.perf.stage, super::FrameStages::default(), "the last pass closed the record"); + } + + #[test] + fn the_stroke_trace_gets_one_row_per_frame_not_per_pass() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.stroke_trace.output = crate::stroke_trace::Output::Stderr; + let ctx = egui::Context::default(); + for _ in 0..3 { + frame(&mut app, &ctx, 2, 1, true); + } + frame(&mut app, &ctx, 2, 1, false); + let s = app.stroke_trace.last.clone().expect("the stroke ended"); + assert_eq!(s.frames, 3, "{s:?}"); + assert_eq!(s.moves, [1.0, 1.0], "each row has its frame's moves: {s:?}"); + assert_eq!(s.stroke, [2.0, 2.0], "both passes' stroke rendering: {s:?}"); + } + + #[test] + fn a_stroke_live_only_in_a_discarded_pass_still_gets_its_frame_traced() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.stroke_trace.output = crate::stroke_trace::Output::Stderr; + let ctx = egui::Context::default(); + app.perf.stage.start(crate::gpu_canvas::now_ms(), 1); + ctx.run_ui(egui::RawInput::default(), |ui| { + let ctx = ui.ctx().clone(); + app.perf.stage.ui_start(crate::gpu_canvas::now_ms(), None); + if ctx.current_pass_index() == 0 { + // The first pass's live stroke (its `finish_frame` saw `live_stroke`), which the + // last pass cancels before rendering any stroke points. + app.perf.stage.stroking = true; + ctx.request_discard("a sizing pass"); + } + app.finish_frame(&ctx, 1.0); + }) + .drop_without_applying_deltas(); + assert!(app.live_stroke.is_none() && app.stroke_trace.last.is_none()); + frame(&mut app, &ctx, 2, 1, false); + let s = app.stroke_trace.last.clone().expect("the stroke ended"); + assert_eq!(s.frames, 1, "the frame whose stroke the last pass cancelled: {s:?}"); + } + #[test] fn an_app_frame_with_a_full_refresh_records_its_stages() { let (w, h) = (4000u64, 3000u64); diff --git a/crates/ui-egui/src/stroke_timing_tests.rs b/crates/ui-egui/src/stroke_timing_tests.rs index ed59943fae..e50e85d4db 100644 --- a/crates/ui-egui/src/stroke_timing_tests.rs +++ b/crates/ui-egui/src/stroke_timing_tests.rs @@ -390,7 +390,7 @@ fn the_stroke_trace_times_each_frame_of_a_stroke_and_ends_on_release() { app.perf.stage.start(t0, moves); app.perf.stage.ui_start(t0, Some(0.004)); egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui)); - app.finish_frame(crate::gpu_canvas::now_ms() - t0); + app.finish_frame(&ctx, crate::gpu_canvas::now_ms() - t0); }, app, ); diff --git a/crates/ui-egui/src/tools/stroke_trace.rs b/crates/ui-egui/src/tools/stroke_trace.rs index 8bbd1c887a..443c695792 100644 --- a/crates/ui-egui/src/tools/stroke_trace.rs +++ b/crates/ui-egui/src/tools/stroke_trace.rs @@ -83,7 +83,7 @@ impl Summary { } /// Where the trace goes ([`StrokeTrace::from_env`]). -// The web build has no clock, so it never traces. +// The web build never traces: it has no environment, stderr or files to write to. #[cfg_attr(target_arch = "wasm32", allow(dead_code))] #[derive(Clone, Debug, Default, PartialEq)] pub(crate) enum Output { @@ -120,7 +120,7 @@ fn percentiles(mut v: Vec) -> [f64; 2] { } impl StrokeTrace { - /// Reads `PHOTOCRAFT_STROKE_TRACE` (off on the web, where there is no clock). + /// Reads `PHOTOCRAFT_STROKE_TRACE` (off on the web, which has no environment, stderr or files). pub fn from_env() -> Self { #[cfg(not(target_arch = "wasm32"))] if let Some(v) = std::env::var_os("PHOTOCRAFT_STROKE_TRACE") { @@ -202,7 +202,7 @@ impl StrokeTrace { } /// The CSV text for `rows` of stroke `stroke` (with the header when `header`). -// The web build has no clock, so it never traces. +// The web build never traces: it has no environment, stderr or files to write to. #[cfg_attr(target_arch = "wasm32", allow(dead_code))] pub(crate) fn csv(stroke: usize, rows: &[Row], header: bool) -> String { let mut s = String::new(); diff --git a/docs/control-protocol.md b/docs/control-protocol.md index ad8d63ab6d..8f1260ad9d 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -46,7 +46,7 @@ The transport is `apps/photocraft/src/control_server.rs`, and the handlers are i - `engine.execute {command, params}`: run any engine or UI command by id. Engine commands run directly with their default params and never open a dialog. Use `ui.menu.invoke` for menu-click behaviour, which opens a command's dialog when no params are given. `params` must be a JSON object (omit it or pass `null` for none); an array, string, number or boolean is an error naming the command, in every transport (control channel, `serve`, MCP and the CLI) - `engine.commands`: list commands with enablement; the `result` is a JSON array of command objects (see [Command list replies](#command-list-replies)) -- `ui.inspect`: full UI state (tool, panels, views, dialogs, windows, window size). The menu tree is not included; use `ui.menu.list`. `brushPicker` is `null` while closed and `{pos: [x, y], size: [w, h]?, list: {collapsed, filter, renaming, showName, showStroke, showTip, scale}}` while the Brush Preset picker is open (coordinates in screen points; `size` is the picker's content size once its corner grip was dragged, `null` before that, and the drag remembers both dimensions; the three `show*` flags pick the parts of each preset's card — at least one is always on; `scale` is the footer slider, 0.15–2 with 1 the standard, multiplying the cards' width and height — the heights stop at half size and the name and tip-size text hold their 1.0 size — and dropping the tips' size numbers at 0.40 and below; the parts and the scale are remembered across restarts, while the search, collapsed groups and a rename in progress are not). `view` holds the View/Window/Type preferences: `screen_mode`, `extras`, `show` and `snap_to` flags, `flip_horizontal`, `arrange` (Window › Arrange layout), pixel aspect, font preview size, language options. `perf.timings.gpuInfo` holds the graphics adapter, backend, driver, the backend chosen at launch and why, the canvas renderer (`gpu`/`cpu`) and, after a device loss, `lost` (`help.systemInfo` returns the same as `info`). `perf.renderPath` says why the active document is drawn on the CPU: `current` is `null` on the GPU, else `{doc, kind, detail}` (`kind` is one of `overBudget`, `canvasTooLarge`, `compositorBuild`, `deviceLost`, `gpuError`, `unsupported`, `adjustPreview`, `viewTransform`, `softwareAdapter`, `cpuMode`; `detail` is the English reason, with the working set and budget for `overBudget`), and `history` holds the last 32 changes, oldest first (`{t, doc, kind, detail}`, `kind` `null` for back on the GPU, `doc` the changed document's id, or 0 for a change to every document). An adjustment dialog's CPU proxy preview has its own slot: `current` reports it (`adjustPreview`) only when neither the window nor the canvas has a reason, it isn't recorded while the whole window is off the GPU, and its history entries always have `kind` `adjustPreview`, with `detail` `null` when the preview stops using the proxy (never read as back on the GPU). `perf.timings.gpuFallback` is `current`'s `detail` as text. `perf.slowFrames` lists the last 64 frames over 50 ms, oldest first, each with its stages in ms: `t` (start), `frameMs`, `inputMs` (raw input to the UI build, commands excluded), `commandMs` and `command` (the last command run since the previous frame), `damageMs` (damage tracking and GPU memory budgeting), `compositeMs`, `uploadMs`, `gpuMs` (the GPU's own composite time, or `null`), `presentMs` (the previous frame's tessellation and submission, or `null`), `refresh` and `refreshPx` (the canvas redraw's kind and pixels) and `path` (`gpu` or `cpu`). It stays empty on the web, which has no clock +- `ui.inspect`: full UI state (tool, panels, views, dialogs, windows, window size). The menu tree is not included; use `ui.menu.list`. `brushPicker` is `null` while closed and `{pos: [x, y], size: [w, h]?, list: {collapsed, filter, renaming, showName, showStroke, showTip, scale}}` while the Brush Preset picker is open (coordinates in screen points; `size` is the picker's content size once its corner grip was dragged, `null` before that, and the drag remembers both dimensions; the three `show*` flags pick the parts of each preset's card — at least one is always on; `scale` is the footer slider, 0.15–2 with 1 the standard, multiplying the cards' width and height — the heights stop at half size and the name and tip-size text hold their 1.0 size — and dropping the tips' size numbers at 0.40 and below; the parts and the scale are remembered across restarts, while the search, collapsed groups and a rename in progress are not). `view` holds the View/Window/Type preferences: `screen_mode`, `extras`, `show` and `snap_to` flags, `flip_horizontal`, `arrange` (Window › Arrange layout), pixel aspect, font preview size, language options. `perf.timings.gpuInfo` holds the graphics adapter, backend, driver, the backend chosen at launch and why, the canvas renderer (`gpu`/`cpu`) and, after a device loss, `lost` (`help.systemInfo` returns the same as `info`). `perf.renderPath` says why the active document is drawn on the CPU: `current` is `null` on the GPU, else `{doc, kind, detail}` (`kind` is one of `overBudget`, `canvasTooLarge`, `compositorBuild`, `deviceLost`, `gpuError`, `unsupported`, `adjustPreview`, `viewTransform`, `softwareAdapter`, `cpuMode`; `detail` is the English reason, with the working set and budget for `overBudget`), and `history` holds the last 32 changes, oldest first (`{t, doc, kind, detail}`, `kind` `null` for back on the GPU, `doc` the changed document's id, or 0 for a change to every document). An adjustment dialog's CPU proxy preview has its own slot: `current` reports it (`adjustPreview`) only when neither the window nor the canvas has a reason, it isn't recorded while the whole window is off the GPU, and its history entries always have `kind` `adjustPreview`, with `detail` `null` when the preview stops using the proxy (never read as back on the GPU). `perf.timings.gpuFallback` is `current`'s `detail` as text. `perf.slowFrames` lists the last 64 frames over 50 ms, oldest first, each with its stages in ms: `t` (start), `frameMs`, `inputMs` (raw input to the UI build, commands excluded), `commandMs` and `command` (the last command run since the previous frame), `damageMs` (damage tracking and GPU memory budgeting), `compositeMs`, `uploadMs`, `gpuMs` (the GPU's own composite time, or `null`), `presentMs` (the previous frame's tessellation and submission, or `null`), `refresh` and `refreshPx` (the canvas redraw's kind and pixels) and `path` (`gpu` or `cpu`). The web build keeps them too (its clock is `performance.now()`) and logs them to the browser console - `ui.set {tool?, panels?, dockTabs?, dock?, dockWidth?, colorPanel?, maskTarget?, vectorMaskTarget?, filterMaskTarget?, selectionMode?, zoom?, center?, rotation?, fit?, theme?, brushSize?, brushSection?, brushTab?, brushesView?, brushPicker?, brushPickerName?, brushPickerStroke?, brushPickerTip?, brushPickerScale?, gradientBlendMode?, gradientClassic?, shapeStroke?}`: change UI state; any other field is an error, checked before anything changes (`zoom` is the canvas zoom where 1 = 100%, one document pixel per physical display pixel, so a scaled display doesn't magnify the image; `theme` is `pro`, `proMedium`, `studio`, `studioLight` or `classic`; `selectionMode` is the selection tools' options-bar mode, 0 New, 1 Add, 2 Subtract, 3 Intersect; `brushSection` indexes the Brush Settings sections, `brushTab` 0 = Brush Settings, 1 = Brushes; `brushesView` is `list` or `grid` for the Brushes panel; `brushPickerName`, `brushPickerStroke` and `brushPickerTip` are the Brush Preset picker's card parts (booleans, at least one on), and `brushPickerScale` its footer card-scale slider (0.15 to 2, 1 the standard); `brushPicker` is `[x, y]` in screen points to open the Brush Preset picker there (as a right-click with a painting tool does) or `null` to close it, and picking a preset in it is `tools.setBrush {"preset": name}`; `dock` is `{order: ["layers", …], heights: {"properties": 180}, collapsed: ["color"], tabOrder: {"layers": ["Paths", "Layers", "Channels"]}}`, the right-dock groups top to bottom, their heights in points, the groups collapsed to their tab strip and each group's tab order left to right by panel name (a group left out keeps its default order, unknown names are ignored and tabs not listed follow in their default order; `dockTabs` keeps indexing tabs in their default order); `dockWidth` sets the right dock width in points, clamped to 250..520; `colorPanel` is `{background?, mode?, ramp?, webSafeRamp?}`, merged into the Color panel's state: `background` is whether it edits the background colour, `mode` its panel-menu display (`hueCube`, `brightnessCube`, `colorWheel`, `grayscaleSlider`, `rgbSliders`, `hsbSliders`, `cmykSliders`, `labSliders` or `webColorSliders`), `ramp` the colour ramp under the sliders (`rgbSpectrum`, `cmykSpectrum`, `grayscaleRamp` or `currentColors`) and `webSafeRamp` Make Ramp Web Safe; `maskTarget` targets the active layer's mask, which, like Photoshop, swaps in the foreground/background pair kept for masks (white/black until one is picked) and swaps the pixels' pair back when the pixels are targeted again; `filterMaskTarget` targets the active smart object's filter mask (an error without smart filters), so painting, fills, filters and adjustments edit it (`"target":"filterMask"`) while Move and Edit › Transform still act on the smart object) - `typeTransform` is `null` outside a temporary Ctrl/Cmd Type-tool drag. During a drag it reports its source document/revision, original affine, oriented `frame` (layer, local bounds, document-space corners and pivot), and captured `gesture`. Drive it with `ui.pointer` and `command: true` at `down`; `move`/`up` may release the modifier. The document/history remain unchanged during preview, and `up` applies one `type.edit` within `textEdit`'s session. Pressing Escape during the drag cancels only the preview. This pointer state is never restored from saved UI state. - `ui.menu.invoke {id, params?, wait?}` / `ui.menu.list`: activate a menu item by id; list the menu tree. A menu item that starts a background job (a filter without a dialog, such as Blur More) replies with the job's result once it has been applied; with `"wait": false` the reply is `{job, pending: true}` at once. Window ends with the open documents as `window.document.` (tab order, the active one checked, #2991); invoking one brings that document to the front and replies `{document: index}`. Camera Raw and the full-window workspaces (Liquify, Content-Aware Fill, Filter Gallery, Adaptive Wide Angle) are modal: while one is open, `ui.menu.invoke` refuses every other menu item ("menu command is unavailable while a modal dialog is open") and accepts only that workspace's own `{"ui": {...}}` requests (`filter.liquify`, `edit.contentAwareFill`, `filter.filterGallery`, `filter.adaptiveWideAngle`, `filter.cameraRaw`; `params` must hold only the `ui` object), so finish it with `{"ui":{"commit":true}}` or `{"ui":{"cancel":true}}` first. Those requests are refused too while a dialog, an unsaved-changes prompt or a crop that blocks the command is open: resolve that first, then commit or cancel the workspace. `ui.menu.list` reports the same gate: an item the modal state refuses is listed with `enabled: false`. `engine.execute` is not a menu click and is not gated