Make CompositeCommand.Undo all-or-nothing - #86
Merged
Merged
Conversation
When a sub-command's Undo threw, the composite kept undoing the rest and rethrew, but the stack (since #75) keeps its position on a failed Undo. The next Undo then undid the already-undone parts a second time. Stop at the first failure and re-execute what this call undid, mirroring the rollback in Execute(). Redo goes through Execute() and was already safe. Fixes #82 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016ToeUpj3nH61YEnatKdb8d
|
matt-edmondson
deleted the
claude/undoredo-82-composite-undo-rollback
branch
September 26, 2026 09:53
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Fixes #82
What was wrong
CompositeCommand.Undo()kept going when a sub-command'sUndothrew, then rethrew. Since #75, the stack keeps its position whenUndothrows, so it still recorded the composite as fully applied. The retry then undid the already-undone parts a second time. In the issue's repro that leavesa=-1.Change
Undo()now stops at the first failure and re-Executes the sub-commands it already undid in this call, in forward order, ignoring restore errors. It then rethrows the original exception. This mirrors the rollback inExecute().Redo()goes throughExecute(), so it was already all-or-nothing.CompositeCommand_UndoFailure_DoesNotAffectOtherCommandsasserted the old partial-undo behaviour. It is renamed toCompositeCommand_UndoFailure_LeavesEveryCommandAppliedand now expects the composite to stay fully applied.CompositeCommand_UndoFailureThenRetry_UndoesEachCommandOnceis the issue's repro run throughUndoRedoService. It expectsa=1 b=1at position 0 after the failed Undo, anda=0 b=0at -1 after the retry.Verification
🤖 Generated with Claude Code
https://claude.ai/code/session_016ToeUpj3nH61YEnatKdb8d
Generated by Claude Code