Skip to content

Feat: Add repo-local backend affinity to persist AI code backend per Git repo - #188

Merged
tninja merged 1 commit into
mainfrom
kang_feat
Feb 24, 2026
Merged

Feat: Add repo-local backend affinity to persist AI code backend per Git repo#188
tninja merged 1 commit into
mainfrom
kang_feat

Conversation

@tninja

@tninja tninja commented Feb 23, 2026

Copy link
Copy Markdown
Owner

I want ai-code-select-backend (and ai-code--select-backend-description) should keep same backend for the git repo which already started ai-code-cli session, unless user explicitly want to switch in side that git repo. Eg. switch backend in git repo B should not switch backend in git repo A which already has a session, and next time user start session in repo A, it should use the same backend as before. This will be more intelligent and user friendly, and also avoid the problem that user switch backend in one repo but forget to switch back when work on another repo which already has session.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds repo-local “backend affinity” so ai-code remembers and reuses the previously used AI backend per Git repository, preventing backend switches in one repo from affecting active sessions in another.

Changes:

  • Track (git-root . backend) mappings and compute an “effective backend” per current repo.
  • Automatically activate the effective backend on CLI actions (start/resume/switch/send) and remember backend choices per repo.
  • Add an ERT test covering cross-repo backend selection behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
ai-code-backends.el Implements repo-local backend affinity and uses it when selecting/activating backends.
ai-code.el Updates the transient menu area with a new comment near backend selection.
test/test_ai-code-backends.el Adds an ERT test to ensure backend switches don’t bleed across repos.
Comments suppressed due to low confidence (2)

test/test_ai-code-backends.el:116

  • This test relies on the global ai-code--repo-backend-alist being empty, but it isn't reset/bound here. If any other test (or prior interactive runs) populates it, this test can become order-dependent/flaky. Bind ai-code--repo-backend-alist to nil within the let* (and optionally restore it with unwind-protect) to fully isolate state.
  (let* ((ai-code-backends
          '((backend-a
             :label "Backend A"
             :start ai-code-test-backend-a-start
             :switch ai-code-test-backend-a-switch
             :send ai-code-test-backend-a-send
             :resume nil
             :cli "a")
            (backend-b
             :label "Backend B"
             :start ai-code-test-backend-b-start
             :switch ai-code-test-backend-b-switch
             :send ai-code-test-backend-b-send
             :resume nil
             :cli "b")))
         (ai-code-selected-backend 'backend-a)
         (ai-code--cli-start-fn #'ignore)
         (ai-code--cli-switch-fn #'ignore)
         (ai-code--cli-send-fn #'ignore)
         (ai-code--cli-resume-fn #'ignore)
         (repo-root "/repo-a/")
         (start-calls nil))

ai-code.el:414

  • The added "DONE:" block comment reads like a PR requirement / scratch note and is extremely long and unstructured for in-code documentation. Please remove it (or replace with a short, polished comment if needed) to avoid permanently embedding PR-specific text into the transient menu definition.
    ;; DONE: I want ai-code-select-backend (and ai-code--select-backend-description) should keep same backend for the git repo which already started ai-code-cli session, unless user explicitly want to switch in side that git repo. Eg. switch backend in git repo B should not switch backend in git repo A which already has a session, and next time user start session in repo A, it should use the same backend as before. This will be more intelligent and user friendly, and also avoid the problem that user switch backend in one repo but forget to switch back when work on another repo which already has session.
    ("s" ai-code-select-backend :description ai-code--select-backend-description)

@tninja
tninja merged commit 882c3b5 into main Feb 24, 2026
6 checks passed
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.

2 participants