mirror of
https://github.com/storytold/effectcraft.git
synced 2026-12-02 15:01:26 -05:00
a11548f909
* feat(engine): reload external .ecproj edits into the live session Adds a project-file watcher on a worker thread (size + mtime stamps, 250 ms debounce, 1 s focused / 5 s unfocused) that wakes the UI only when the open project's file changed. The UI applies the change on its own thread through the existing file.revert -> replace_project path, so CLI/MCP edits show in the running window without a restart. Session.project_stamp is recorded on open/save so the app's own writes do not reload themselves. A dirty session, active script or render job holds the change and surfaces a status instead of discarding work; autosave is paused while a change is pending. Closes #4168 * fix(engine): close stamp races and correct reload guidance - record the stamp only when the saved bytes are still on disk, so a concurrent external write is not mistaken for our own save - read the project and its stamp as one observation when opening, retrying if the file changes mid-read - install the watcher baseline with the loaded session stamp under one lock, and advance it only after the debounced change is published - add tests for self-save acknowledgement, dirty guard and autosave pause - replace the misleading Save-before-Revert status with Save a Copy guidance Addresses CodeRabbit review on PR #4170 * fix(engine): handle unverified saves and stale reload reports A save whose post-write byte check fails is marked unverified so the watcher reports the first stamp of that path as an external edit instead of adopting it as a baseline. Before reverting, compare the on-disk stamp with the session stamp so a completed self-save does not discard undo history. Defer reload while a script is waiting on a file dialog. Drop a failed reload observation so it is retried only after a new stamp, not every frame. Addresses the second CodeRabbit review on PR #4170 * fix(engine): require known stamp for reload shortcut and cache disk stamp The stamp-matching shortcut only applies when the session stamp is known; an unknown stamp keeps the observation pending. The on-disk stamp is read once when a watcher observation is taken and carried through deferral, avoiding file I/O on every frame. Addresses the final CodeRabbit review on PR #4170 * fix(ui): keep recovery auto-saves while an external edit is pending Auto-save writes recovery copies to their own files, never the project file, so pausing it while a reload was pending only removed crash recovery for unsaved local work. Keep it running, and hold it only when the recovery target would alias the open project file. Adds a regression proving the external project and the local recovery copy both survive, and corrects the spec's wrong premise. * fix(ui): check the autosave alias only on a due write; test every reload guard Move the project-alias check into the engine write path (autosave_tick_guarded) so it runs on the final WritePlan only when auto-save is enabled and a write is due; idle frames do no file-system work. Add regressions holding a pending external change for an active script render, an open script file dialog and an active render job. * test: add ignored measurement benches for the #4168 budgets frame_tick_cost_of_project_reload: per-frame A/B of the UI tick with and without tick_project_reload (p50/p95/p99/max over 100k ticks). watcher_idle_cpu_and_reload_memory: watcher-only idle CPU (focused and background), write->detect latency and RSS over 100 external saves. * fix: rustfmt and strict clippy on the project reload watcher Rewrite the watcher's recv loop as a while condition (clippy::while_let_loop) with unchanged behaviour: a wake or a poll timeout runs one check, a dropped Watcher (channel disconnected) ends the thread. Collapse the pending-change if into its let chain, keep unwrap() inside test functions only, format both files, and normalise project_reload.rs to LF like the rest of the tree. --------- Co-authored-by: matthewdonsemail-lab <matthewdonsemail-lab@users.noreply.github.com> Co-authored-by: FredApps <FredApps@users.noreply.github.com>