Repository navigation
fix(engine): a nested command's "changed nothing" flag no longer reaches the command that ran it (#2637) - #2834
choupeanut wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| let counts = mutates.then(|| self.edit_counts.clone()); | ||
| self.request_only = false; | ||
| // Its flag is its own: the enclosing command's comes back after it, whatever it left. | ||
| let outer_request_only = std::mem::take(&mut self.request_only); |
There was a problem hiding this comment.
Possible regression, low confidence (about 30%), not reproduced.
Before this change, a non-mutating nested command's "left a request" flag leaked up to whatever step ran it. shared_step reads that flag as unchanged and feeds shared_steps.requested and edited. Now guarded_inner restores the enclosing flag on exit, so a Shared step (Txn::Shared in dispatch.rs) whose handler runs a non-mutating nested command that only left a download will see unchanged == false. If the step is declared mutates, edited becomes true, and the script or plugin then takes an empty undo step, where it previously took none.
The PR description says "Nothing would read it", but shared_step (lib.rs ~2316) does read the signal. I did not find a shipped handler that combines a non-mutating nested request with a mutating step, so the impact may be hypothetical. A test would settle it: a Registered mutating command whose handler calls s.guarded("x", false, |s| s.request_url(..)) and makes no edits, run as a script line. Expected result: no undo step. If that case is intended to stay "no step", the isolation needs to carry the nested signal up to shared_steps.requested rather than dropping it.
Category: bug
Code reviewBugs
Security
Performance
Quality
AGENTS.md
Checked and found correct
I left no earlier threads alone, since Change sizeCompared with the base branch: the whole PR, merge base dd3d011 to head 4b12a7a. Files changed: 5 (0 added, 5 modified, 0 removed, 0 renamed).
Sizes are in binary KB and MB (1 KB = 1024 B).
|
📖 Docs previewCommit |
Summary
Session::request_only("this command only left a request, or changed nothing: no undo step") is one flag for the whole session.guarded_innercleared it when a command started and read it only in the branch for commands that mutate, so a nested command that did not mutate, or that set it and then failed, left it set. The command that ran it then read that as its own and took no undo step for its own edit. No command known on main does this today;run_part(the GeoLibre and QGIS imports),model.importand any command that runs another can.guarded_inner(crates/engine/src/lib.rs) now saves the enclosing command's flag when a command starts and puts it back when it ends, asshared_stepalready does for a script line. Both reads of the flag happen before the restore, so a command still decides its own step. There is no?or early return between the save and the restore, and a panic in the command is caught into an error first, so the restore runs on every path.shared_stepsdoes for shared steps). Nothing would read it: a nested command takes its own undo step or none, and the command that ran it does not follow it. A command that wants to follow its tools (the model) already counts them itself.model.rs: a model sets its own flag from what its tools did (file_pending && !tool_completed), where it cleared a flag its tools had left.cmd/geolibre.rs: the line that sets the flag to false stays, with a comment saying why. The import callsrequest_import_urlitself, which sets the flag in the import's own scope. That is not a nested-command leak, so the guard change does not cover it: with the line removed, an import that leaves a download took no undo step (0 steps, expected 1). A new test pins it.shared_steps.requested, becauserestore_url_request_checkpointwithdraws its request and its flag no longer outlives it. Before, a plugin command whose only request failed could end up with no undo step.cmd/plugins.rs: comments only. A plugin command that may edit keeps its undo step even when it changed nothing, and two existing tests pin that (plugin_settings_are_kept_per_plugin_across_sessions_updates_and_toggles,shape_conversion_plugin_handled_rejection_is_atomic_and_has_no_inner_undo); a script or task takes none in that case. The issue allowed writing the reason next to the rule instead of unifying, so that is what this does. Unifying would change the Undo list for plugin commands, a rule change for the maintainer.Testing
a_nested_commands_request_flag_is_not_the_enclosing_commands: a mutating command that runs a non-mutating nested command which leaves a request, or a nested one that sets the flag and fails, and then edits, records one undo step and Undo takes the edit back; a command that sets the flag itself still records none. Fails on the old code (the outer edit takes its step, left 0, right 1), passes now.a_nested_panic_leaves_the_enclosing_commands_request_flag_alone: a nested command sets the flag and panics; the panic becomes its error, and the enclosing command that goes on keeps its step.a_script_that_leaves_a_request_and_then_edits_is_one_undo_step: throughscript.runwith no network (layer.addUrlheld for the app): request then edit is one step, a request alone none. The script's lines were already isolated byshared_step; this pins it.geolibre_import_that_leaves_a_download_is_one_undo_step: passes before and after; it fails if the kept line incmd/geolibre.rsis removed.file_only_model_still_skips_an_empty_undo_step_and_completes_on_delivery) and "a queued file beside a completed tool keeps the step" (queued_file_does_not_hide_undo_for_prior_model_tools); they pass.cargo test -p rustgis-engineandcargo clippy -p rustgis-engine --all-targets -- -D warnings: pass (engine lib 2257 passed, 0 failed, 9 ignored; engine integration 214 passed, 0 failed, 2 ignored; clippy clean).origin/main(463133b) with this branch and my other branch fix/2758-inline-graph-capabilities merged, in an English locale: pre-commit on every file,cargo fmt --check, clippy with-D warnings,cargo xtask layers,cargo xtask schema --checkwith the fixtures and test hygiene,cargo xtask rows, and the Python package's tests (maturin + pytest, 49 passed) pass.cargo test --workspace: 9313 passed, 3 failed. The 3 compare memory limits read at two moments while free memory moved under the gate's load (oversized_geojson_publish_gives_vector_advice,oversized_shapefile_dbf_read_for_publish_gives_dataset_advice,analysis_workflows_models_scripts_and_raster_functions), and each passes when run alone. Not run here: the wasm32 build (no clang on this machine; CI's Web app job checks it), macOS and Windows.Reach every surface
Engine only, so every surface that runs commands gets it: desktop, browser, command line, Python, the phone, the Assistant, MCP and plugins. No command, parameter, notice, saved-file or interface text changes, so the ribbon, the Assistant's tool descriptions, the command-surface snapshot and the translation catalogs are unchanged. Undo and Redo behave as before; the change only stops a command that edited from losing its step. Nothing drops or approximates data, so there is no notice to add. Nothing is behind
cfg, so the browser build is unchanged.UI evidence
No visible UI change.
Related issue
Closes #2637
Summary by CodeRabbit