From 1386e9dc33d9e815481dfe4af10e47f6ce3f33e6 Mon Sep 17 00:00:00 2001 From: David Mann Date: Fri, 4 Dec 2026 21:18:42 +0100 Subject: [PATCH] fix(automation): the app's own reload and native menu run outside a waiting agent's scope While an agent's queued input waits, its gate and footage wrapper are installed. The reload of a changed project and commands from the native menu are the app's or the person's, not the agent's: `Session::without_gate` now lifts the footage wrapper too, the reload runs through it, and native-menu commands run through `as_person`. The agent's own project still keeps its limits on a reload (`Session::reverting`). Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/session/dispatch.rs | 9 +++++++-- crates/engine/tests/it/command_gate.rs | 15 +++++++++++++++ crates/ui-egui/src/app/frame.rs | 7 +++++-- crates/ui-egui/src/app/input.rs | 16 ++++++++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/session/dispatch.rs b/crates/engine/src/session/dispatch.rs index 5b7f0feee..66ae25897 100644 --- a/crates/engine/src/session/dispatch.rs +++ b/crates/engine/src/session/dispatch.rs @@ -77,14 +77,19 @@ impl Session { r } - /// Runs `f` without the [`Session::command_gate`]: work the app does on its own (a Watch - /// Folder's poll), not for the agent whose request or input is being handled. + /// Runs `f` without the [`Session::command_gate`] and the agent's footage wrapper + /// ([`Session::agent_footage`]): work the app does on its own (a Watch Folder's poll, the + /// reload of a changed project), not for the agent whose request or input is being handled. pub fn without_gate(&mut self, f: impl FnOnce(&mut Session) -> R) -> R { let gate = self.command_gate.take(); + let footage = self.agent_footage.take(); let r = f(self); if self.command_gate.is_none() { self.command_gate = gate; } + if self.agent_footage.is_none() { + self.agent_footage = footage; + } r } diff --git a/crates/engine/tests/it/command_gate.rs b/crates/engine/tests/it/command_gate.rs index c903d5fc3..32e70f70d 100644 --- a/crates/engine/tests/it/command_gate.rs +++ b/crates/engine/tests/it/command_gate.rs @@ -48,3 +48,18 @@ fn the_commands_a_command_runs_are_not_checked_again() { assert!(s.without_gate(|s| s.execute("layer.newSolid", json!({"name": "S"}))).is_ok()); assert!(s.command_gate.is_some()); } + +/// The app's own work (the reload of a changed project) runs as the person's: a project it opens +/// doesn't take the footage wrapper of an agent whose input waits, which comes back afterwards. +#[test] +fn work_without_the_gate_opens_projects_without_the_agents_footage_wrapper() { + let seen = Arc::new(Mutex::new(vec![])); + let wrapped: Arc = Arc::new(effectcraft_engine::render::NoFootage); + let wrapper = wrapped.clone(); + let wrap: effectcraft_engine::FootageWrap = Arc::new(move |_| wrapper.clone()); + let mut s = Session { command_gate: Some(gate(&seen)), agent_footage: Some(wrap), ..Default::default() }; + let own = s.footage.clone(); + s.without_gate(|s| s.execute("file.newProject", json!({}))).unwrap(); + assert!(Arc::ptr_eq(&s.footage, &own), "the app's own open took the agent's footage wrapper"); + assert!(s.agent_footage.is_some() && s.command_gate.is_some(), "the agent's scope didn't come back"); +} diff --git a/crates/ui-egui/src/app/frame.rs b/crates/ui-egui/src/app/frame.rs index a27522d20..438796c04 100644 --- a/crates/ui-egui/src/app/frame.rs +++ b/crates/ui-egui/src/app/frame.rs @@ -358,7 +358,8 @@ impl EffectcraftApp { } if let Some(rx) = self.command_inbox.take() { while let Ok(id) = rx.try_recv() { - if let Err(e) = menus::invoke(self, ctx, &id, json!({})) { + // The person's native menu: not confined by an agent whose input waits. + if let Err(e) = self.as_person(|app| menus::invoke(app, ctx, &id, json!({}))) { self.ui.status = e; } } @@ -904,7 +905,9 @@ impl EffectcraftApp { self.ui.status = "Project changed on disk. To keep your changes, use File ▸ Save As ▸ Save a Copy... Then File ▸ Revert loads the disk version; Revert discards unsaved changes.".into(); return; } - match self.session.execute("file.revert", serde_json::json!({})) { + // The app's own reload, not an agent's request: its gate doesn't apply, and only the agent's + // own project keeps the agent's footage limits (`Session::reverting`). + match self.session.without_gate(|s| s.execute("file.revert", serde_json::json!({}))) { Ok(_) => { self.ui.status = format!("Reloaded {path} changed on disk"); watcher.acknowledge(self.session.project_stamp); diff --git a/crates/ui-egui/src/app/input.rs b/crates/ui-egui/src/app/input.rs index 76da531af..e2437b7d8 100644 --- a/crates/ui-egui/src/app/input.rs +++ b/crates/ui-egui/src/app/input.rs @@ -86,6 +86,22 @@ impl EffectcraftApp { } } + /// Runs `f` as the person: without the gate and footage wrapper of an agent whose queued + /// input waits, both put back afterwards ([`effectcraft_engine::Session::without_gate`] for + /// what needs the whole app, such as a native-menu command). + pub(crate) fn as_person(&mut self, f: impl FnOnce(&mut Self) -> R) -> R { + let gate = self.session.command_gate.take(); + let footage = self.session.agent_footage.take(); + let r = f(self); + if self.session.command_gate.is_none() { + self.session.command_gate = gate; + } + if self.session.agent_footage.is_none() { + self.session.agent_footage = footage; + } + r + } + /// Take the pending synthetic input (from `ui.click`, `ui.key`, …). Hosts that don't call /// [`eframe::App::raw_input_hook`] (the headless test harness) feed these in themselves. pub fn take_synthetic_input(&mut self) -> Vec {