You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(engine): Undo history counts the rasters its steps hold against its memory limit (#2908) - #3005
Budget::trim decides how much Undo/Redo history to keep by summing only the rows each step holds (private_bytes(&step.8, …)). Budget::held already counts rasters too, but trim didn't, so a project made mostly of rasters kept every step up to the step limit, each one with its own copy of the pixels. On a large DEM or image that can add up to gigabytes.
trim now also counts the pixels and embedded files that each step holds on its own. Rasters the open project still shares cost the history nothing, the same rule rows already follow, and an allocation shared by several steps is counted once, at the step kept first. raster_bytes takes the shared seen set to make that possible; held counts what it did before.
Size for real data: nothing new is stored or copied. The fix only counts what history already keeps, so a raster project's history now stays within the Undo memory limit instead of growing to 40 full copies. Cost per trim: one walk over the layers of each step, not over pixels.
Reach every surface: the change is in the engine's Undo budget, which every surface shares (desktop, browser, command line, Python, phone). It adds no command, parameter or UI. The notice that says older steps are dropped is the existing one.
Testing
New raster_edits_count_their_pixels_against_the_undo_budget tests both ways. A 64 × 64 raster (16 KiB) under a 40 KiB limit, edited 5 times with raster.editPixels, keeps 2 steps and gives one "older steps are dropped" notice. With room for every step, it keeps all 5 and says nothing.
Without the fix, the test fails: it keeps 5 steps instead of 2.
Undo-history memory tracking now includes raster pixel buffers and embedded files, while counting shared allocations only once. This helps ensure undo history stays within its configured memory limit.
…ts memory limit (opengeos#2908)
Budget::trim summed only the rows each step kept, so a project of rasters kept
every step up to the step limit, each with its own copy of the pixels. It now
adds the pixels and embedded files a step holds that the open project and newer
steps don't, each shared allocation once, as held() already counted them.
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
No actionable comments were generated in the recent review.
Walkthrough
Undo-memory accounting now includes raster pixel buffers and embedded raster-file bytes. Trimming excludes live-project raster allocations from history cost and deduplicates shared allocations. Held-memory accounting also deduplicates raster allocations across projects and history.
Changes: Raster undo memory accounting
Layer / File(s)
Summary
Raster accounting and regression coverage crates/engine/src/undo_memory.rs
The raster-byte helper accepts a shared identity set. Trimming includes deduplicated raster bytes in its budget calculation, and held-memory accounting avoids recounting shared allocations. Tests check that a 40 KiB budget retains two of five raster-edit steps and emits a history-drop notice, while a 1 GiB budget retains all five without the notice.
opengeos/RustGIS#2431: This PR extends undo-memory trimming to raster allocations, but does not change how vector rows are copied or counted.
Possibly related PRs
opengeos/RustGIS#2437: This PR extends the Undo and Redo memory-budget accounting introduced there to include raster allocations.
Suggested reviewers:pick2510
Merge Risk: Minimal · up to 726f9
Undo trimming now counts raster pixel and embedded-file memory held privately by history steps, so raster-heavy projects evict older steps when over budget. The change is small and covered by a regression test, and no merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: Undo history now counts raster pixel buffers held by its steps against the memory limit. It also names the affected component (engine) and the issue number. The change…
Description check
The description follows the repository template. It has Summary, Testing, UI evidence, and Related issue sections. The Summary explains the cause (trim ignored rasters while held counted them) and the…
Linked Issues check
[#2908] Requirement: Budget::trim must count private raster pixel buffers and embedded raster-file bytes per undo step, deduplicated, in the same priority order as vector rows. A regression test mus…
Out of Scope Changes check
The whole-PR diff (merge base ffd04d5 to head 726f9ff) changes only crates/engine/src/undo_memory.rs. Every hunk serves #2908: the trim change adds raster accounting, the raster_bytes signature gain…
Full details: Title check
Explanation
The title names the main change: Undo history now counts raster pixel buffers held by its steps against the memory limit. It also names the affected component (engine) and the issue number. The changeset matches this: Budget::trim now counts raster pixels and embedded files per step, and the PR fixes issue #2908.
Full details: Description check
Explanation
The description follows the repository template. It has Summary, Testing, UI evidence, and Related issue sections. The Summary explains the cause (trim ignored rasters while held counted them) and the fix, including the shared-allocation rule. Testing names the new test, the expected results with and without the fix, and cargo xtask changed. UI evidence states no visible UI change, which the template allows. Related issue reads Closes #2908.
Full details: Linked Issues check
Explanation
[#2908] Requirement: Budget::trim must count private raster pixel buffers and embedded raster-file bytes per undo step, deduplicated, in the same priority order as vector rows. A regression test must show that repeated raster edits evict older steps. The whole-PR diff (merge base ffd04d5 to head 726f9ff) in crates/engine/src/undo_memory.rs meets this. In trim, raster_bytes runs over each step's project (step.0) inside the existing account closure, and the result is added to private_bytes(&step.8) before the used <= self.limit check. Rasters held by the live project are seeded into rasters_seen first, so they cost history nothing. A shared set counts each allocation once, at the first step kept. held passes a fresh set, so its result is unchanged. The test raster_edits_count_their_pixels_against_the_undo_budget covers eviction (40 KiB limit, 5 edits, 2 steps kept, one drop notice) and retention (1 GiB limit, 5 steps kept, no notice). The issue proposed tracking raster allocations per step in advance; the PR computes them during trim by walking each step's layers. This meets the behavioral requirement. The incremental diff from the previous reviewed head (da9e308) was unavailable, so this verdict rests on the whole-PR diff, which covers the current head. I did not run the test; the claim that it fails without the fix comes from the PR author.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff (merge base ffd04d5 to head 726f9ff) changes only crates/engine/src/undo_memory.rs. Every hunk serves #2908: the trim change adds raster accounting, the raster_bytes signature gains a shared seen parameter so trim and held use the same dedup logic, and the added test covers the trim change. The held call site passes a new set and keeps its prior behavior. The diff adds no commands, parameters, UI, or unrelated refactors. The PR description's claim of no new storage or copies matches the diff. The incremental diff from the previous reviewed head was unavailable, so this verdict also relies on the whole-PR diff.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the raster store, And counts each buffer, never more. The oldest steps hop out of sight, When budgets reach their measured height. With shared bytes counted once, all’s clear, The Undo trail stays bounded here.
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: 14dad285-41a3-4448-8f7d-9a4d231d050b
Commits
Reviewing files that changed from the base of the PR and between da9e308 and 726f9ff.
Files selected for processing: 1
crates/engine/src/undo_memory.rs
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Two small readability nits here, both behaviour-neutral, so they can wait for the release quality pass.
raster_bytes(std::iter::once(live), &mut rasters_seen) is called only for its side effect of filling rasters_seen. Its returned byte total is discarded, and the call reads like a measurement. A small helper that only records the live project's raster allocations, or a comment saying "fills the set, the total is unused", would make the intent clear.
Inside account, let rows = ... shadows the module-level fn rows(project) used a few lines above. It compiles, but a name such as stored would avoid the clash.
Scope: One file, crates/engine/src/undo_memory.rs (+50/−7). Budget::trim now counts the pixels and embedded files of rasters held by each Undo/Redo step, not only their rows. Rasters the live project shares cost nothing, and a shared allocation is counted once, at the first step kept. This is the fix for #2908.
Bugs: None found. I checked:
The accounting order matches the eviction logic. The newest undo is always kept, then redos, then older undos.
Dedup by Arc pointer is consistent with held(), which make_room and publish use, so the budget agrees with the memory planning.
Keys in the raster set are separate from the row-allocation keys, so the two cannot collide.
Hand-tracing the new test gives depth 2 and one notice with a 40 KiB limit, which matches the assertions.
trim runs from trim_undo_memory after each committed edit or history move, and only on the live project, so the call site is correct.
Confidence: high.
Security: None. No input handling, I/O or secrets are touched.
Performance: No concern. Each trim walks the raster layers of each step, not pixels. band.data.capacity() is O(bands). Confidence: high.
Quality:
Inline comment on undo_memory.rs:104: raster_bytes(once(live), …) is called only to fill rasters_seen, and its return value is discarded. A let rows = … inside account also shadows the module-level fn rows. Both are behaviour-neutral and can wait for the release quality pass. Confidence: high.
The trim doc comment still describes only rows, though it now also covers rasters. Minor. Confidence: medium.
AGENTS.md: No violations found.
Never silent: the existing "older steps are dropped" notice still covers the new drops.
Test both ways: the test covers a lossy case with one notice and a clean case with none.
Wasm: no platform-specific code is added.
Size for real data: the change adds no stored or copied layer data, so no multiple is required.
Twins checked: held, make_room and publish all use the same raster accounting, so they agree with trim.
Prior reviews: The thread list is empty, so no earlier concerns were left alone.
Change size
Compared with the base branch: the whole PR, merge base ffd04d5 to PR head da9e308.
The reason will be displayed to describe this comment to others. Learn more.
Nit, for the release quality pass: the doc above trim (lines 97-98, not in this diff) still says only "a shared allocation" and talks about rows. Rasters (pixels and embedded files) are now counted the same way, so that doc could say so.
Also untested: the "count once" path, a raster shared by two undo steps, which the doc describes. The new test covers only one raster per step.
Scope: One file, crates/engine/src/undo_memory.rs (+51/−7). Budget::trim now counts each history step's raster pixels and embedded files against the Undo limit, not only its rows. Rasters the open project still holds cost nothing, and a raster shared by several steps is counted once. I read the surrounding Budget code, the call sites in lib.rs (trim_undo_memory, room_for_edit), and the new tests. I could not compile or run the tests, since I have no shell here.
Bugs
None found. I checked the seen handling (live rasters are pre-marked, shared allocations are counted once, and used is still monotonic), the u64 and usize conversions, and the undo-protected and redo ordering. The newest-undo-always-kept rule is unchanged. Confidence: high.
Security
None found.
Performance
None significant. trim now walks the layers of each step once more per history move, but never the pixels. That is in line with the existing row walk. Confidence: high.
Quality
Nit (inline, posted): the doc above trim (lines 97-98, not in the diff) still speaks only of rows and shared allocations, and the new "count once" path for a raster shared by two undo steps has no test. The new test only covers one raster per step. Confidence: high. Left for the release quality pass.
Earlier threads on the raster_bytes side-effect call and the rows shadowing are answered by the author, and the code shows both fixes. I left them alone.
AGENTS.md
Low confidence, PR description only: the AGENTS.md "Size for real data" rule asks for a multiple of the layer when a change compares layer data. This change now compares raster bytes in trim, and the body says only "nothing new is stored or copied", with no multiple given. Confidence: low.
Twins checked
held() already counted rasters, and trim now matches it, sharing the same dedupe rule.
room_for_edit estimates the copy from rows_bytes only, so a raster edit's pixel copy is not planned. This is pre-existing and outside this diff, so I did not raise it as a finding. Confidence that it is a real gap: medium. It's worth a follow-up issue.
Nothing in the layer.add*, overlay-tool, or wasm32 families is touched.
Prior reviews
1 earlier thread checked, both of its points answered by the author. Nothing re-raised. Only my one new inline comment was posted.
Change size
Compared with main (merge base ffd04d5 to PR head 726f9ff).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Budget::trimdecides how much Undo/Redo history to keep by summing only the rows each step holds (private_bytes(&step.8, …)).Budget::heldalready counts rasters too, buttrimdidn't, so a project made mostly of rasters kept every step up to the step limit, each one with its own copy of the pixels. On a large DEM or image that can add up to gigabytes.trimnow also counts the pixels and embedded files that each step holds on its own. Rasters the open project still shares cost the history nothing, the same rule rows already follow, and an allocation shared by several steps is counted once, at the step kept first.raster_bytestakes the sharedseenset to make that possible;heldcounts what it did before.Size for real data: nothing new is stored or copied. The fix only counts what history already keeps, so a raster project's history now stays within the Undo memory limit instead of growing to 40 full copies. Cost per trim: one walk over the layers of each step, not over pixels.
Reach every surface: the change is in the engine's Undo budget, which every surface shares (desktop, browser, command line, Python, phone). It adds no command, parameter or UI. The notice that says older steps are dropped is the existing one.
Testing
raster_edits_count_their_pixels_against_the_undo_budgettests both ways. A 64 × 64 raster (16 KiB) under a 40 KiB limit, edited 5 times withraster.editPixels, keeps 2 steps and gives one "older steps are dropped" notice. With room for every step, it keeps all 5 and says nothing.cargo xtask changedpasses.UI evidence
No visible UI change.
Related issue
Closes #2908
Summary by CodeRabbit