From 84016f036e43baca088b0c1bd182a2d93da45c4e Mon Sep 17 00:00:00 2001 From: Colin Faulkingham Date: Wed, 28 Oct 2026 14:02:44 +0000 Subject: [PATCH] Redefine: the reply reports the features it rebuilt (#5694) (#8244) * claim: #5694 * Redefine: the reply reports the features it rebuilt (#5694) timeline.redefine builds the edited feature and the features after it in its trial session; the session's own evaluation then only takes those results from what the trial kept, so the reply reported that second evaluation and read as "nothing was rebuilt" although the geometry changed. Report the trial's rebuild, plus anything the session still had to compute itself, as timeline.edit reports the same change; `restored` keeps counting only genuine reuse of earlier results. Tests: redefining_reports_the_features_it_rebuilt fails before the change with {"feature": 2, "recomputed": 0, "restored": 2} and passes after it; redefining_computes_the_later_features_once still guards the single computation (the reply doubles if the kept results are lost). --- crates/engine/src/cmd/edit.rs | 9 ++++++++- crates/engine/src/cmd/edit_tests.rs | 23 +++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index d3f9259f4..d393eb7ee 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -1670,6 +1670,11 @@ fn redefine(s: &mut Session, p: &Value) -> Result { if let Some(e) = trial.model.result(id).and_then(|r| r.error.clone()) { return Err(EngineError::Other(e)); } + // What this edit rebuilt: the trial computed the edited feature and the features after it. The + // session's evaluation below only takes those results from what the trial kept, so its own + // counters read as "nothing was rebuilt" (#5694). + let rebuilt = trial.model.last_recomputed; + let reused = trial.model.last_restored; let original_ids: std::collections::BTreeSet = s.doc.features.iter().map(|feature| feature.id).collect(); let added_ids: std::collections::BTreeSet = trial.doc.features.iter().filter(|feature| !original_ids.contains(&feature.id)).map(|feature| feature.id).collect(); @@ -1711,7 +1716,9 @@ fn redefine(s: &mut Session, p: &Value) -> Result { if let Some(e) = s.model.result(id).and_then(|r| r.error.clone()) { return Err(EngineError::Other(e)); } - Ok(json!({"feature": id, "recomputed": s.model.last_recomputed, "restored": s.model.last_restored})) + // Report the trial's rebuild, plus anything the session still had to compute itself (a kept + // result its budget dropped); `s.model`'s own counters would only report the reuse (#5694). + Ok(json!({"feature": id, "recomputed": rebuilt + s.model.last_recomputed, "restored": reused})) } fn dependents(s: &mut Session, p: &Value) -> Result { diff --git a/crates/engine/src/cmd/edit_tests.rs b/crates/engine/src/cmd/edit_tests.rs index 9f1cf41b4..140c4a552 100644 --- a/crates/engine/src/cmd/edit_tests.rs +++ b/crates/engine/src/cmd/edit_tests.rs @@ -185,7 +185,8 @@ fn redefining_a_blend_replaces_persistent_edge_selection_and_survives_resize() { /// A redefine computes the features after the edited one once: its trial's results are kept /// for the session's own evaluation, though the cache holds only the last state (a large -/// design's). +/// design's). The reply reports that one rebuild (#5694): a session that had to compute the +/// features again would count them twice. #[test] fn redefining_computes_the_later_features_once() { let mut s = Session::default(); @@ -196,11 +197,29 @@ fn redefining_computes_the_later_features_once() { *s.model.cache.lock().unwrap() = solidcraft_doc::EvalCache::with_budget(1); let reply = run(&mut s, "timeline.redefine", json!({"feature": "Base", "command": "solid.box", "params": {"length": 25, "width": 10, "height": 5}})); - assert_eq!(reply["recomputed"], 0, "{reply}"); + assert_eq!((reply["recomputed"].as_u64(), reply["restored"].as_u64()), (Some(4), Some(0)), "{reply}"); let volume = run(&mut s, "inspect.measure", json!({}))["total"]["volume_mm3"].as_f64().unwrap(); assert!((volume - (25.0 * 10.0 * 5.0 + 3.0 * 125.0)).abs() < 1e-6, "{volume}"); } +/// #5694: the reply reports what the redefine rebuilt — the edited feature and the features +/// after it — not the session's reuse of the trial's own results, which read as "nothing was +/// rebuilt" and did not match what the same change reports through `timeline.edit`. +#[test] +fn redefining_reports_the_features_it_rebuilt() { + let mut s = Session::default(); + run(&mut s, "solid.box", json!({"length": 40, "width": 40, "height": 20, "center": [0, 0, 10], "name": "Block"})); + run(&mut s, "solid.hole", json!({"position": [0, 0, 20], "diameter": 6, "depth": 12, "name": "H"})); + run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 5, "center": [30, 0, 2.5], "operation": "new", "name": "Other"})); + let reply = run( + &mut s, + "timeline.redefine", + json!({"feature": "H", "command": "solid.hole", + "params": {"position": [0, 0, 20], "type": "counterbore", "diameter": 6, "depth": 12, "cb_diameter": 10, "cb_depth": 4}}), + ); + assert_eq!((reply["recomputed"].as_u64(), reply["restored"].as_u64()), (Some(2), Some(0)), "{reply}"); +} + #[test] fn redefining_preserves_body_names_participants_and_marker_without_temporary_features() { let mut s = Session::default();