Skip to content

feat: sort backend selection by MRU order with history persistence#411

Open
tninja wants to merge 3 commits into
mainfrom
kang_feat_1
Open

feat: sort backend selection by MRU order with history persistence#411
tninja wants to merge 3 commits into
mainfrom
kang_feat_1

Conversation

@tninja

@tninja tninja commented Jun 25, 2026

Copy link
Copy Markdown
Owner

This pull request implements backend selection ordering based on the user's most recently used (MRU) history, resolving the issue where the candidate order in C-c a s remained static.

Approach

  1. MRU History Persistence: Added a history file ai-code-backends-history.el under the user-emacs-directory to serialize the list of recently selected AI backends.
  2. Robust Loading: Implemented checks to gracefully discard and automatically delete the history file if it gets corrupted or contains malformed data.
  3. Smart Reordering: Reordered candidate choices in ai-code-select-backend such that the active effective backend remains first, followed by valid historical backend keys in MRU order, and lastly any remaining available backends. This ensures all backends stay accessible even if the history is partial or contains outdated keys.

Verification

  • Added comprehensive ERT unit tests in test_ai-code-backends.el to verify MRU list sorting, corrupted file automatic deletion, and partial history handling.
  • Ran the entire test suite successfully to ensure all tests continue to pass and no regressions were introduced.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5e15926f87

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ai-code-backends.el Outdated
Comment on lines +437 to +438
(unless (string-empty-p content)
(read content))))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate history shape before returning it

If ai-code-backends-history.el contains valid Lisp that is not a proper list of backend symbols, such as a truncated atom or dotted list, this read returns it as-is instead of treating it as corrupted. The next C-c a s or backend switch then iterates/removes over that malformed value and can signal wrong-type-argument, leaving the selector broken until the user manually deletes the history file; the loader should reject and delete malformed-but-readable history too.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant