Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2050,10 +2050,18 @@ impl Session {
let over = self.undo.len().saturating_sub(UNDO_LIMIT);
self.undo.drain(..over);
}
// Freed: by the copy (none left), or because the history moved on.
_ => {
// Not taken by a copy, but the history changed while a background edit ran (another
// edit, Undo, trimming): the steps can't follow on from it. Rare, and not about making
// room, so said each time.
Some(_) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AGENTS.md (confidence ~45%, a judgment call for maintainers). AGENTS.md says a loss gets "one notice per kind with a count". This arm says the drop again on every occurrence (the PR body says so on purpose, as it is rare). The earlier say_room() gate limits the make-room notice to once a project, so this arm is now the only path that can repeat a notice of the same kind. Either keep the per-occurrence notice and say so in the PR's Suggested AGENTS.md additions, or gate it the same way. The message text and the (N Undo or Redo steps) count look right: the foreground path always passes in_place = true, so this arm is only reached from the background and reclaim paths where history moved on.

let template = "Undo history set aside for a background edit of {layer} is dropped ({count} Undo or Redo steps), as the Undo history changed while the edit ran.";
let args = [("count", count.to_string().into()), ("layer", name.to_string().into())];
self.notify_text(notice_text::NoticeText::format(template, args), false);
}
// Freed by the edit's copy (the hook took them).
None => {
if self.undo_memory.say_room() {
let template = "Memory is nearly full: older Undo steps are dropped to make room for edits ({count} before editing {layer}). An edit that still doesn't fit is refused.";
let template = "Memory is nearly full: Redo steps, then the oldest Undo steps, are dropped to make room for edits ({count} before editing {layer}). An edit that still doesn't fit is refused.";
let args = [("count", count.to_string().into()), ("layer", name.to_string().into())];
self.notify_text(notice_text::NoticeText::format(template, args), false);
}
Expand Down
24 changes: 23 additions & 1 deletion crates/engine/src/undo_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,8 @@ mod tests {
let mark = session.notice_mark();
session.run("layer.addDataText", &json!({"fileName": "third.csv", "text": "a\n1\n"})).unwrap();
let notices = session.notices_since(mark);
assert!(notices.iter().any(|n| n.text.contains("(3 before editing calc)")), "{notices:?}");
assert!(notices.iter().any(|n| n.text.contains("background edit of calc is dropped (3 Undo or Redo steps)")), "{notices:?}");
assert!(!notices.iter().any(|n| n.text.contains("make room")), "{notices:?}");
assert_eq!(session.undo_depth(), 2, "only the two later steps");
}

Expand Down Expand Up @@ -731,6 +732,27 @@ mod tests {
assert!(!session.notices_since(mark).iter().any(|n| n.text.contains("make room")));
}

/// Undo and Redo copy no rows and aren't checked (they are registered as `.view()`, so they
/// don't count as edits): they run when even one copy of the active layer doesn't fit, as the
/// way back from an edit (#2431).
#[test]
fn undo_and_redo_run_when_an_edit_would_not_fit() {
let mut session = session(4096);
session.undo_memory.limit = 1 << 30;
session.undo_memory.memory = None;
for text in ["b", "c"] {
edit(&mut session, &text.repeat(4096));
}
session.active_layer = Some(session.map().layer_by_name("rows").unwrap().id);
session.undo_memory.memory = Some(4);
assert!(session.run("edit.setValue", &json!({"layer": "rows", "row": 0, "field": "text", "value": "d"})).is_err());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage (confidence ~80%). This assertion only checks that the edit fails. It does not check why, so the premise of the test ("the edit would not fit even with no history") is unverified: an unrelated error, such as a wrong layer or field, would also pass. The neighbouring tests at lines 683-684 and 727-730 check the message. Suggested change:

Suggested change
assert!(session.run("edit.setValue", &json!({"layer": "rows", "row": 0, "field": "text", "value": "d"})).is_err());
let err = session.run("edit.setValue", &json!({"layer": "rows", "row": 0, "field": "text", "value": "d"})).unwrap_err();
assert!(err.contains("not enough memory"), "{err}");

session.run("edit.undo", &json!({})).unwrap();
assert_eq!(value(&session), &Value::Text("b".repeat(4096)));
session.run("edit.redo", &json!({})).unwrap();
assert_eq!(value(&session), &Value::Text("c".repeat(4096)));
assert_eq!((session.undo_depth(), session.can_redo()), (2, false));
}

#[test]
fn paste_special_is_not_measured_by_the_active_layer() {
let mut session = session(4096);
Expand Down
16 changes: 9 additions & 7 deletions docs/user-guide/analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -1582,15 +1582,17 @@ computer's memory. When it doesn't fit, Redo steps are set aside first (the edit
anyway), then the oldest Undo steps. They are freed only once the edit starts copying; an edit
that fails before that, or is cancelled before it starts copying, gives them back, unless the
project was changed while it ran in the background. One that fails after it started copying has
used them, as a finished edit would have. A message says when steps are freed, the
first time in a project. An edit that wouldn't fit even with no Undo
history is refused before anything changes, and the message gives the size of the copy and what is
held. An edit the desktop runs in the background is checked when it starts; one that needs Undo
used them, as a finished edit would have. A message says when steps are freed to make room, the
first time in a project, and each time steps set aside for a background edit are freed because the
Undo history changed while it ran. Undo and Redo copy nothing and aren't checked. An edit that
wouldn't fit even with no Undo history is refused before anything changes, and the message gives
the size of the copy and what is held. An edit the desktop runs in the background is checked when it starts; one that needs Undo
steps set aside while another such edit is still running is refused, to run again once that one
has finished. Edits made by a
script, model, task or plugin aren't checked, nor is reloading or repairing a layer's data, and the
web app doesn't check, as it can't read the memory. Sizes are estimated, counting each text and part
as the block of memory it takes, so they come out above the bytes themselves.
script, model, task or plugin aren't checked, nor is Paste Special (it makes a layer of its own) or
reloading or repairing a layer's data. Nothing is checked where RustGIS can't read the computer's
memory: in the web app, and on a computer that doesn't report it. Sizes are estimated, counting
each text and part as the block of memory it takes, so they come out above the bytes themselves.

So a computer with 16 GB reads rasters of up to about 500 million samples. A run that passes on one
computer can be refused on a smaller one; the error names the limit there. Project Raster (`raster.project`) puts a raster
Expand Down
Loading