Skip to content

KeybindingManager.SetChords can split one batch across two profiles if the active profile changes mid-call #149

Description

@matt-edmondson

What's wrong

Keybinding/KeybindingManager.cs L197-L205:

Profile activeProfile = Profiles.GetActiveProfile() ?? throw new InvalidOperationException("No active profile is set");

return OperationHelper.ExecuteWithCount(chords, Keybindings.BindChord);

activeProfile is fetched only to check that an active profile exists, and is never used afterwards. Each entry goes through the two-argument IKeybindingService.BindChord(commandId, chord), which looks up the active profile again for every entry.

Failure scenario

  1. Profile a is active, and thread 1 calls SetChords with N entries.
  2. Partway through, thread 2 calls SetActiveProfile("b").
  3. The remaining entries are bound into b.
  4. SetChords reports N bindings set. They are split across two profiles, and neither profile has the batch the caller asked for.

CLAUDE.md promises thread-safe services, and recent fixes (#142 and the lookup-overload guards) close this kind of gap elsewhere.

Suggested fix

Bind against the profile the method already resolved, using the existing three-argument overload (IKeybindingService.BindChord(string profileId, string commandId, Chord chord)):

return OperationHelper.ExecuteWithCount(chords, (commandId, chord) => Keybindings.BindChord(activeProfile.Id, commandId, chord));

Check other KeybindingManager batch helpers for the same pattern.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions