Skip to content

fix(undo): restore originals after replacing moves - #2080

Merged
l0gicgate merged 4 commits into
mainfrom
fix/2077-restore-replaced-item-on-undo
Nov 7, 2026
Merged

l0gicgate merged 4 commits into
mainfrom
fix/2077-restore-replaced-item-on-undo

Conversation

@JoeJoeflyn

@JoeJoeflyn JoeJoeflyn commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Restore both items when undoing a Move with Replace. Move history now retains the staged original's Trash identity and reuses guarded restoration after completed move batches settle. Originals are looked up together, preserving flush batching rather than adding per-item scans or flushes. Redo refreshes the identity for the next Undo.

Covers file/folder restoration, conflicts, missing backups, partial failure, cancellation, failed flushes, redo, and folder customizations. Existing no-Trash fallback behavior is unchanged.

Validation exception: the owner explicitly authorized skipping CodeScene because it requires a paid service/token. That check was not run; other selected checks were completed. Detailed verification and benchmark record.

Benchmark

Three private QA-container sessions per version; 256 × 4 KiB files in each conflicting folder, Move → Replace → Undo. Medians:

Metric Before After
End-to-end elapsed 3.49 s 3.21 s
App CPU time 0.49 s 0.47 s
Peak RSS 230.40 MiB 231.55 MiB
Original restored 0/3 3/3

Debug/software-rendered GUI measurements include driver overhead. Samples are noisy and the baseline omitted restoration work; no statistically established speedup or RAM reduction is claimed.

Visual evidence

strata-2077-fixed.mp4

How to test

  1. Create a/note.txt and b/note.txt with different contents.
  2. Cut b/note.txt, paste it into a, and choose Replace.
  3. Press Ctrl+Z.
  4. Redo, confirm Replace again, then undo once more. Repeat with folders containing different files if desired.

Expected result: each Undo returns the moved item to b and restores the original in a, including its contents and folder customizations. A new arrival is never silently overwritten.

Related issue

Closes #2077

Keep the staged Trash identity in move history instead of discarding it. Reuse the guarded restore pipeline after completed move batches settle, with one lookup for all originals and refreshed identities across redo.

Extend the existing replacement QA scenario and customization fixture, and cover files, folders, conflicts, missing backups, durability, partial failure and cancellation.

Refs #2077
Requiring every staged original before moving anything made one emptied
Trash entry stop the whole undo. A failed undo stays on top of the history,
so every later Ctrl+Z failed the same way and older entries were out of
reach, where the move-back worked before.

Look up a failed batch item by item, move everything back, restore what is
still there and report the rest with the lookup's own message.

Drop a_move_back_conflict_keeps_both_items_and_the_staged_original: its
assertions are a subset of a_partial_replacing_move_undo_restores_only_completed_originals.
Only the QA scenario, which pull request CI skips, exercised this. Undo and
redo each record what they replaced at their own end, and a replay that
replaced nothing clears the identity it consumed.
The added Undo row lowered the file's code health from 8.26 to 8.22. Moving
the conflict step tables to constants raises it to 8.52.
@l0gicgate

Copy link
Copy Markdown
Contributor

Review and cleanup

Merged main: nothing to merge; the branch already contains 6e954377d.

Review against the description and #2077. Confirmed: both items come back on Undo for files and folders, conflicts and failed flushes leave the original in Trash, cancellation restores only committed moves, a new arrival is never overwritten, redo refreshes the identity, and folder customizations are restored. Non-local destinations report no Trash identity, so they keep the plain move-back. There were no earlier review comments to reconcile.

Fixes pushed

  • fe0dda4cf fix(undo): move items back when a replaced original is gone. The PR required every staged original before moving anything. After Replace, emptying Trash and pressing Ctrl+Z, no item moved back, where main moved them. The failed entry also stayed on top of the history, so each later Ctrl+Z failed the same way and older entries were unreachable. Now a failed batch lookup is retried per item, everything moves back, the originals still in Trash are restored, and the undo reports "One or more recently trashed items are no longer available". This reverses the behaviour the PR tested deliberately, so please say if refusing the undo was intended.
  • c0bbb53fa test(undo): cover the originals move replays record. Only the QA scenario covered redo's identity refresh, and PR CI skips QA. Nothing covered an undo that replaces at its source. each_move_replay_records_only_the_original_it_replaced covers both, plus clearing a consumed identity.
  • 9c918ed85 refactor(preferences): move customization conflict steps out of the test. The added Undo row lowered item_customizations.rs from 8.26 to 8.22; it is now 8.52.

Tests removed or replaced

  • a_move_back_conflict_keeps_both_items_and_the_staged_original: its assertions are a subset of the failing item's in a_partial_replacing_move_undo_restores_only_completed_originals, which owns that coverage.
  • undoing_a_replacing_move_requires_its_staged_original_before_moving: replaced by a_missing_original_does_not_hold_back_the_undo, for the behaviour change above.

The comments the PR added each explain something the code does not show, so all were kept.

Validation (on 9c918ed85 unless noted)

  • ./scripts/test-headless.py -- adapters::local_operations::tests::undo:: adapters::local_operations::tests::replacement:: adapters::local_operations::tests::merge::undo_ adapters::local_operations::tests::release:: app::browser::tests::undo:: app::browser::tests::undo_refresh:: app::browser::tests::background_operations:: app::browser::tests::operation_events:: ui::browser::transfer::tests::undo:: ui::window::tests::preferences::item_customizations::: 208 passed
  • ./scripts/qa.sh --test-threads 6 replace-restores-original-on-undo undo-restores-completed-move keep-both-then-undo keep-both-then-undo-remaining undo-created-folder-trashes rename-and-undo-restores: 9 passed
  • ./scripts/quality.sh fmt, ./scripts/quality.sh clippy, git diff --check: clean
  • ./scripts/code-health.sh: run, since the PR recorded it as skipped. No touched file scores below main; undo_move/replaced.rs scores 10.0
  • Driven by hand in the QA container: Replace, empty Trash, Ctrl+Z moved the item back and showed an error, and a second Ctrl+Z undid the older move. That session predates the message change, when the dialog read "No such file or folder". The final wording is asserted by the new test, not seen on screen.
  • Not run: full Rust and full QA suites. The change is bounded to move undo, and CI ran the Rust suite. The scenario's cost header is still unmeasured.

Follow-ups outside this PR (from reading the code, not reproduced; none loses data)

  • When the moved item is gone before Undo, the replay preflight drops its record, so the original stays in Trash and nothing says so. undo_merge keeps such entries.
  • Restore guards run after the move-back, so a refusal such as a bind-mount boundary leaves the item moved and the original in Trash, with the identity dropped.
  • A cross-volume move-back that keeps part of its source reports "something already exists" instead of a kept report.
  • Undo still retires record.current from Recent views, although the restored original is back at that path.
  • trash:/// is only in affected_locations, which only the Cancelled outcome reads, so a Trash column relies on its file monitor after a successful undo.
  • Restores ignore Cancel and report no progress. That matters only for the copy fallback when a rename is unsupported.

CI: all required checks green on 9c918ed85; QA scenarios is skipped on PRs as usual. GitHub reports the PR as blocked and it has no approving review yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(undo): undoing a Replace doesn't bring back the replaced item

2 participants