Keep save-boundary timestamps through load and restore [minor] - #117
Merged
matt-edmondson merged 1 commit intoSep 28, 2026
Merged
Conversation
SaveBoundary.Timestamp was get-only and not a constructor parameter, so System.Text.Json discarded the saved value and stamped every loaded boundary with the load time, and RestoreFromState re-created each boundary through CreateSaveBoundary, which stamped it again. Add a public SaveBoundary(position, description, timestamp) constructor marked [JsonConstructor]; a missing timestamp still means now, so older data loads as before. RestoreFromState adds boundaries with their original timestamp when the manager is the built-in SaveBoundaryManager; ISaveBoundaryManager is unchanged, so custom managers keep working and create boundaries afresh. Trimming already carried the timestamp over; a test now guards that too. Correct the SaveBoundary shape in the API reference and the binary serializer example. Fixes #91 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TXZMdofSRgS8oXS9RgTRhM
|
This was referenced Sep 28, 2026
matt-edmondson
deleted the
claude/undoredo-91-preserve-boundary-timestamps
branch
September 28, 2026 08:21
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 #91
What was wrong
SaveBoundary.Timestamp("when the save boundary was created") was replaced with the current time in two of the three places the issue lists:Timestampwas get-only and not a constructor parameter, so System.Text.Json discarded the saved value.RestoreFromState. Each boundary was re-created throughCreateSaveBoundary(position, description), which stamped it again.main: since UndoToSaveBoundaryAsync undoes to the wrong position when given a SaveBoundary obtained before the stack was trimmed #88,AdjustPositionsuses the internal copy constructor, which carriesTimestampover. This PR adds a regression test for it.Change
SaveBoundary: new public constructorSaveBoundary(int position, string? description, DateTimeOffset timestamp), marked[JsonConstructor]. Adefaulttimestamp means "now". That is also what STJ passes when saved data has notimestamp, so older data still loads.SaveBoundaryManager.RestoreSaveBoundary(internal): adds a boundary with its original timestamp and marks the initial state as not clean, asCreateSaveBoundarydoes.UndoRedoService.RestoreFromState: usesRestoreSaveBoundarywhen the manager is the built-inSaveBoundaryManager. Otherwise it falls back toCreateSaveBoundary.api-reference.mdshowedSaveBoundaryas arecordwith aDateTime Timestamp, which it isn't.serialization.md's binary serializer example called a constructor that didn't exist. Both now match the real type.Design note: why
ISaveBoundaryManageris unchangedA clean fix for (2) would add a member to
ISaveBoundaryManager. The library targetsnetstandard2.0, which has no default interface methods, so a new member would break every external implementer. That calls for a major version bump. This PR keeps the interface as it is and special-cases the built-in manager instead. A custom manager keeps working, but its restored boundaries still get fresh timestamps. If you'd rather add something likeISaveBoundaryManager.RestoreSaveBoundary(SaveBoundary)in a breaking release, the type check inRestoreFromStatecan go.The commit is tagged
[minor]because it adds a public constructor.Testing
New tests:
JsonSerializer_SerializeDeserialize_PreservesSaveBoundaryTimestamp: a serializer-only round tripUndoRedoService_SaveLoadState_PreservesSaveBoundaryTimestamp:SaveStateAsync→LoadStateAsync. The saved timestamp is rewritten to a fixed past time, so a restamp cannot match by chanceUndoRedoService_RestoreFromState_PreservesSaveBoundaryTimestampJsonSerializer_DeserializeSaveBoundaryWithoutTimestamp_UsesLoadTime: older data without a timestamp still loadsSaveBoundary_StackTrimmed_KeepsTimestamp: guards the existing trim behaviorTo check that the tests catch the bug, I temporarily reinstated the old behavior (the constructor ignored the timestamp, and restore went back through
CreateSaveBoundary). The three load/restore tests failed. With the fix,dotnet test UndoRedo.Testpasses 105/105, anddotnet build UndoRedobuilds all 7 target frameworks.🤖 Generated with Claude Code
https://claude.ai/code/session_01TXZMdofSRgS8oXS9RgTRhM
Generated by Claude Code