镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

A "default" profile the user deleted comes back for good when CreateDefaultProfile() runs before InitializeAsync() (#189 returns on the #206 path) #248

Open

Description

@matt-edmondson

What's wrong

CreateDefaultProfile (Keybinding/KeybindingManager.cs:269-299) promises that "a startup call therefore does not bring back a default profile the user deleted after making another". It decides that from Profiles.GetAllProfiles() at :280, which only looks at memory. Before InitializeAsync() memory is empty, so it creates "default". Init then loads the user's other profiles next to it, and SaveAsync writes "default" back to disk.

#206 made calling CreateDefaultProfile() (or sharing a profile manager through DI) before init a supported path. #189's fix only covers init-first.

Reproduction (HEAD 5d08140)

using (KeybindingManager m = new(dir)) {
    await m.InitializeAsync(); m.CreateDefaultProfile();
    m.Profiles.CreateProfile("vim", "Vim"); m.Profiles.SetActiveProfile("vim");
    m.Profiles.DeleteProfile("default"); await m.SaveAsync();
}
using (KeybindingManager m = new(dir)) {
    Profile? created = m.CreateDefaultProfile();   // before init
    await m.InitializeAsync();
    // created = default, profiles = default,vim
    await m.SaveAsync();
}
using (KeybindingManager m = new(dir)) {
    await m.InitializeAsync();
    // profiles = default,vim   (expected: vim)
}

Why it matters

A user who deleted the default profile gets it back on the next launch, and the save makes that permanent. This is #189's symptom again for any app that seeds its default before loading.

Suggested fix

Do one of these:

  • Have KeybindingManager track whether InitializeAsync has run. Before it has, have CreateDefaultProfile either throw InvalidOperationException or defer the decision until the stored profiles are loaded.
  • In InitializeAsync, drop an untouched placeholder "default" (created by CreateDefaultProfile, never bound and never persisted) when the stored data has other profiles but no "default".

Acceptance criteria

  • A test with the sequence above ends with only vim stored, and CreateDefaultProfile either returns null, throws a clear error, or has its placeholder discarded by init.

Activity

  1. matt-edmondson commented on Nov 12, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

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

Metadata

Metadata

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