Repository navigation
Lock the navigation stack so concurrent navigation keeps its history [patch] - #83
Merged
Merged
Conversation
…[patch] NavigationStack mutated _items and _currentIndex with no synchronization, so the README's "Thread-safe operations" claim did not hold: concurrent NavigateTo calls threw ArgumentException from the undo snapshot racing a List resize and could lose history entries. Every read and write of the history and current index now happens under one private lock, including the undo snapshots, GetHistory, RestoreState, LoadStateAsync and SaveStateAsync. NavigationChanged is raised after the lock is released. GetHistory now returns a copy rather than a live view, so it cannot change under a caller enumerating it. Undo actions are registered under the lock so they reach the provider in the order the changes were made. Fixes #57 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qm7dX7JTJR6dTnKfSngfvp
|
This was referenced Oct 17, 2026
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 #57
What
The README claims "Thread-safe operations", but
Navigation<T>mutated_itemsand_currentIndexwith no synchronization. ConcurrentNavigateTocalls threwArgumentException(the undo snapshot racing aList<T>resize) and could lose history. Per the maintainer's decision on the issue, this makes the claim true, scoped toNavigationStack:Lockguards every read and write of_itemsand_currentIndex:Current,CanGoBack,CanGoForward,Count,NavigateTo,GoBack,GoForward,Clear, the history getters,RestoreState,LoadStateAsyncandSaveStateAsync.NavigationChangedis raised after the lock is released.GetHistory()now returns a copy instead of a liveAsReadOnly()view, so another thread's navigation can't change it while a caller enumerates it.SaveStateAsyncreads the items and the current index in one locked step, instead of two separate calls that another navigation could land between.SimpleUndoRedoProvideris left alone because Delegate undo/redo to ktsu.UndoRedo #46 replaces it.Test
NavigateTo_FromManyThreads_KeepsEveryItemAndAValidCurrentturns the issue'sParallel.For(0, 2000, …)repro into a test. It checks that nothing throws, that all 2000 distinct items are kept, thatCurrentis the last item, and that the back stack holds 1999 entries.ArgumentExceptionfrom the issue. I checked this by stashing the source change and running the test again.🤖 Generated with Claude Code
https://claude.ai/code/session_01Qm7dX7JTJR6dTnKfSngfvp
Generated by Claude Code