Lock a profile's chords so concurrent binds cannot corrupt them [minor] - #142
Merged
Merged
Conversation
Profile kept its bindings in a plain Dictionary that SetChord, RemoveChord and ClearChords changed without synchronization while FindCommandByChord and SaveAsync enumerated it. Parallel binds lost bindings and threw. Every read and write of the bindings now takes a per-profile lock, and the services read them through snapshots. The public Chords dictionary is marked [Obsolete] because touching it bypasses the lock; ChordCount replaces its only internal use that wasn't a snapshot. Fixes #109 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015BJVibRvmTotkqEGp3695R
The new code's coverage fell below SonarCloud's gate. These tests exercise the rewritten accessors, their blank-id guards, the obsolete Chords property, and the registration filter ExecuteChord applies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015BJVibRvmTotkqEGp3695R
|
This was referenced Sep 28, 2026
This was referenced Sep 29, 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.



Parallel
BindChord,UnbindChordandFindCommandByChordcalls no longer lose bindings or throw.Profilekept its bindings in a plainDictionarythat was changed without synchronization while other calls enumerated it.Change
Lock:SetChord,GetChord,HasChord,RemoveChord,ClearChords,BoundCommandsandGetAllChords.KeybindingService.FindCommandByChord/ExecuteChord,ProfileManager.DuplicateProfileand bothJsonKeybindingRepositorysave paths now read through theGetAllChords()snapshot instead of enumerating the live dictionary.Profile.ChordCount, which replacesKeybindingManager.GetSummary's use ofChords.Count.API decision
The triage asked for a decision between a breaking change and an
[Obsolete]transition. This PR takes the transition.Profile.Chordskeeps its type and still returns the live dictionary, but it is now[Obsolete]because anything done through it bypasses the lock. It can be removed or narrowed toIReadOnlyDictionaryin a later major version. That is why this is[minor].The
RenameProfilerace from the issue is already gone onmain, because rename now happens in place (Profile.Rename) rather than as aTryRemove+TryAddswap.Tests
ProfileChordConcurrencyTestsregisters 20,000 commands. It runsBindChord,FindCommandByChord,GetAllChords, andUnbindChordfor every even command, all underParallel.For. It then requires exactly 10,000 bindings, all of them odd.AggregateException(IndexOutOfRangeExceptionfrom the torn dictionary). I ran it by reverting the library changes and swappingChordCountforGetAllChords().Count.Fixes #109
🤖 Generated with Claude Code
https://claude.ai/code/session_015BJVibRvmTotkqEGp3695R
Generated by Claude Code